Linux本地yum配置

聽海★藍心夢發表於2013-09-23

安裝本地yum,可以很方便的安裝本地的系統包。就Linux作業系統而言,一般的安裝包都在光碟目錄下的Server資料夾下(RedHat 6以後資料夾為Packages)。
一、尋找包源
如果是物理機器,一般透過掛載光碟來獲取光碟包上的rpm包。掛載光碟命令如下:
[root@localhost Server]# mount /dev/dvd-sr1 /mnt/rhel

如果是虛擬機器透過iso安裝,則光碟掛載的命令如下:
[root@localhost Server]# mount -o loop /root/rhel-server-5.4-i386-dvd.iso /mnt/rhel

如果有多臺機器,一張光碟,為了不頻繁的跑到機房去換盤,則可以把Server資料夾直接複製到系統本地,然後再下面的yum源配置檔案中,把baseurl直接指向該資料夾即可。

二、配置yum
方法一:
設定yum源:
直接在/etc/yum.repos.d資料夾狹隘建立新的repo檔案即可,檔名可以任意指定。
[root@localhost Server]# vi /etc/yum.repos.d/local.repo
[dvd]
name=install dvd
baseurl=file:///mnt/rhel/Server
enabled=1
gpgcheck=0

配置完yum源之後,記得要清除舊記錄並生成新的倉庫。
[root@localhost Server]# yum clean all
Loaded plugins: rhnplugin, security
Cleaning up Everything
[root@localhost Server]# yum list
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Installed Packages
Deployment_Guide-en-US.noarch                                         5.2-11                                               installed
GConf2.i386                                                           2.14.0-9.el5                                         installed
GConf2.x86_64                                                         2.14.0-9.el5                                         installed
ImageMagick.i386                                                      6.2.8.0-4.el5_1.1                                    installed
ImageMagick.x86_64                                                    6.2.8.0-4.el5_1.1                                    installed
MAKEDEV.x86_64                                                        3.23-1.2                                             installed
NetworkManager.i386                                                   1:0.7.0-3.el5                                        installed
NetworkManager.x86_64                                                 1:0.7.0-3.el5                                        installed
NetworkManager-glib.i386                                              1:0.7.0-3.el5                                        installed
NetworkManager-glib.x86_64                                            1:0.7.0-3.el5                                        installed
NetworkManager-gnome.x86_64                                           1:0.7.0-3.el5                                        installed
ORBit2.i386                                                           2.14.3-5.el5                                         installed
ORBit2.x86_64                                                         2.14.3-5.el5                                         installed
OpenIPMI.x86_64                                                       2.0.6-11.el5                                         installed
OpenIPMI-libs.x86_64                                                  2.0.6-11.el5                                         installed
OpenIPMI-tools.x86_64                                                 2.0.6-11.el5                                         installed
PyQt.x86_64                                                           3.16-4                                               installed
PyXML.x86_64                                                          0.8.4-4                                              installed
SysVinit.x86_64                                                       2.86-15.el5                                          installed
Xaw3d.x86_64                                                          1.5E-10.1                                            installed
..............................................省略去了很多包........................................................................
yum-rhn-plugin.noarch                                                 0.5.3-30.el5                                         installed
yum-security.noarch                                                   1.1.16-13.el5                                        installed
yum-updatesd.noarch                                                   1:0.9-2.el5                                          installed
zenity.x86_64                                                         2.16.0-2.el5                                         installed
zip.x86_64                                                            2.31-2.el5                                           installed
zisofs-tools.x86_64                                                   1.0.6-3.2.2                                          installed
zlib.i386                                                             1.2.3-3                                              installed
zlib.x86_64                                                           1.2.3-3                                              installed
zsh.x86_64                                                            4.2.6-1                                              installed

測試yum install:
[root@localhost yum.repos.d]# yum install samba
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
dvd                                                                                                          | 1.3 kB     00:00    
primary.xml.gz                                                                                               | 825 kB     00:00    
dvd                                                            2985/2985
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--&gt Running transaction check
---&gt Package samba.x86_64 0:3.0.33-3.7.el5 set to be updated
--&gt Processing Dependency: perl(Convert::ASN1) for package: samba
--&gt Running transaction check
---&gt Package perl-Convert-ASN1.noarch 0:0.20-1.1 set to be updated
--&gt Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                               Arch                       Version                             Repository               Size
====================================================================================================================================
Installing:
 samba                                 x86_64                     3.0.33-3.7.el5                      dvd                      16 M
Installing for dependencies:
 perl-Convert-ASN1                     noarch                     0.20-1.1                            dvd                      41 k

