RedHat5.4 / 7.5 使用 centOS源更新

1.卸载HedHat5.4的yum命令 
    先查看RedHat上是否安装yum 
    
   
    删除所有的yum软件 
    rpm -qa | grep yum | xargs rpm -e --nodeps 

2.下载新的yum包 

 wget http://vault.centos.org/5.4/os/x86_64/CentOS/yum-fastestmirror-1.1.16-13.el5.centos.noarch.rpm

 wget http://vault.centos.org/5.4/os/x86_64/CentOS/yum-3.2.22-20.el5.centos.noarch.rpm

 wget http://vault.centos.org/5.4/os/x86_64/CentOS/yum-updatesd-0.9-2.el5.noarch.rpm

 wget http://vault.centos.org/5.4/os/x86_64/CentOS/yum-metadata-parser-1.1.2-3.el5.centos.x86_64.rpm

# rpm -ivh yum-*    #安装

# rpm -qa yum    #查看是否已经安装上
注意:yum和yum-fastestmirror相互依赖,所以同时安装即可。 

 

  1. 在CentOS下有的时候用yum安装软件的时候最后会提示:  
  2. warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID*****  
  3. 这是由于yum安装了旧版本的GPG keys造成的,解决办法就是  
  4. 下载并导入Key  
  5. cd /etc/pki/rpm-gpg  
  6. wget http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5  
  7. rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*   
  8. 或者  一条  rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
检测安装的 yum 是否有问题,执行命令进行测试:
yum clean all 重建yum缓存 
yum makecache

外网的yum源
vim /etc/yum.repos.d/CentOS-Base.repo
输入一下内容

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://vault.centos.org/5.11/os/$basearch/
gpgcheck=1 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5


#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://vault.centos.org/5.11/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5


#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://vault.centos.org/5.11/extras/$basearch/
gpgcheck=1 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

 


#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://vault.centos.org/5.11/centosplus/$basearch/
gpgcheck=1 
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

 


#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
baseurl=http://vault.centos.org/5.11/contrib/$basearch/
gpgcheck=1 
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5</span></strong></span>

 

无视依赖关系安装 --force --nodeps   

# rpm -ivh db4-devel-4.3.29-9.fc6.i386.rpm --force --nodeps 


 https://blog.csdn.net/m0_37886429/article/details/75009382 

 

centos7.5.1804配置本地yum源和阿里云yum源以及163源


3.在dell服务器上挂载CentOS镜像文件

[root@kangvcar ~]# mount -t iso9660 /dev/sr0 /opt/centos
mount: /dev/sr0 is write-protected, mounting read-only


4.编写repo文件并指向镜像的挂载目录
[root@kangvcar ~]# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0


5.清除缓存
[root@kangvcar ~]# yum clean all
[root@kangvcar ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list //列出了3780个包

 

二、把默认的CentOS yum源修改成国内的aliyun yum源
阿里云官方教程:https://developer.aliyun.com/mirror/

3.下载aliyun yum源repo文件(对应自己的系统版本下载即可)
#各系统版本repo文件对应的下载操作
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo


[root@kangvcar ~]# cat /etc/redhat-release //查看系统的版本
CentOS Linux release 7.2.1511 (Core)

[root@kangvcar ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

4.清除缓存
[root@kangvcar ~]# yum clean all
[root@kangvcar ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list //总共列出了9954个包


三、把默认的CentOS yum源修改成国内的163源
163官方教程:http://mirrors.163.com/.help/centos.html

 

3.下载163 yum源repo文件
#各系统版本repo文件对应的下载操作
CentOS 5
wget -O /etc/yum.repos.d/CentOS5-Base-163.repo http://mirrors.163.com/.help/CentOS5-Base-163.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS6-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo


[root@kangvcar ~]# cat /etc/redhat-release //查看系统的版本
CentOS Linux release 7.2.1511 (Core)

vi /etc/yum.repo.d/7.repo     复制下列信息

[163.repo]
name=mirrors.163.com.repo
baseurl=http://mirrors.163.com/centos/7/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7


4.清除缓存
[root@kangvcar ~]# yum clean all
[root@kangvcar ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list //总共列出了9951个包

四、修改yum源的优先级
ps:当既有本地yum源又有163源的时候,我们在装软件包的时候当然希望先用本地的yum源去安装,本地找不到可用的包时再使用163源去安装软件,这里就涉及到了优先级的问题,yum提供的插件yum-plugin-priorities.noarch可以解决这个问题

1.查看系统是否安装了优先级的插件
[root@kangvcar ~]# rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.31-34.el7.noarch
//这里看到没有安装yum-plugin-priorities.noarch这个插件


[root@kangvcar ~]# yum search yum-plugin-priorities
//用search查看是否有此插件可用
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
====================================================== N/S matched: yum-plugin-priorities =======================================================
yum-plugin-priorities.noarch : plugin to give priorities to packages from different repos
2.安装yum-plugin-priorities.noarch插件
[root@kangvcar ~]# yum -y install yum-plugin-priorities.noarch
1
3.查看插件是否启用
[root@kangvcar ~]# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1
//1为启用;0为禁用
4.修改本地yum源优先使用
[root@kangvcar ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 2573 May 15 2015 CentOS-Base.repo
-rw-r--r--. 1 root root 67 Jun 20 06:04 local.repo
//有两个repo文件
[root@kangvcar ~]# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
priority=1
//在原基础上加入priority=1 ;数字越小优先级越高
//可以继续修改其他源的priority值,经测试仅配置本地源的优先级为priority=1就会优先使用本地源了
5.测试
配置优先级前:(使用阿里云yum源)
[root@kangvcar ~]# yum -y install vim
Dependencies Resolved
=================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Installing:
vim-enhanced x86_64 2:7.4.160-1.el7_3.1 updates 1.0 M
Updating for dependencies:
vim-common x86_64 2:7.4.160-1.el7_3.1 updates 5.9 M
省略···
配置优先级后:(使用本地yum源)
[root@kangvcar ~]# yum -y install vim
Dependencies Resolved
=================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Installing:
vim-enhanced x86_64 2:7.4.160-1.el7 local 1.0 M
Installing for dependencies:
gpm-libs x86_64 1.20.7-5.el7 local 32 k
perl x86_64 4:5.16.3-286.el7 local 8.0 M
perl-Carp noarch 1.26-244.el7 local 19 k
perl-Encode x86_64 2.51-7.el7 local 1.5 M
perl-Exporter noarch 5.68-3.el7 local 28 k
perl-File-Path noarch 2.09-2.el7 local 26 k
perl-File-Temp noarch 0.23.01-3.el7 local 56 k
省略···

————————————————
版权声明:本文为CSDN博主「neo_will_mvp」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_33468857/article/details/81612560

 

posted @ 2019-02-18 15:11  jjp816  阅读(596)  评论(0编辑  收藏  举报