我们在安装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. RobotFramework + HTTP接口自动化实现

    一.          什么是自动化测试? 1.      定义 自动化测试是把以人为驱动的测试行为转化为机器执行的一种过程,也可以说是软件测试的一种技术手段. 2.      常见工具 Appium ...

  2. DBA主宰一切请求,MySQL 查询重写

    这个功能一年左右之前就以知晓,应该是5.7的高版本中.今天难得有兴致测试.随之也就总结一下. 前言: 一般来说,我们都会让开发自己去改sql.这样需要重启应用,单节点不可避免有或多或少的停服时间.同事 ...

  3. 微服务-springboot+websocket在线聊天室

    一.引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  4. 分布式理论基础(四)Paxos

    1 背景 分布式理论基础(一)一致性及解决一致性的两种方式:2PC和3PC 中介绍了一致性,Paxos协议在节点宕机恢复.消息无序或丢失.网络分化的场景下能保证决议的一致性,是被讨论最广泛的一致性协议 ...

  5. 职业生涯之完成OCM考试后的感想

    背景知识:关于OCM认证,百科是这样描述的: Oracle Certified Master(OCM) 大师认证资质是Oracle认证的最高级别.此认证是对技术.知识和操作技能的最高级别的认可.Ora ...

  6. Linux命令学习-mkdir命令

    Linux中,mkdir命令的全称是make directory,即创建目录的意思. 假设当前处于wintest用户的主目录,路径为 /home/wintest ,存在文件夹testA,进入testA ...

  7. Android开发-百度地图之电子围栏

    功能实现:根据经纬度创建一个坐标,判断该坐标是否在指定圆形覆盖范围内 两个计算方法,直接套用: /** * 地球半径 */private static double EARTH_RADIUS = 63 ...

  8. Web前端_微信小程序实战开发

    微信小程序开发实战教程 一.微信小程序 它是一种混合开发的方式. 是安装在微信中的程序(一个程序最多2M空间). 1.1 注册 1  2 点击立即注册:进入下方页面 3  4 点击小程序进入表单填写页 ...

  9. 数据结构与算法---堆排序(Heap sort)

    堆排序基本介绍 1.堆排序是利用堆这种数据结构而设计的一种排序算法,堆排序是一种选择排序,它的最坏,最好,平均时间复杂度均为O(nlogn),它也是不稳定排序. 2.堆是具有以下性质的完全二叉树:每个 ...

  10. SSH框架,xml配置实现动态定时器

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-// ...