5.滚动日志文件
squid将大量的重要信息写入日志,假如写不进去了,squid会发生错误并退出。为了合理控制磁盘空间消耗,必须周期性的滚动日志文件。
/usr/local/squid/sbin/squid -k rotate
ls -alh /usr/local/squid/var/logs/
通过上图,可以看到日志已经被分割了,将此命令加入到crontab里,让它在每天的凌晨4点运行。
crontab -e
在最后添加
0 4 * * * /usr/local/squid/sbin/squid -k rotate附1:安全停止squid
/usr/local/squid/sbin/squid -k shutdown
附2:立即停止squid
/usr/local/squid/sbin/squid -k interrupt
附3:在squid运行中,对squid.conf做了修改,使修改后的配置生效
/usr/local/squid/sbin/squid -k reconfigure
注:在使用reconfigure选项时你须谨慎,因为所做的改变可能会导致致命错误,必须确保所做的修改是正确的。
附4:前端用LVS做负载均衡的话,请做以下修改
vi /root/Desktop/lvs_vip.sh #编写VIP的绑定脚本
#!/bin/bash # description: Config realserver SNS_VIP=192.168.0.56 /etc/rc.d/init.d/functions case "$1" in start) /sbin/ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP /sbin/route add -host $SNS_VIP dev lo:0 echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce sysctl -p >/dev/null 2>&1 echo "RealServer Start OK" ;; stop) /sbin/ifconfig lo:0 down /sbin/route del $SNS_VIP >/dev/null 2>&1 echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce echo "RealServer Stoped" ;; *) echo "Usage: $0 {start|stop}" exit 1 esac exit 0chmod +x /root/Desktop/lvs_vip.sh #赋予lvs_vip.sh脚本执行权限
/root/Desktop/lvs_vip.sh start #启动lvs_vip.sh
echo "/root/Desktop/lvs_vip.sh start" >> /etc/rc.d/rc.local #设置lvs_vip.sh开机启动
ip add #查看VIP是否已绑定
vi /usr/local/squid/etc/squid.conf #修改squid的配置文件
cache_effective_user squid cache_effective_group squid visible_hostname squid1.cache.cn http_port 0.0.0.0:80 vhost vport icp_port 3130 cache_peer 192.168.0.150 sibling 80 3130 cache_peer 192.168.0.108 parent 80 0 no-query originserver cache_peer 192.168.0.109 parent 80 0 no-query originserver cache_peer 192.168.1.115 parent 80 0 no-query originserver acl localnet src 192.168.0.149 http_access allow all icp_access allow localnet hierarchy_stoplist cgi-bin ? hierarchy_stoplist -i ^https:\\ ? acl QueryString urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi acl denyssl urlpath_regex -i ^https:\\ no_cache deny QueryString no_cache deny denyssl cache_log /usr/local/squid/var/logs/cache.log access_log /usr/local/squid/var/logs/access.log squid cache_dir aufs /var/cache 1024 16 256 cache_dir aufs /var/squid 3072 16 256 cache_mem 128 MB cache_swap_low 90 cache_swap_high 95 maximum_object_size 4096 KB maximum_object_size_in_memory 80 KB ipcache_size 1024 ipcache_low 90 ipcache_high 95 cache_replacement_policy lru memory_replacement_policy lru memory_pools on memory_pools_limit 32 MB forwarded_for on log_icp_queries off forward_timeout 20 seconds connect_timeout 30 seconds read_timeout 3 minutes request_timeout 1 minutes persistent_request_timeout 30 seconds client_lifetime 15 minutes shutdown_lifetime 5 seconds negative_ttl 30 seconds acl OverConnLimit maxconn 50 http_access deny OverConnLimit client_persistent_connections off server_persistent_connections on tcp_recv_bufsize 65535 bytes half_closed_clients off via on request_header_access via deny all httpd_suppress_version_string off ie_refresh off/usr/local/squid/sbin/squid -k reconfigure #使用修改后的配置生效
六、测试
找一台windows的机器用来测试,修改hosts文件,hosts文件在C:\WINDOWS\system32\drivers\etc目录下,添加如下内容
192.168.0.149 192.168.0.149 aaa.xuad.com 192.168.0.149 bbb.xuad.com打开浏览器,在地址栏里输入:,确保网站可正常访问。
ls -alh /var/squid/00/00/
通过上图可看到缓存文件已经生成,然后关闭一台web服务器,看网站可否正常访问。
对于另一台的测试,也请按此方法来进行测试。
如果缓存服务器前面还有一层负载均衡,hosts文件需要配置成负载机器的IP地址,然后可尝试在两台缓存都开启的情况下进行测试。