1、应用场景:

某些应用场景中,Linux服务器需要通过yum安装应用的包,但是这些Linux服务器可能不能连接到外网,但是内部也没有对应的yum服务器,这个时候,找一台内部能够访问外网的服务器配置一个代理,然后使用代理进行yum的动作。


2、在可以上外网的机器上配置squid代理:

[root@test_20190130_wanl01 ~]# yum -y install openssl squid
[root@test_20190130_wanl01 ~]# vim /etc/squid/squid.conf
# And finally deny all other access to this proxy
# http_access deny all
http_access allow all
[root@test_20190130_wanl01 ~]# systemctl start squid
[root@test_20190130_wanl01 ~]# systemctl enable squid
Created symlink from /etc/systemd/system/multi-user.target.wants/squid.service to /usr/lib/systemd/system/squid.service.
[root@test_20190130_wanl01 ~]# systemctl status squid
● squid.service - Squid caching proxy
   Loaded: loaded (/usr/lib/systemd/system/squid.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-04-29 22:01:31 CST; 14s ago
 Main PID: 16818 (squid)
   CGroup: /system.slice/squid.service
           ├─16818 /usr/sbin/squid -f /etc/squid/squid.conf
           ├─16820 (squid-1) -f /etc/squid/squid.conf
           └─16821 (logfile-daemon) /var/log/squid/access.log
Apr 29 22:01:31 test_20190130_wanl01 systemd[1]: Starting Squid caching proxy...
Apr 29 22:01:31 test_20190130_wanl01 systemd[1]: Started Squid caching proxy.
Apr 29 22:01:32 test_20190130_wanl01 squid[16818]: Squid Parent: will start 1 kids
Apr 29 22:01:32 test_20190130_wanl01 squid[16818]: Squid Parent: (squid-1) process 16820 started
[root@test_20190130_wanl01 ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2129/mongod         
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      25748/nginx: master 
tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN      25708/httpd         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2291/sshd           
tcp        0      0 127.0.0.1:32000         0.0.0.0:*               LISTEN      1275/java           
tcp6       0      0 :::80                   :::*                    LISTEN      25748/nginx: master 
tcp6       0      0 :::3128                 :::*                    LISTEN      16820/(squid-1) 
# 说明3128端口开启,说明代理是正常

3、客户端服务器配置yum代理配置

首先需要在yum的客户端编辑repo文件,因为安装相关包的时候会用到,这里参考https://www.cnblogs.com/jimboi/p/8437788.html

[root@iZvy2dcjg9cbw404qmksfhZ ~]# vim /etc/yum.conf
#添加如下信息
proxy=http://27.0.1.90:3128
[root@iZvy2dcjg9cbw404qmksfhZ ~]# ping www.baidu.com
ping: www.baidu.com: Name or service not known
[root@iZvy2dcjg9cbw404qmksfhZ yum.repos.d]# yum -y install squid
Loaded plugins: fastestmirror
base                                                                                                                                                                                      | 3.6 kB  00:00:00     
epel                                                                                                                                                                                      | 4.7 kB  00:00:00     
extras                                                                                                                                                                                    | 3.4 kB  00:00:00     
updates                                                                                                                                                                                   | 3.4 kB  00:00:00     
(1/7): base/7/x86_64/group_gz                                                                                                                                                             | 166 kB  00:00:00     
(2/7): epel/x86_64/group_gz                                                                                                                                                               |  88 kB  00:00:00     
(3/7): extras/7/x86_64/primary_db                                                                                                                                                         | 188 kB  00:00:00     
(4/7): epel/x86_64/updateinfo                                                                                                                                                             | 991 kB  00:00:00     
(5/7): epel/x86_64/primary_db                                                                                                                                                             | 6.7 MB  00:00:00     
(6/7): updates/7/x86_64/primary_db                                                                                                                                                        | 3.4 MB  00:00:00     
(7/7): base/7/x86_64/primary_db                                                                                                                                                           | 6.0 MB  00:00:01     
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies