设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 开源资讯 查看内容

使用pdnsd和squid命令加快上网速度

2011-1-23 20:25| 发布者: xyxzfj| 查看: 6347| 评论: 0

摘要: 使用pdnsd和squid命令加快上网速度像我,生活在乡村,缓慢的网速很难让人接受。我的正常网速是512Kbs,有时连达到这个速度都是奢望。我的解决方案是使用一个互联网加速应用,其建立与配置方详细介绍于:www.Internet ...

使用pdnsd和squid命令加快上网速度

像我,生活在乡村,缓慢的网速很难让人接受。

我的正常网速是512Kbs,有时连达到这个速度都是奢望。

我的解决方案是使用一个互联网加速应用,其建立与配置方详细介绍于:

www.InternetAccelerationAppliance.com

缓存DNS代理服务器

首先把PDNSD装成本地服务器。

具体指导及做法理由详述于www.internetaccelerationappliance.com – installing pdnsd,因此此处我只提供一个扼要的概述。

什么事DNS?

Imagine, if you will, that you want to send a letter to your friend Joe Bloggs. If you were just to address that letter to Joe Bloggs, it would almost certainly never arrive.如果可以的话,请想象一下子:你想给你朋友小刚捎封信的。如果你只在地址栏写下他的名字,那信极有可能永远无法到达。

If, however, you were to address that letter to Joe’s address… 24 Staunton Court, Streatham, London, England then, sooner or later, it will be delivered.然而,如果你在地址栏写下:XX省XX市XX县XX镇XX村小刚收,只要是准确物理地址,信迟早会送达。

The internet is similar. We know sites by their names (i.e. www.google.com) but the delivery service needs the address (in this case the IP address – 74.125.77.104).互联网通信是同样的道理。我们通过名字记住一个网站(如,www.google.com),但是传输服务需要的是地址(此例即为IP地址—— 74.125.77.104)。

When we type www.google.com into our browser, that information goes up the line to our Service Provider (in my case Orange.fr) 当我们在浏览器地址栏输入www.google.com时,这一信息沿着网线上传到我们的服务提供商(在我的例子中是Orange.fr)。

Now, the server(s) at Orange don’t know who Google.com is so they have to look up an address for it. For this, they request the information from their DNS servers. These are basically just servers that contain lists of names and their associated IP addresses. A bit like telephone directories except there can only be one Google.com whereas in a telephone directory there may be many entries for Joe Bloggs.可是,提供商的服务器不知道Google.com是哪一台服务器,于是它(们)得从其的DNS服务器查表得到地址。这些DNS服务器主体包含着域名及其相映射的IP地址,实现名址映射。有点像电话本,不同的是电话本可能有多个同名条目(人名),Google.com在DNS服务器只会有一个。

If the local DNS servers at Orange.fr don’t have an address, then the request is forwarded to the national DNS servers and then, finally, the root DNS servers (which, for .COM addresses are in Singapore.)如果本地DN服务器找不到地址,这一请求将被送往国家DNS服务器,然后最终送达根DNS服务器(其中,解析.com地址的根服务器在新加坡)。

All this can take time. What we are going to do here is make this process local so that every time we get an IP address from the Service Provider, it is going to be noted here in a local caching DNS server so that the next time we want to visit Google.com we don’t have to wait for Orange.fr to supply the address – we’ll already have it. 所有这些都要花费时间。我们这里所做的,就是要让这一过程本地化,以使每次我们从服务提供商获取新IP地址,本地DNS缓存服务器都记录下来。于是第二次我们访问Google.com时,我们不需要再等待Orange.fr提供其IP地址了——我们本机已经有了。

Hopefully this will speed up my effective internet speed.这很有希望加快我们的网速。

dnsd的安装

1). On my Debian system the installation was simple… 在我Debian系统上,安装十分简单:

apt-get install pdnsd dnsutils

2). Once this is complete we need to edit one file… 当上面的结束,你需要编辑文件:

nano /etc/default/pdnsd and press Enter. This will load the file in the nano text editor. 输入nano /etc/default/pdnsd并按回车,这将将这一文件载入nano文本编辑器。

Change line 2 so that it reads… START_DAEMON=yes 将第二行改为:START_DAEMON=yes

Ctrl & O – to save file and press Enter 按Ctrl+O 保存文件并按回车

3). Now we need to edit the pdnsd configuration file (/etc/psdnd.conf) 现在我们需要编辑pdnsd配置文件:

My /etc/pdnsd.conf now looks like this…. 我的/etc/pdnsd.conf现在看起来是这样子的:

