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
相关文章
相关标签/搜索