Posts Tagged: yum


6
七 11

创建自己的yum源

  最终还是决定使用rpm来管理系统上“定制”的软件包,之前一直使用shell脚本,从源码编译安装。
  排除规模引出的效率因素不讲,脚本的可维护性比起rpm要糟糕一些,当然使用rpm就需要深入了解rpmbuild以及spec文档,似乎也并不简单。但从长远来看,rpm、yum源的可维护性,要比“脚本”可靠一些——我这样认为。

  创建yum源需要一个ftp或者http服务,鉴于ftp烦人的防火墙策略(防火墙配制不当,ftp的模式——主动/初动使用不当,服务会变得不可用),建议使用http服务。
  管理yum源需要一个工具createrepo,使用yum安装:yum -y install createrepo

  然后就可以开始了:

1. 规划、创建yum源目录。
  比如在http://www.bsdmap.com的根目录下创建一个yum目录,来保存 yum 源数据。
  观察官方yum源的目录规划,像是yum并不能自己维护arch,即并不能自己区分i386还是x86_64,所以是单独放在不同的目录下。
  我维护的是基于CentOS Linux 5的包,规划目录如下:
  $mkdir -p yum/centos/5/{i386,x86_64}

2. 初始化repodata信息:
  $createrepo -p -d -o yum/centos/5/i386 yum/centos/5/i386
  $createrepo -p -d -o yum/centos/5/x86_64 yum/centos/5/x86_64
  这个时候,会在yum/centos/5/i386和yum/centos/5/x86_64目录下,分别看到一个repodata目录,这个就是yum源的Meta数据,有了这个,yum就可以和这个“源”进行“数据信息”了。
  当然这个时候,这个源是空的,没有任何包可以安装。后面再说如何在yum源中提供安装包。

3. 配置本地的yum,使之使用自建的yum源。
  简单的来说,就是在本地的/etc/yum.repos.d目录下新建一个配置文件文件(也可配置语句添加到已经存在文件中),以.repo为文件名后缀,比如bsdmap.repo,然后内容大概如下:

[bsdmap-yum]
name=bsdmap-yum
baseurl=http://www.bsdmap.com/yum/centos/$releasever/$basearch/
enabled=1
gpgcheck=0
gpgkey=

解释:
[....] 代表这个库的名字,必须是唯一的,不可以重复。
name= 是这个库的说明,没有太大的实际意义,只是一个字段说明。
baseurl= 说明采取什么方式传输,具体路径在哪里,可以使用的方式有,file://,ftp://,http://等,关于baseurl中的变量,可以查看yum.conf 的手册:man yum.conf ,在手册的最后一段有详细描述。($release
enabled=1 说明启用这个更新库,0表示不启用。
gpgcheck=1 表示使用gpg文件来检查软件包的签名
gpgkey= 表示gpg文件所存放的位置,此处也可以有http方式的位置。

  这时,当我们yum repolist 时,就可以看到 bsdmap-yum 源了。


25
六 11

yum使用技巧

YUM工具加速:

1. 善用镜象和缓存。

安装 yum 的 fastestmirror 插件 yum-fastestmirror,这个插件,会测试镜象里的主机,并生成一个文件 /var/cache/yum/timedhosts.txt,这个文件里记录了 Repository 镜象的响应时间,yum会有这些镜象里选择响应时间最短的主机上下载 metadata 或 rpm 包。

yum 还有一个 makecache 命令,是用来专门更新 metadata 数据的,在执行别的 yum  命令之前可以先用这个命令预热一下。

另外,还有一个 -C 选项,这个选项是告诉 yum 使用缓存的 metadata 而不去更新 metadata 信息,这样执行类似 search 的命令,就会快很多啦。其实 apt-cache search 之所以快,也正是他搜索的是本地缓存数据,而 yum search 通常都会先去下载 metadata ,而后即使是在很短的时间内又一次使用 yum search 命令,yum 也仍然不快。-C 参数可以强制使用它快起来。

2. 禁用插件

上面我们安装了 fastestmirror 插件,我还安装了其他的插件,这时即使使用 -C 参数在执行 search 或者 list 、info 命令,也并不是很快,原因是每次 yum 都会去加载 fastestmirror 插件,可以使用 –noplugins 来禁用插件,这时就 yum 就快多了:yum –noplugins -C info tidy

 

可以设置一个别名:

alias fyum='yum --noplugins -C'


6
八 09

CentOS自动升级问题

CentOS的yum-updatesd服务是可以自动更新系统的,只用稍微调整一个配置文件/etc/yum/yum-updatesd.conf:
[main]
# how often to check for new updates (in seconds)
run_interval = 3600# how often to allow checking on request (in seconds)
updaterefresh = 600

# how to send notifications (valid: dbus, email, syslog)
#emit_via = dbus
emit_via = email
email_from = yum-updatesd@MO01H36
email_to = caoyuwei@xxxx.com

# should we listen via dbus to give out update information/check for
# new updates
dbus_listener = yes

# automatically install updates
do_update = yes

# automatically download updates
do_download = yes

# automatically download deps of updates
do_download_deps = yes

但是最近发生一件怪事儿,由到了许多邮件,内容大致如下:
Hi,
This is the automatic update system on MO01H36.There was a problem updating the system. The following error message was reported:Failed to build transaction: Missing Dependency: /usr/lib/python2.4 is needed by package libxml2-python-2.6.26-2.1.2.7.i386 (installed)
Missing Dependency: /usr/lib/python2.4 is needed by package gamin-python-0.1.7-8.el5.i386 (installed)
If the problem persists, manual intervention may be required.
Thank You,
Your Computer

最终解决方法是:yum clean all
然后便可以 yum update了,yum-updated也会自动更新系统。

感慨一下团队的力量。这个解决办法是神仙发现的,哈,我们总是能遇到这样的惊喜!

PS: 2010-5-14

阅读CentOS 5.4发行说明的时候发现:

CentOS 5.4 包含了 glibc 及内核的更新。通过 yum 来更新的推荐程序是:
yum clean all
yum update glibc\*
yum update yum\* rpm\* python\*
yum clean all
yum update
shutdown -r now
升级是讲求顺序的。

4
七 08

yum终于有了yum-fastestmirror模块

相信不少人在使用yum install/update 的时候会不耐烦的按Ctrl+c。Debian有netselect-apt来帮助用户定位速度最快的mirror,现在yum也有这个功能了。
  
  升级你的yum,立刻!
  #yum -y update yum

PS: 然而貌似程序始终是程序,还不够完善。


28
五 08

配置yum使用速度快的源

CentOS 中科大源
====
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.

#
#
[base]
name=CentOS-$releasever – Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://centos.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
#released updates
[updates]
name=CentOS-$releasever – Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://centos.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever – Addons
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
baseurl=http://centos.ustc.edu.cn/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://centos.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://centos.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
建议gpgkey仍然使用官方的地址,安全第一!
假如本地有安装源,比如:http://192.168.0.45/linux
那么可以使用如下两行命令编辑yum的配置文件,使用本地源来安装软件(update的话,恐怕仍然需要官方指定的源):
sed -i ‘s/^mirrorlist/#mirrorlist/g’                                      /etc/yum.repos.d/CentOS-Base.repo  
sed -i ‘/^#baseurl/abaseurl=http://192.168.0.45/linux/’  /etc/yum.repos.d/CentOS-Base.repo