1. 程式人生 > >Yum源----Linux的軟體倉庫

Yum源----Linux的軟體倉庫

Yum(Shell前端包管理器)

Yum(全稱為 Yellow dog Updater, Modified)是一個在Fedora和RedHat以及CentOS中的Shell前端軟體包管理器。基於RPM包管理,能夠從指定的伺服器自動下載RPM包並且安裝,可以自動處理依賴性關係,並且一次安裝所有依賴的軟體包,無須繁瑣地一次次下載、安裝。

一、配置Yum源
1.新建目錄進行儲存映象和掛載
[root@foundation79 /]# mkdir /resource7.0 /resource7.2 /iso

   #目錄iso用於儲存映象,目錄resource7.0和resource7.2用於映象的掛載
[root@foundation79 iso]# mount rhel-server-7.2-x86_64-dvd.iso /resource/ mount: /dev/loop0 is write-protected, mounting read-only #將映象rhel-server-7.2-x86_64-dvd.iso掛載到resource目錄下面。
##備份本地快取

新建目錄repobackup在根目錄,用於備份本地快取

 [[email protected] yum.repos.d]# mkdir /repobackup
##清除快取
 [[email protected] yum.repos.d]# mv * /repobackup/
2.編輯yum.repo即yum源的配置檔案
[[email protected] yum.repos.d]# vim yum.repo
[rhel7.2]
name=rhel7.2
baseurl=file:///resource #掛載映象的本地目錄
baseurl=http:/// gpgcheck=0 #是否使用gpg校驗

4.清除yum快取
以上配置結束之後,要清空yum 快取,並重建yum快取。
yum clean all
或 rm -rf /var/cache/yum/*

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

Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-

              : manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

掛載映象後,resource目錄下會產生一些相關檔案,其中安裝包就在Packages目錄下。至此,yum源就安裝好了,可以直接與yum指令

二、使用yum源安裝軟體
1.檢視相關軟體

(1)在目錄中查詢

[[email protected] iso]# ls /resource/Packages/ |grep dhcp

dhcp-4.2.5-42.el7.x86_64.rpm

dhcp-common-4.2.5-42.el7.x86_64.rpm

dhcp-libs-4.2.5-42.el7.i686.rpm

dhcp-libs-4.2.5-42.el7.x86_64.rpm

(2)使用yum指令檢視

[kiosk@foundation79 Desktop]$ yum list dhcp
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
Installed Packages
dhcp.x86_64                       12:4.2.5-42.el7                       @rhel7.2
2.安裝軟體
[[email protected] yum.repos.d]# yum install dhcp

Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-

              : manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Resolving Dependencies

--> Running transaction check

---> Package dhcp.x86_64 12:4.2.5-42.el7 will be installed

--> Finished Dependency Resolution



Dependencies Resolved



================================================================================

 Package       Arch            Version                   Repository        Size

================================================================================

Installing:

 dhcp          x86_64          12:4.2.5-42.el7           rhel7.2          511 k

...

Installed:

  dhcp.x86_64 12:4.2.5-42.el7                                                  

Complete!


Cleaning repos: rhel7.2

Cleaning up everything
##檢視軟體是否安裝
[[email protected] yum.repos.d]# yum list installed | grep dhcp

dhcp.x86_64                             12:4.2.5-42.el7            @rhel7.2     

dhcp-common.x86_64                      12:4.2.5-42.el7            @anaconda/7.2

dhcp-libs.x86_64                        12:4.2.5-42.el7            @anaconda/7.2
二、共享yum源到區域網中
  • 配置yum源
  • 安裝好http服務
  • 將yum源掛載到http目錄下
  • 客戶機更改yum配置
1.使用yum源安裝httpd服務
[[email protected] yum.repos.d]# yum install httpd

Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Resolving Dependencies

--> Running transaction check

---> Package httpd.x86_64 0:2.4.6-40.el7 will be installed

--> Processing Dependency: httpd-tools = 2.4.6-40.el7 for package: httpd-2.4.6-40.el7.x86_64

--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.x86_64
...
Installed:
  httpd.x86_64 0:2.4.6-40.el7                                                           
Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7            apr-util.x86_64 0:1.5.2-6.el7            httpd-tools.x86_64 0:2.4.6-40.el7           

Complete!
2.啟動httpd程式

同時可以選擇設定開機自啟實現重啟後自動共享

[[email protected] yum.repos.d]# systemctl start httpd
[[email protected] ~]# systemctl enable httpd.service

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
3.關閉防火牆
[root@foundation79 ~]# systemctl stop firewalld
[root@foundation79 ~]# systemctl disable firewalld
4.新建目錄,該目錄下的檔案可以通過httpd共享
[[email protected] ~]# mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/source7.0/
mount: /dev/loop1 is write-protected, mounting read-only
You have new mail in /var/spool/mail/root
##利用df指令檢視映象是否被掛載
[root@foundation79 ~]# df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda9      125254908 13544464 111710444  11% /
devtmpfs         3951352        0   3951352   0% /dev
tmpfs            3964400      160   3964240   1% /dev/shm
tmpfs            3964400     9128   3955272   1% /run
tmpfs            3964400        0   3964400   0% /sys/fs/cgroup
/dev/sda7         505580   149292    356288  30% /boot
tmpfs             792884       36    792848   1% /run/user/1000
/dev/sdb1       15133232 10161792   4971440  68% /run/media/kiosk/D6BC-DE4E
tmpfs            3964400       88   3964312   1% /tmp
/dev/loop0       3947824  3947824         0 100% /resource
/dev/loop1       3654720  3654720         0 100% /var/www/html/source7.0
You have new mail in /var/spool/mail/root
##如何實現開機時自動掛載

新增可執行許可權—->編輯開機自啟動配置

[root@foundation79 ~]# chmod +x /etc/rc.d/rc.local
[root@foundation79 ~]# vim /etc/rc.d/rc.local

mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/source7.0/
mount /iso/rhel-server-7.2-x86_64-dvd.iso /var/www/html/source7.2/
5.在客戶機中檢測

在瀏覽器中鍵入ip:/yum源掛載目錄/

效果如圖:

這裡寫圖片描述