因爲單位的服務器均使用的是內網,而安裝一些軟件如Git,須要不少的依賴包,使用yum安裝相對簡單,因爲不能聯網故配置本地yum源配置。html
1.首先將須要rpm庫添加到系統中:python
1).虛擬機中安裝的linux操做系統:則只需將安裝包ISO文件掛載到media下面(如沒法掛載請參考http://www.cnblogs.com/shenliang123/p/3203278.html)linux
2).單獨的服務器系統,則先在/media下新建centos(名字能夠自定義,但與下面4中添加的目錄相關),而後將ISO包裏面的內容所有複製到該文件夾中git
2.進入到 /etc/yum.repos.d/ ,該目錄下包含了四個文件:centos
[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,因此選了另一種方法從新安裝:this
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