制作CentOS7 yum私有源的方法

离线化yum源的方法

首先准备一个excludes.list文件,作为排除的列表,如果不想排除,可以不用这个文件,并且将离线化脚本中的参数--exclude-from=exclude.list删除。

exclude.list文件内容:

SRPMS
aarch64
ppc64
ppc64le
debug
repodata
EFI
LiveOS
images
isolinux
CentOS_BuildTag
EULA
GPL
RPM-GPG-KEY-CentOS-7
RPM-GPG-KEY-CentOS-Testing-7
drpms

离线化脚本rsync.sh,会在当前目录下创建一个centos的目录,并将源内容同步到这个目录,通过createrepo命令创建yum仓库。离线文件总计27G左右,执行前确认空间足够。如果不使用exclude.list,占用空间只会更多。脚本内容:

#!/bin/bash

#epel
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/epel/7/ epel/7/
createrepo epel/7/
 
#centos7-base
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/ centos/7/os/x86_64/
createrepo centos/7/os/x86_64/
 
#centos7-updates
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/ centos/7/updates/x86_64/
createrepo centos/7/updates/x86_64/
 
#centos7-extras
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/x86_64/ centos/7/extras/x86_64/
createrepo centos/7/extras/x86_64/
 
#centos7-centosplus
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/centosplus/x86_64/ centos/7/centosplus/x86_64/
createrepo centos/7/centosplus/x86_64/

在执行脚本之前,需要确定系统上已经安装命令rsynccreaterepo

yum install rsync createrepo -y

搭建本地文件源

现在,可以使用local.repo使用当前目录为yum源,文件内容如下:

[base]
name=Local Repository
baseurl=file:///centos/7/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=Local Repository
baseurl=file:///centos/7/updates/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=Local Repository
baseurl=file:///centos/7/extras/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[centosplus]
name=Local Repository
baseurl=file:///centos/7/centosplus/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

上边是开启gpgcheck了,如果不想启用,把它设置成0

搭建http源

如果想要搭建http服务访问源,使用apache或者nginx搭建一个http服务,将文件放到web目录里面即可。然后把repo文件中的每一个repo的baseurl改为对应的url就行了。

猜你喜欢

转载自blog.csdn.net/stpice/article/details/100382502
今日推荐