Centos6.4 本地yum源配置


由於單位的服務器均使用的是內網,而安裝一些軟件如Git,需要很多的依賴包,使用yum安裝相對簡單,由於不能聯網故配置本地yum源配置。

1.首先將需要rpm庫添加到系統中:

1).虛擬機中安裝的linux操作系統:則只需將安裝包ISO文件掛載到media下面(如無法掛載請參考http://www.cnblogs.com/shenliang123/p/3203278.html)

2).單獨的服務器系統,則先在/media下新建centos(名字可以自定義,但與下面4中添加的目錄相關),然后將ISO包里面的內容全部復制到該文件夾中

2.進入到 /etc/yum.repos.d/  ,該目錄下包含了四個文件:

[root@sl media]# ls -l /etc/yum.repos.d/
total 16
-rw-r--r--. 1 root root 1926 Feb 25  2013 CentOS-Base.repo
-rw-r--r--. 1 root root  638 Feb 25  2013 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  630 Feb 25  2013 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Feb 25  2013 CentOS-Vault.repo

3.將 CentOS-Base.repo和CentOS-Debuginfo.repo兩個文件改名,繞過網絡安裝:

[root@sl yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repose_bak
[root@sl yum.repos.d]# mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo_bak

4.編輯文件CentOS-Media.repo:(也可以自己新增一個repo文件,more用於查看,使用vi進行編輯)

[root@sl yum.repos.d]# more CentOS-Media.repo  #repo后綴
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-6.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c6-media [command]
#
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c6-media [command]

[c6-media]               #庫名稱
name=CentOS-$releasever - Media  #名稱描述
baseurl=file:///media/centos/     #yum源目錄,源地址
gpgcheck=1                #檢查GPG-KEY,0為不檢查,1為檢查
enabled=1               #是否用該yum源,0為禁用,1為使用
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6  #gpgcheck=0時無需配置

5.測試yum是否配置成功:

[root@sl yum.repos.d]# yum list
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Installed Packages
ConsoleKit.x86_64                        0.4.1-3.el6                          @anaconda-CentOS-201303020151.x86_64/6.4
ConsoleKit-libs.x86_64                   0.4.1-3.el6                          @anaconda-CentOS-201303020151.x86_64/6.4
MAKEDEV.x86_64                           3.24-6.el6                           @anaconda-CentOS-201303020151.x86_64/6.4
MySQL-python.x86_64                      1.2.3-0.3.c1.1.el6                   @anaconda-CentOS-201303020151.x86_64/6.4
PyGreSQL.x86_64                          3.8.1-2.el6                          @anaconda-CentOS-201303020151.x86_64/6.4
SDL.x86_64                               1.2.14-3.el6                         @anaconda-CentOS-201303020151.x86_64/6.4
TurboGears2.noarch                       2.0.3-4.el6                          @anaconda-CentOS-201303020151.x86_64/6.4
abrt.x86_64                              2.0.8-15.el6.centos                  @anaconda-CentOS-201303020151.x86_
more.........

6.清除yum緩存:

[root@sl yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, security
Cleaning repos:
Cleaning up Everything
Cleaning up list of fastest mirrors

 

可能由於沒有使用光驅的緣故,以上設置后安裝一直報nothing to do,所以選了另外一種方法重新安裝:

1.將yum源放到/opt目錄下,並復制系統安裝包下的packages文件夾中所有的repo文件

[root@sl opt]# mkdir yumserver
[root@sl opt]# cp -rv /media/centos/Packages/* /opt/yumserver/

2.安裝createrepo命令

[root@sl opt]# cd localserver/
[root@sl localserver]# rpm -ivh createrepo-0.9.9-17.el6.noarch.rpm
warning: createrepo-0.9.9-17.el6.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
        python-deltarpm is needed by createrepo-0.9.9-17.el6.noarch

以上提示安裝失敗,需要安裝依賴包:python-deltarpm

[root@sl localserver]# rpm -ivh createrepo-0.9.9-17.el6.noarch.rpm python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
warning: createrepo-0.9.9-17.el6.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
   1:deltarpm               ########################################### [ 33%]
   2:python-deltarpm        ########################################### [ 67%]
   3:createrepo             ########################################### [100%]

createrepo安裝成功

3.利用createrepo創建yum倉庫,創建索引信息(需要等待一段時間)

[root@sl localserver]# createrepo -v ./

4.配置文件,將/etc/yum.repos.d/下現存文件都刪除或重命名.bak,然后新建一個local.repo文件,並添加相應內容:

[root@sl yum.repos.d]# touch local.repo
[root@sl yum.repos.d]# vi local.repo  #repo后綴
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-6.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c6-media [command]
#
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c6-media [command]

[local]               #庫名稱
name=CentOS-local                 #名稱描述
baseurl=file:///opt/localserver/    #yum源目錄,源地址
gpgcheck=1             #檢查GPG-KEY,0為不檢查,1為檢查
enabled=1             #是否用該yum源,0為禁用,1為使用
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6  #gpgcheck=0時無需配置        

5.安裝成功后,測試:

[root@sl yum.repos.d]# yum clean all          #清除緩存
Loaded plugins: fastestmirror, security
Cleaning repos:
Cleaning up Everything
Cleaning up list of fastest mirrors

[root@sl yum.repos.d]# yum makecache        #重新建立緩存
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
local                                                                                           | 2.9 kB     00:00 ...
local/filelists_db                                                                              | 3.9 MB     00:00 ...
local/other_db                                                                                  | 1.7 MB     00:00 ...
Metadata Cache Created
    

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM