linux之yum源代理

在不能直接访问外网的内网环境中,可以通过配置一台可以上外网的服务器作为代理,以解决Centos7服务器安装软件时的依赖问题。文章详细介绍了如何在A服务器上配置nginx代理yum源,以及如何在B服务器上修改yum配置,使其通过A服务器的代理进行软件安装和更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境介绍

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

A服务器

192.168.1.100

可以访问外网

B服务器

192.168.1.200

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

A服务器代理yum源

#安装nginx服务器
[root@gby-A ~]# yum install nginx -y
#配置nginx服务
[root@gby-A ~]# cat /etc/nginx/conf.d/yum.conf
server {
        listen 80;
        server_name yum.com;
        location /centos/ {
        #具体代理url根据实际情况更改。可以根据b服务器url编写
            proxy_pass http://mirrors.aliyun.com/centos/ ;
        }

        location /epel/ {
        #具体代理url根据实际情况更改。可以根据b服务器url编写
            proxy_pass http://mirrors.aliyun.com/epel/ ;
        }
    }
#重启nginx
[root@gby-A ~]# nginx -s reload

B服务器yum指向A服务器

#备份yum文件
[root@gby-B ~]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
[root@gby-B ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - yum.com
failovermethod=priority
baseurl=http://yum.com/centos/$releasever/os/$basearch/
        http://yum.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://yum.com/centos/RPM-GPG-KEY-CentOS-7

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

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

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

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - yum.com
failovermethod=priority
baseurl=http://yum.com/centos/$releasever/contrib/$basearch/
        http://yum.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://yum.com/centos/RPM-GPG-KEY-CentOS-7
#B服务器hosts指向A服务器
[root@gby-B ~]# echo "192.168.1.100 yum.com" >>/etc/hosts
#B服务器验证yum.com是否指向A服务器
[root@gby-B ~]# ping 192.168.1.100
#刷新yum缓存
[root@gby-B ~]# yum clean all
[root@gby-B ~]# yum makecache
#进行yum操作如安装升级等。

结束之有话想说

既然看完了那就赶紧去试试吧骚年。👊

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xtgby

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值