歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> Squid優化完全手冊(2)

Squid優化完全手冊(2)

日期:2017/2/27 9:47:10   编辑:更多Linux
  三、 使用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



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



Copyright © Linux教程網 All Rights Reserved