使用yum安裝軟件
命令:
####查看軟件包
yum list all ##列出yum源倉庫裏面的所有可用的安裝包
yum list installed ##列出所有已經安裝的安裝包
yum list available ##列出沒有安裝的安裝包
####安裝軟件
yum install softwarename ##安裝指定的軟件
yum reinstall softarename ##重新安裝指定的軟件
yum localinstall 第三方software ##安裝第三方文件並且會解決軟件的依賴關係
yum remove softwarename ##卸裝指定的軟件
####查找軟件的信息
yum info software ##查看軟的信息
yum search keywords ##根據關鍵字查找到相關安裝包軟件的信息
yum whatprovides filename ##查找包含指定文件的相關安裝包
####對於軟件組
yum groups list ##列出軟件組
yum groups install ##安裝一個軟件組
yum group remove ##卸載一個軟件組
yum groups info ##查看一個軟件組的信息
關於yum源:
yum源倉庫指向文件指向yum倉庫。
yum源的指向文件存在於/etc/yum.repos.d/目錄下。
以下是通過修改配置倉庫指向文件,製作本地yum源;通過配置http服務和yum倉庫指向文件製作共享yum源。
開始之前看一下查看一下當前的配置裏面有什麼已經安裝好的yum源倉庫
yum repolist
由上面可以知道現在的yum源配置沒有成功可以讀取利用的信息,下面將修改yum倉庫指向文件製作yum的軟件可用安裝源。
第一種:利用iso鏡像文件進行本地yum源的製作
1.掛載
mkdir /mount ##創建的空的文件夾用於掛載iso鏡像文件
mount /iso/ iso的文件的名 /mount ##爲了讓iso鏡像文件能夠被像文件一樣被便利地讀取利用,將iso文件掛載在一個空的文件裏面
(在這裏被掛載的iso鏡像文件是一個存在的yum倉庫,但是系統並不能讀取識別,我們通過修改yum倉庫指向文件讓系統可以讀取到這個倉庫,被我們利用)
2.修改yum源指向文件
mkdir /etc/backup ##創建/etc 下的一個空文件夾用於備份原來的yum源讀取文件
mv /etc/yum.repos.d/* /etc/backup/ ##備份yum倉庫指定文件
touch /etc/yum.repos.d/myyum.repo
cat > /etc/yum.repos.d/myyum.repo<<end ##編寫自己的yum倉庫指向文件(以repo結尾)當讀取yum源的時候系統查找repo結尾文件,讀取文件內容,在相應的地方尋找信息。
>[test]
>name=myyumsource
>baseurl=file:///mount
>gpgcheck=0 ## 0表示不檢查rpm數字證書,1爲檢查rpm數字證書
>end
3.刷新測試
yum clean all ##清空本地/var/cache/yum容器清單列表舊數據。
yum repolist ##列出所有的可用的yum倉庫,執行這個命令,會重讀yum源設置志向文件,刷新本地容器清單列表。
現在看一下我們設置好的yum源倉庫集合
由上面我們可以看到我們的掛載已被成功讀取。
利用已經做好的iso-yum本地源安裝http 服務方便製作共享軟件源
yum install httpd
安裝http服務成功,現在我們啓動一下相關服務。
systemctl start httpd ##開啓http服務
systemctl enable httpd ##設置開機啓動http服務
systemctl stop firewalld ##關閉火牆服務方便下面的htpp服務的使用
第二種:利用iso鏡像文件進行http共享yum源的製作
1.解掛載
umount /mount ##將掛載在/mount下的文件解掛載將要掛載在http服務相關目錄下
2.重新掛載
mkdir /var/www/html/myshare ##在http服務的目錄下面創建一個掛載點(http服務可以默認的服務目錄)
mount /iso/iso文件名 /var/www/html/myshare
刷新服務
systemctl restart httpd
3.瀏覽器測試
打開瀏覽器,輸入設置的主機的ip地址後面加上掛載的文件當看到文件出現則成功了。
添加repo倉庫指向文件,讓系統在尋找yum源的時候可以找到設置的http分享的yum源。
touch /etc/yum.repo.d/myshare.repo
cat > /etc/yum.repos.d/myshare.repo << end
>[share]
>name=mysharesource
>baseurl=http://172.25.6.10/myshare
>gpgcheck=0
>end
yum clean all
yum repolist 出現了錯誤
由於本文裏面我們本地yum源製作和http-yum分享源製作使用了同一個iso文件所以我們解掛載了本地源掛載iso,執行yum repolist 命令yum源找不到我們在倉庫指向文件裏面指定的原本掛載在/mount的內容。現在我們可以修改第一個文件的查找點,讓它找/var/www/html/myshare
掛載點。
yum repolist
這下本地的掛載也成功被讀取了,沒有出現報錯。
由於這僅僅是設置的臨時的掛載我們還可以設置開機自動掛載
cat >> /etc/fstab << end
掛載文件 掛載點 文件類型 掛載參數 備份 檢測
/iso/***.iso /var/www/html/myshare iso9660 ro 0 0
end
利用rpm安裝包文件進行自己的yum倉庫的製作
前面兩種是利用廠商發佈的iso鏡像文件作爲yum倉庫。當我們需要安裝一些第三方提供的軟件的時候我們需要到網上下載rpm的安裝包,但是每次都下載多麻煩,我們可以將較常使用的rpm安裝包歸到一個文件裏面製作成一個可以被系統識別的yum倉庫,通過配置yum倉庫指向文件可以將它設置成本地的yum源也可以是通過http發佈的共享yum源。
1.首先下幾個rpm包放在一個文件夾裏面。
2.生成符合要求的yum倉庫
執行createrepo /software
##將放置rpm安裝包的文件夾創造成一個倉庫文件,文件夾裏面會多出一個repodata倉庫數據文件夾。
可以看到多了一個repodata的倉庫數據文件,此時創建庫成功。
其實在iso的掛載點可以看到它也有一個repodata的文件,這個標誌性的文件夾標誌着這個文件夾具備成爲yum源的可能。
接下來可以修改yum的倉庫文件,製作本地yum源以及http發佈共享yum源。
一個自動執行腳本
#!/bin/bash
###make a local yum source to install httpd service#####
#before start,copy the **.iso to a file i choose '/iso' #
mkdir /mount #make a file use to mount the **.iso
mount /iso/rhel-server-7.0-x86_64-dvd.iso /mount #mount the **.iso to the mount file
mkdir /etc/backup ##make a file to bak the *.repo file
mv /etc/yum.repos.d/* /etc/backup/ #move the *.repo file to the backfile
yum clean all ##to refesh
######add the yum.repo file to add the yum source##
cat > /etc/yum.repos.d/yum.repo << end
>[test]
>name=myyum
>baseurl=file:///mount
>gpgcheck=0
>end
yum clean all ## to refresh
yum repolist ##to see whether the yum-repo-setting is working
### above, the local yum-source is ok! now use the local yum-source we create to down httpd server. setting the httpd server to share the local-iso-source with http###
######install http server###
yum install httpd -y ##install the httpd server
systemctl start httpd ##start the httpd server
systemctl enable httpd ##set start httpd server every time start the sys
systemctl stop firewalld
systemctl disable firewalld
###setting http server let the httpd server can find our iso source
umount /mount #unmount the **iso file inorder to let it mount under the http sserver
yum clean all
yum repolist
mkdir /var/www/html/myshare ##make a file in http server-file to let it find the iso-source
mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/myshare ##mount the iso-source to the http server
systemctl restart httpd
###now because we unmount the /mount that we set local-source to mount the http server so we can not use localyum###
###to modify the local-yum-source to let it share the source with http server###
cat > /etc/yum.repos.d/yum.repo << end
>[test]
>name=myyum
>baseurl=http://172.25.6.11/myshare
>gpgcheck=0
>end
yum clean all
yum repolist
#####set automount when start the system######
cat >> /etc/fstab << end
>/iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/myshare iso9660 ro 0 0
>end
all