一.下载并安装wget curl vim工具
yum -y install wget curl vim
二.备份原repo文件
tar -zcf repo.tar.gz *.repo
rm -rf *.repo
三.配置yum仓库源
1.通过wget等命令下载repo文件
1.1 配置网易base源:
wget -c -P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS7-Base-163.repo
1.2 配置阿里base源:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
2.手动配置仓库源
2.1 配置nginx仓库
[root@local yum.repos.d]# cat nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
2.2 配置本地仓库
#挂载光盘
mount /dev/cdrom /mnt
[root@local yum.repos.d]# cat local.repo
[local]
name=centos 7 local repo
baseurl=file:///mnt
#0表示不校验,1表示校验
gpgcheck=0
#如果需要校验则要指定gpgkey
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7
#1表示启用该仓库,0表示禁用该仓库
enabled=1
2.3 配置清华base源
[root@local yum.repos.d]# cat tsinghua.repo
[tsinghua]
name=centos 7 tsinghua repo
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
enabled=1
3.通过yum-config-manager命令自动配置仓库
# 安装yum的扩展包:
yum -y install yum-utils
#配置网易base源
[root@local yum.repos.d]# yum-config-manager --add-repo=http://mirrors.163.com/.help/CentOS7-Base-163.repo
Loaded plugins: fastestmirror
adding repo from: http://mirrors.163.com/.help/CentOS7-Base-163.repo
grabbing file http://mirrors.163.com/.help/CentOS7-Base-163.repo to /etc/yum.repos.d/CentOS7-Base-163.repo
repo saved to /etc/yum.repos.d/CentOS7-Base-163.repo
#配置清华base源
[root@zw yum.repos.d]# yum-config-manager --add-repo=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
Loaded plugins: fastestmirror
adding repo from: https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
[mirrors.tuna.tsinghua.edu.cn_centos_7_os_x86_64_]
name=added from: https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
enabled=1
[root@zw yum.repos.d]# cat >> mirrors.tuna.tsinghua.edu.cn_centos_7_os_x86_64_.repo << E
> gpgcheck=1
> gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
> E
[root@zw yum.repos.d]# cat mirrors.tuna.tsinghua.edu.cn_centos_7_os_x86_64_.repo
[mirrors.tuna.tsinghua.edu.cn_centos_7_os_x86_64_]
name=added from: https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
4、同步外网源
安装工具
yum -y install createrepo yum-utils
创建本地目录
reposync -r nginx-stable -p /data/centos/
#做元数据缓存
createrepo /data/centos/nginx-stable/
yum-config-manager --add-repo=file:///data/centos/nginx-stable
四、清除原来的缓存,建立新的缓存
清除缓存
yum clean all
建立缓存
yun makecache
显示所有仓库
yum repolist