Creating a local yum repository mirror server

安装配置Rsync服务

安装Rsync

1
$ yum -y install rsync

创建Yum Repository存放的目录

1
2
3
4
$ mkdir -p /opt/nginx/html/centos
$ mkdir -p /opt/nginx/html/epel
$ mkdir -p /opt/nginx/html/repoforge
$ mkdir -p /opt/nginx/html/exclude

创建Rsync同步脚本

1
2
3
4
5
6
7
8
9
10
11
12
$ cat <<EOF > /opt/nginx/html/rsync_cron.sh
#!/bin/bash
# Yum Repository Server.
/usr/bin/rsync -avrt --delete-excluded rsync://mirrors.tuna.tsinghua.edu.cn/centos/ --exclude-from=/opt/nginx/html/exclude/exclude_centos.list /opt/nginx/html/centos/
/usr/bin/rsync -avrt --delete-excluded rsync://mirrors.tuna.tsinghua.edu.cn/repoforge/ --exclude-from=/opt/nginx/html/exclude/exclude_repoforge.list /opt/nginx/html/repoforge/
/usr/bin/rsync -avrt --delete-excluded rsync://mirrors.tuna.tsinghua.edu.cn/epel/ --exclude-from=/opt/nginx/html/exclude/exclude_epel.list /opt/nginx/html/epel/
exit 0
EOF

创建Rsync同步脚本排除文件列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
$ cat <<EOF > /opt/nginx/html/exclude/exclude_centos.list
2
2.1
3
3.1
3.3
3.4
3.5
3.6
3.7
3.8
3.9
4
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.0
5.1
5.10
5.11
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
6.0
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8/centosplus/i386
6.8/contrib/i386
6.8/extras/i386
6.8/isos/i386
6.8/updates/i386
6.8/cr/i386
6.8/fastrack/i386
6.8/os/i386
7.0.1406
7.1.1503
7.2.1511
RPM-GPG-KEY-beta
RPM-GPG-KEY-CentOS-3
RPM-GPG-KEY-centos4
RPM-GPG-KEY-CentOS-4
RPM-GPG-KEY-CentOS-5
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ cat <<EOF > /opt/nginx/html/exclude/exclude_epel.list
4
4AS
4ES
4WS
5
5Client
5Server
6/i386
6/ppc64
6/SRPMS
7/aarch64
7/ppc64
7/ppc64le
7/SRPMS
project
testing
epel-release-latest-5.noarch.rpm
RPM-GPG-KEY-EPEL-4
RPM-GPG-KEY-EPEL-5
EOF
1
2
3
4
5
6
7
8
9
10
11
12
$ cat <<EOF > /opt/nginx/html/exclude/exclude_repoforge.list
5
6/i386
7/i386
redhat/el2.1
redhat/el3
redhat/el4
redhat/el5
redhat/el6/en/i386
redhat/el6/en/ppc
source
EOF

配置Rsync同步脚本定时执行任务

1
2
3
4
5
$ chmod 755 /opt/nginx/html/rsync_cron.sh
$ cat <<EOF >> /var/spool/cron/root
# Yum Repository Rsync.
3 2 * * * /opt/nginx/html/rsync_cron.sh > /dev/null 2>&1
EOF

安装配置Web服务

安装Nginx

1
2
3
$ wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
$ rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
$ yum -y install nginx

修改Nginx配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ cat <<EOF > /etc/nginx/conf.d/default
# The default server
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /opt/nginx/html;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
EOF

### 配置Nginx开机启动

1
2
$ systemctl start nginx
$ systemctl enable nginx

生成Yum客户端配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ cat <<EOF > /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://YOUR_LAN_IP_ADDR/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://YOUR_LAN_IP_ADDR/centos/RPM-GPG-KEY-CentOS-$releasever
# released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://YOUR_LAN_IP_ADDR/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://YOUR_LAN_IP_ADDR/centos/RPM-GPG-KEY-CentOS-$releasever
# additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://YOUR_LAN_IP_ADDR/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://YOUR_LAN_IP_ADDR/centos/RPM-GPG-KEY-CentOS-$releasever
# additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://YOUR_LAN_IP_ADDR/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://YOUR_LAN_IP_ADDR/centos/RPM-GPG-KEY-CentOS-$releasever
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ cat <<EOF > /etc/yum.repos.d/epel.repo
# epel.repo
[epel]
name=Extra Packages for Enterprise Linux $releasever
baseurl=http://YOUR_LAN_IP_ADDR/epel/$releasever/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=http://YOUR_LAN_IP_ADDR/epel/RPM-GPG-KEY-EPEL-$releasever
priority=10
[epel-debuginfo]
name=Extra Packages for Enterprise Linux $releasever - Debug
baseurl=http://YOUR_LAN_IP_ADDR/epel/$releasever/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=http://YOUR_LAN_IP_ADDR/epel/RPM-GPG-KEY-EPEL-$releasever
gpgcheck=1
priority=10
[epel-source]
name=Extra Packages for Enterprise Linux $releasever - Source
baseurl=http://YOUR_LAN_IP_ADDR/epel/$releasever/SRPMS
failovermethod=priority
enabled=0
gpgkey=http://YOUR_LAN_IP_ADDR/epel/RPM-GPG-KEY-EPEL-$releasever
gpgcheck=1
priority=10
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ cat <<EOF > /etc/yum.repos.d/rpmforge.repo
# rpmforge.repo
[rpmforge]
name = RHEL $releasever - dag
baseurl = http://YOUR_LAN_IP_ADDR/repoforge/redhat/el$releasever/en/$basearch/rpmforge
enabled = 1
protect = 0
gpgkey = http://YOUR_LAN_IP_ADDR/repoforge/RPM-GPG-KEY.dag.txt
gpgcheck = 1
priority = 20
[rpmforge-extras]
name = RHEL $releasever - extras
baseurl = http://YOUR_LAN_IP_ADDR//repoforge/redhat/el$releasever/en/$basearch/extras
enabled = 0
protect = 0
gpgkey = http://YOUR_LAN_IP_ADDR/repoforge/RPM-GPG-KEY.dag.txt
gpgcheck = 1
priority = 20
[rpmforge-testing]
name = RHEL $releasever - testing
baseurl = http://YOUR_LAN_IP_ADDR/repoforge/redhat/el$releasever/en/$basearch/testing
enabled = 0
protect = 0
gpgkey = http://YOUR_LAN_IP_ADDR/repoforge/RPM-GPG-KEY.dag.txt
gpgcheck = 1
priority = 20
EOF

最后,将上面生成的Yum客户端配置文件复制到其他服务器即可。