Yum(全稱為 Yellow dog Updater, Modified)是一個在Fedora和RedHat以及CentOS中的Shell前端軟件包管理器。基于RPM包管理,能夠從指定的服務器自動下載RPM包并且安裝,可以自動處理依賴性關系,并且一次安裝所有依賴的軟件包,無須繁瑣地一次次下載、安裝。
使用本地yum源有兩種方式:第一直接使用光盤鏡像,不過此方法僅限本機使用;第二種創建本地倉庫,然后使用http或者nfs和ftp等方式向外部提供yum repository。
第一種:如何使用發行版光盤作為yum repository(以CentOS 6.8為例實驗)
1.掛載光盤到制定掛載點: 此處我們使用CentOS的自動掛載功能來實現:
[root@localhost ~]# cd /misc
[root@localhost misc]# cd cd
[root@localhost cd]# ls
CentOS_BuildTag GPL Packages RPM-GPG-KEY-CentOS-6
RPM-GPG-KEY-CentOS-Testing-6
EFI images RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Debug-6
TRANS.TBL
EULA isolinux repodata RPM-GPG-KEY-CentOS-
Security-6
2.新建yum repo配置文件:
[root@localhost cd]# cd /etc/yum.repos.d [root@localhost yum.repos.d]# ls base.repo [root@localhost yum.repos.d]# cat base.repo #必須以.repo結尾 # # # # [base] #倉庫的ID唯一不能重復 name=CentOS 7 #倉庫功能的描述 baseurl=file:///misc/cd/ #repodata所在路徑 enabled=1 #開啟倉庫,0是關閉,不寫默認是1 gpgcheck=1 #是否檢查gpg,1是檢查,0是不檢查 gpgkey=file:///etc/pki/rpm-gpg/ #gpgkey的路徑
第二種:創建本地yum倉庫
如果你是一名運維工程師,為了方便公司內部網絡中的服務器安裝軟件,同時也節省網絡帶寬,此時就可以在公司內部創建一個yum倉庫。
具體步驟:
1.在發行版光盤中尋找createrepo:
[root@localhost ~]# type createrepo createrepo is hashed (/usr/bin/createrepo) #此處安裝系統時已做安裝
2.確定repository輸出方式:
(1)本地輸出:提供一個放置rpm包的本地路徑;file的形式
(2)網絡輸出:提供一個文件服務器,配置好ftp或http服務;
ftp服務:
安裝程序包:vsftpd
文件存放路徑:/var/ftp/pub
啟動服務:service vsftpd start
http服務:
安裝程序包:httpd
文件存放路徑:/var/www/html
啟動服務:service httpd start
注意確保防火墻關閉;
我們此處以本地輸出為例。
3.在準備好的目錄中放置rpm程序包文件
可以通過cp命令將光盤中的程序包拷貝到以上輸出目錄當中。
[root@localhost ~]# mkdir yum
[root@localhost ~]# cp mogilefs/* yum
[root@localhost ~]# cp galera_cluster/* yum
#創建yum文件夾并做了倉庫路徑,將準備好的rpm包復制進yum目錄當中
[root@localhost ~]# cd yum [root@localhost yum]# ls galera-25.3.9-1.rhel7.el7.centos.x86_64.rpm MariaDB-5.5.46-centos7-x86_64-shared.rpm Perlbal-1.78-1.el6.noarch.rpm jemalloc-3.6.0-1.el7.x86_64.rpm MariaDB-5.5.46-centos7-x86_64-test.rpm Perlbal-doc-1.78-1.el6.noarch.rpm jemalloc-devel-3.6.0-1.el7.x86_64.rpmMariaDB-Galera-5.5.46-centos7-x86_64-server.rpm perl-Danga-Socket-1.61-1.el6.rf.noarch.rpm MariaDB-5.5.46-centos7-x86_64-client.rpm MariaDB-Galera-5.5.46-centos7-x86_64-test.rpmperl-MogileFS-Client-1.14-1.el6.noarch.rpm MariaDB-5.5.46-centos7-x86_64-common.rpm MogileFS-Server-2.46-2.el6.noarch.rpmperl-Net-Netmask-1.9015-8.el6.noarch.rpm MariaDB-5.5.46-centos7-x86_64-compat.rpm MogileFS-Server-mogilefsd-2.46-2.el6.noarch.rpm perl-Perlbal-1.78-1.el6.noarch.rpm MariaDB-5.5.46-centos7-x86_64-devel.rpm MogileFS-Server-mogstored-2.46-2.el6.noarch.rpm MariaDB-5.5.46-centos7-x86_64-server.rpm MogileFS-Utils-2.19-1.el6.noarch.rpm
4.對此目錄運行createrepo命令即可
cd到yum目錄執行createrepo;
[root@localhost ~]# createrepo yum Spawning worker 0 with 6 pkgs Spawning worker 1 with 6 pkgs Spawning worker 2 with 5 pkgs Spawning worker 3 with 5 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete 
此處可以看到repodata文件夾已經創建成功
下面我們來測試創建的yum倉庫是否可用
1.在本機/etc/yum.repos.d/目錄中創建一個.repo結尾的文件,這里我們就叫test.repo,里面添加上如下內容:
[root@localhost yum]# cd /etc/yum.repos.d [root@localhost yum.repos.d]# touch test.repo
[root@localhost yum]# yum list
2.在本機上更新本地yum緩存
清理緩存:yum clean all
[root@localhost yum.repos.d]# yum clean all Loaded plugins: fastestmirror, langpacks Cleaning repos: test Cleaning up everything Cleaning up list of fastest mirrors
創建緩存:yum makecache
root@localhost yum.repos.d]# yum makecache Loaded plugins: fastestmirror, langpacks test| 2.9 kB 00:00:00 (1/3): test/filelistsdb| 67 kB 00:00:00 (2/3): test/otherdb| 4.0 kB 00:00:00 (3/3): test/primary_db | 25 kB 00:00:00 Determining fastest mirrors Metadata Cache Created
3.查詢新的yum倉庫內容
yum list all
[root@localhost yum.repos.d]# yum list all Available Packages MariaDB-Galera-server.x86_64 5.5.46-1.el7.centos test MariaDB-Galera-test.x86_64 5.5.46-1.el7.centos test MariaDB-client.x86_645.5.46-1.el7.centos test MariaDB-common.x86_645.5.46-1.el7.centos test MariaDB-compat.x86_645.5.46-1.el7.centos test MariaDB-devel.x86_64 5.5.46-1.el7.centos test MariaDB-server.x86_645.5.46-1.el7.centos test MariaDB-shared.x86_645.5.46-1.el7.centos test MariaDB-test.x86_64 5.5.46-1.el7.centos test MogileFS-Server.noarch 2.46-2.el6 test MogileFS-Server-mogilefsd.noarch 2.46-2.el6 test MogileFS-Server-mogstored.noarch 2.46-2.el6 test MogileFS-Utils.noarch2.19-1.el6 test Perlbal.noarch 1.78-1.el6 test Perlbal-doc.noarch 1.78-1.el6 test galera.x86_6425.3.9-1.rhel7.el7.centostest jemalloc.x86_64 3.6.0-1.el7 test jemalloc-devel.x86_643.6.0-1.el7 test perl-Danga-Socket.noarch 1.61-1.el6.rftest perl-MogileFS-Client.noarch 1.14-1.el6 test perl-Net-Netmask.noarch 1.9015-8.el6 test perl-Perlbal.noarch 1.78-1.el6
4.安裝應用
yum install [Packge_name]
[root@localhost yum.repos.d]# yum install Perlbal.noarch Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package Perlbal.noarch 0:1.78-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved =========================================================================================================================================== Package ArchVersion Repository Size =========================================================================================================================================== Installing: Perlbal noarch 1.78-1.el6 test 5.7 k Transaction Summary =========================================================================================================================================== Install 1 Package Total download size: 5.7 k Installed size: 4.4 k Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : Perlbal-1.78-1.el6.noarch 1/1 Verifying : Perlbal-1.78-1.el6.noarch 1/1 Installed: Perlbal.noarch 0:1.78-1.el6 Complete!
安裝測試成功!
原創文章,作者:YOUNG,如若轉載,請注明出處:http://www.www58058.com/38965