1. 程式人生 > >使用Nginx制作內網yum鏡像代理

使用Nginx制作內網yum鏡像代理

yum nginx

使用Nginx制作內網yum鏡像代理


  • 使用Nginx制作內網yum鏡像代理

    • 1. 背景

    • 2. 環境需求

    • 3. Nginx安裝配置


1. 背景

公司內網服務器不能直接通過Internet上網,但為了與外網通信和同步時間等,會指定那麽幾臺服務器可以訪問Internet。這裏就是通過能上網的機器作為代理,制作內網使用的yum倉庫。

2. 環境需求

  1. 內網dns(推薦,非必須,因為可使用IP代替)

  2. 一臺能上Internet的服務器A

  3. 不能上Internet的服務器能與A服務器通信

  4. 這裏示例為CentOS7和Ubuntu16

3. Nginx安裝配置

Nginx安裝在能上網的A服務器上,安裝過程略。
具體一個nginx server配置如下:

# mirrors
server
{
listen 80;
#listen [::]:80;
server_name mirrors.yourdomain.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/html;

location /ubuntu/ {
proxy_pass http://mirrors.aliyun.com/ubuntu/ ;
}

location /centos/ {
proxy_pass http://mirrors.aliyun.com/centos/ ;
}

location /epel/ {
proxy_pass http://mirrors.aliyun.com/epel/ ;
}
}

以上使用阿裏雲鏡像,其鏡像版本很全,速度也很快。
http://mirrors.aliyun.com/

CentOS7系統鏡像源:
cat /etc/yum.repos.d/CentOS-7.repo

[base]
name=CentOS-$releasever - Base - mirrors.yourdomain.com
failovermethod=priority
baseurl=http://mirrors.yourdomain.com/centos/$releasever/os/$basearch/
http://mirrors.yourdomain.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.yourdomain.com
failovermethod=priority
baseurl=http://mirrors.yourdomain.com/centos/$releasever/updates/$basearch/
http://mirrors.yourdomain.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.yourdomain.com
failovermethod=priority
baseurl=http://mirrors.yourdomain.com/centos/$releasever/extras/$basearch/
http://mirrors.yourdomain.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.yourdomain.com
failovermethod=priority
baseurl=http://mirrors.yourdomain.com/centos/$releasever/centosplus/$basearch/
http://mirrors.yourdomain.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.yourdomain.com
failovermethod=priority
baseurl=http://mirrors.yourdomain.com/centos/$releasever/contrib/$basearch/
http://mirrors.yourdomain.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.yourdomain.com/centos/RPM-GPG-KEY-CentOS-7

EPEL第三方擴展源:
cat /etc/yum.repos.d/epel.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.yourdomain.com/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://download.yourdomain.com/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://download.yourdomain.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

Ubuntu16 apt鏡像源:
cat /etc/apt/sources.list

deb http://mirrors.yourdomain.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.yourdomain.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.yourdomain.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.yourdomain.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.yourdomain.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.yourdomain.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.yourdomain.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.yourdomain.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.yourdomain.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.yourdomain.com/ubuntu/ xenial-backports main restricted universe multiverse


本文出自 “ygqygq2” 博客,請務必保留此出處http://ygqygq2.blog.51cto.com/1009869/1960791

使用Nginx制作內網yum鏡像代理