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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
| 一、基础环境
1、在tvm-base的基础上,复制一个镜像为tvm-yum来测试。
2、网络:
eth0:host-only(用于虚拟内网,手动固定IP,这样从宿主机可以直接连接到这个vm)
eth1:NAT(用于上外网,动态IP)
[iyunv@tvm-yum ~]# cd /etc/sysconfig/network-scripts/
[iyunv@tvm-yum network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.56.254
PREFIX=24
GATEWAY=192.168.56.1
[iyunv@tvm-yum network-scripts]# cat ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
[iyunv@tvm-yum ~]# ip a s dev eth0 |grep global
inet 192.168.56.254/24 brd 192.168.56.255 scope global eth0
[iyunv@tvm-yum ~]# ip a s dev eth1 |grep global
inet 10.0.3.15/24 brd 10.0.3.255 scope global eth1
[iyunv@tvm-yum ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
0.0.0.0 10.0.3.2 0.0.0.0 UG 0 0 0 eth1
2、初步计划是:
yum仓库,在hosts配置加入:
192.168.56.254 mirrors.office.test
然后这样访问yum仓库:
http://mirrors.office.test/centos
接下来需要:
1)配置一个local yum 镜像,并定时从公网的mirrors同步数据。
注1:不需要i386目录,此处只用x86_64的版本。
注2:不需要isos目录,里面存放的是iso文件。
2)配置一个http服务。
3)提供local-office.repo文件,供客户端用。
二、配置目录和脚本,制作本地的yum镜像
[iyunv@tvm-yum ~]# mkdir -p /data/yum/repo/centos/ /data/download/ /data/ops/bin/
1、上传centos6.5-x64的iso文件到/data/download/
[iyunv@tvm-yum ~]# ls /data/download/
CentOS-6.5-x86_64-bin-DVD1.iso CentOS-6.5-x86_64-bin-DVD2.iso
[iyunv@tvm-yum ~]# mkdir -p /data/yum/repo/centos/6/os/x86_64
2、同步iso文件中的内容:
[iyunv@tvm-yum ~]# mount -ro loop /data/download/CentOS-6.5-x86_64-bin-DVD1.iso /mnt
[iyunv@tvm-yum ~]# rsync -avHPS /mnt/ /data/yum/repo/centos/6/os/x86_64/
[iyunv@tvm-yum ~]# umount /mnt
[iyunv@tvm-yum ~]# mount -ro loop /data/download/CentOS-6.5-x86_64-bin-DVD2.iso /mnt
[iyunv@tvm-yum ~]# rsync -avHPS /mnt/ /data/yum/repo/centos/6/os/x86_64/
[iyunv@tvm-yum ~]# umount /mnt
3、选一个mirrors,通过脚本从mirrors同步。
查找镜像列表:http://www.centos.org/download/mirrors/
这里我选择了一个支持rsync协议的镜像:http://mirrors.hust.edu.cn/centos/
注3:目前最新版本的是centos6.6,因此,实际上同步的后,这个仓库的版本是6.6,做个软连接,6 -> 6.6
[iyunv@tvm-yum ~]# ln -s /data/yum/repo/centos/6 /data/yum/repo/centos/6.6
开始同步
[iyunv@tvm-yum ~]# rsync -avzP --delete --delete-excluded --exclude "local*" --exclude "isos" --exclude "i386" rsync://mirrors.hust.edu.cn/centos/6/ /data/yum/repo/centos/6/
三、配置http方式来访问yum镜像
1、防火墙放行80端口
2、配置httpd服务
1)若没有禁用selinux,则应当这样配置:
[iyunv@tvm-yum ~]# chcon -Rv --type=httpd_sys_content_t /data/yum/repo/
2)配置httpd服务:
[iyunv@tvm-yum ~]# cat /etc/httpd/conf/httpd.conf |grep ServerName |grep ^[^#]
ServerName 127.0.0.1
3)配置虚拟主机
[iyunv@tvm-yum ~]# mv /etc/httpd/conf.d/welcome.conf /tmp/
[iyunv@tvm-yum ~]# cat /etc/httpd/conf.d/mirrors.office.test.conf
<VirtualHost *:80>
ServerAdmin pc@office.test
ServerName mirrors.office.test
DocumentRoot /data/yum/repo
ErrorLog logs/mirrors.office.test-error_log
CustomLog logs/mirrors.office.test-access_log common
<Directory /data/yum/repo>
options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
3、启动httpd服务
[iyunv@tvm-yum ~]# chown -R apache:apache /data/yum/repo
[iyunv@tvm-yum ~]# service httpd start
4、测试
宿主机配置hosts文件:
192.168.56.254 mirrors.office.test
访问:
http://mirrors.office.test/centos
抓包信息:
[iyunv@tvm-yum ~]# curl -o /dev/null -v -I http://mirrors.office.test/centos/
* About to connect() to mirrors.office.test port 80 (#0)
* Trying 192.168.56.254... connected
* Connected to mirrors.office.test (192.168.56.254) port 80 (#0)
> HEAD /centos/ HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: mirrors.office.test
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Tue, 14 Jul 2015 02:32:14 GMT
< Server: Apache/2.2.15 (CentOS)
< Connection: close
< Content-Type: text/html;charset=UTF-8
<
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Closing connection #0
chrome抓包信息:
Remote Address:192.168.56.254:80
Request URL:http://mirrors.office.test/centos/
Request Method:GET
Status Code:200 OK
Remote Address:192.168.56.254:80
Request URL:http://mirrors.office.test/centos/
Request Method:GET
Status Code:200 OK
四、提供local-office.repo文件
1、现有的目录:
[iyunv@tvm-yum ~]# ls /data/yum/repo/centos/6/
centosplus cloud contrib cr extras fasttrack os SCL updates xen4
2、local-office.repo
[iyunv@tvm-yum ~]# cat /etc/yum.repos.d/local-office.repo
# local-office.repo
# 2015/7/14
# 把Centos-Base.repo更新成自己的mirror,其余的repo移除。
# - 包含基础的os里面的rpm包
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.office.test/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#released updates - 包含可以更新的包
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.office.test/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful - 包含额外的包
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.office.test/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages - 包含功能扩展的包
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.office.test/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users - 包含用户贡献的包
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirrors.office.test/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
五、等mirros同步完成后,开始测试
1、本机测试
先清除缓存:
[iyunv@tvm-yum ~]# yum clean all
Loaded plugins: fastestmirror, security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
试着更新下系统:
[iyunv@tvm-yum ~]# yum update
(略)
(369/369): yum-utils-1.1.30-30.el6.noarch.rpm | 110 kB 00:00
-----------------------------------------------------------------------------------------------------
Total 16 MB/s | 430 MB 00:26
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
(略)
yum.noarch 0:3.2.29-60.el6.centos
yum-plugin-fastestmirror.noarch 0:1.1.30-30.el6
yum-plugin-security.noarch 0:1.1.30-30.el6
yum-utils.noarch 0:1.1.30-30.el6
Replaced:
libsss_autofs.x86_64 0:1.9.2-129.el6
Complete!
[iyunv@tvm-yum ~]#
[iyunv@tvm-yum ~]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m
2、瞧,已经升级到6.6的版本,建议reboot一下先。
reboot前,先将httpd服务加入开机启动。
[iyunv@tvm-yum centos]# chkconfig httpd on
[iyunv@tvm-yum centos]# chkconfig --list |grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[iyunv@tvm-yum ~]# cp /etc/yum.repos.d/local-office.repo /data/yum/repo/centos/
[iyunv@tvm-yum ~]# chown -R apache:apache /data/yum/repo/centos/
用update升级系统后,在/etc/yum.repos.d/里面更新了CentOS相关的repo文件,因此在重启后可以考虑移除
[iyunv@tvm-yum ~]# mv CentOS-* /etc/yum.repos.d/ /tmp/
3、配置脚本来同步,并放到crontab中执行
[iyunv@tvm-yum ~]# cat /data/ops/bin/repo_update.sh
#!/bin/bash
#
# 2015/7/14
if [ -f /var/lock/subsys/repo_update ]; then
echo "[`date`] yum repo update via rsync is already running."
exit 0
fi
if [ -d /data/yum/repo/centos/6 ]; then
touch /var/lock/subsys/repo_update
rsync -avzP --delete --delete-excluded --exclude "local*" --exclude "isos" --exclude "i386" rsync://mirrors.hust.edu.cn/centos/6/ /data/yum/repo/centos/6/
rm /var/lock/subsys/repo_update
else
echo "[`date`] [error] dir not proesent: /data/yum/repo/centos/6"
fi
chown -R apache:apache /data/yum/repo
放到crontab中
[iyunv@tvm-yum ~]# cat <<_NTP >>/var/spool/cron/$(whoami)
# repo update
0 4 * * * /bin/bash /data/ops/bin/repo_update.sh >/tmp/repo.log 2>&1 &
_NTP
六、TODO
1、加入epel源
本地新增epel源的方式:
[iyunv@tvm-yum ~]# rpm -Uvh http://dl.fedoraproject.org/pub/ ... latest-6.noarch.rpm
[iyunv@tvm-yum ~]# yum makecache
网上没找到可以rsync的epel源,期望,官方没有提供针对epel的mirrors的列表吗?我简单找了找,没发现。
sohu的这个可以用不?
http://mirrors.sohu.com/fedora-epel/
遗留epel的同步问题1个,待解决。
2、客户端使用local-office.repo文件
[iyunv@tvm-rpm ~]# mv /etc/yum.repos.d/CentOS* /tmp/ \
&& echo '192.168.56.254 mirrors.office.test' >> /etc/hosts \
&& wget http://mirrors.office.test/centos/local-office.repo -O /etc/yum.repos.d/local-office.repo \
&& yum makecach
[iyunv@tvm-rpm ~]# yum update
符合预期。
ZYXW、参考
1、Creating a local repo (Mirror) with CentOS 6.2+
http://darktraining.com/93/
2、Creating Local Mirrors for Updates or Installs
https://wiki.centos.org/HowTos/CreateLocalMirror
3、List of CentOS Mirrors
http://www.centos.org/download/mirrors/
4、How To Set Up and Use Yum Repositories on a CentOS 6 VPS
https://www.digitalocean.com/com ... s-on-a-centos-6-vps
|