天天看點

VMware下yum的倉庫源配置

yum源概述

yum更新軟體需要有源檔案,而源檔案所在的檔案目錄就可以設定為yum更新的源。CentOS 本身就有一個源,在/etc/yum.repos.d/目錄下有一些預設的配置檔案。但是需要連到國外的鏡像,有些時候為了下載下傳速度,我們可以配置國内鏡像或者CD光牒鏡像。

linux下配置yum源以下有三種方式。

(一)國内鏡像

(1)通過網絡,搜尋開源yum鏡像

通路⽹易鏡像站點: http://mirrors.163.com/ 選擇centos并點選進⼊:因為我們使⽤的centos7的iso鏡像版本是7.6.1810,是以選擇該版本。 進⼊後,選擇os,點選進⼊:選擇x86_64,(隻有⼀個項⽬)點選進⼊: 點選進⼊後,看到有repodata⽬錄即可,複制目前浏覽器的位址,即url位址。該位址就為yum配置⽂件中baseurl的位址。

(2)配置yum源路徑

[[email protected] yum.repos.d]# cd /etc/yum.repos.d/   
[[email protected] yum.repos.d]# vim create.repo  
           

(設定yum倉庫源的配置⽂件:

yum的配置⽂件在/etc/yum.repos.d/⽬錄下,配置内容可以寫在該⽬錄下的任意⼀個以.repo結尾的⽂件

中,也可建立⼀個以.repo結尾的⽂件。本例采⽤後者即建立⼀個create.repo⽂件。

)

内容為:

[base]  
name=CentOS-$releasever - Base  
baseurl=http://mirrors.163.com/centos/7.6.1810/os/x86_64/  
gpgcheck=1  
gpgkey=http://mirrors.163.com/centos/7.6.1810/os/x86_64/RPM-GPG-KEY-CentOS-7

           

(3)重新加載yum檔案

yum clean all
yum makecache  
           

阿裡雲的鏡像使用人數比較多,也可以換幾個 :

       阿裡雲

       163網易

       搜狐

       清華大學

(二)本地挂載目錄(使⽤iso⽂件源配置yum倉庫源并使⽤yum指令安裝軟體包)

(1)建立iso挂載點并挂載

Centos7的iso⽂件在/home/CentOS-7-x86_64-Everything-1804.iso

[[email protected] ~]# mkdir /home/mnt/{iso,vcdrom}
[[email protected] ~]# mv /home/CentOS-7-x86_64-Everything-1804.iso /home/mnt/iso
[[email protected] ~]# mount -r -o loop /home/mnt/iso/CentOS-7-x86_64-Everything1804.iso /home/mnt/vcdrom/
           

(2)配置yum⽂件

[[email protected] ~]# vim /etc/yum.repos.d/create.repo
           

(設定yum倉庫源的配置⽂件:

yum的配置⽂件在/etc/yum.repos.d/⽬錄下,配置内容可以寫在該⽬錄下的任意⼀個以.repo結尾的⽂件

中,也可建立⼀個以.repo結尾的⽂件。本例采⽤後者即建立⼀個create.repo⽂件。

)

内容為:

[base]
name=CentOS-$releasever - Base
baseurl=file:///home/mnt/vcdrom/
gpgcheck=0
enabled=1  
           

(3)重新加載yum檔案

yum clean all
yum makecache  
           

(三)使⽤虛拟機的CD光牒配置yum倉庫源并使⽤yum指令安裝軟體包

(1)先把centos7系統的iso鏡像⽂件,放⼊虛拟機的虛拟光驅中。

-本地挂載CD光牒:

[[email protected] ~]# mount -r /dev/cdrom /mnt
[[email protected] ~]# ls -d /mnt/Packages/
/mnt/Packages/
           

(設定yum倉庫源的配置⽂件:

yum的配置⽂件在/etc/yum.repos.d/⽬錄下,配置内容可以寫在該⽬錄下的任意⼀個以.repo結尾的⽂件

中,也可建立⼀個以.repo結尾的⽂件。本例采⽤後者即建立⼀個create.repo⽂件。

)

[[email protected] ~]# vim /etc/yum.repos.d/create.repo
           

内容為:

[create]
name=create
baseurl=file:///mnt/
gpgcheck=0
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7
enabled=1  
           

(2)使⽤yum倉庫源

[[email protected] ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: create
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned
data from disabled or removed repos
Cleaning up list of fastest mirrors
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[[email protected] yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
create | 3.6 kB 00:00
(1/2): create/group_gz | 166 kB 00:00
(2/2): create/primary_db | 5.9 MB 00:00
repo id repo name status
create create 9,911
repolist: 9,91  
           

(3)實作開機⾃動挂載CD光牒

[[email protected] ~]# vim /etc/fstab  
/dev/cdrom /mnt iso9660 defaults,loop 0 0   
[[email protected] ~]# mount -a
           

(4)重新加載yum檔案

yum clean all
yum makecache  
           

繼續閱讀