一、軟件源配置文件
1、/etc/yum.conf 配置文件
[main] cachedir=/var/cache/yum #yum下載的RPM包的緩存目錄 keepcache=0 #緩存是否保存,1保存,0不保存。 debuglevel=2 #調試級別(0-10),默認為2(具體調試級別的應用,我也不了解)。 logfile=/var/log/yum.log #yum的日志文件所在的位置 exactarch=1 #在更新的時候,是否允許更新不同版本的RPM包,比如是否在i386上更新i686的RPM包。 obsoletes=1 #這是一個update的參數,具體請參閱yum(8),簡單的說就是相當於upgrade,允許更新陳舊的RPM包。 gpgcheck=1 #是否檢查GPG(GNU Private Guard),一種密鑰方式簽名。 plugins=1 #是否允許使用插件,默認是0不允許,但是我們一般會用yum-fastestmirror這個插件。 installonly_limit=3 #允許保留多少個內核包。 exclude=selinux* #屏蔽不想更新的RPM包,可用通配符,多個RPM包之間使用空格分離。 # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE or IN separate files named file.repo # in /etc/yum.repos.d
2、關於*.repo文件
[fedora] #方括號里面的是軟件源的名稱,將被yum取得並識別 name=Fedora $releasever - $basearch #這里也定義了軟件 倉庫的名稱,通常是為了方便閱讀配置文件,一般沒什么作用,$releasever變量定義了發行版本,通常是8,9,10等數字,$basearch變 量定義了系統的架構,可以是i386、x86_64、ppc等值,這兩個變量根據當前系統的版本架構不同而有不同的取值,這可以方便yum升級的時候選擇 適合當前系統的軟件包,以下同…… failovermethod=priority #failovermethod 有兩個值可以選擇,priority是默認值,表示從列出的baseurl中順序選擇鏡像服務器地址,roundrobin表示在列出的服務器中隨機選擇 exclude=compiz* *compiz* fusion-icon* #exclude這個選項是后來我自己加上去的,用來禁止這個軟件倉庫中的某些軟件包的安裝和更新,可以使用通配符,並以空格分隔,可以視情況需要自行添加 #baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/ #上面的一行baseurl第一個字符是'#'表示該行已經被注釋,將不會被讀取,這一行的意思是指定一個baseurl(源的鏡像服務器地址) #mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch #上面的這一行是指定一個鏡像服務器的地址列表,通常是開啟的,本例中加了注釋符號禁用了,我們可以試試,將$releasever和$basearch替換成自己對應的版本和架構,例如10和i386,在瀏覽器中打開,我們就能看到一長串鏡可用的鏡像服務器地址列表。 選擇自己訪問速度較快的鏡像服務器地址復制並粘貼到repo文件中,我們就能獲得較快的更新速度了,格式如下baseurl所示: baseurl= ftp://ftp.sfc.wide.ad.jp/pub/Linux/Fedora/releases/10/Everything/i386/os http://ftp.chg.ru/pub/Linux/fedora/linux/releases/10/Everything/i386/os http://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/releases/10/Everything/i386/os http://mirror.nus.edu.sg/fedora/releases/10/Everything/i386/os http://mirror.yandex.ru/fedora/linux/releases/10/Everything/i386/os http://ftp.twaren.net/Linux/Fedora/linux/releases/10/Everything/i386/os http://ftp.itu.edu.tr/Mirror/Fedora/linux/releases/10/Everything/i386/os enabled=1 #這個選項表示這個repo中定義的源是啟用的,0為禁用 gpgcheck=1 #這個選項表示這個repo中下載的rpm將進行gpg的校驗,已確定rpm包的來源是有效和安全的 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch #定義用於校驗的gpg密鑰 ##以下的軟件倉庫基本上用不到,選項含義同上 [fedora-debuginfo] name=Fedora $releasever - $basearch - Debug failovermethod=priority #baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/debug/ mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-debug-$releasever&arch=$basearch enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch [fedora-source] name=Fedora $releasever - Source failovermethod=priority #baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/source/SRPMS/ mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-source-$releasever&arch=$basearch enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
二、更換軟件源
第一步:備份你的原鏡像文件,以免出錯后可以恢復。
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
第二步:下載新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
Centos7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
三、本地rpm包變成軟件源--不是iso,是含有rpm包的文件夾
1、上傳r所有的pm包放到如下目錄
mkdir /opt/localserver/
2、安裝createrepo命令
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
3、把文件夾變成軟件源,利用createrepo創建yum倉庫,創建索引信息(需要等待一段時間)
cd /opt/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源目錄,源地址為rpm的目錄 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
四、iso軟件源的配置
mv CentOS-7.0-1406-x86_64-DVD.iso /mnt mkdir /mnt/centos #創建鏡像掛載目錄 vi /etc/fstab #配置開機自動掛載iso鏡像 #追加下面一行 /mnt/CentOS-7.0-1406-x86_64-DVD.iso /mnt/centos iso9660 defaults,ro,loop 0 0 mount -a #全量掛載一次 sudo vi /etc/yum.repos.d/CentOS-Local.repo #新建本地源配置文件 #添加下面幾行 [local] name=local baseurl=file:///mnt/centos enabled=1 gpgcheck=1 gpgkey=file:///mnt/centos/RPM-GPG-KEY-CentOS-7 #接着重建下yum源緩存
五、離線安裝軟件的方式
1、yum 命令的 Downloadonly 插件下載 RPM 軟件包及其所有依賴包后,上傳 到服務器上安裝
yum install yum-plugin-downloadonly
2、yum install --downloadonly --downloaddir=<directory> <package-name> 下載包
yum install --downloadonly --downloaddir=/root/mypackages/ httpd
3、ls /root/mypackages/ 查看下載的包,並上傳到服務器
cd 進入到目錄
rpm -ivh *.rpm