一般在内网环境中,多数服务器是不能直接上外网的(为了安全),只有个别的服务器可以访问外网,在不能访问外网的服务器上安装软件由于依赖的问题很容易出错,安装不下去,这时候就可以借助可以上外网的服务器做代理来安装软件。

A服务器192.168.1.10可以访问外网
B服务器192.168.1.20不能访问外网,可以通过内网IP访问A服务器

在10上安装nginx 用来代理转发yum源

 server
 {
     listen 1080;
     server_name  yum.anyline.org;
        location /centos/ {
            proxy_pass http://mirrors.aliyun.com/centos/ ;
        }

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


修改20服务器的repo文件

> cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
> vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - yum.anyline.org
failovermethod=priority
baseurl=http://yum.anyline.org/centos/$releasever/os/$basearch/
        http://yum.anyline.org/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://yum.anyline.org/centos/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates - yum.anyline.org
failovermethod=priority
baseurl=http://yum.anyline.org/centos/$releasever/updates/$basearch/
        http://yum.anyline.org/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://yum.anyline.org/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - yum.anyline.org
failovermethod=priority
baseurl=http://yum.anyline.org/centos/$releasever/extras/$basearch/
        http://yum.anyline.org/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://yum.anyline.org/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - yum.anyline.org
failovermethod=priority
baseurl=http://yum.anyline.org/centos/$releasever/centosplus/$basearch/
        http://yum.anyline.org/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://yum.anyline.org/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - yum.anyline.org
failovermethod=priority
baseurl=http://yum.anyline.org/centos/$releasever/contrib/$basearch/
        http://yum.anyline.org/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0

gpgkey=http://yum.anyline.org/centos/RPM-GPG-KEY-CentOS-7

修改20的hosts文件

vi /etc/hosts
192.168.1.10 yum.anyline.org

> yum clean all
> yum makecache