写点什么

linux 之 yum 源设置代理

用户头像
入门小站
关注
发布于: 刚刚

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

Centos7 下设置代理案例

在 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.comfailovermethod=prioritybaseurl=http://yum.com/centos/$releasever/os/$basearch/        http://yum.com/centos/$releasever/os/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=osgpgcheck=1gpgkey=http://yum.com/centos/RPM-GPG-KEY-CentOS-7
#released updates [updates]name=CentOS-$releasever - Updates - yum.comfailovermethod=prioritybaseurl=http://yum.com/centos/$releasever/updates/$basearch/ http://yum.com/centos/$releasever/updates/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updatesgpgcheck=1gpgkey=http://yum.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful[extras]name=CentOS-$releasever - Extras - yum.comfailovermethod=prioritybaseurl=http://yum.com/centos/$releasever/extras/$basearch/ http://yum.com/centos/$releasever/extras/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extrasgpgcheck=1gpgkey=http://yum.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages[centosplus]name=CentOS-$releasever - Plus - yum.comfailovermethod=prioritybaseurl=http://yum.com/centos/$releasever/centosplus/$basearch/ http://yum.com/centos/$releasever/centosplus/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplusgpgcheck=1enabled=0gpgkey=http://yum.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users[contrib]name=CentOS-$releasever - Contrib - yum.comfailovermethod=prioritybaseurl=http://yum.com/centos/$releasever/contrib/$basearch/ http://yum.com/centos/$releasever/contrib/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contribgpgcheck=1enabled=0gpgkey=http://yum.com/centos/RPM-GPG-KEY-CentOS-7
复制代码

B 服务器上修改/etc/hosts

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


> vim /etc/hosts192.168.1.111 yum.com
复制代码


验证 B 服务器是否可以解析


> ping yum.com
复制代码

刷新 yum 缓存

> yum clean all> yum makecache
复制代码


原文链接:https://rumenz.com/rumenbiji/linux-yum-proxy.html

微信公众号:入门小站

发布于: 刚刚阅读数: 2
用户头像

入门小站

关注

还未添加个人签名 2020.01.18 加入

还未添加个人简介

评论

发布
暂无评论
linux之yum源设置代理