Centos8下搭建Squid代理服务器

简介: Centos8下搭建Squid代理服务器

本来想搭建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.service命令哦):

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
目录
相关文章
|
1月前
|
存储 安全 Linux
新 CentOS 7 服务器的基本配置
新 CentOS 7 服务器的基本配置
25 1
|
13天前
|
XML 存储 缓存
Squid 缓存服务器配置
Squid 缓存服务器配置
33 0
|
1月前
|
运维 网络协议 Linux
揭秘CentOS 7:系统目录奥秘大起底,网卡配置秒变高手,让你的服务器管理飞一般的感觉!
【8月更文挑战第5天】CentOS 7作为RHEL的社区版本,以其稳定性和丰富功能广受好评。本文通过案例分析介绍其系统目录结构及网卡配置方法。系统目录如/(根)、/bin(基本命令)、/boot(启动文件)、/dev(设备文件)、/etc(配置文件)、/home(用户目录)和/lib(共享库)等各司其职。网卡配置通过编辑/etc/sysconfig/network-scripts/下的ifcfg文件实现,如设置ens33接口的静态IP地址、子网掩码、网关和DNS服务器,并通过重启网络服务使配置生效。这是系统管理员必备的技能之一。
43 2
|
30天前
|
网络协议 Linux Shell
如何在运行Centos 6的虚拟服务器上安装cPanel
如何在运行Centos 6的虚拟服务器上安装cPanel
17 0
|
30天前
|
关系型数据库 MySQL Linux
在 CentOS 7 服务器上安装和保护 phpMyAdmin 与 Apache 的方法
在 CentOS 7 服务器上安装和保护 phpMyAdmin 与 Apache 的方法
30 0
|
1月前
|
Linux 数据安全/隐私保护
在CentOS 7服务器上添加和删除用户的方法
在CentOS 7服务器上添加和删除用户的方法
22 0
|
2月前
|
弹性计算 安全 Ubuntu
新手3分钟1Panel安装教程,使用阿里云服务器CentOS操作系统
在阿里云CentOS 7.9服务器上安装1Panel面板,包括远程连接ECS、执行安装命令、设置安装目录(默认/opt)、开启20410端口、配置安全入口和用户密码。记得在阿里云安全组中开放20410端口以访问面板。
新手3分钟1Panel安装教程,使用阿里云服务器CentOS操作系统
|
2月前
|
缓存 Linux 开发工具
centos设置ntp服务同步目标服务器时间
【7 月更文挑战第 1天】linux+centos设置ntp服务同步目标服务器时间
|
3月前
|
NoSQL 关系型数据库 应用服务中间件
jdk1.8、mysql、redis、nginx centos云服务器安装配置
jdk1.8、mysql、redis、nginx centos云服务器安装配置
|
4月前
|
网络协议 物联网 Linux
你不能不知道的:无公网IP,SSH远程连接CentOS服务器【内网穿透】
你不能不知道的:无公网IP,SSH远程连接CentOS服务器【内网穿透】
227 0