1. 程式人生 > >Linux下的yum命令及yum源設定

Linux下的yum命令及yum源設定

1、常用命令
yum install softwarename  #安裝

yum repolist #列出設定yum源資訊


yum remove softwarename #解除安裝軟體

yum list softwarename #檢視軟體源中是否有此軟體


yum list all #列出所有軟體名稱
yum list installed #列出已經安裝的軟體名稱

yum list available #列出可以用yum安裝的軟體


yum clean all #清空yum快取

yum search softwareinfo #根據軟體資訊搜尋軟體名字(如,使用search web搜尋web瀏覽器)


yum whatprovides filename #在yum源中查詢包含filename檔案的軟體包

(如,whatprovides rm搜尋漢含rm的軟體,命令實質上是檔案)


yum update #更新軟體,會存在未知問題,一般不對伺服器升降級
yum history #檢視系統軟體改變歷史
yum reinstall softwarename #重新安裝
yum info softwarename #檢視軟體資訊

yum groups list #檢視軟體組資訊


yum groups info softwarename #檢視軟體組內包含的軟體
yum groups install softwarename #安裝元件

yum groups remove softwarename #解除安裝元件

2、本地yum源的自定義安裝
(1)找和系統匹配的映象檔案到系統中
hostnamectl檢視本機系統版本
(2)mkdir /iso #建立目錄
(3)mv /home/kiosk/Desktop/*.iso /iso #將映象放至/iso目錄下,防止誤刪(本步操作不是必須的)


(4)mkdir /rhel7.0 /rhel7.2 #建立掛載裝置
(5)mount /iso/rhel-server-7.0-x86_64-dvd.iso /rhel7.0 #將7.0映象掛在到/rhel7.0目錄

(6)mount /iso/rhel-server-7.2-x86_64-dvd.iso /rhel7.2 #將7.0映象掛在到/rhel7.2目錄



(7)cd /etc/yum.repos.d
(8)mkdir /repobackup
(9)mv * /repobackup #備份檔案,以便日後使用
(10)vim yum.repo #檔名可以任意,但必須是.repo字尾
(寫入內容:
[rhel7.2] #倉庫名
name=rhel7.2
baseurl=file:///rhel7.2(file:// 訪問本地檔案
))

gpgcheck=0 #對是否官方授權進行檢測,0表示可以安裝非官方軟體


(11)yum clean all #清理快取


4、共享yum源的安裝

在本地yum源安裝完成後,執行如下操作:

(1)安裝apache

yum install httpd #安裝
systemctl start httpd
systemctl enable httpd #開啟服務
systemctl stop firewalld
systemctl disable firewalld #關閉防火牆

systemctl status httpd #檢視服務狀態是否正常



(2)掛載映象
mkdir /var/www/html/rhel7.0
mkdir /var/www/html/rhel7.2 #建立目錄(注意路徑,只有/var/www/html/才能被時別
mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0

mount /iso/rhel-server-7.2-x86_64-dvd.iso /var/www/html/rhel7.2 #掛載映象



(3)訪問測試
在瀏覽器中輸入地址
http://172.25.254.68/rhel7.0

http://172.25.254.68/rhel7.2



(4)配置虛擬機器yum
cd /etc/yum.repos.d
ls
rm -fr *
vim yum.repo
(寫入內容
[rhel7.0]
name=rhel7.0
baseurl=http://172.25.254.68/rhel7.0

gpgcheck=0)

yum clean all


yum install httpd #測試,虛擬機器可以下載軟體



如圖,虛擬機器可以使用yum命令正常下載httpd

注:掛載會在關機後消失,如圖,reboot後掛載消失

(5)為了使其自動掛載,可在掛載後執行作如下操作:

vim /etc/rc.d/rc.local #開機時自動執行的指令碼
(寫入:
mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0

mount /iso/rhel-server-7.2-x86_64-dvd.iso /var/www/html/rhel7.2)


將本地yum源裡yum.repo內容修改為

baseurl=file:///var/www/html/rhel7.2


chmod +x /etc/rc.d/rc.local #新增執行許可權

測試如下:


設定完成後,reboot之後檢視,掛載仍然存在