ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux本地yum配置

Linux本地yum配置

原创 Linux操作系统 作者:听海★蓝心梦 时间:2013-09-23 22:30:31 0 删除 编辑

安装本地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
--> Running transaction check
---> Package samba.x86_64 0:3.0.33-3.7.el5 set to be updated
--> Processing Dependency: perl(Convert::ASN1) for package: samba
--> Running transaction check
---> Package perl-Convert-ASN1.noarch 0:0.20-1.1 set to be updated
--> 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
--> Running transaction check
---> Package samba.x86_64 0:3.0.33-3.7.el5 set to be updated
--> Processing Dependency: perl(Convert::ASN1) for package: samba
--> Running transaction check
---> Package perl-Convert-ASN1.noarch 0:0.20-1.1 set to be updated
--> 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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-02-18

  • 博文量
    256
  • 访问量
    1197811