squid安装:
1.下载squid源码安装包
wget http://www.squid-cache.org/Versions/v3/3.2/squid-3.2.3.tar.gz
解压缩
tar zxvf squid-3.2.3.tar.gz
进入解压后的目录
cd squid-3.2.3(目录位置依据个人设定而不同)
安装
[root@localhost squid-3.2.3]# ./configure --prefix=/usr/local/squid --enable-gnuregex --enable-icmp --enable-linux-netfilter --enable-default-err-language="Simplify_Chinese" --enable-kill-parent-hack --enable-cache-digests --enable-dlmalloc --enable-poll --enable-async-io=240 --enable-delay-pools --with-filedescriptors=65536 --enable-snmp --enable-arp-acl --mandir=/usr/share/man/ --with-large-files
[root@localhost squid-3.2.3]#make && make install
如果你用的是centos系统的最小化安装,可能没有安装c语言编译器,需要手动安装,如安装过程中出现以下错误:
-bash: make: command not found
这是因为没有安装编译器,用以下命令安装:
yum install gcc* ;yum -y install gcc-*
安装后,再次make就可以了。至此,squid就安装到服务器上了,接下来配置反向代理。
Squid反向代理配置:
这是本人自己曾经使用的配置
http_port 80 vhost vport
cache_mem 256 MB
maximum_object_size_in_memory 2048 KB
memory_replacement_policy lru
cache_dir ufs /var/spool/squid 20480 16 256
access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
max_open_disk_fds 0
minimum_object_size 0 KB
maximum_object_size 32768 KB
#logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h""%{User-Agent}>h" %Ss:%Sh
cache_peer 125.39.127.22 parent 80 0 no-query no-digest originserver name=88181
#需要反向代理的源WEB服务器,可以添加多个 ,若只有一个源WEB服务器,可不设name
cache_peer 118.144.78.54 parent 80 0 no-query no-digest originserver name=jj
#需要反向代理的源WEB服务器,可以添加多个
cache_peer_domain 88181 88181.com
#若只有一个源WEB服务器,可不设cache_peer_domain
cache_peer_domain jj www.linuxidc.com
http_access allow all
cache_effective_user nobody
cache_effective_group nobody
cache_mgr zifu.199s0@163.com
#refresh_pattern ^ftp: 60 20% 10080
#refresh_pattern ^gopher: 60 0% 1440
#refresh_pattern ^gopher: 60 0% 1440
#refresh_pattern . 0 20% 1440
refresh_pattern -i \.css$ 360 50% 2880
refresh_pattern -i \.js$ 1440 50% 2880
refresh_pattern -i \.html$ 720 50% 1440
refresh_pattern -i \.jpg$ 1440 90% 2880
refresh_pattern -i \.gif$ 1440 90% 2880
refresh_pattern -i \.swf$ 1440 90% 2880
refresh_pattern -i \.jpg$ 1440 50% 2880
refresh_pattern -i \.png$ 1440 50% 2880
refresh_pattern -i \.bmp$ 1440 50% 2880
refresh_pattern -i \.doc$ 1440 50% 2880
refresh_pattern -i \.ppt$ 1440 50% 2880
refresh_pattern -i \.xls$ 1440 50% 2880
refresh_pattern -i \.pdf$ 1440 50% 2880
refresh_pattern -i \.rar$ 1440 50% 2880
refresh_pattern -i \.zip$ 1440 50% 2880
refresh_pattern -i \.txt$ 1440 50% 2880
************************************************************************************************************
chmod 777 /usr/local/squid/var
chmod 777 /usr/local/squid/var/logs
/usr/local/squid/sbin/squid -z
/usr/local/squid/sbin/squid -k parse 测试配置文件
/usr/local/squid/sbin/squid -k reconfigure 重新配置文件
/usr/local/squid/sbin/squid -k shutdown 关闭squid
/usr/local/squid/sbin/squid -s 开启squid 后台
/usr/local/squid/sbin/squid -N -d1 前台开启squid
/usr/local/squid/sbin/squid -k interrupt 关闭squid(更高优先级,直接关闭squid)
/usr/local/squid/sbin/squid -k kill 关闭squid(最高优先级,直接杀死squid进程)
设置squid自启动
echo "/usr/local/squid/sbin/squid -s " >>/etc/rc.local
设置每周二凌晨两点25分自动滚动日志
echo "25 2 * * 2 root /usr/local/squid/sbin/squid -k rotate " >>/etc/crontab
设置squid自启动
/etc/rc.local
/usr/local/squid/sbin/squid
至此,配置完成。
本文出自 “王升的游泳池” 博客,转载请与作者联系!
原文地址:http://wangsheng1.blog.51cto.com/29473/1598799