linux配置yum源

yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。

--1.1 实验环境

RHEL6:虚拟机

--1.2 挂载光驱

(在VMware虚拟机下,可共享主机本地磁盘上的解压后的镜像文件,直接copy里面的Packages目录到/opt/rpm/local_repo/) [root@redhat6 yum.repos.d]# mount /dev/cdrom /mnt    

mount: block device /dev/sr0 is write-protected, mounting read-only 备注:将光盘 ISO 文件挂载到目录 /mnt 

卸载:umount /mnt

========

如果是iso镜像文件,挂载方式如下:

#mkdir -p /opt/rpm/local_repo/

#mount -o loop -t iso9660 /tmp/rhel-server-6.3-x86_64-dvd.iso   /mnt --之后,可在/mnt目录下看到iso镜像里的所有文件。

把/mnt/Packages下的所有rpm名拷贝到/opt/rpm/local_repo

--1.3 创建本地目录,用来 copy 光盘包

[root@redhat6 local_repo]# mkdir -p /opt/rpm/local_repo

--1.4 copy RPM 包到指定目录

[root@redhat6 log]# cd /mnt/Packages/ [root@redhat6 Packages]# cp * /opt/rpm/local_repo

--1.5 安装 createrepo 包

[root@redhat6 local_repo]# rpm -ivh createrepo-0.9.8-4.el6.noarch.rpm

warning: createrepo-0.9.8-4.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies:         deltarpm is needed by createrepo-0.9.8-4.el6.noarch        

python-deltarpm is needed by createrepo-0.9.8-4.el6.noarch You have new mail in /var/spool/mail/root

--1.5.1根据提示,安装需要的包

 [root@redhat6 local_repo]# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.i686.rpm

warning: deltarpm-3.5-0.5.20090913git.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing...                ########################################### [100%]    1:deltarpm               ########################################### [100%]

[root@redhat6 local_repo]

# [root@redhat6 local_repo]#

[root@redhat6 local_repo]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm

warning: python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing...                ########################################### [100%]    1:python-deltarpm        ########################################### [100%]

[root@redhat6 local_repo]# rpm -ivh createrepo-0.9.8-4.el6.noarch.rpm

warning: createrepo-0.9.8-4.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing...                ########################################### [100%]    1:createrepo             ########################################### [100%]          备注:createrepo 包安装成功   

--1.6 创建 repo 数据库  

[root@redhat6 local_repo]# createrepo -d /opt/rpm/local_repo

1944/2804 - MAKEDEV-3.24-6.el6.i686.rpm                                       

  iso-8859-1 encoding on Ville [email protected]> - 2.8.2-2

2804/2804 - perl-Archive-Extract-0.38-119.el6_1.1.i686.rpm      Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete             

备注:这个步骤需要点时间。 (配置完成)

--1.7 编写 /etc/yum.repos.d/local_repo.repo 文件

   文件 /etc/yum.repos.d/local_repo.repo   内容如下。

 [rhel-source]
name=Red Hat Enterprise Linux Local repo  
##仓库描述
baseurl=file:///opt/rpm/local_repo        
##软件仓库位置
enabled=1                                 
##是否启用
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release  
##签名秘钥

=======================================

关于gpgkey的值说明:应该填写什么值要到/etc/pki/rpm-gpg目录下去查看。根据自己安装的操作系统来填写相应的值。

[root@localhost rpm-gpg]# pwd
/etc/pki/rpm-gpg
[root@localhost rpm-gpg]# ls
RPM-GPG-KEY RPM-GPG-KEY-fedora RPM-GPG-KEY-fedora-test RPM-GPG-KEY-oracle

二 yum 源测试

yum的命令形式一般是如下:

yum [options] [command] [package ...]

其中的[options]是可选的,选项包括-h(帮助),-y(当安装过程提示选择全部为"yes"),-q(不显示安装的过程)等等。[command]为所要进行的操作,[package ...]是操作的对象。

概括了部分常用的命令包括:

自动搜索最快镜像插件:   yum install yum-fastestmirror

安装yum图形窗口插件:    yum install yumex

查看可能批量安装的列表: yum grouplist

1 安装 yum install 全部安装 yum install package1 安装指定的安装包package1 yum groupinsall group1 安装程序组group1

2 更新和升级 yum update 全部更新 yum update package1 更新指定程序包package1 yum check-update 检查可更新的程序 yum upgrade package1 升级指定程序包package1 yum groupupdate group1 升级程序组group1

3 查找和显示 yum info package1 显示安装包信息package1 yum list 显示所有已经安装和可以安装的程序包 yum list package1 显示指定程序包安装情况package1 yum groupinfo group1 显示程序组group1信息yum search string 根据关键字string查找安装包

4 删除程序 yum remove | erase package1 删除程序包package1 yum groupremove group1 删除程序组group1 yum deplist package1 查看程序package1依赖情况

5 清除缓存 yum clean packages 清除缓存目录下的软件包 yum clean headers 清除缓存目录下的 headers yum clean oldheaders 清除缓存目录下旧的 headers yum clean, yum clean all (= yum clean packages; yum clean oldheaders) 清除缓存目录下的软件包及旧的headers  be disabled. Setting up Insta

《FROM:http://francs3.blog.163.com/blog/static/40576727201221644041342/

四、错误处理:

[root@localhost rpm-gpg]# yum install ksh  --执行yum安装测试时发生错误,如下:
已加载插件:langpacks
http://public-yum.oracle.com/repo/OracleLinux/OL7/UEKR3/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: public-yum.oracle.com; 未知的错误"
正在尝试其它镜像。


One of the configured repositories failed (Latest Unbreakable Enterprise Kernel for Oracle Linux 7Server (x86_64)),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:

1. Contact the upstream for the repository and get them to fix the problem.

2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).

3. Disable the repository, so yum won't use it by default. Yum will then
just ignore the repository until you permanently enable it again or use
--enablerepo for temporary usage:

yum-config-manager --disable ol7_UEKR3

4. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:

yum-config-manager --save --setopt=ol7_UEKR3.skip_if_unavailable=true

failure: repodata/repomd.xml from ol7_UEKR3: [Errno 256] No more mirrors to try.
http://public-yum.oracle.com/repo/OracleLinux/OL7/UEKR3/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: public-yum.oracle.com; 未知的错误"

错误分析:从上面可看出,在执行Yum安装时应该没有用到我们配置文件 /etc/yum.repos.d/local_repo.repo.

查看/etc/yum.repos.d目录:

[root@localhost yum.repos.d]# ls
local_repo.repo public-yum-ol7.repo
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
[root@localhost yum.repos.d]# mv public-yum-ol7.repo public-yum-ol7.repo_bak  --把原来的配置文件备份

安装测试:--正常

[root@localhost yum.repos.d]# yum install ksh
已加载插件:langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 ksh.x86_64.0.20120801-19.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

===================================
Package 架构 版本 源 大小
====================================
正在安装:
ksh x86_64 20120801-19.el7 oracle-linux-source 878 k

事务概要
=========================================
安装 1 软件包

总下载量:878 k
安装大小:3.1 M
Is this ok [y/d/N]:

……

你可能感兴趣的:(linux)