Debian配置squid缓存服务器

2021-12-14T20:50:00

debian系统中配置squid

安装

apt-get install squid

安装成功之后,请先备份原始文件squid.conf

mv squid.conf  squid.conf.bak

打开配置文件

nano /etc/squid/squid.conf
http_port 3128      //设置监听的IP与端口号
 
cache_mem 64 MB      //额外提供给squid使用的内存,squid的内存总占用为 X * 10+15+“cache_mem”,其中X为squid的cache占用的容量(以GB为单位),
               //比如下面的cache大小是100M,即0.1GB,则内存总占用为0.1*10+15+64=80M,推荐大小为物理内存的1/3-1/2或更多。
maximum_object_size 4 MB   //设置squid磁盘缓存最大文件,超过4M的文件不保存到硬盘
 
minimum_object_size 0 KB   //设置squid磁盘缓存最小文件
 
maximum_object_size_in_memory 4096 KB   //设置squid内存缓存最大文件,超过4M的文件不保存到内存
 
cache_dir ufs /var/spool/squid 100 16 256   //定义squid的cache存放路径 、cache目录容量(单位M)、一级缓存目录数量、二级缓存目录数量
 
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}&>h" %Ss:%Sh        //log文件日志格式
 
access_log /var/log/squid/access.log combined  //log文件存放路径和日志格式
 
cache_log /var/log/squid/cache.log   //设置缓存日志
 
logfile_rotate 60   //log轮循 60天
 
cache_swap_high 95  //cache目录使用量大于95%时,开始清理旧的cache
 
cache_swap_low 90   //cache目录清理到90%时停止。
 
acl localnet src 192.168.0.0/16  //定义本地网段
 
http_access allow localnet  //允许本地网段使用
 
http_access deny all  //拒绝所有
 
visible_hostname  dmgls.com  //主机名
 
cache_mgr [email protected]  //管理员邮箱
 
offline_mode on   //表示不会后台验证资源是否有效 直接从缓存中获取
cache_peer 192.168.80.172 parent 80 0  originserver no-query round-robin //指定后端真实的web服务

配置squid的配置文件,修改squid监听端口改成非3128的端口,因3128端口作为squid的普通代理和透明代理来使用,而我们这里是让squid做缓存和反向代理来使用,当客户端访问squid的服务的时候,如果squid缓存上没有缓存客户需要的数据,那么squid就会反向代理向后端的web集群拉取数据给客户端并缓存到本地一份。

http_port 80 accel vhost
cache_mem 64 MB
maximum_object_size 4 MB
minimum_object_size 0 KB
maximum_object_size_in_memory 4096 KB
cache_dir ufs /var/spool/squid 100 16 256
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
access_log /var/log/squid/access.log combined
cache_log /var/log/squid/cache.log
logfile_rotate 60
cache_swap_high 95
cache_swap_low 90
forwarded_for on
cache_effective_user squid
cache_effective_group squid
tcp_recv_bufsize 65535 bytes
# acl localnet src 192.168.0.0/16
# http_access allow localnet
# http_access deny all
http_access allow  all
icp_access  allow all
visible_hostname dmgls.com
cache_mgr [email protected]
cache_peer 192.168.80.172 parent 80 0  originserver no-query round-robin
cache_peer 192.168.80.173 parent 80 0  originserver no-query round-robin
offline_mode on

重启:systemctl restart squid.service

开机启动:systemctl enable squid

squid -z
#初始化你在 squid.conf 里配置的 cache 目录
squid -k parse
#验证 squid.conf 的 语法和配置
squid -s
#启动squid在后台运行
squid
#启动squid在前台运行
squid -k shutdown
#停止squid
squid -k reconfigure [-f <配置文件路劲>]
#squid配置重载,相当于重启
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »