利用nginx 来实现内网yum源(反向代理)

简介

在项目部署时,尤其是在政府企业,对于外网简直是奢望,但是对于运维来说,没有外网的话只能自建yum源。我今天来说的是一种简单的自建yum源方法,前提是必须有一台内外网都有的机器,我们一般称为前置机。

操作思路

1、使用nginx 反向代理 阿里云源

2、在内网机器自建repo指向nginxip

nginx配置

12345678
server    {        listen 80;        location /centos/ {            proxy_pass http://mirrors.aliyun.com/centos/ ;        }}

比较简单,不过我们要求不高能用即可。

另外我们常用的linux系统是Centos,所以我这边只写了Centos的。其它的你也可以参考上面配置配置。

内网机器配置

1、备份CentOS-Base.repo

1
# mv CentOS-Base.repo CentOS-Base.repo.bak

2、增加反向代理的repo

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
vim /etc/yum.repos.d/Centos-7.repo[base]name=CentOS-$releasever - Base - 10.12.64.130failovermethod=prioritybaseurl=http://10.12.64.130/centos/$releasever/os/$basearch/http://10.12.64.130/centos/$releasever/os/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=osgpgcheck=1gpgkey=http://10.12.64.130/centos/RPM-GPG-KEY-CentOS-7#released updates [updates]name=CentOS-$releasever - Updates - 10.12.64.130failovermethod=prioritybaseurl=http://10.12.64.130/centos/$releasever/updates/$basearch/http://10.12.64.130/centos/$releasever/updates/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updatesgpgcheck=1gpgkey=http://10.12.64.130/centos/RPM-GPG-KEY-CentOS-7#additional packages that may be useful[extras]name=CentOS-$releasever - Extras - 10.12.64.130failovermethod=prioritybaseurl=http://10.12.64.130/centos/$releasever/extras/$basearch/http://10.12.64.130/centos/$releasever/extras/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extrasgpgcheck=1gpgkey=http://10.12.64.130/centos/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages[centosplus]name=CentOS-$releasever - Plus - 10.12.64.130failovermethod=prioritybaseurl=http://10.12.64.130/centos/$releasever/centosplus/$basearch/http://10.12.64.130/centos/$releasever/centosplus/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplusgpgcheck=1enabled=0gpgkey=http://10.12.64.130/centos/RPM-GPG-KEY-CentOS-7#contrib - packages by Centos Users[contrib]name=CentOS-$releasever - Contrib - 10.12.64.130failovermethod=prioritybaseurl=http://10.12.64.130/centos/$releasever/contrib/$basearch/http://10.12.64.130/centos/$releasever/contrib/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contribgpgcheck=1enabled=0gpgkey=http://10.12.64.130/centos/RPM-GPG-KEY-CentOS-7

注:其中的10.12.64.130为我的前置机ip地址,大家可以更具情况自行修改。

测试

12
# yum makecache

在随机安装一个net-tools 测试即可

以上

End

相关推荐