设为首页 收藏本站
查看: 1303|回复: 0

[经验分享] Squid使用总结(安装、配置、优化...)

[复制链接]

尚未签到

发表于 2017-4-17 19:40:13 | 显示全部楼层 |阅读模式
  较早的工作日志,记下来备忘
1. 编译和安装
暂时使用CENTOS 5.2上缺省安装的2.6STABLE7版本
2. squid配置
2.1 最简单配置
http_port 80
cache_peer 127.0.0.1   parent    8080  0 no-query default originserver  name=bes
acl all src all
http_access allow all

access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log

2.2 监控管理
acl snmppublic snmp_community public
snmp_port 3401
snmp_access allow snmppublic localhost
snmp_access deny all

2.3 更安全的配置
acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443        # https
acl Safe_ports port 80        # http
acl Safe_ports port 443        # https
acl purge method PURGE
acl CONNECT method CONNECT

http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access deny all

cache_effective_user squid
cache_effective_group squid

2.4打开相关性能告警
high_response_time_warning 1000
high_page_fault_warning xxx
high_memory_warning xxx

2.5 其他
visible_hostname proxy.hostname

3. 调试
3.1 在配置文件中设置debug_options ALL,9
3.2 cache.log
3.3 squid -XF 
3.4 squid -k parse  分析配置文件语法

4. 网络相关优化
4.1 减少TIME_WAIT套接字数量
#vi /etc/sysctl.conf
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 1024    65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
#/sbin/sysctl -p
详见http://blog.s135.com/read.php?338

5. DISK IO相关的优化
5.1 cache_dir设置的考虑
· cache_dir采用二级目录方式保存cache object,做配置时不宜过大,建议为规划容量的1倍,否则建立swap目录会花费较多时间。推荐保留10%的空间。这些额外的空间用于存放squid的swap.state文件和临时文件。
· 可以配置多个cache_dir,建议每个cache_dir都放在不同的物理硬盘上,以改善IO效率
5.2 squid相关的目录设置
· log和cahce_dir不要放在一个物理盘上
· cache_dir所在的盘建议使用ReiserFS格式
· mount cache_dir盘时建议使用noatime参数
5.3 DISK Cache的相关设置
· max_open_disk_fds
This directive defines an upper limit on the number of file descriptors that Squid should open for reading and writing cache files on disk. 当达到这个限制后,squid会跳过DISK cache,从而避免IO持续恶化。
缺省为0(无限制)。[建议]For a single disk cache, 900 is a good choice.  For a dual disk cache, try 1400. 
· max_filedescriptors 
允许打开的最大文件描述符,实际允许打开的数量也受编译squid的--with-maxfd的影响。缺省为0。[建议]
· maximum_object_size
maximum_object_size 1024 KB
· cache_swap_low/cache_swap_high  ???
5.4 Linux设置
· filedescriptors
一共有两个方面的限制: 整个系统,当前用户。
http://prefetch.net/blog/index.php/2009/07/31/increasing-the-number-of-available-file-descriptors-on-centos-and-fedora-linux-servers/
整个系统:
  动态调整,每次启动后该设置会丢失:
  #ulimit -HSn 4096
  在/etc/sysctl.confg中设置:
# vi /etc/sysctl.conf
fs.file-max = 100000
# sysctl -p
[ulimit显示的值和/proc/sys/fs/file-max中显示的值有什么关系]
ulimit command provides control over the resources available to the shell and to processes started by it, on systems that allow such control. The maximum number of open file descriptors displayed with following command
  #vi /etc/security/limits.conf单个用户
* - nofile 8192

6. MEM优化考虑
· cache_mem
Squid占用内存量似乎不受这个参数的控制,此参数不必设得太大,适量就行。服务器:cache_mem 100 MB
· maximum_object_size_in_memory:
设置较小的maximum_object_size_in_memory值有助于有效控制squid过度占用内存
· client_db off
· The ratio of memory-to-disk can be important. We recommend that you have at least 32 MB of RAM for each GB of disk space that you plan to use for caching. 
7. CPU优化相关
Squid is a single process application and can not make use of SMP. If you want to make Squid benefit from a SMP system you will need to run multiple instances of Squid and find a way to distribute your users on the different Squid instances just as if you had multiple Squid boxes. 

8. 其他问题

8.1 和Redirect合作的关系
8.2 log rotate

  定期进行log rotate
8.3 cachemgr.cgi
 
9. 参考资料

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-365535-1-1.html 上篇帖子: 更全面的 用Squid搭建Cache服务器 下篇帖子: 关于Squid缓存命中率 一则
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表