适用场景:有多台服务器,但是只有1台服务器可以出公网,此时即可使用如下方式,进行yum代理,解决内网服务器不能yum的尴尬。

一、首先需要把/etc/yum.repos.d下的文件备份到bak,然后留一个CentOS-Base.repo。编辑这个文件,我使用的是科大的yum源。

如下代码:

# 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
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

################################################################

二、然后需要编辑内网服务器另一个配置文件:vi /etc/yum.conf       需要注意   proxy=http://172.21.7.20:3621,这里是配置代理的ip和端口,就是可出公网的那台服务器的nginx端口。

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
proxy=http://172.21.7.20:3621
http_caching=none
# This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

################################################################

三、设置nginx代理

在可出公网的那台服务器设置nginx代理:添加如下配置

server {
listen 3621;
#禁用multipart range功能
max_ranges 1;
server_name _;
server_tokens off;
location / {
access_log /data3/log1/nginx/mirrors.log;
proxy_pass http://mirrors.ustc.edu.cn;
}
}

保存,退出,重启nginx。

此时在内网服务器上执行yum makecache fast,之后内网服务器就可以正常使用yum了,再也不用上传5G的镜像资源挂载了!!!!

nginx代理yum的更多相关文章

  1. 使用nginx代理centos yum 源

    我们在安装centos 服务器时,可能会有以下情况: 局域网内有若干台服务器,但是只有一台服务器可以连接外网,其余服务器都不可以连接外网,但通过局域网与外网机器联通. 那么我们再使用 yum 安装软件 ...

  2. Nginx反向代理YUM请求

    一.安装配置Nginx服务(Nginx服务器上建议先关闭iptables/firewalld服务,待实验完成后再根据实际情况配置) [root@localhost ~]# yum install ng ...

  3. CentOS 7 安装Subversion, 并用Nginx代理

    环境:CentOS 7.3.1611 分三步:第一步:安装subversion第二步:安装httpd第三步:安装nginx 操作步骤: 安装subversion, 命令 -> yum -y in ...

  4. Nginx代理TCP服务

    利用nginx代理tpc 部署nginx 安装编译所需环境 # yum install -y apr-devel apr-util-devel pcre-devel openssl-devel 添加w ...

  5. Nginx代理转发Apache+svn

    1.安装svn和httpd yum install httpd yum install subversion mod_dav_svn 创建仓库目录 mkdir -p /var/www/svn 3.创建 ...

  6. nginx做yum源

    我这边环境是原先有个nginx只是做了代理转发,现在需要在通过nginx做yum源方便后期安装源 1.原先的配置代理转发,为不影响原先配置及端口,在http中最末尾加“include include ...

  7. Nginx代理MysqlCluster集群(二)

    Nginx代理MySql集群本次实验采用nginx 版本1.12以上 集合了tcp代理功能只需在编译时明文开启指定的功能 --with-stream--prefix=/usr/local/ngin - ...

  8. FastDFS + Nginx代理方式访问

    FastDFS + Nginx代理方式访问 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.在storage上安装nginx 1>.下载nginx软件(http://ngi ...

  9. Docker Compose 一键部署Nginx代理Tomcat集群

    Docker Compose 一键部署Nginx代理Tomcat集群 目录结构 [root@localhost ~]# tree compose_nginx_tomcat/ compose_nginx ...

随机推荐

  1. Access 中case when then else end不支持使用switch代替

    Access 中case when then else end不支持使用switch代替 这里主要是实现一个表中多个字段,多个字段之间作比较然后取得最大值或者最小值用来处理 case when the ...

  2. python之条件判断、循环和字符串格式化

    1. python的条件判断:if和else 在条件判断中可以使用算数运算符 等于:== 不等于:!= 大于:> 小于:< 大于等于:>= 小于等于:<= 示例1: usern ...

  3. 水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift

    题目传送门 /* 水题:vector容器实现插入操作,暴力进行判断是否为回文串 */ #include <cstdio> #include <iostream> #includ ...

  4. magento 开启 3D secure credit card validation

    因为国外盗刷严重,于是得开启验证. 首先可以去 https://developer.cardinalcommerce.com/try-it-now.shtml.这上面有测试账号,截图如下:

  5. 根据 目录号 案卷号 用户名 查询 page 中 的条数

    select count(*) from am_b_page a join am_b_entry b on a.entry_id=b.entry_id where b.catalogue_code=' ...

  6. php使用json_decode返回NULL

    php5.2以后自带json_decode函数,但是对json文本串的格式要求非常严格. 很可能使用该函数得到的返回值是NULL 可以使用使用json_last_error()函数获取到的返回值来帮助 ...

  7. intellij idea 调试 lua程序, 突然崩溃或者xmx不够的情况

    将内存各方面的数值都改大一点.都什么时代了,默认数值还这么低... -server-Xms256m-Xmx1024m-XX:ReservedCodeCacheSize=240m-XX:+UseConc ...

  8. 将vue-cli项目配置在nginx上

    登录使用的是node.js搭建的注册登录接口,关于对数据库的读写则是用spring boot的框架来实现的. 1.首先是vue-cli项目里的前端页面的配置: location / { root    ...

  9. HTTPS时代已来,你做好准备了吗?

    早在今年年初,Google在其安全博客上已经表明,从7月开始,Chrome68会将所有的HTTP网站标记为不安全.随后,Mozilla也表明,Firefox浏览器也准备将所有HTTP网站标记为不安全. ...

  10. 【HEVC帧间预测论文】P1.9 Coding Tree Depth Estimation for Complexity Reduction of HEVC

    Coding Tree Depth Estimation for Complexity Reduction of HEVC <HEVC标准介绍.HEVC帧间预测论文笔记>系列博客,目录见: ...