当前位置:   article > 正文

linux之yum源设置代理_yum install proxy

yum install proxy

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

Centos7下设置代理案例

A服务器192.168.1.10可以访问外网
B服务器192.168.1.111不能访问外网,可以通过内网IP访问A服务器
在A服务器安装nginx

我们使用nginx作为yum的反向代理软件

> yum install nginx -y
  • 1

配置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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
修改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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
B服务器上修改/etc/hosts

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

> vim /etc/hosts
192.168.1.111 yum.com
  • 1
  • 2

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

> ping yum.com
  • 1
刷新yum缓存
> yum clean all
> yum makecache
  • 1
  • 2

原文链接:https://rumenz.com/rumenbiji/linux-yum-proxy.html
微信公众号:入门小站

  • 回复【1001】获取 linux常用命令速查手册
  • 回复【10010】获取 阿里云ECS运维Linux系统诊断
  • 回复【10012】获取 Linux学习笔记【强悍总结值得一看】
  • 回复【10013】获取 shell简明教程

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/168688
推荐阅读
相关标签
  

闽ICP备14008679号