安装Nginx

yum -y install nginx

新增yum.conf配置文件

server {
    listen       80;
    server_name  yum.gogen.cn;

    location / {
        root   /usr/share/nginx/yum;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }
}

启动nginx

systemctl start nginx
systemctl enable nginx

创建目录

mkdir -p /usr/share/nginx/yum/epel/6/x86_64
mkdir -p /usr/share/nginx/yum/centos/6/updates/x86_64
mkdir -p /usr/share/nginx/yum/centos/6/extras/x86_64
mkdir -p /usr/share/nginx/yum/centos/6/os/x86_64
mkdir -p /usr/share/nginx/yum/epel/7/x86_64
mkdir -p /usr/share/nginx/yum/centos/7/updates/x86_64
mkdir -p /usr/share/nginx/yum/centos/7/extras/x86_64
mkdir -p /usr/share/nginx/yum/centos/7/os/x86_64

注:如果需要其它系统还需要创建对应的其它目录

同步镜像

#!/bin/bash
#
# 此脚本用于同步"http://mirrors.ustc.edu.cn"的镜像到本地 
# 如果还需要其它系统那么直接往后面加上去
#
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64/  /usr/share/nginx/yum/epel/7/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/7/extras/x86_64/  /usr/share/nginx/yum/centos/7/extras/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/7/updates/x86_64/  /usr/share/nginx/yum/centos/7/updates/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/  /usr/share/nginx/yum/centos/7/os/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/epel/6/x86_64/  /usr/share/nginx/yum/epel/6/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/6/extras/x86_64/  /usr/share/nginx/yum/centos/6/extras/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/6/updates/x86_64/  /usr/share/nginx/yum/centos/6/updates/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/6/os/x86_64/  /usr/share/nginx/yum/centos/6/os/x86_64

加入计划任务

0 1 * * * sh /usr/local/sbin/sync.sh &> /tmp/yum.log

CentOS7的repo文件

CentOS-Base.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
baseurl=http://yum.gogen.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
baseurl=http://yum.gogen.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
baseurl=http://yum.gogen.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
baseurl=http://yum.gogen.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

epel.repo

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

CentOS6的repo文件

CentOS-Base.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 - yum.gogen.cn
baseurl=http://yum.gogen.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://yum.gogen.cn/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates - yum.gogen.cn
baseurl=http://yum.gogen.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://yum.gogen.cn/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - yum.gogen.cn
baseurl=http://yum.gogen.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://yum.gogen.cn/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - yum.gogen.cn
baseurl=http://yum.gogen.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://yum.gogen.cn/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - yum.gogen.cn
baseurl=http://yum.gogen.cn/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://yum.gogen.cn/centos/RPM-GPG-KEY-CentOS-6

epel.repo

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://yum.gogen.cn/epel/6/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
baseurl=http://yum.gogen.cn/epel/6/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
baseurl=http://yum.gogen.cn/epel/6/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1