一、背景
其一:部署项目时,需要在操作系统上安装一些软件,但是RedHat使用yum源需要注册,所以需要卸载RedHat自带的yum,换装普通CentOs软件源;
其二:某些软件安装时,需要大量依赖,手工下载、手动编译费时费力,而生产环境不宜开通直接访问外部yum源的权限。因此,采用在测试环境在线安装,之后将在线安装好的rpm包以及依赖重新打包到生产环境离线安装的方法。
二、环境
操作系统:Red Hat Enterprise Linux Server release 7.3 Linux version 3.10.0-514.el7.x86_64
源:国内的话我们使用清华源:https://mirrors.tuna.tsinghua.edu.cn/
三、步骤
1、下载新源需要的软件包并更新
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/rpm-build-4.11.3-45.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/rpm-libs-4.11.3-45.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/rpm-python-4.11.3-45.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/rpm-4.11.3-45.el7.x86_64.rpm
然后使用rpm命令安装
rpm -Uvh python-iniparse-0.4-9.el7.noarch.rpm
rpm -Uvh python-urlgrabber-3.10-9.el7.noarch.rpm
rpm -Uvh rpm-4.11.3-45.el7.x86_64.rpm –nodeps
rpm -Uvh rpm-build-4.11.3-45.el7.x86_64.rpm
rpm -Uvh rpm-python-4.11.3-45.el7.x86_64.rpm
rpm -Uvh rpm-libs-4.11.3-45.el7.x86_64.rpm
2、卸载旧yum源
rpm -qa|grep yum|xargs rpm -e –nodeps
3、安装新yum源
rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh yum-3.4.3-163.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm
4、替换源链接
cd /etc/yum.repos.d/
vim CentOS7-Base-tuna.repo
编辑该文件,具体的也可以参考 https://mirrors.tuna.tsinghua.edu.cn/help/centos/
# 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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
#released updates
[updates]
name=CentOS-$releasever – Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
将其中的$releasever替换为7保存即可,然后更新yum。
yum clean all
yum makecache
5、替换GPG-KEY
cd /etc/pki/rpm-gpg/
wget https://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7
mv RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-7
至此,RedHat的源已经被替换为了CentOS的普通源。