首先备份/etc/yum.repos.d/CentOS-Base.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载对应版本 repo 文件, 放入 /etc/yum.repos.d/ (操作前请做好相应备份)

CentOS5 :http://mirrors.163.com/.help/CentOS5-Base-163.repo
CentOS6 :http://mirrors.163.com/.help/CentOS6-Base-163.repo
CentOS7 :http://mirrors.163.com/.help/CentOS7-Base-163.repo

wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

mv CentOS7-Base-163.repo CentOS-Base.repo

#运行命令生成缓存

yum clean all

yum makecache

除了网易之外,国内还有其他不错的 yum 源,比如中科大和搜狐。

中科大的 yum 源,安装方法查看:https://lug.ustc.edu.cn/wiki/mirrors/help/centos

sohu 的 yum 源安装方法查看: http://mirrors.sohu.com/help/centos.html

#配置本地Yum仓库
#实现此案例需要按照如下步骤进行。
#步骤一:搭建一个本地Yum,将RHEL6光盘手动挂载到/media
#命令操作如下所示:

[root@localhost ~]# mount /dev/cdrom /media/

mount: block device /dev/sr0 is write-protected, mounting read-only

[root@localhost ~]# mount | tail -1

/dev/sr0 on /media type iso9660 (ro)

#步骤二:将本地设置为客户端,进行Yum验证

#Yum客户端需编辑配置文件,命令操作如下所示:

[root@localhost ~]# cd /etc/yum.repos.d/         //必须在这个路径下

[root@localhost yum.repos.d]# ls                  //此路径下事先有配置文件的模板

rhel-source.repo

[root@localhost yum.repos.d]# cp rhel-source.repo rhel6.repo //配置文件必须以.repo结尾

[root@localhost yum.repos.d]# vim rhel6.repo

[rhel-6]                                     //中括号里内容要求唯一,但不要出现特殊字符

name=Red Hat Enterprise Linux 6           //此为描述信息,可以看情况填写

baseurl=file:///media/                     //此项为yum软件仓库位置,指向光盘挂载点

enabled=1                                   //此项为是否开启,1为开启, 0为不开启

gpgcheck=1                                  //此项为是否检查签名,1为检测, 0为不检测

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release  //签名认证信息的路径

[root@localhost /]# yum repolist

Loaded plugins: product-id, refresh-packagekit, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

rhel-6                                            | 3.9 kB     00:00 ... 

rhel-6/primary_db                                  | 3.1 MB     00:00 ... 

repo id             repo name                                     status

rhel-6              Red Hat Enterprise Linux 6                    3,690

repolist: 3,690

li1121567428

   li1121567428

  li1***567428@live.com

  zrs***07@163.com

对于 Linux 软件安装时提示缺失库的,可以使用 yum 的 provides 参数查看 libstdc++.so.6 的库文件包含在那个安装包中只需要执行:

yum provides libstdc++.so.6

然后按查询到安装包包名,使用 yum install 安装即可