[转载]使用reposync同步centos历史源
一、同步Centos各版本源
1.配置repo文件
-
以6.0为例
vim /etc/yum.repo.d/CentOS-6.0.repo #贴入下方配置文件 ## centos6.0 [base6.0] name=CentOS-6.0-os-local baseurl=http://archive.kernel.org/centos-vault/6.0/os/x86_64/ gpgcheck=1 gpgkey=http://archive.kernel.org/centos-vault/6.0/os/x86_64/RPM-GPG-KEY-CentOS-6 #released updates [updates6.0] name=CentOS-6.0-updates-local baseurl=http://archive.kernel.org/centos-vault/6.0/updates/x86_64/ gpgcheck=1 gpgkey=http://archive.kernel.org/centos-vault/6.0/os/x86_64/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras6.0] name=CentOS-6.0-extras-local baseurl=http://archive.kernel.org/centos-vault/6.0/extras/x86_64/ gpgcheck=1 gpgkey=http://archive.kernel.org/centos-vault/6.0/os/x86_64/RPM-GPG-KEY-CentOS-6 #运行如下命令 yum repolist
2.多个repo文件
-
多版本解决方案
[root@local]# ls CentOS-6.0.repo CentOS-6.1.repo CentOS-6.3.repo CentOS-6.5.repo CentOS-6.7.repo CentOS-6.9.repo CentOS-6.10.repo CentOS-6.2.repo CentOS-6.4.repo CentOS-6.6.repo CentOS-6.8.repo [root@]# yum repolist Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile repo id repo name status base6.0 CentOS-6.0-os-local 6,019 base6.1 CentOS-6.1-os-local 6,188 base6.2 CentOS-6.2-os-local 6,294 base6.3 CentOS-6.3-os-local 6,346 base6.4 CentOS-6.4-os-local 6,381 base6.5 CentOS-6.5-os-local 6,367 base6.6 CentOS-6.6-os-local 6,518 base6.7 CentOS-6.7-os-local 6,575 base6.8 CentOS-6.8-os-local 6,696 base6.9 CentOS-6.9-os-local 6,706 extras6.0 CentOS-6.0-extras-local 1 extras6.1 CentOS-6.1-extras-local 3 extras6.2 CentOS-6.2-extras-local 6 extras6.3 CentOS-6.3-extras-local 17 extras6.4 CentOS-6.4-extras-local 13 extras6.5 CentOS-6.5-extras-local 15 extras6.6 CentOS-6.6-extras-local 38 extras6.7 CentOS-6.7-extras-local 64 extras6.8 CentOS-6.8-extras-local 64 extras6.9 CentOS-6.9-extras-local 53 updates6.0 CentOS-6.0-updates-local 1,042 updates6.1 CentOS-6.1-updates-local 1,253 updates6.2 CentOS-6.2-updates-local 1,154 updates6.3 CentOS-6.3-updates-local 1,233 updates6.4 CentOS-6.4-updates-local 1,555 updates6.5 CentOS-6.5-updates-local 1,608 updates6.6 CentOS-6.6-updates-local 1,370 updates6.7 CentOS-6.7-updates-local 1,622 updates6.8 CentOS-6.8-updates-local 974 updates6.9 CentOS-6.9-updates-local 1,308
3.同步脚本
同步命令如下:
vim update-yum.sh
# update-yum.sh的内容如下
#!/bin/bash reposync -n --repoid=extras6.0 --repoid=updates6.0 --repoid=base6.0 -p /data/centos/6.0 reposync -n --repoid=extras6.1 --repoid=updates6.1 --repoid=base6.1 -p /data/centos/6.1 reposync -n --repoid=extras6.2 --repoid=updates6.2 --repoid=base6.2 -p /data/centos/6.2 reposync -n --repoid=extras6.3 --repoid=updates6.3 --repoid=base6.3 -p /data/centos/6.3 reposync -n --repoid=extras6.4 --repoid=updates6.4 --repoid=base6.4 -p /data/centos/6.4 reposync -n --repoid=extras6.5 --repoid=updates6.5 --repoid=base6.5 -p /data/centos/6.5 reposync -n --repoid=extras6.6 --repoid=updates6.6 --repoid=base6.6 -p /data/centos/6.6 reposync -n --repoid=extras6.7 --repoid=updates6.7 --repoid=base6.7 -p /data/centos/6.7 reposync -n --repoid=extras6.8 --repoid=updates6.8 --repoid=base6.8 -p /data/centos/6.8 reposync -n --repoid=extras6.9 --repoid=updates6.9 --repoid=base6.9 -p /data/centos/6.9
执行参数
nohup sh update-yum.sh > log 2>&1 &
4.使用createrepo创建本地yum仓库
4.1 创建索引
#以一个为例,格式:createrepo -po 源目录 索引元数据的输出位置目录 createrepo -po /data/centos/7.4/base7.4 /data/centos/7.4/base7.4 createrepo -po /data/centos/7.4/updates7.4 /data/centos/7.4/updates7.4 createrepo -po /data/centos/7.4/extras7.4 /data/centos/7.4/extras7.4
4.2 创建组文件的索引
支持yum groupinstall ,也可略过
4.3 引入签名
wget http://archive.kernel.org/centos-vault/RPM-GPG-KEY-CentOS-7 -P /data/centos
二、建立本地yum源
2.1搭建http服务
安装apache
yum install httpd
配置
修改文件/etc/httpd/conf/httpd.conf
DocumentRoot "/data/centos" <Directory "/data/centos"> Options Indexes FollowSymLinks Options Indexes AllowOverride All Order allow,deny IndexOptions Charset=UTF-8 Allow from all Require all granted </Directory>
删除welcome配置
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak
-
启动
systemctl restart httpd systemctl enable httpd
2.2配置本地yum文件
-
客户端配置repo文件
[base7.4] name=CentOS-7.4-Base-local baseurl=http://10.x.x.x/7.4/base7.4/ gpgcheck=1 gpgkey=http://10.x.x.x/RPM-GPG-KEY-CentOS-7 #released updates [updates7.4] name=CentOS-7.4-Updates-local baseurl=http://10.x.x.x/7.4/updates7.4/ gpgcheck=1 gpgkey=http://10.x.x.x/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras7.4] name=CentOS-7.4-Extras-local baseurl=http://10.x.x.x/7.4/extras7.4/ gpgcheck=1 gpgkey=http://10.x.x.x/RPM-GPG-KEY-CentOS-7
三、同步任务
3.1同步任务脚本
-
update.sh
#!/bin/bash echo 开始同步centos7 reposync -n --repoid=extras7.4 --repoid=updates7.4 --repoid=base7.4 -p /data/centos/7.4 echo centos7同步结束 #更新元数据 createrepo --update /data/centos/7.4/base7.4 createrepo --update /data/centos/7.4/updates7.4 createrepo --update /data/centos/7.4/extras7.4
3.2 crontab设置
0 6 * * * /data/update.sh
参考资料
搬砖
共有 0 条评论