导读 环境:网关服务器可以上网、客户端为内网,不允许上网

服务端配置nginx代理

server{
       listen 16666;
       server_name _;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-With;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /centos/ {
            proxy_pass //mirrors.aliyun.com/centos/;
        }

        location /epel/ {
            proxy_pass //mirrors.aliyun.com/epel/;
        }

        location /mariadb/ {
            proxy_pass //mirrors.ustc.edu.cn/mariadb/;
        }

    }

使用yum源的客户端配置

[root@master1 ~]# cd /etc/yum.repos.d/
[root@master1 yum.repos.d]# vim CentOS-Base.repo 
[base]
name=CentOS-$releasever - Base - 192.168.100.100:16666
failovermethod=priority
baseurl=//192.168.100.100:16666/centos/$releasever/os/$basearch/
        //192.168.100.100:16666/centos/$releasever/os/$basearch/
#        //mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=//192.168.100.100:16666/centos/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates - 192.168.100.100:16666
failovermethod=priority
baseurl=//192.168.100.100:16666/centos/$releasever/updates/$basearch/
        //192.168.100.100:16666/centos/$releasever/updates/$basearch/
#        //mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=//192.168.100.100:16666/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 192.168.100.100:16666
failovermethod=priority
baseurl=//192.168.100.100:16666/centos/$releasever/extras/$basearch/
        //192.168.100.100:16666/centos/$releasever/extras/$basearch/
#        //mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=//192.168.100.100:16666/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 192.168.100.100:16666
failovermethod=priority
baseurl=//192.168.100.100:16666/centos/$releasever/centosplus/$basearch/
        //192.168.100.100:16666/centos/$releasever/centosplus/$basearch/
#        //mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=//192.168.100.100:16666/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - 192.168.100.100:16666
failovermethod=priority
baseurl=//192.168.100.100:16666/centos/$releasever/contrib/$basearch/
        //192.168.100.100:16666/centos/$releasever/contrib/$basearch/
        //mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=//192.168.100.100:16666/centos/RPM-GPG-KEY-CentOS-7

清理yum缓存

yum clean all

测试

yum list

原文来自:

本文地址://lrxjmw.cn/ali-yum-proxy.html编辑:薛鹏旭,审核员:逄增宝

Linux大全:

Linux系统大全:

红帽认证RHCE考试心得: