设置

设置

无法使 Squid 的默认安装监听其默认端口 tcp/3128。

在 Ubuntu 18.04.4 LTS 上运行的 Squid 版本 3.5.27

设置

apt install squid -y
service squid start

默认配置

root@proxy:/etc/squid# cat /etc/squid/squid.conf | grep -v ^# | grep -v ^$
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localhost
http_access deny all
http_port 3128
coredump_dir /var/spool/squid
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern (Release|Packages(.gz)*)$      0       20%     2880
refresh_pattern .               0       20%     4320

监听端口

root@proxy:~# netstat -plunt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      31074/sshd
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      9102/systemd-resolv
udp        0      0 0.0.0.0:43440           0.0.0.0:*                           30521/(squid-1)
udp        0      0 127.0.0.53:53           0.0.0.0:*                           9102/systemd-resolv
udp        0      0 0.0.0.0:68              0.0.0.0:*                           9094/systemd-networ
udp6       0      0 :::47733                :::*                                30521/(squid-1)

故障排除第 1 部分

因此默认安装不起作用,我添加了一些新的端口 3129、3130、3131 以及各种常用选项。

root@proxy:/etc/squid# cat /etc/squid/squid.conf | grep -v ^# | grep -v ^$
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localhost
http_access deny all
http_port 3128
http_port 3129 transparent
http_port 0.0.0.0:3130
http_port 0.0.0.0:3131 transparent
coredump_dir /var/spool/squid
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern (Release|Packages(.gz)*)$      0       20%     2880
refresh_pattern .               0       20%     4320

侦听端口故障排除

root@proxy:~# netstat -plunt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      31074/sshd
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      9102/systemd-resolv
udp        0      0 0.0.0.0:57748           0.0.0.0:*                           30521/(squid-1)
udp        0      0 127.0.0.53:53           0.0.0.0:*                           9102/systemd-resolv
udp        0      0 0.0.0.0:68              0.0.0.0:*                           9094/systemd-networ
udp6       0      0 :::53094                :::*                                30521/(squid-1)

故障排除第 2 部分

之前没有成功,所以在前台运行 squid 并指定确切的修改后的配置文件

root@proxy:/etc/squid# service squid stop && pkill squid && sleep 1 && squid -N -d 9 -f /etc/squid/squid.conf
2020/06/05 06:55:27| Set Current Directory to /var/spool/squid
2020/06/05 06:55:27| Starting Squid Cache version 3.5.27 for x86_64-pc-linux-gnu...
2020/06/05 06:55:27| Service Name: squid
2020/06/05 06:55:27| Process ID 4430
2020/06/05 06:55:27| Process Roles: master worker
2020/06/05 06:55:27| With 1024 file descriptors available
2020/06/05 06:55:27| Initializing IP Cache...
2020/06/05 06:55:27| DNS Socket created at [::], FD 9
2020/06/05 06:55:27| DNS Socket created at 0.0.0.0, FD 10
2020/06/05 06:55:27| Adding nameserver 127.0.0.53 from /etc/resolv.conf
2020/06/05 06:55:27| Adding domain members.linode.com from /etc/resolv.conf
2020/06/05 06:55:27| Logfile: opening log daemon:/var/log/squid/access.log
2020/06/05 06:55:27| Logfile Daemon: opening log /var/log/squid/access.log
2020/06/05 06:55:27| Local cache digest enabled; rebuild/rewrite every 3600/3600 sec
2020/06/05 06:55:27| Store logging disabled
2020/06/05 06:55:27| Swap maxSize 0 + 262144 KB, estimated 20164 objects
2020/06/05 06:55:27| Target number of buckets: 1008
2020/06/05 06:55:27| Using 8192 Store buckets
2020/06/05 06:55:27| Max Mem  size: 262144 KB
2020/06/05 06:55:27| Max Swap size: 0 KB
2020/06/05 06:55:27| Using Least Load store dir selection
2020/06/05 06:55:27| Set Current Directory to /var/spool/squid
2020/06/05 06:55:27| Finished loading MIME types and icons.
2020/06/05 06:55:27| HTCP Disabled.

侦听端口故障排除

root@proxy:~# netstat -plunt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      31074/sshd
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      9102/systemd-resolv
udp        0      0 0.0.0.0:52552           0.0.0.0:*                           30521/(squid-1)
udp        0      0 127.0.0.53:53           0.0.0.0:*                           9102/systemd-resolv
udp        0      0 0.0.0.0:68              0.0.0.0:*                           9094/systemd-networ
udp6       0      0 :::56473                :::*                                30521/(squid-1)

仍然没有监听 tcp/3128、tcp/3129、tcp/3130、tcp/3131。

不成功。

答案1

今天,无论我怎么尝试,我都无法让 squid 监听 Ubuntu 20.04 主机上的 3128 端口或任何其他端口。我终于通过添加

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

到我的 sysctl 设置。我的 IPv6 设置一定很奇怪。

答案2

netstat -lnp | grep squid
udp        0      0 0.0.0.0:36147           0.0.0.0:*                           3524/(squid-1)      
udp6       0      0 :::34275                :::*                                3524/(squid-1)   

更新 sysctl.conf

在 sysctl 设置中加载

sysctl -p
 net.ipv6.conf.all.disable_ipv6 = 1
 net.ipv6.conf.default.disable_ipv6 = 1
 net.ipv6.conf.lo.disable_ipv6 = 1


systemctl restart squid

netstat -lnp | grep squid
 tcp        0      0 0.0.0.0:3128            0.0.0.0:*               LISTEN      3551/(squid-1)      
 udp        0      0 0.0.0.0:38988           0.0.0.0:*                           3551/(squid-1) 

答案3

鱿鱼配置是为外星人制作的,我思考了很久才意识到:

http_port 0.0.0.0:3128

当然你必须确保 UFW 能够支持 squid:

sudo ufw allow 3128/allow

相关内容