#tar xzvf squid-2.5.STABLE7.tar.gz #cd squid-2.5.STABLE7 #./configure --prefix=/usr/local/squid --enable-delay-pools #make #make install
看到类似于下图的提示,并且没有出现 Error Code :1 之类的错误提示,证明Squid已经安装完成了!
********************************* /usr/local/squid/sbin/squid -z **************************** /usr/local/squid/sbin/squid ************************
配置Squid.conf
好,接下来要做的仅仅是配置Squid.conf.
#ee /usr/local/squid/etc/squid.conf
但是原来的squid.conf并不是最好的,最好是你自己新建一个Squid.conf.
#cd /usr/local/squid/etc #mv squid.conf squid.conf.bak #touch squid.conf #ee squid.conf
照我的Squid.conf写,就能正常运行啦. 在ee编辑器中输入: http_port 3128 cache_dir ufs /usr/cache 530 16 256 cache_mem 32 MB cache_store_log /var/log/squid/store.log cache_access_log /var/log/squid/access.log cache_log /var/log/squid/cache.log cache_effective_user nobody cache_effective_group nogroup http_access allow all delay_pools 1 delay_class 1 1 delay_access 1 allow all delay_parameters 1 1500000/1500000 delay_initial_bucket_level 50
http_port 3128 # squid 的端口 cache_dir ufs /cache 530 16 256 # 缓存目录:/cache 类型:ufs 大小:530mb 允许Squid在目录下建立一级(16)和二级目录(256) cache_mem 32 MB # cache内存大小:32mb cache_store_log /var/log/squid/store.log #Squid的日志1:在/var/log/squid下 cache_access_log /var/log/squid/access.log #Squid的日志2:在/var/log/squid下 cache_log /var/log/squid/cache.log #Squid的日志3:在/var/log/squid下 ### cache user cache_effective_user nobody #缓存用户UID cache_effective_group nogroup #缓存用户组 GID ### cache admin visible_hostname etclub.3322.org #发生错误时,生成提示所显示的缓存服务器名 cache_mgr [email]horus@etclub.3322.org[/email] #发生错误时,生成提示所显示的缓存服务器管理员名 acl badurls dstdomain popme.163.com http_access deny badurls #以上2句不允许使用该缓存服务器访问popme.163.com acl badwords url_regex -i *** http_access deny badwords #以上2句不允许使用该缓存服务器访问URL正则表达式中含***字样的URL httpd_accel_host virtual httpd_accel_port 80 httpd_accel_with_proxy on httpd_accel_uses_host_header on #httpd 透明代理设置 acl all src 0.0.0.0/0.0.0.0 http_access allow all #以上2句允许所有ip使用该缓存服务器,这两句要放在所有的ACL语句的最后!
限速设置
delay_pools 1 delay_class 1 1 delay_access 1 allow all delay_parameters 1 1500000/1500000 delay_initial_bucket_level 50
按Ctrl C 在command:后输入exit,再回车.存盘退出.
以上是一个简单,但足以正常工作的squid.conf. 接下来,建立缓存目录和Squid的日志.
建立Squid的日志&缓存目录
#mkdir /squid #chmod 777 /squid (缓存目录必须可写!) #chown -R nobody:nogroup /squid #cd /var/log #mkdir squid #cd squid #touch access.log #touch cache.log #touch store.log #cd .. #chown -R nobody:nogroup /var/log/squid #chown -R nobody:nogroup /usr/local/squid
然后:你应该让squid在/squid建立缓存文件系统
#/usr/local/squid/sbin/squid -z
squid提示:Creating swap ... 然后回到shell提示符:#. 注意:以上指不出意外的话,若出现visible_hostname错误的话,证明你的squid.conf没写完整.
运行Squid
好了,运行你的Squid吧!
#/usr/local/squid/sbin/squid
停止 squid #/usr/local/squid/sbin/squid -k shutdown 这个不用解释吧。
重引导修改过的 squid.conf #/usr/local/squid/sbin/squid -k reconfigure //载入新的配置文件
对你的squid.conf 排错,即验证 squid.conf 的 语法和配置。 #/usr/local/squid/sbin/squid -k parse 如果squid.conf 有语法或配置错误,这里会返回提示你,如果没有返回,恭喜,可以尝试启动squid。
/usr/local/squid/sbin/squid -k rotate 轮循日志
取得squid运行状态信息: squidclient -p 80 mgr:info *取得squid内存使用情况: squidclient -p 80 mgr:mem *取得squid已经缓存的列表: squidclient -p 80 mgrbjects. use it carefully,it may crash *取得squid的磁盘使用情况: squidclient -p 80 mgr:diskd
Q & A
Q:如何判断已经成功实现缓存功能
A:
#ps -waux | grep squid #cat /var/log/squid/cache.log (有没有正常输出) #netstat -a | more (找3128端口)
|