作者:胖妞-Debbie_982 | 来源:互联网 | 2023-08-13 09:43
环境:centos7使用的工具:yum-utilscreaterepoyum源:这里使用的是清华源,之前使用ali发现失败的太多epel[epel]nameExtraPackage
环境:centos7
使用的工具:yum-utils createrepo
yum源:这里使用的是清华源,之前使用ali发现失败的太多
epel
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[base]
name=qinghua
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
gpgcheck=0
enable=1
注坑1:使用清华的yum源就得使用清华的dns要不然可能没办法解析地址,如果你能解析当我没说
一、yum源准备
1.备份yum源
mkdir mv /etc/yum.repos.d/bak && mv /etc/yum.repos.d/* mv /etc/yum.repos.d/bak
2.配置清华yum源
cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=qinghua
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
gpgcheck=0
enable=1
cat /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
3.修改dns地址为清华dns
sed -i -r "s/DNS1=.*$/DNS1=101.6.6.6/g" /etc/sysconfig/network-scripts/ifcfg-eth0
systemctl restart network
二、同步源
1.安装工具
yum -y install yum-utils createrepo
2.同步yum源到本地
reposync -r base -p /usr/local/nginx/htm
reposync -r epel -p /usr/local/nginx/htm
注:这里 base 是需要同步的源标签。/usr/local/nginx/htm是同步到的目录。有亿点久1w多个包
3.生成依赖关系
createrepo /usr/local/nginx/htm/base
createrepo /usr/local/nginx/htm/epel
注:
1.base后面别加/
2.记住可能会报有些包错误,去清华开源下载同样的包替换即可
出现以下无报错则成功
[root@recall-2 yum.repos.d]# createrepo /usr/local/nginx/htm/base
Spawning worker 0 with 10072 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
查看base源依赖是否生成。
[root@recall-2 base]# ls /usr/local/nginx/htm/base/repodata/
3832a731b5c792dfb45df995404af0ae1afcf003586230f340344a3e8f4267fd-primary.xml.gz
5319616dde574d636861a6e632939f617466a371e59b555cf816cf1f52f3e873-filelists.xml.gz
845e42288d3b73a069e781b4307caba890fc168327baba20ce2d78a7507eb2af-other.xml.gz
a0d333d0f084bf28e4c53b1d72460b31ccfad4473d8defd35b8cf1a377f0b7b4-primary.sqlite.bz2
d6d94c7d406fe7ad4902a97104b39a0d8299451832a97f31d71653ba982c955b-filelists.sqlite.bz2
ecaab5cc3b9c10fefe6be2ecbf6f9fcb437231dac3e82cab8d9d2cf70e99644d-other.sqlite.bz2
repomd.xml
查看epel源是否生成
[root@recall-2 base]# ls /usr/local/nginx/htm/epel/repodata/
01804ab395688485c228ff437eb1e68b4143b8cac7ce48130d7d7c76f0ca9f7d-other.xml.gz
0a8abbef6a7ee6755308db47d6ec41b8126b04f2c843524d7aafe834e916848a-primary.xml.gz
2ef279558cd213fae592482c4f2cea6e699cc0943d609b4b0d29613f7d213a54-primary.sqlite.bz2
c7e97f5114ef81cc2ecbb0608b27c4da9621527d2edc7acf6e44331483413576-other.sqlite.bz2
ed589cc2a7fe25f483f82682d029d527da749bdaeafcb95cdff22e425642860a-filelists.sqlite.bz2
f437f7b63bbaa7bc6e764c967ded4ea7559d21083bb5ac259f228209741cc71c-filelists.xml.gz
repomd.xml
三、配置yum
配置base源
[root@yum yum.repos.d]# cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=qinghua
baseurl=file:///usr/local/nginx/htm/base/
gpgcheck=0
enable=1
配置epel源
[root@yum yum.repos.d]# cat /etc/yum.repos.d/epel-7.repo
[epel]
name=myepel
baseurl=file:///usr/local/nginx/htm/epel
enabled=1
gpgcheck=0
[root@yum yum.repos.d]# yum clean all
[root@yum yum.repos.d]# yum repolist
已加载插件:fastestmirror
Determining fastest mirrors
base | 2.9 kB 00:00:00
epel | 2.9 kB 00:00:00
(1/2): base/primary_db | 6.1 MB 00:00:00
(2/2): epel/primary_db | 6.8 MB 00:00:00
源标识 源名称 状态
base qinghua 10,072
epel myepel 13,676
repolist: 23,748
到此base、epel源已经成功同步至本地了,实验不难,就是下载需要消耗大量时间
原文链接:https://www.cnblogs.com/RRecal/p/15408777.html