1. 程式人生 > >vmware虛擬機器設定yum源,國內阿里雲映象yum源

vmware虛擬機器設定yum源,國內阿里雲映象yum源

實驗時需要開啟好幾臺虛擬機器(最小化安裝),將映象掛載直接配置yum源,不用將iso拷貝到虛擬機器中,減少磁碟佔用;

檢查是否虛擬機器掛載映象

這裡寫圖片描述
檢查掛載目錄是否掛載
檢視該目錄下是否含有其他檔案,如果沒有建立目錄cdrom,再次將/dev/sr0掛載到該目錄下

[root@localhost ~]# cd /media/
[root@localhost media]# ls
cdrom

在其他目錄下建立cdrom目錄掛載:

[root@localhost ~]# mount -o loop  /dev/sr0 /mnt/cdrom

再次檢視是否掛載成功:

[root@localhost
media]# df /dev/sr0 3654720 3654720 0 100% /media/cdrom /dev/loop0 3654720 3654720 0 100% /mnt/cdrom

配置yum源:

[[email protected] media]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# cat yum.repo 
[rhel7.0]
name=redhat7.0
baseurl=file:///mnt/cdrom
enable=1   ###1表示啟用,0表示不啟用
gpgkey=1
###是否進行gpg校驗,1表示檢查,0表示不檢查 gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release ###定義檢查gpgkey的地址

檢視是否配置完成:

[[email protected] yum.repos.d]# yum clean all
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to
register. Cleaning repos: rhel7.0 Cleaning up everything [[email protected] yum.repos.d]# yum repolist Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. rhel7.0 | 4.1 kB 00:00 (1/2): rhel7.0/group_gz | 134 kB 00:00 (2/2): rhel7.0/primary_db | 3.4 MB 00:00 repo id repo name status rhel7.0 redhat7.0 4,305 repolist: 4,305

設定國內阿里雲Centos映象

redhat 預設自帶的 yum 源需要註冊,才能更新。不花錢更新,需要替換掉redhat的yum源。

檢查系統自帶的yum包

[[email protected] yum.repos.d]# rpm -qa | grep yum
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-utils-1.1.31-24.el7.noarch
yum-langpacks-0.4.2-3.el7.noarch
PackageKit-yum-0.8.9-11.el7.x86_64
yum-3.4.3-118.el7.noarch
yum-rhn-plugin-2.0.1-4.el7.noarch
[[email protected] yum.repos.d]# rpm -qa | grep yum | xargs rpm -e --nodeps    ###解除安裝系統自帶的yum包,--nodeps不檢查依賴關係
[[email protected] yum.repos.d]# rpm -qa | grep yum
[[email protected] yum]# rpm -qa | grep python-urlgrabber
python-urlgrabber-3.10-4.el7.noarch
[[email protected] yum]# rpm -qa | grep python-urlgrabber | xargs rpm -e --nodeps[[email protected] yum]# rpm -qa | grep python-urlgrabber

阿里雲映象下載解除安裝軟體

[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-45.el7.noarch.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm

解決報錯

rpm -ivh *.rpm時報錯,rpm包的版本太低需要進行升級

[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-python-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-libs-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-build-libs-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# ls
rpm-4.11.3-32.el7.x86_64.rpm
rpm-build-libs-4.11.3-32.el7.x86_64.rpm
rpm-libs-4.11.3-32.el7.x86_64.rpm
rpm-python-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# rpm -Uvh rpm-4.11.3-32.el7.x86_64.rpm rpm-libs-4.11.3-32.el7.x86_64.rpm rpm-python-4.11.3-32.el7.x86_64.rpm rpm-build-libs-4.11.3-32.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:rpm-libs-4.11.3-32.el7           ################################# [ 13%]
   2:rpm-4.11.3-32.el7                ################################# [ 25%]
   3:rpm-build-libs-4.11.3-32.el7     ################################# [ 38%]
   4:rpm-python-4.11.3-32.el7         ################################# [ 50%]
Cleaning up / removing...
   5:rpm-python-4.11.1-16.el7         ################################# [ 63%]
   6:rpm-build-libs-4.11.1-16.el7     ################################# [ 75%]
   7:rpm-libs-4.11.1-16.el7           ################################# [ 88%]
   8:rpm-4.11.1-16.el7                ################################# [100%]
[[email protected] yum]# rpm -qa | grep rpm 
rpm-4.11.3-32.el7.x86_64
rpm-python-4.11.3-32.el7.x86_64
rpm-libs-4.11.3-32.el7.x86_64
python-deltarpm-3.6-3.el7.x86_64
rpm-build-libs-4.11.3-32.el7.x86_64

安裝下載的阿里雲yum包

[root@localhost yum]# rpm -ivh yum-3.4.3-158.el7.centos.noarch.rpm yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm yum-utils-1.1.31-45.el7.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 25%]
   2:yum-plugin-fastestmirror-1.1.31-4################################# [ 50%]
   3:yum-3.4.3-158.el7.centos         ################################# [ 75%]
   4:yum-utils-1.1.31-45.el7          ################################# [100%]

配置yum原始檔

###檢視yum.repo.d目錄下是否含有yum源配置檔案,如果有備份原始檔;
[[email protected] yum]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
###下載阿里雲的centos映象檔案
[[email protected] yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] yum.repos.d]# ls
CentOS-Base.repo
###修改yum源配置檔案,將$releasever替換為7版本(這個看自己的伺服器系統),enable的值修改為0;
[[email protected] yum.repos.d]# sed -i 's/$releasever/7/g' CentOS-Base.repo 
[[email protected] yum.repos.d]# sed -i 's/enabled=1/enabled=0/g' CentOS-Base.repo 

yum源

# 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-7 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
        http://mirrors.aliyuncs.com/centos/7/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-7 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/7/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/7/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/7/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-7 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/7/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

清除快取和快取元資料

[[email protected] yum.repos.d]# yum clean all
[[email protected] yum.repos.d]# yum makecache