统信UOS搭建Squid代理服务器,2024年最新Linux运维基础开发入门

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Linux运维全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注运维)
img

正文

OsBuild=12038.101.100
[root@pdsyw ~]#
[root@pdsyw ~]# uname -a
Linux pdsyw 4.19.90-2305.1.0.0199.56.uel20.x86_64 #1 SMP Fri May 12 19:23:49 CST 2023 x86_64 x86_64 x86_64 GNU/Linux
[root@pdsyw ~]#


![image.png](https://img-blog.csdnimg.cn/img_convert/d2353ab51ae88fa2eb46011f0211843c.png)


2.安装 squid



[root@pdsyw ~]# yum install squid -y
Last metadata expiration check: 0:02:04 ago on 2024年01月04日 星期四 19时24分51秒.
Dependencies resolved.

Package Arch Version Repository Size

Installing:
squid x86_64 7:4.9-16.uel20 UnionTechOS-Server-20-everything 3.3 M
Installing dependencies:
libecap x86_64 1.0.1-4.uel20 UnionTechOS-Server-20-everything 21 k

Transaction Summary

Install 2 Packages

Total download size: 3.3 M
Installed size: 11 M
Downloading Packages:
(1/2): libecap-1.0.1-4.uel20.x86_64.rpm 107 kB/s | 21 kB 00:00
(2/2): squid-4.9-16.uel20.x86_64.rpm 746 kB/s | 3.3 MB 00:04

Total 750 kB/s | 3.3 MB 00:04
UnionTechOS-Server-20-1060-everything 19 kB/s | 1.7 kB 00:00
Importing GPG key 0x8DF595ED:
Userid : “UnionTech security@uniontech.com
Fingerprint: C822 503F 2F4C E25A 6EA0 65BE 9055 A64E 8DF5 95ED
From : https://euler-packages.chinauos.com/server-euler//fuyu/1060/everything/x86_64/RPM-GPG-KEY-UnionTech
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : libecap-1.0.1-4.uel20.x86_64 1/2
Running scriptlet: libecap-1.0.1-4.uel20.x86_64 1/2
Running scriptlet: squid-7:4.9-16.uel20.x86_64 2/2
Installing : squid-7:4.9-16.uel20.x86_64 2/2
Running scriptlet: squid-7:4.9-16.uel20.x86_64 2/2
Verifying : libecap-1.0.1-4.uel20.x86_64 1/2
Verifying : squid-7:4.9-16.uel20.x86_64 2/2

Installed:
libecap-1.0.1-4.uel20.x86_64 squid-7:4.9-16.uel20.x86_64

Complete!
[root@pdsyw ~]#


![image.png](https://img-blog.csdnimg.cn/img_convert/18245bf29571710f2e28d3075cd0af67.png)


3.编辑squid.conf配置文件  
 1)在进行更改之前,备份原始的Squid配置文件  
 2)确保在任何http\_access deny all规则之前添加http\_access allow authenticated。



[root@pdsyw ~]# cp /etc/squid/squid.conf /etc/squid/squid.conf.backup
[root@pdsyw ~]#
[root@pdsyw ~]# vi /etc/squid/squid.conf
[root@pdsyw ~]#
[root@pdsyw ~]# cat /etc/squid/squid.conf
#指定Squid监听的内网接口和端口(默认3128)
http_port 172.16.0.2:3128

#定义ACL:设置允许公司内网访问的规则
acl localnet src 172.16.0.0/24 # 你的公司内网IP段

#添加认证配置,如不需要可以注释,并且可以选择更加安全的认证方式,这里只做最基本但不安全的演示
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated

#设置访问权限:允许定义的内网访问
http_access allow localnet

#配置基本安全规则:拒绝所有其他访问
http_access deny all

设置缓存目录和大小 (这里设置为10000 MB)

cache_dir ufs /var/spool/squid 10000 16 256

指定访问日志文件位置

access_log /var/log/squid/access.log squid


![image.png](https://img-blog.csdnimg.cn/img_convert/b2c8f80003bd14ecff7197b9e83ef805.png)


4.安装Apache工具(包含htpasswd)  
 htpasswd是Apache服务器的一部分,用于创建和更新经过哈希处理的密码文件。



[root@pdsyw ~]# yum install httpd-tools -y
Last metadata expiration check: 0:41:09 ago on 2024年01月04日 星期四 19时24分51秒.
Dependencies resolved.

Package Arch Version Repository Size

Installing:
httpd-tools x86_64 2.4.43-23.up1.uel20
UnionTechOS-Server-20-everything 68 k
Installing dependencies:
apr x86_64 1.7.0-5.uel20 UnionTechOS-Server-20-everything 108 k
apr-util x86_64 1.6.1-15.uel20 UnionTechOS-Server-20-everything 108 k

Transaction Summary

Install 3 Packages

Total download size: 284 k
Installed size: 763 k
Downloading Packages:
(1/3): apr-1.7.0-5.uel20.x86_64.rpm 465 kB/s | 108 kB 00:00
(2/3): apr-util-1.6.1-15.uel20.x86_64.rpm 427 kB/s | 108 kB 00:00
(3/3): httpd-tools-2.4.43-23.up1.uel20.x8 238 kB/s | 68 kB 00:00

Total 973 kB/s | 284 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: apr-1.7.0-5.uel20.x86_64 1/3
Installing : apr-1.7.0-5.uel20.x86_64 1/3
Running scriptlet: apr-1.7.0-5.uel20.x86_64 1/3
Running scriptlet: apr-util-1.6.1-15.uel20.x86_64 2/3
Installing : apr-util-1.6.1-15.uel20.x86_64 2/3
Running scriptlet: apr-util-1.6.1-15.uel20.x86_64 2/3
Installing : httpd-tools-2.4.43-23.up1.uel20.x86_64 3/3
Running scriptlet: httpd-tools-2.4.43-23.up1.uel20.x86_64 3/3
Verifying : apr-1.7.0-5.uel20.x86_64 1/3
Verifying : apr-util-1.6.1-15.uel20.x86_64 2/3
Verifying : httpd-tools-2.4.43-23.up1.uel20.x86_64 3/3

Installed:
apr-1.7.0-5.uel20.x86_64 apr-util-1.6.1-15.uel20.x86_64
httpd-tools-2.4.43-23.up1.uel20.x86_64

Complete!
[root@pdsyw ~]#


![image.png](https://img-blog.csdnimg.cn/img_convert/5a62cf0e4de849840da9c78396b9e44f.png)


5.创建密码文件  
 使用htpasswd来创建一个新的密码文件。此文件将存储经过验证的用户名和密码。  
 这里,pdsyw是你希望创建的第一个用户名。系统会提示你输入密码。-c参数用于首次创建新文件,如果你想要添加更多用户,再次运行命令但省略-c参数。



[root@pdsyw ~]# htpasswd -c /etc/squid/passwords pdsyw
New password:
Re-type new password:
Adding password for user pdsyw
[root@pdsyw ~]#
[root@pdsyw ~]# htpasswd /etc/squid/passwords pdsywer
New password:
Re-type new password:
Adding password for user pdsywer
[root@pdsyw ~]#


![image.png](https://img-blog.csdnimg.cn/img_convert/75edff7e0a0c23f34ac8685410f5c60c.png)


6.调整文件权限  
 确保Squid进程能够读取密码文件



[root@pdsyw ~]# chmod o+r /etc/squid/passwords
[root@pdsyw ~]#
[root@pdsyw ~]# ll /etc/squid/passwords
-rw-r–r-- 1 root root 90 1月 4 20:07 /etc/squid/passwords
[root@pdsyw ~]#


![image.png](https://img-blog.csdnimg.cn/img_convert/eb83798941a7c47e8800c23a7f56b366.png)


7.验证配置  
 这个命令将检查配置文件语法是否有误。确保没有错误再继续。



http_port 172.16.0.2:3128:Squid将监听在内网地址172.16.0.2的3128端口上。
acl localnet src 172.16.0.0/24:定义了一个名为localnet的访问控制列表(ACL),包含IP范围172.16.0.0/24,即你的公司内网。
http_access allow localnet:允许localnet定义的内网访问Squid代理。
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwords:配置了基本认证,使用/usr/lib64/squid/basic_ncsa_auth程序和密码文件/etc/squid/passwords。
auth_param basic realm proxy:定义了在认证提示中显示的领域(realm)名称为proxy。
acl authenticated proxy_auth REQUIRED:定义了一个名为authenticated的ACL,要求必须通过代理认证。
http_access allow authenticated:允许通过认证的用户访问代理。
http_access deny all:默认拒绝所有其他访问。
cache_dir ufs /var/spool/squid 10000 16 256:配置了Squid的缓存目录和参数。
access_log /var/log/squid/access.log squid:定义了Squid的访问日志文件路径。



[root@pdsyw ~]# squid -k parse
2024/01/04 20:16:31| Startup: Initializing Authentication Schemes …
2024/01/04 20:16:31| Startup: Initialized Authentication Scheme ‘basic’
2024/01/04 20:16:31| Startup: Initialized Authentication Scheme ‘digest’
2024/01/04 20:16:31| Startup: Initialized Authentication Scheme ‘negotiate’
2024/01/04 20:16:31| Startup: Initialized Authentication Scheme ‘ntlm’
2024/01/04 20:16:31| Startup: Initialized Authentication.
2024/01/04 20:16:31| Processing Configuration File: /etc/squid/squid.conf (depth 0)
2024/01/04 20:16:31| Processing: http_port 172.16.0.2:3128
2024/01/04 20:16:31| Processing: acl localnet src 172.16.0.0/24 # 你的公司内网IP段
2024/01/04 20:16:31| Processing: auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwords
2024/01/04 20:16:31| Processing: auth_param basic realm proxy
2024/01/04 20:16:31| Processing: acl authenticated proxy_auth REQUIRED
2024/01/04 20:16:31| Processing: http_access allow authenticated
2024/01/04 20:16:31| Processing: http_access allow localne
2024/01/04 20:16:31| Processing: http_access deny all
2024/01/04 20:16:31| Processing: cache_dir ufs /var/spool/squid 10000 16 256
2024/01/04 20:16:31| Processing: access_log /var/log/squid/access.log squid
2024/01/04 20:16:31| Initializing https:// proxy context


![image.png](https://img-blog.csdnimg.cn/img_convert/737d2f3178cabeaee57d257c3faccab3.png)


8.启动服务  
 应用配置更改并重新启动Squid服务,确保Squid服务正在正常运行。



[root@pdsyw ~]# systemctl restart squid
[root@pdsyw ~]#
[root@pdsyw ~]# systemctl status squid
● squid.service - Squid caching proxy
Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendo>
Active: active (running) since Thu 2024-01-04 19:35:48 CST; 4s ago
Process: 27751 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exit>
Process: 27757 ExecStart=/usr/sbin/squid $SQUID_OPTS -f $SQUID_CONF (co>
Main PID: 27758 (squid)
Tasks: 3
Memory: 12.5M
CGroup: /system.slice/squid.service
├─27758 /usr/sbin/squid -f /etc/squid/squid.conf
├─27760 (squid-1) --kid squid-1 -f /etc/squid/squid.conf
└─27763 (logfile-daemon) /var/log/squid/access.log

1月 04 19:35:48 pdsyw systemd[1]: Starting Squid caching proxy…
1月 04 19:35:48 pdsyw systemd[1]: Started Squid caching proxy.
1月 04 19:35:48 pdsyw squid[27758]: Squid Parent: will start 1 kids
1月 04 19:35:48 pdsyw squid[27758]: Squid Parent: (squid-1) process 27760>
[root@pdsyw ~]#


![image.png](https://img-blog.csdnimg.cn/img_convert/f198d6e5e073c50bcfbe0979e3729321.png)


9.放开防火墙  
 放开Squid默认端口(3128)



[root@pdsyw ~]# firewall-cmd --permanent --add-port=3128/tcp
success
[root@pdsyw ~]#
[root@pdsyw ~]# firewall-cmd --reload
success
[root@pdsyw ~]#


![image.png](https://img-blog.csdnimg.cn/img_convert/9bbced152b3ed1972b193ae290dd3e0e.png)



### 最后的话

最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!

### 资料预览

给大家整理的视频资料:

![](https://img-blog.csdnimg.cn/img_convert/3892650bf940059babfbd72f75d95529.png)

给大家整理的电子书资料:

  

![](https://img-blog.csdnimg.cn/img_convert/28d7dd2f0c107a5a4596db1621a4edbd.png)



**如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!**


**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注运维)**
![img](https://img-blog.csdnimg.cn/img_convert/f506be8ff2708bf94cf46262410977c7.jpeg)

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
:

  

[外链图片转存中...(img-yGvpxpxW-1713265923250)]



**如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!**


**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注运维)**
[外链图片转存中...(img-pxc8i1I2-1713265923250)]

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值