squid 服务器搭建

in 默认分类 with 0 comment

2023-10-11T07:28:20.png
Squid是一个支持HTTP,HTTPS,FTP等服务的Web缓存代理软件,它可以通过缓存页面来提高服务器的相应速度并降低带宽占用。 并且,Squid还具有强大的访问控制功能。 Squid可以运行在各种操作系统平台上。 Squid会将访问页面的结果缓存在硬盘和内存上。

关闭防火墙并修改网卡信息。

[root@localhost ~]# systemctl stop firewalld         /*关闭防火墙*/
[root@localhost ~]# systemctl disable firewalld        /*禁止防火墙关机自启动*/

2023-10-11T07:41:43.png

DHCP自动获取IP地址后,设置为静态获取并打开开机自启网卡

[root@localhost ~]# Ip addr               /*查看IP地址并查看网卡名称*/

2023-10-11T07:42:07.png

[root@localhost ~]# cd /etc/sysconfig/network-scripts   /*进入存放网卡配置文件的文件夹中*/

2023-10-11T07:42:25.png

[root@localhost network-scripts]# Vi ifcfg-eno*******      /*编辑网卡配置文件*/

2023-10-11T07:42:43.png
将以下两处进行修改。修改为BOOTPROTO=static ONBOOT=yes
2023-10-11T07:42:55.png
2023-10-11T07:43:02.png

安装yum源,安装Squid服务

[root@localhost ~] # yum -y install squid

2023-10-11T07:43:18.png
安装后可查看Squid服务器状态。当安装完Squid服务后默认为关闭状态。需将其启动。

[root@localhost ~] # Systemctl status squid         /*查看Squid服务器状态*/

未启动时则显示【dead】,【dead】状态下可使用systemctl restart squid 重启Squid代理。

[root@localhost ~] #systemctl restart squid                 /*用于重启squid*/

2023-10-11T07:43:41.png

此时会面临无法启动问题。则需要对openssh进行升级。

[root@localhost ~] # systemctl restart squid                 /*用于重启squid*/

2023-10-11T07:43:56.png

[root@localhost ~] # yum install openssh-server -y            /*安装openssh*/

2023-10-11T07:44:07.png
安装完毕后重新启动Squid并重新查看Squid状态。

[root@localhost ~] # systemctl restart squid          /*用于重启squid*/
[root@localhost ~] # Systemctl status squid         /*查看Squid服务器状态*/

2023-10-11T07:44:18.png

Squid服务启动后需设置Squid服务自启动。停止并关闭防火墙自启动

[root@localhost ~] #  systemctl enable squid             /*用于开机自启squid*/

2023-10-11T07:44:31.png

设置完毕后可用测试机进行telnet测试

C:\Users\admin>telnet 111.1.1.88 3128

如图所示为Squid代理服务器设置成功。
2023-10-11T07:44:44.png

IP地址设置完毕后设置DNS

用于解析Google等外国网站,如图所示操作即可。
2023-10-11T07:45:43.png
2023-10-11T07:45:48.png
2023-10-11T07:45:53.png
或者根据命令添加DNS(推荐方式)

[root@localhost ~] #  vi /etc/NetworkManager/NetworkManager.conf

在main 里添加上dns=none
添加完毕后重启NetworkManager服务

[root@localhost ~] #  systemctl restart NetworkManager.service         /*重启NetworkManager服务*/

2023-10-11T07:46:08.png

[root@localhost ~] #  /etc/resolv.conf

nameserver 8.8.8.8            
nameserver 114.114.114.114

2023-10-11T07:46:21.png
添加完毕后重启网卡

[root@localhost ~] #  service network restart                 /*重启网卡*/

添加进策略路由。(用于访问外网)

进入防火墙。点击【网络】->【路由】->【智能选路】,将Squid代理服务器IP添加入策略路由中。
2023-10-11T07:47:45.png
2023-10-11T07:48:26.png

Responses