curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
yum repolist
安裝軟件
yum install -y yum-utils createrepo # yum-utils包含reposync同步工具,createrepo用于對rpm文件進行索引建立
reposync -n --repoid=extras --repoid=updates --repoid=base --repoid=epel -p /library/Centos7.9/ # -n 指下載最新軟件包,-p 指定目錄,--repoid 指定本地的源,如果不指定就同步所有源# 創建源索引
createrepo -po /library/Centos7.9/base/ /library/Centos7.9/base/
createrepo -po /library/Centos7.9/extras/ /library/Centos7.9/extras/
createrepo -po /library/Centos7.9/updates/ /library/Centos7.9/updates/
createrepo -po /library/Centos7.9/epel/ /library/Centos7.9/epel/
# 更新源索引
createrepo --update /library/Centos7.9/base/
createrepo --update /library/Centos7.9/extras/
createrepo --update /library/Centos7.9/updates/
createrepo --update /library/Centos7.9/epel/
創建yum源客repo配置文件
cat << EOF > /mirror/repo/CentOS-Base.repo[base]
name=CentOS- Base
baseurl=file:///library/Centos7.9/base/
enable=1
gpgcheck=0[updates]
name=CentOS- Updates
baseurl=file:///library/Centos7.9/updates/
enable=1
gpgcheck=0[extras]
name=CentOS- Extras
baseurl=file:///library/Centos7.9/extras/
enable=1
gpgcheck=0[epel]
name=CentOS- Epel
baseurl=file:///library/Centos7.9/epel/
enable=1
gpgcheck=0
EOF