本地源
先创建一个挂载文件夹,再挂载光盘镜像。
[root@Server ~]# mkdir /mnt/cdrom
[root@Server ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@Server ~]# vi /etc/yum.repos.d/rhel-source.repo
编辑配置文件/etc/yum.repos.d/rhel-source.repo,当然也可在/etc/yum.repos.d/目录下新建一个.repo文件并修改。
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
#baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/
baseurl=file:///mnt/cdrom/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[rhel-source-beta]
name=Red Hat Enterprise Linux $releasever Beta - $basearch - Source
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/SRPMS/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
"/etc/yum.repos.d/rhel-source.repo" 14L, 557C
在[rhel-source]这里注释掉原来的ftp源的所在一行:
#baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/
新建一行
baseurl=file:///mnt/cdrom/
并修改
enabled=1
其它的[rhel-source-beta]的enabled=0不启用。
保存退出,看看是否能正确启用:
[root@Server ~]# yum repolist
Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel-source | 3.9 kB 00:00 ...
repo id repo name status
rhel-source Red Hat Enterprise Linux 6Server - i386 - Source 2,844
repolist: 2,844
网易镜像源
http://mirrors.163.com/
注意:CentOS6及之前的版本已不支持
This directory (and version of CentOS) is deprecated. Please see this FAQ concerning the CentOS release scheme:
https://wiki.centos.org/FAQ/General
Please keep in mind that 6.0, 6.1, 6.2, 6.3, 6.4 , 6.5, 6.6, 6.7, 6.8 , 6.9 and 6.10 no longer get any updates, nor any security fix’s. The whole CentOS 6 is and be used anywhere at all
镜像使用说明:
http://mirrors.163.com/.help/
下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份)
从网易下载的配置文件中,用到$releasever这个变量,yum中的$releasever变量是取redhat-release-serverrpm包的属性值( %{version}),在Linux7中其值为7Server,与网易的目录不符,不做修改电话,会提示镜像找不到:
http://mirrors.163.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
所以,为了简单起见直接把$releasever改为7 。
[root@webserver ~]# vi /etc/yum.repos.d/CentOS7-Base-163.repo
[base]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
查看一下源列表:
[root@webserver ~]# yum repolist
源标识 源名称 状态
base/x86_64 CentOS-7Server - Base - 163.com 10,071+1
extras/x86_64 CentOS-7Server - Extras - 163.com 468
updates/x86_64 CentOS-7Server - Updates - 163.com 1,923+1
repolist: 12,462
阿里镜像源
https://developer.aliyun.com/mirror/
清华大学镜像源
https://mirrors.cnnic.cn/
https://mirrors.tuna.tsinghua.edu.cn/
https://mirrors.tuna.tsinghua.edu.cn/help/centos/
网页已将配置方法讲的很清楚。