centos--軟件源--本地軟件源---離線安裝

1、軟件源配置文件

一、/etc/yum.conf 配置文件python

[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

二、關於*.repo文件linux

[fedora]      #方括號裏面的是軟件源的名稱,將被yum取得並識別

name=Fedora $releasever - $basearch   #這裏也定義了軟件 倉庫的名稱,一般是爲了方便閱讀配置文件,通常沒什麼做用,$releasever變量定義了發行版本,一般是8,9,10等數字,$basearch變 量定義了系統的架構,能夠是i38六、x86_6四、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

2、更換軟件源

第一步:備份你的原鏡像文件,以避免出錯後能夠恢復。git

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

第二步:下載新的CentOS-Base.repo 到/etc/yum.repos.d/centos

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 

3、本地rpm包變成軟件源--不是iso,是含有rpm包的文件夾

一、上傳r全部的pm包放到以下目錄服務器

mkdir  /opt/localserver/ 

 二、安裝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

三、把文件夾變成軟件源,利用createrepo建立yum倉庫,建立索引信息(須要等待一段時間)ide

  cd  /opt/localserver
  createrepo -v ./

 四、配置文件,將/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時無需配置

注意刪除全部的中文

 五、安裝成功後,測試:

[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

4、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源緩存

 

5、離線安裝軟件的方式

 一、yum 命令的 Downloadonly 插件下載 RPM 軟件包及其全部依賴包後,上傳 到服務器上安裝

yum install yum-plugin-downloadonly

 二、yum install --downloadonly --downloaddir=<directory> <package-name> 下載包

yum install --downloadonly --downloaddir=/root/mypackages/ httpd

 三、ls /root/mypackages/ 查看下載的包,並上傳到服務器

cd 進入到目錄

rpm  -ivh   *.rpm
相關文章
相關標籤/搜索