Redhat7.4配置yum源


linux配置yum源:https://www.cnblogs.com/liuzgg/p/11660442.html

Redhat系統是一款收費系統,安裝免費,但使用yum安裝軟件時會提示需要注冊

可以通過切換yum源為centos源來實現免費使用

1.配置阿里源

1.1 

yum install wget

網上有其他教程,一開始就要求卸載本地yum文件,但如果系統不自帶wget命令的話,后面可能要從外面網站上單獨下載所需rpm文件

再導入系統安裝,會非常麻煩

1.2  卸載原有yum源

先使用命令查看原有的yum,然后使用卸載命令卸載yum:

rpm -qa|grep yum
rpm -qa|grep yum |xargs -e --nodeps

1.3 根據你的redhat版本下載對應centos版本的yum源安裝包,

所需安裝包:

python-chardet-2.2.1-3.el7.noarch.rpm

python-kitchen-1.1.1-5.el7.noarch.rpm

yum-3.4.3-167.el7.centos.noarch.rpm

yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm

yum-updateonboot-1.1.31-53.el7.noarch.rpm

yum-utils-1.1.31-53.el7.noarch.rpm

到以下目錄去查找所需要的安裝包:

http://mirrors.163.com/centos/7/os/x86_64/Packages/

找到上面所需安裝文件就可以了,版本號不需要一樣,但文件前綴要一樣

如果你的虛擬機可以聯網,可直接用以下命令下載

wget -P /temp http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget -P /temp http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget -P /temp http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget -P /temp http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-50.el7.noarch.rpm
wget -P /temp http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm

這里偷懶了,最好事先搜索對應文件,不可直接復制

1.4 下載完成后開始安裝

cd到下載目錄,執行以下命令,沒有報錯即算成功

rpm -ivh yum-*.rpm

1.5 創建CentOS-Base.repo文件

cd /etc/yum.repos.d/
touch CentOS-Base.repo
vi CentOS-Base.repo
mv redhat.repo redhat.repo.bak
#網易雲鏡像站點:
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.163.com/centos/7.4.1708/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/7.4.1708/os/x86_64/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.163.com/centos/7.4.1708/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/7.4.1708/os/x86_64/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.163.com/centos/7.4.1708/extras//$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/7.4.1708/os/x86_64/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.163.com/centos/7.4.1708/centosplus//$basearch/
gpgcheck=1
enabled=0
#阿里雲鏡像站點:
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.aliyun.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.aliyun.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.aliyun.com/centos/7/extras//$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.aliyun.com/centos/7/centosplus//$basearch/
gpgcheck=1
enabled=0

1.5 

yum clean all
yum makecache

1.6 查看更新源 yum repolist all

使用yum install xxx 安裝文件仍然有如下提示,

[This system is not registered with an entitlement server.You can use subscription-manager to register.]

並且在替換自帶的repo源時發現無論是將redhat.repo重命名還是刪除,在執行yum命令后總是自動又生成redhat.repo得問題,導致替換的CentOS-Base.repo,一直無法使用的。

經過查找,發現是redhat自帶的插件subscription-manager給弄得的。而這個插件的作用就是Red Hat Subscription Manager訂閱管理器,就是它讓你一直register

找到subscription-manage的配置文件/etc/yum/pluginconf.d/subscription-manager.conf

[root@application-server pluginconf.d]# vi subscription-manager.conf

[main]
enabled=0 #將它禁用掉
~
...
[root@application-server pluginconf.d]#



重新執行yum clean 、yum makecache,使用yum install vim 安裝測試成功

1.6 備注

subscription-manager訂閱管理器
腳本文件: /usr/lib/yum-plugins/subscription-manager.py
配置文件: /etc/yum/pluginconf.d/subscription-manager.conf
調用了腳本 /usr/share/rhsm/repolib.py 
去重寫或者更新/etc/yum.repos.d/redhat.repo文件。
每次yum調用(不禁掉plugins的情況下),都會更新此文件。
因此,為了不沖突,可以如下操作:
第一:重命名自己的repo文件,比如RHEL.repo
第二:停止掉該插件的使用,在配置文件中把enable=0即可。
為了不影響系統自帶功能,建議選取第一種方法,
另外,該現象好像只是rhel6系統存在,4和5沒有發現。

2、配置本地源

2.1  設置源。打開終端,以ROOT身份去執行。

mv /etc/yum.repos.d/redhat.repo /etc/yum.repos.d/redhat.repo.bak

vi /etc/yum.repos.d/iso.repo
[iso]
name=yumformcdrom
baseurl=file:///yum/cdrom
enable=1
gpgcheck=0
gpgkey=file:///yum/REM-GPG-KEY-redhat-release

2.2 配置開機自動掛載

vi /etc/fstab
#在文件中增加一行,
/dev/sr0 /yum/cdrom auto defaults 0 0

2.3 創建目錄,重啟,建立緩存

mkdir -p /yum/cdrom
reboot
yum clean all
yum makecache

2.4 若只是單純想使用光盤或者安裝源中的文件時

mkdir /cdrom
#光盤文件默認位置為/dev/sr0
chmod 777 /dev/sr0
mount /dev/sr0 /cdrom

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM