三、 使用reiserfs文件系统
有人做过测试,在相同条件下,如果cache分区使用reiserfs文件系统,性能要比使用ext2的高出20%,所以我们将在cache分区中采用reiserfs文件系统。在上一步中,我们已经在内核中提供了对reiserfs的支持,下面我们要做的,就是将原来的cache分区重新格式化成reiserfs文件系统。
首先从ftp://ftp.namesys.com/pub/reiserfsprogs/reiserfsprogs-3.x.0j.tar.gz下载reiserfs文件系统相关工具reiserfsprogs,然后解开该文件: tar xvzf reiserfsprogs-3.x.0j.tar.gz
进入新生成目录,执行: ./configure make make install 这将生成mkreiserfs、reiserfsck、debugreiserfs、resize_reiserfs四个reiserfs的工具。
完成后我们将reiserfs工具安装成功了。这时,假设原来的cache分区为/dev/sda7,所装载的目录为/cache,在对其格式化之前,我们要先umount 原来的分区: umount /cahce
对分区格式化,我们执行: mkreiserfs –h r5 /de/sda7
完成后我们修改/etc/fstab,将/cache一行改为: /dev/sda7 /cache reiserfs notail,noatime 0 0 然后重启动。
四、 重新编译squid
经过大量的测试表明:squid-2.2.STABLE5+hno补丁的组合要比2.3或者是其他版本的squid都要稳定的多、效率也要高的多,如果您不相信可以自己化几天时间做一下测试。所以我们将采用这个版本的squid。 首先从http://www.squid-cache.org/Versions/v2/2.2/下载squid-2.2.STABLE5-src.tar.gz, 从http://prdownloads.sourceforge.net/squid/下载squid-2.2.STABLE5-hno.20000202.snapshot.gz补丁,然后分别解开这两个包: tar xvzf squid-2.2.STABLE5-src.tar.gz gunzip –d squid-2.2.STABLE5-hno.20000202.snapshot.gz
然后打补丁: cd squid-2.2.STABLE5 patch –p1 < ../ squid-2.2.STABLE5-hno.20000202.snapshot
接下来,就可以开始编译squid了,在采用异步io(多线程模式)之外,我们本着这样一个原则:那就是去掉一切不需要的功能,如下所示: ./configure --prefix=/usr --exec_prefix=/usr --bindir=/usr/sbin --libexecdir=/usr/lib/squid --localstatedir=/var --sysconfdir=/etc/squid --mandir=/usr/share/man --enable-async-io=20 --disable-icmp --disable-delay-pools --disable-mem-gen-trace --disable-useragent-log --enable-kill-parent-hack --disable-arp-acl --enable-poll --disable-ident-lookups
make make install
其中,--enable-async-io=20说明我们采用异步io,并采用18个线程。 编译通过后,我们就可以开始配置squid了。
五、 优化squid配置
以下是我的squid.conf及相关解释:
#取消对代理阵列的支持 icp_port 0
#对日志文件和pid文件位置进行设置 cache_store_log none cache_access_log /var/log/squid/access.log cache_log /var/log/squid/cache.log emulate_httpd_log on pid_filename /var/run/squid.pid
#设置运行时的用户和组权限 cache_effective_user squid cache_effective_group squid
#设置管理信息 visible_hostname proxy.yxtc.edu.cn cache_mgr [email protected]
#设置监听地址和端口 http_port 3128 tcp_incoming_address x.x.x.x udp_incoming_address x.x.x.x
#见下面补充说明 cache_mem 32 MB cache_dir /cache 6000 14 256
#设置cache对象超时时间 reference_age 3 months
#访问控制设置 acl mynet src 192.168.1.0/255.255.255.0 acl all src 0.0.0.0/0.0.0.0 http_access allow mynet http_access deny all
#透明代理设置 httpd_accel_host virtual httpd_accel_port 80 httpd_accel_with_proxy on httpd_accel_uses_host_header on
#swap 性能微调 half_closed_clients off cache_swap_high 100% cache_swap_low 80% maximum_object_size 1024 KB
#见补充说明 refresh_pattern -i .html 1440 90% 129600 reload-into-ims refresh_pattern -i .shtml 1440 90% 129600 reload-into-ims refresh_pattern -i .hml 1440 90% 129600 reload-into-ims refresh_pattern -i .gif 1440 90% 129600 reload-into-ims refresh_pattern -i .swf 1440 90% 129600 reload-into-ims refresh_pattern -i .jpg 1440 90% 129600 reload-into-ims refresh_pattern -i .png 1440 90% 129600 reload-into-ims refresh_pattern -i .bmp 1440 90% 129600 reload-into-ims refresh_pattern -i .js 1440 90% 129600 reload-into-ims
补充说明:
1.cache_mem 32 MB 注意:cache_mem并不是squid所能使用内存的大小,而是squid用户hot object的物理内存的大小,所以这个值可以小一些。
2.cache_dir /cache 6000 14 256 对于第一级子目录和第二级子目录的计算方法,可以参考笔者以前的文章《用LINUX架设代理服务器(上)(中)(下)》;
3.refresh_pattern -i .html 1440 90% 129600 reload-into-ims等 这几句其实是强行控制对象的超时时间,这违反了http协议的精神,但是在带宽较窄的场合,可以提高明显系统相应时间。
4.注意/cache目录及日志文件的权限,其所有用户和所有组必须为squid;
5.可以采用rpm包的脚本/etc/rc.d/init.d/squid控制squid,也可以采用squid命令控制,具体可以参考squid –h

|