global {
perm_cache=1024;
cache_dir=”/var/cache/pdnsd”;
run_as=”pdnsd”;
server_ip = 127.0.0.1;
server_port=53;
status_ctl = on;
paranoid=on;
query_method=udp_tcp;
max_ttl=1w; # One week.
timeout=10;
}
server {
label=OpenDNS;
ip=208.67.222.222;
ip=208.67.220.220;
timeout=30;
uptest=ping;
interval=30;
ping_timeout=300;
purge_cache=off;
caching=on;
preset=off;
}
source {
owner=localhost;
serve_aliases=on;
file=”/etc/hosts”;
}
rr {
name=localhost;
reverse=on;
a=127.0.0.1;
owner=localhost;
soa=localhost,root.localhost,42,86400,900,86400,86400;
}
global {perm_cache=1024;cache_dir=”/var/cache/pdnsd”;run_as=”pdnsd”; server_ip = 127.0.0.1; server_port=53;status_ctl = on;paranoid=on; query_method=udp_tcp;max_ttl=1w; # One week.timeout=10; }server {label=OpenDNS;ip=208.67.222.222;ip=208.67.220.220;timeout=30;uptest=ping;interval=30; ping_timeout=300;purge_cache=off;caching=on;preset=off;}
source {owner=localhost;serve_aliases=on;file=”/etc/hosts”;}
rr {name=localhost;reverse=on;a=127.0.0.1;owner=localhost; soa=localhost,root.localhost,42,86400,900,86400,86400;}

4). Now we must resolv.conf - nano /etc/resolv.conf and press Enter 现在输入resolv.conf - nano /etc/resolv.conf并按回车

Change the file so that it contains just one line which reads exactly as follows….. nameserver 127.0.0.1 更改文件,使之只包含一行:nameserver 127.0.0.1

5). Because my machine already used a fixed IP address I didn’t have to do the following, you may have to if you use DHCP… 因为我的机器已经使用上了固定IP地址,我不必做如下的一步;如果你是用的是DHCP,你可能需要。

Edit dhclient.conf - nano /etc/dhcp3/dhclient.conf and press Enter 编辑dhclient.conf - nano /etc/dhcp3/dhclient.conf并按回车

Find the line that starts #prepend domain-name-servers (about 20 lines down) and remove the # so that the line reads as follows… prepend domain-name-servers 127.0.0.1; 找到以#prepend domain-name-servers开头的一行(大概向下第二十行),移除井号,这一行于是应为:prepend domain-name-servers 127.0.0.1;

Ctrl & O – to save file and press Enter 按 CtrlCtrl+O保存并回车

Ctrl & X – to quit nano 按CtrlCtrl+X离开nano

6). Finally, Edit interfaces - nano /etc/network/interfaces 最后,编辑interfaces - nano /etc/network/interfaces

Edit the line that starts… dns-nameservers so that it reads….. dns-nameservers 192.168.1.2 编辑以…dns-nameservers开始的哪一行,使之读作….. dns-nameservers 192.168.1.2

Ctrl & O – to save file and press Enter 按CtrlCtrl+O保存并回车

Ctrl & X – to quit nano 按CtrlCtrl+X离开nano

Reboot the machine. 重启机器

7). Log into the rebooted machine, open a terminal and type in the command… 进入重启了的机器,打开终端输入以下命令:

dig Google.com

Note the Query time: (this is the time spent to retrieve Google’s IP address from the OpenDNS servers) – on my machine it was 316 msec. 我机器上从OpenDNS服务器检索Google IP地址的时间是316毫秒。

Now run the same command again (arrow up will redisplay the last command.) 现在再次运行那一命令(使用向上键翻开上一条命令历史记录)。

Note the Query time: (the address should be resolved locally by pdnsd) – it should now be about 3 msec. 现在的检索时间只有3毫秒!这一地址是被pdnsd本地检索来的。

Squid(傻瓜)缓存代理服务器

Now it’s time to install the squid caching proxy server – this is even easier! 现在要安装Squid缓存代理服务器了——此步非常简单!

什么是缓存代理服务器?

Now that pdnsd knows the IP Address of Google, we are saving some time everytime we wish to visit Google (by not having to look up the IP Address at Orange.fr’s DNS servers.) 由于pdnsd知道了Google的IP地址,每次我们访问Google都会省下一些时间了(因为不需要再去查Orange.fr DNS服务器上的IP地址了)。

But, we are still downloading logo.gif (the Google logo) from the site and even at only 8Kb large, it is using up some of our bandwidth. 但是,我们仍然要从该网站下载8Kb大小的logo.gif(Google 图标)。这也要占带宽。

What our caching proxy server does is keep a copy of that logo (and a whole hosts of other HTTP Objects) and, according to a complex set of rules, doesn’t bother going to the originating site the next time the object is requested – it delivers it from its local cache. 我们缓存代理服务器所做的事,就是保留那一图标的一份副本(和其他HTTP对象的全部内容),并根据一系列复杂的规则,让第二次访问该网站,不再麻烦地去取浏览器要访问的重复对象——而直接从本地缓存返回给浏览器。

This can dramatically reduce bandwidth. 这极大地消减了带宽占用。

