Squid 是一个高性能的代理缓存服务器,Squid 支持 FTP、gopher、HTTPS 和 HTTP 协议;和一般的代理缓存软件不同,Squid 用一个单独的、非模块化的、I/O 驱动的进程来处理所有的客户端请求。
主要提供缓存加速、应用层过滤控制的功能,能代替客户机向网站请求数据,从而可以隐藏用户的真实 IP 地址;将获得的网页数据(静态 Web 元素)保存到缓存中并发送给客户机,以便下次请求相同的数据时快速响应。
1 2 3 4
| systemctl stop firewalld && systemctl disable firewalld setenforce 0 yum -y install gcc gcc-c++ make perl mkdir -pv /app/service/squid
|
http://www.squid-cache.org/Versions/v5/
https://www.phpfans.net/manu/Squid/
编译安装
1 2 3 4 5 6
| wget http://www.squid-cache.org/Versions/v5/squid-5.6.tar.gz cd /app/software tar -zxvf squid-5.6.tar.gz cd squid-5.6 ./configure --prefix=/app/service/squid --sysconfdir=/app/service/squid/conf --enable-arp-acl --enable-linux-netfilter --enable-linux-tproxy --enable-async-io=100 --enable-err-language="Simplify_Chinese" --enable-underscore --enable-poll --enable-gnuregex --enable-kill-parent-hack --enable-snmp make && make install
|
配置选项
—prefix= |
指定安装目录 |
—sysconfdir= |
指定配置文件路径 |
—enable-arp-acl |
可在 ACL 中设置通过 MAC 进行管理,防止 IP 欺骗 |
—enable-linux-netfilter |
使用内核过滤 |
—enable-linux-tproxy |
支持透明模式 |
—enable-async-io=100 |
异步 I/O,提升储存性能,值可修改 |
—enable-err-language=”Simplify_Chinese” |
错误信息的显示语言 |
—enable-underscore |
允许 URL 中有下划线 |
—enable-poll |
使用 poll() 模式,提升性能 |
—enable-gnuregex |
使用 GNU 正则表达式 |
—enable-kill-parent-hack |
关掉 Squid 的时候连同父进程一起关掉 |
—enable-snmp |
使 Squid 支持 SNMP 接口 |
编译完成以后的目录层级如下:
1 2 3 4 5 6 7 8
| tree -L 1 . ├── bin ├── conf ├── libexec ├── sbin ├── share └── var
|
修改配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| vi /app/service/squid/conf/squid.conf
cache_effective_user app
cache_effective_group app
acl localnet src 0.0.0.1-0.255.255.255 acl localnet src 10.0.0.0/8 acl localnet src 100.64.0.0/10 acl localnet src 169.254.0.0/16 acl localnet src 172.16.0.0/12 acl localnet src 192.168.0.0/16 acl localnet src fc00::/7 acl localnet src fe80::/10 acl MyNetwork src xxx.xxx.xxx.xxx/16
acl SSL_ports port 443 acl Safe_ports port 80 acl Safe_ports port 21 acl Safe_ports port 443 acl Safe_ports port 70 acl Safe_ports port 210 acl Safe_ports port 1025-65535 acl Safe_ports port 280 acl Safe_ports port 488 acl Safe_ports port 591 acl Safe_ports port 777
http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow localhost manager http_access deny manager
http_access allow MyNetwork http_access deny all
http_port 10086
coredump_dir /app/service/squid/var/cache/squid
cache_mem 64 MB
reply_body_max_size 10 MB
maximum_object_size 4096 KB
cache_log /app/logs/squid/cache.log access_log /app/logs/squid/access.log cache_store_log none
logformat squid %tl.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt
visible_hostname squid.yuwei.cc cache_mgr support@yuwei.cc
request_header_access X-Forwarded-For deny all request_header_access From deny all request_header_access Via deny all request_header_access Server deny all request_header_access X-Cache deny all request_header_access X-Cache-Lookup deny all
|
运行控制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| squid -k parse
squid -z
squid
squid -N -d1
netstat -anpt | grep "squid"
squid -k rotate -f /app/service/squid/conf/squid.conf
|
服务脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #!/bin/bash
PID="/app/service/squid/var/run/squid/squid.pid"
CONF="/app/service/squid/conf/squid.conf"
CMD="/app/service/squid/sbin/squid"
case "$1" in start) netstat -natp | grep squid &> /dev/null if [ $? -eq 0 ] then echo "squid is running" else echo "正在启动 squid..." $CMD fi ;; stop) $CMD -k kill &> /dev/null rm -rf $PID &> /dev/null ;; status) [ -f $PID ] &> /dev/null if [ $? -eq 0 ] then netstat -natp | grep squid else echo "squid is not running" fi ;; restart) $0 stop &> /dev/null echo "正在关闭 squid..." $0 start &> /dev/null echo "正在启动 squid..." ;; reload) $CMD -k reconfigure ;; check) $CMD -k parse ;; *) echo "用法:$0{start|stop|status|reload|check|restart}" ;; esac
|