我们在安装centos 服务器时,可能会有以下情况:

  局域网内有若干台服务器,但是只有一台服务器可以连接外网,其余服务器都不可以连接外网,但通过局域网与外网机器联通。

那么我们再使用 yum 安装软件时,可以采用以下方式

  • 搭建本地 yum 源
  • 使用nginx 代理 yum 源

其中方法1比较复杂且一旦需要第三方数据源时,更麻烦,因此我们这里介绍使用方法2。

1. 在有外网的服务器上安装 nginx

  安装 epel 源

yum -y install epel-release

  安装 nginx

yum -y install nginx

  

2. 配置nginx 代理 yum 源

  新增 nginx 配置文件

vim /etc/nginx/conf.d/centos-7-yum.conf

  输入以下内容,这里添加了一些常用的yum源,如果需要其他yum源可以自行添加

    # centos 7 yum local source
server {
listen 7000;
server_name 192.168.251.148; add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS; location / {
root html;
index index.html index.htm;
} location /centos/ {
proxy_pass http://mirrors.aliyun.com/centos/;
} location /epel/ {
proxy_pass http://mirrors.aliyun.com/epel/;
} location /mariadb/ {
proxy_pass http://mirrors.ustc.edu.cn/mariadb/;
} }

  检查nginx 配置,并重载nginx配置

nginx -t
nginx -s reload

  

3. 在没有外网的服务器上面配置 yum 源

  备份以前的yum 源配置文件

cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak

  根据上方代理的 yum 源,创建如下配置文件,注意将ip 192.168.1.100 换成对应的有外网服务器的局域网ip

  CentOS-Base-nginx.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://192.168.251.148:7000/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://192.168.251.148:7000/centos/RPM-GPG-KEY-CentOS-7 #released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://192.168.251.148:7000/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://192.168.251.148:7000/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://192.168.251.148:7000/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://192.168.251.148:7000/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://192.168.251.148:7000/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://192.168.251.148:7000/centos/RPM-GPG-KEY-CentOS-7

  epel-nginx.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://192.168.251.148:7000/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://192.168.251.148:7000/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1 [epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://192.168.251.148:7000/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

  MariaDB-nginx.repo

# MariaDB 10.2 CentOS repository list - created 2017-07-03 06:59 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://192.168.251.148:7000/mariadb/yum/10.3/centos7-amd64
gpgkey=http://192.168.251.148:7000/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

  刷新 yum 源

yum clean all
yum makecache

使用nginx代理centos yum 源的更多相关文章

  1. 其他综合-CentOS 7 rsync+nginx实现公网yum源

    CentOS 7 rsync+nginx实现公网yum源 1.实验描述 镜像同步公网 yum 源上游 yum 源必须要支持 rsync 协议,否则不能使用 rsync 进行同步.CentOS 7.6 ...

  2. redhat centos yum源的安装

    redhat centos yum源的安装 1.除旧 #cd /etc/yum.repos.d #mv rhel-debuginfo.repo rhel-debuginfo.repo.bak 此处将其 ...

  3. centos yum源配置 与yum配置文件

    参考博客 http://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html 1.centos . yum配置文件在目录 /etc/yum.re ...

  4. RedHat 更新CentOS Yum源(转)

    经测试,可用.转自:https://www.cnblogs.com/tangsen/p/5151994.html 一.随笔引言 1.1随笔内容: 1.RedHat 配置Centos yum源 2.yu ...

  5. CentOS yum源设定使用方法的整理(转)

    CentOS yum更新了很多版本更新,我本人认为CentOS yum很好使的文件系统,在此向大家推荐CentOS应该是做为服务器的linux的佼佼者.CentOS采用的二进制包是rpm,不过包的依赖 ...

  6. RHEL6配置CentOS yum源

    RHEL6配置CentOS yum源

  7. CentOS配置Nginx官方的Yum源

    由于yum源中没有我们想要的nginx,那么我们就需要创建一个"/etc/yum.repos.d/nginx.repo"的文件,其实就是新增一个yum源. [root@niaoyu ...

  8. 【nginx】利用yum源安装nginx

    先安装nginx的yum源 http://nginx.org/en/linux_packages.html#stable 找到链接,安装: rpm -ivh http://nginx.org/pack ...

  9. 配置nginx官网yum源

    由于yum源中没有我们想要的nginx,那么我们就需要创建一个“/etc/yum.repos.d/nginx.repo”的文件,其实就是新增一个yum源 二.添加nginx.repo 文件: [roo ...

随机推荐

  1. 一文看懂Python的面向对象编程

    之前在网络上看了很多关于面向对象的编程详解,还是不够过瘾,所以决定自己动手写一篇. 面向对象:Object Oriented Programming,简称OOP,即面向对象程序设计. 类(Class) ...

  2. 如何查看jsplumb.js的API文档(YUIdoc的基本使用)

    目录 一.问题描述 二. 处理方法 三. YUIdoc工具介绍 示例代码托管在:http://www.github.com/dashnowords/blogs 博客园地址:<大史住在大前端> ...

  3. 为什么我使用 Linux 开发

    Linux 能用吗? 当我对 Linux 的印象似乎还停留在黑乎乎的命令行界面上的时候,我身边的一些朋友告诉我或者建议我使用 Linux 时,我会一脸惊讶的问他,那个怎么用(来开发或者日常使用)? L ...

  4. Appium+python自动化(十八)- 你难道是猴哥失散多年的混血弟弟还是妹妹???- Monkey事件(超详解)

    操作事件简介 Monkey所执行的随机事件流中包含11大事件,分别是触摸事件.手势事件.二指缩放事件.轨迹事件.屏幕旋转事件.基本导航事件.主要导航事件.系统按键事件.启动Activity事件.键盘事 ...

  5. c++学习书籍推荐《C和C++安全编码》下载

    <华章程序员书库:C和C++安全编码(原书第2版)>致力于解决C和C++中已经导致危险的.破坏性的常见软件漏洞的基本编程错误,这些漏洞自CERT 1988年创立以来就记录在案.针对导致这些 ...

  6. ServiceFabric极简文档-4.1 学习路线图

    Service Fabric学习路线图 原文地址:Service Fabric学习路线图 ​

  7. I/O:Reader

    FileReader: /* 用来读取字符文件的便捷类.此类的构造方法假定默认字符编码和默认字节缓冲区大 小都是适当的.要自己指定这些值,可以先在 FileInputStream 上构造一个 Inpu ...

  8. Windows10 OpenSSH 快捷设置 避免 Bad owener or permission on

    配置ssh 有两个地方 ~/.ssh/config 这个亲测失败,怎么搞都报错 bad owner .... c:/programdata/ssh/ssh_config 亲测有效 (显示隐藏文件才看的 ...

  9. QQ Music 音乐插件DFX unable to open skin configration 的解决方法

    设置 C:\Program Files (x86)\Tencent\QQMusic\Plugins\Dfx\dfx_skin.txt  它的权限 允许程序读取执行

  10. springBean生命周期----来自spring实战总结

    1.Spring对bean进行实例化 2.Spring将值和bean的引用注入到bean对应的属性中(比如说注入到被依赖的bean的方法中或属性里) 3.如果bean实现了BeanNameAware接 ...