Transaction Summary
====================================================================================================================================
Install      2 Package(s)        
Update       0 Package(s)        
Remove       0 Package(s)        

Total download size: 16 M
Is this ok [y/N]: y
Downloading Packages:
------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                               1.8 GB/s |  16 MB     00:00    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : perl-Convert-ASN1                                 [1/2]
  Installing     : samba                                             [2/2]

Installed: samba.x86_64 0:3.0.33-3.7.el5
Dependency Installed: perl-Convert-ASN1.noarch 0:0.20-1.1
Complete!

方法二:
1、安裝createrepo
createrepo是配置YUM源的配置工具,檢查當前是否已經安裝createrepo包的安裝情況:
[root@localhost Server]# rpm  -qa |grep  createrepo 

如果顯示為尚未安裝,則需要執行如下的命令完成安裝:
[root@localhost Server]# rpm  -ivh  createrepo-0.4.11-3.el5.noarch.rpm
warning: createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
   1:createrepo             ########################################### [100%]
 
2、建立yum repository的xml-rpm-metadata
 
執行如下命令:

[root@localhost yum.repos.d]# createrepo  -g  /mnt/rhel/Server/repodata/comps-rhel5-server-core.xml  /var/yum/Server/
[root@localhost yum.repos.d]# createrepo  -g  /mnt/rhel/VT/repodata/comps-rhel5-vt.xml  /var/yum/VT/
[root@localhost yum.repos.d]# createrepo  -g  /mnt/rhel/Cluster/repodata/comps-rhel5-cluster.xml  /var/yum/Cluster/
[root@localhost yum.repos.d]# createrepo -g  /mnt/rhel/ClusterStorage/repodata/comps-rhel5-cluster-st.xml  /var/yum/ClusterStorage/

執行createrepo命令後系統會自動掃描相關目錄,將rpm包加入到YUM源的資料庫中。

3、建立本地yum客戶端的repo檔案
配置使用本地yum repository:
[root@localhost yum.repos.d]# cd  /etc/yum.repos.d
[root@localhost yum.repos.d]# vim local.repo
  (名字可以隨便起,但是要以.repo為字尾)
接下來在檔案中新增如下內容後儲存:
[local]                                                #(yum塊區域)
name=aaa                                      #  (名字可以隨便起)
baseurl=file:///mnt/rhel/Server     #(搜尋路徑,必須指向你本機的yum源路徑)
gpgcheck=0                                    #(gpgcheck是gpg驗證是否開啟的選項,1是開啟,0是不開啟,一般情況可以關掉)
enabled=1                                      #(是否啟用,0為不啟用,1為啟用,過沒這一項,就是啟用)
 
[VT]
name=VT
baseurl=file:///var/yum/VT
gpgcheck=0
 
[Cluster]
name= Cluster
baseurl=file:///var/yum/Cluster
gpgcheck=0
 
[CS]
name= ClusterStorage
baseurl=file:///var/yum/ClusterStorage
gpgcheck=0

4、測試使用yum來安裝軟體包
[root@localhost yum.repos.d]# yum install samba
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
dvd                                                                                                          | 1.3 kB     00:00    
primary.xml.gz                                                                                               | 825 kB     00:00    
dvd                                                            2985/2985
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--&gt Running transaction check
---&gt Package samba.x86_64 0:3.0.33-3.7.el5 set to be updated
--&gt Processing Dependency: perl(Convert::ASN1) for package: samba
--&gt Running transaction check
---&gt Package perl-Convert-ASN1.noarch 0:0.20-1.1 set to be updated
--&gt Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                               Arch                       Version                             Repository               Size
====================================================================================================================================
Installing:
 samba                                 x86_64                     3.0.33-3.7.el5                      dvd                      16 M
Installing for dependencies:
 perl-Convert-ASN1                     noarch                     0.20-1.1                            dvd                      41 k

Transaction Summary
====================================================================================================================================
Install      2 Package(s)        
Update       0 Package(s)        
Remove       0 Package(s)        

Total download size: 16 M
Is this ok [y/N]: y
Downloading Packages:
------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                               1.8 GB/s |  16 MB     00:00    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : perl-Convert-ASN1                                 [1/2]
  Installing     : samba                                             [2/2]

Installed: samba.x86_64 0:3.0.33-3.7.el5
Dependency Installed: perl-Convert-ASN1.noarch 0:0.20-1.1
Complete!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/751371/viewspace-773266/,如需轉載,請註明出處,否則將追究法律責任。

相關文章