本来想搭建tinyproxy,结果一直提示找不到包,更新了yum源也没用。就搭建squid吧
[root@VM-24-14-centos ~]# yum install tinyproxy -y
Last metadata expiration check: 1:13:37 ago on Tue 25 Jan 2022 07:17:54 AM CST.
No match for argument: tinyproxy
Error: Unable to find a match: tinyproxy
yum源中的版本:
[root@VM-24-14-centos ~]# yum list | grep squid
Repository epel is listed more than once in the configuration
squid.x86_64 7:4.15-1.module_el8.5.0+860+303ccf92 AppStream
squidGuard.x86_64 1.4-36.el8 epel
直接yum安装:
yum install -y squid
查看已安装:
whereis squid
[root@VM-24-14-centos ~]# whereis squid
squid: /usr/sbin/squid /usr/lib64/squid /etc/squid /usr/libexec/squid /usr/share/squid /usr/share/man/man8/squid.8.gz
查看启动服务:
[root@VM-24-14-centos ~]# ll /usr/lib/systemd/system | grep squid
-rw-r--r-- 1 root root 451 Jul 12 2021 squid.service
编辑配置文件squid.conf
:
[root@VM-24-14-centos ~]# cd /etc/squid/
cachemgr.conf cachemgr.conf.default errorpage.css errorpage.css.default mime.conf mime.conf.default squid.conf squid.conf.default
# 这里我们编辑的是squid.conf
[root@VM-24-14-centos ~]# vim /etc/squid/squid.conf
修改配置如下:
# 默认是3128
http_port 3228
#http_access deny all #注释掉该行
http_access allow all # 添加 ,为容许全部ip
检查配置文件是否有误:
squid -k parse # 配置文件解析日志中,没有出现ERROR 就没有问题
服务操作:
# 启动服务
[root@VM-24-14-centos ~]# systemctl start squid
#查看服务状态
[root@VM-24-14-centos ~]# systemctl status squid
● squid.service - Squid caching proxy
Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2022-01-25 08:52:29 CST; 5s ago
Docs: man:squid(8)
Process: 2984503 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS)
Main PID: 2984509 (squid)
Tasks: 3 (limit: 23722)
Memory: 13.9M
CGroup: /system.slice/squid.service
├─2984509 /usr/sbin/squid --foreground -f /etc/squid/squid.conf
├─2984511 (squid-1) --kid squid-1 --foreground -f /etc/squid/squid.conf
└─2984512 (logfile-daemon) /var/log/squid/access.log
Jan 25 08:52:29 VM-24-14-centos systemd[1]: Starting Squid caching proxy...
Jan 25 08:52:29 VM-24-14-centos squid[2984509]: Squid Parent: will start 1 kids
Jan 25 08:52:29 VM-24-14-centos squid[2984509]: Squid Parent: (squid-1) process 2984511 started
Jan 25 08:52:29 VM-24-14-centos systemd[1]: Started Squid caching proxy.
查看运行端口:
[root@VM-24-14-centos ~]# netstat -nlp|grep squid
tcp6 0 0 :::3228 :::* LISTEN 2984511/(squid-1)
udp 0 0 0.0.0.0:36982 0.0.0.0:* 2984511/(squid-1)
udp6 0 0 :::41622 :::* 2984511/(squid-1)
查看日志:
[root@VM-24-14-centos squid]# pwd
/var/log/squid
[root@VM-24-14-centos squid]# ll
total 4
-rw-r----- 1 squid squid 0 Jan 25 08:52 access.log
-rw-r----- 1 squid squid 1849 Jan 25 08:52 cache.log
以上就是允许所有访问的squid代理服务。当然我们也可以限制IP使用。
建立ip白名单文件,/etc/squid/squid_allow_ips
, 每一个ip一行,注意文件的用户和组权限( squid.root
):
cat /etc/squid/squid_allow_ips
192.168.22.232
192.168.22.132
192.168.22.133
修改squid配置,添加acl 访问规则:
acl allowed_ips src "/etc/squid/squid_allow_ips" # ip白名单
http_access allow localnet
http_access allow localhost
http_access allow allowed_ips # 配置allow
# And finally deny all other access to this proxy
http_access deny all # 禁止全部访问,这个不要漏了
检查配置文件是否有误:
squid -k parse # 配置文件解析日志中,没有出现ERROR 就没有问题
重启服务:
systemctl restart squid
我另外一台服务器是Centos6,这个下面是有tinyproxy和squid的。我们尝试使用tinyproxy搭建代理服务。
[root@VM_0_12_centos ~]# yum list | grep squid
lightsquid.noarch 1.8-11.el6 epel
lightsquid-apache.noarch 1.8-11.el6 epel
squid.x86_64 7:3.1.23-24.el6 os
squid34.x86_64 7:3.4.14-15.el6 os
squidGuard.x86_64 1.4-10.el6 epel
[root@VM_0_12_centos ~]# yum list | grep tinyproxy
tinyproxy.x86_64 1.8.3-1.el6 epel
yum安装:
yum install tinyproxy -y
编写配置文件:
vim /etc/tinyproxy/tinyproxy.conf
#修改端口 默认是8888
Port 9878
#注释掉 说明允许所有访问
#Allow 127.0.0.1
添加开机启动(Centos6下是没有systemctl enable tinyproxy.servic
e命令哦):
chkconfig --level 35 tinyproxy on
# 检测服务
[root@VM_0_12_centos ~]# chkconfig --list |grep tinyproxy
tinyproxy 0:off 1:off 2:off 3:on 4:off 5:on 6:off
启动服务并检测端口:
[root@VM_0_12_centos ~]# service tinyproxy start
Starting tinyproxy: [ OK ]
[root@VM_0_12_centos ~]# netstat -nlp|grep tinyproxy
tcp 0 0 0.0.0.0:9878 0.0.0.0:* LISTEN 4192/tinyproxy