使用nginx代理centos yum 源
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用nginx代理centos yum 源,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3952字,纯文字阅读大概需要6分钟。
内容图文
![使用nginx代理centos yum 源](/upload/InfoBanner/zyjiaocheng/972/f035c2ffa5fc41c29216c4d09e1780c2.jpg)
我们在安装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 源全部内容,希望文章能够帮你解决使用nginx代理centos yum 源所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。