关于linux:linux之yum源设置代理

39次阅读

共计 2542 个字符,预计需要花费 7 分钟才能阅读完成。

个别在内网环境中, 少数服务器是不能间接上外网的 (为了平安), 只有个别的服务器能够拜访外网, 在不能拜访外网的服务器上安装软件因为依赖的问题很容易出错, 装置不上来, 这时候就能够借助能够上外网的服务器做代理来装置软件。

Centos7 下设置代理案例

A 服务器 192.168.1.10 能够拜访外网
B 服务器 192.168.1.111 不能拜访外网, 能够通过内网 IP 拜访 A 服务器

在 A 服务器装置 nginx

咱们应用 nginx 作为 yum 的反向代理软件

> yum install nginx -y

配置 nginx

> vim /etc/nginx/conf.d/yum.conf
 server {
        listen 80;
        server_name yum.com;
        location /centos/ {proxy_pass http://mirrors.aliyun.com/centos/ ;}

        location /epel/ {proxy_pass http://mirrors.aliyun.com/epel/ ;}
    }
// 重启 nginx
> nginx -s reload

批改 B 服务器的 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.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 服务器上批改 /etc/hosts

目标是让 B 服务器能解析 yum.com

> vim /etc/hosts
192.168.1.111 yum.com

验证 B 服务器是否能够解析

> ping yum.com

刷新 yum 缓存

> yum clean all
> yum makecache

原文链接:https://rumenz.com/rumenbiji/…
微信公众号: 入门小站

正文完
 0