Now, Google is a well designed site with a minimum of logos and graphics to download – not all sites are as austere as Google. Over a period of time, a store of HTTP objects (graphics/webpages etc.) will be built up in the cache and these will be served to any machines on the network that are accessing the cache. 还好,Google(主页)是一个设计的极为轻量的网页,有很少的图标和图片要下载——然而并非所与网站都这么自律。HTTP对象(图形/网页等)的内容将会花一些时间在缓存上被建立,并提供给任何访问这一缓存的机器使用。

Squid安装

1). Start off by installing Squid. On my Debian system all I have to do was type apt-get install squid. 首先安装Squid。在我Debian系统上,只要输入apt-get install squid即可。

2). Now we need to stop squid - /etc/init.d/squid stop and press Enter 现在需要停止squid - /etc/init.d/squid stop 并按回车

3). We need to edit /etc/squid/squid.conf 需要编辑/etc/squid/squid.conf

This is my squid.conf 这是我的squid.conf:


# Access Control Lists
acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl SSL_ports port 443 # https
acl SSL_ports port 563 # snews
acl SSL_ports port 873 # rsync
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl Safe_ports port 631 # cups
acl Safe_ports port 873 # rsync
acl Safe_ports port 901 # SWAT
acl apache rep_header Server ^Apache
acl mydomain src 192.168.1.1-192.168.1.24/255.255.255.255
acl purge method PURGE
acl CONNECT method CONNECT

# Refresh patterns
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern (Release|Package(.gz)*)$ 0 20% 2880
refresh_pattern . 0 50% 40320
refresh_pattern -i \.jpg$ 3600 90% 40320 override-expire override-lastmod reload-into-ims ignore-reload
refresh_pattern -i \.jpeg$ 3600 90% 40320 override-expire override-lastmod reload-into-ims ignore-reload
refresh_pattern -i \.gif$ 3600 90% 40320 override-expire override-lastmod reload-into-ims ignore-reload
refresh_pattern -i \.html 300 50% 10 ignore-reload
http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access allow mydomain
http_access deny all

# Denying non-necessary access
icp_access allow localnet
icp_access deny all
htcp_access allow localnet
htcp_access deny all

# Stopping stuff we don’t need
log_fqdn off
log_icp_queries off
buffered_logs on
emulate_httpd_log off
client_db off
cache_store_log none
memory_pools off
forwarded_for off

#General config stuff
http_port 3128
visible_hostname brahms-squid
hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
cache_mgr squid@brahms.com
access_log /var/log/squid/access.log squid

# Caching stuff
cache_mem 64 MB
cache_dir diskd /var/spool/squid 4000 16 256
maximum_object_size_in_memory 32 KB
maximum_object_size 128 MB
request_body_max_size 8 MB

# DNS Stuff
hosts_file /etc/hosts
dns_testnames 127.0.0.1
dns_nameservers 127.0.0.1

4). Now we only need to restart squid by typing /etc/squid/squid start and then forcing it to re-read the config file by typing squid -k reconfigure 现在我们只需要重启Squid:输入/etc/squid/squid start。然后输入 squid -k reconfigure 强制它重读配置文件。

5). You will need to set up your browser to use the local proxy server. 你需要设置你的浏览器以使用本地代理服务器。

To do this just find the configuration screen (this will vary from one browser to another) and set the broser to access the internet via a proxy server. Use an IP address of 127.0.0.1 and a port of 3128. Now tick the box that says Use this proxy server for all protocols and click on the OK button. 只需找到配置窗口(因浏览器而异),设置浏览器通过代理服务器访问网络。使用IP地址127.0.0.1和端口3128。然后选择“为所有协议使用这一代理服务器”复选框,点OK键。

结语

It’s difficult to tell how much this has speeded up my internet access as I was using a separate caching proxy server before. 很难说出它们多大地提高了我网络访问速度。

I know that it’s very rare for me to wait for a website to be found (a function of the DNS server) and once I have visited a site once, the following time the graphics just snap into place (no waiting at all!) 至少对于一个极不愿意忍受等待“正在寻找网站”(DNS服务器的工作)的痛苦的我来说,现在的网络访问几乎没有让我再等待。

Overall, this has proven to be an extremely simple way to improve my internet access without resorting to additional hardware. 总体上,这已经被证明是一个极其简单、无需外加硬件支持的提高网络访问速度的方法。

My pdnsd.conf and squid.conf files are available at http://www.kmeckstein.com/data/pdnsd.conf and http://www.kmeckstein.com/data/squid.conf 我的squid.conf和available在http://www.kmeckstein.com/data/pdnsd.confhttp://www.kmeckstein.com/data/squid.conf可以找到。

To download them you just need to use… 使用以下方法下载它们:wget http://www.kmeckstein.com/data/pdnsd.conf和wgethttp://www.kmeckstein.com/data/squid.conf

wget http://www.kmeckstein.com/data/pdnsd.conf and

wget http://www.kmeckstein.com/data/squid.conf


英文原文:http://www.kmeckstein.com/linux/speed ... net-with-pdnsd-and-squid/
转载请注明:Linux人社区 英文资讯翻译专版 编译



酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部