本文来自Q群52240781
一 yum 简介
yum,是"Yellow dog Updater,Modified"的简称,是杜克大学为了提高RPM软件包安装性而开发的一种软件包管理器. 起初是由yellow dog这一发行版的开发者Terra Soft研发,用python写成,那时还叫做yup(yellow dog updater),后经杜克大学的Linux@Duke开发团队进行改进,遂有此名. yum的宗旨是自动化地升级,安装/移除rpm包,收集rpm包的相关信息,检查依赖性并自动提示用户解决. yum的关键之处是要有可靠的repository,顾名思义,这是软件的仓库,它可以是http或ftp站点,也可以是本地软件池,但必须包含rpm的header,header包括了rpm包的各种信息,包括描述,功能,提供的文件,依赖性等. 正是收集了这些header并加以分析,才能自动化地完成余下的任务.
yum 的理念是使用一个中心仓库(repository)管理一部分甚至一个distribution的应用程序相互关系,根据计算出来的软件依赖关系进行相关的升级,安装, 删除等操作,减少了Linux用户一直头痛的dependencies的问题. 这一点上,yum和apt相同. apt原为debian的deb类型软件管理所使用,但是现在也能用到RedHat 门下的rpm了.
yum主要功能是更方便的添加/删除/更新RPM包,自动解决包的依赖性问题,便于管理大量系统的更新问题.
yum可以同时配置多个资源库(Repository),简洁的配置文件(/etc/yum.conf),自动解决增加或删除rpm包时遇到的依赖性问题,保持与RPM数据库的一致性.
+--------------------------+
| 使用Yum下载RPM包而不安装 |
+--------------------------+
方法一:通过yum自带一个工具:yumdownloader
# yum -y install yum-utils*
# rpm -ql yum-utils
/usr/bin/debuginfo-install
/usr/bin/package-cleanup
/usr/bin/repo-graph
/usr/bin/repo-rss
/usr/bin/repoclosure
/usr/bin/repodiff
/usr/bin/repomanage
/usr/bin/repoquery
/usr/bin/reposync
/usr/bin/repotrack
/usr/bin/verifytree
/usr/bin/yum-builddep
/usr/bin/yum-debug-dump
/usr/bin/yum-groups-manager
/usr/bin/yumdownloader #可以看到yumdownloade这个工具是由yum-utils这个软件安装生成的!
安装好后就可以直接使用了,使用非常简单,如下:
# yumdownloader vlock
vlock-1.3-23.i386.rpm | 11 kB 00:00
# ls
vlock-1.3-23.i386.rpm
方法二:使用yum的一个插件:yum-downloadonly
安装插件
# yum install yum-downloadonly
会自动下载安装yum-plugin-downloadonly
# ls /etc/yum/pluginconf.d/downloadonly.conf
/etc/yum/pluginconf.d/downloadonly.conf
安装yum支持的所有插件
yum install axel
yum install yum-presto
yum install yum-fastestmirror
yum install yum-metadata-parser
yum install yum-downloadonly
yum install yum-priorities
yum install yum-*
下载文件:
# yum install --downloadonly tftp
下载后文件在/var/cache下
# ls /var/cache/yum/i386/6/base/packages/tftp-0.49-7.el6.i686.rpm
# yum install --downloadonly tftp --downloaddir=~/ #指定文件下载路径
二 yum安装
CentOS默认已经安装了yum,不需要另外安装,这里为了实验目的,先将yum卸载再重新安装.
1 查看系统默认安装的yum
# rpm -qa|grep yum
2 卸载yum
# rpm -e yum-fastestmirror-1.1.16-14.el5.centos.1 yum-metadata-parser-1.1.2-3.el5.centos yum-3.2.22-33.el5.centos
3 重新安装yum
这里可以通过wget 从网上下载相关包安装,也可以挂载系统安装光盘进行安装,这里选择挂载系统安装光盘进行安装.
# mount /dev/cdrom /mnt/cdrom/
# rpm -ivh yum-3.2.22-33.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm
# yum -v
yum 的基础安装包包括:
yum //RPM installer/updater
yum-fastestmirror //Yum plugin which chooses fastest repository from a mirrorlist
yum-metadata-parser //A fast metadata parser for yum
三 yum配置
yum的配置文件分为两部分main和repository
main部分定义了全局配置选项,整个yum 配置文件应该只有一个main. 常位于/etc/yum.conf中.
repository部分定义了每个源/服务器的具体配置,可以有一到多个. 常位于/etc/yum.repo.d/目录下的各文件.
yum.conf文件一般位于/etc目录下,一般其中只包含main部分的配置选项.
# cat /etc/yum.conf
############################################
[main]
cachedir=/var/cache/yum
##yum缓存的目录,yum在此存储下载的rpm包和数据库,默认设置为/var/cache/yum
keepcache=0
##安装完成后是否保留软件包,0为不保留(默认为0),1为保留
debuglevel=2
##Debug信息输出等级,范围为0-10,缺省为2
logfile=/var/log/yum.log
##yum日志文件位置. 用户可以到/var/log/yum.log文件去查询过去所做的更新.
pkgpolicy=newest
##包的策略. 一共有两个选项,newest和last,这个作用是如果你设置了多个repository,而同一软件在不同的repository中同时存在,yum应该安装哪一个,如果是newest,则yum会安装最新的那个版本. 如果是last,则yum会将服务器id以字母表排序,并选择最后的那个服务器上的软件安装. 一般都是选newest.
distroverpkg=redhat-release
##指定一个软件包,yum会根据这个包判断你的发行版本,默认是redhat-release,也可以是安装的任何针对自己发行版的rpm包.
tolerant=1
##有1和0两个选项,表示yum是否容忍命令行发生与软件包有关的错误,比如你要安装1,2,3三个包,而其中3此前已经安装了,如果你设为1,则yum不会出现错误信息. 默认是0.
exactarch=1
##有1和0两个选项,设置为1,则yum只会安装和系统架构匹配的软件包,例如,yum不会将i686的软件包安装在适合i386的系统中. 默认为1.
retries=6
##网络连接发生错误后的重试次数,如果设为0,则会无限重试. 默认值为6.
obsoletes=1
##这是一个update的参数,具体请参阅yum(8),简单的说就是相当于upgrade,允许更新陈旧的RPM包.
plugins=1
##是否启用插件,默认1为允许,0表示不允许. 我们一般会用yum-fastestmirror这个插件.
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum
# Note: yum-RHN-plugin doesn't honor this.
metadata_expire=1h
installonly_limit=5
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
############################################
除了上述之外,还有一些可以添加的选项,如:
exclude=selinux* ## 排除某些软件在升级名单之外,可以用通配符,列表中各个项目要用空格隔开,这个对于安装了诸如美化包,中文补丁的朋友特别有用.
gpgcheck=1 ## 有1和0两个选择,分别代表是否是否进行gpg(GNU Private Guard) 校验,以确定rpm包的来源是有效和安全的. 这个选项如果设置在[main]部分,则对每个repository都有效. 默认值为0.
四 配置本地yum源
1 挂载系统安装光盘
# mount /dev/cdrom /mnt/cdrom/
或者挂在系统镜像
# mount -o loop -t iso9660 CentOS-6.6-x86_64-bin-DVD1.iso /media/_local_repo_DVD1
# mount -o loop -t iso9660 CentOS-6.6-x86_64-bin-DVD2.iso /media/_local_repo_DVD2
2 配置本地yum源
# cd /etc/yum.repos.d/
# ls
会看到四个repo 文件
CentOS-Base.repo 是yum网络源的配置文件
CentOS-Media.repo 是yum本地源的配置文件
创建_local_DVD.repo
# vim _local_DVD.repo
#########################################
[_local_DVD]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
file:///mnt/cdrom/
file:///media/cdrecorder/
file:///media/_local_repo_DVD1
file:///media/_local_repo_DVD2
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#########################################
在baseurl中修改第2个路径为/mnt/cdrom(即为光盘挂载点)
将enabled=0改为1
3 禁用默认的yum 网络源
将yum 网络源配置文件改名为CentOS-Base.repo.backup,否则会先在网络源中寻找适合的包,改名之后直接从本地源读取.
4 执行yum 命令
# yum install vim
关于repo 文件的格式
所有repository 服务器设置都应该遵循如下格式:
[serverid]
name=Some name for this server
baseurl=url://path/to/repository/
#serverid 是用于区别各个不同的repository,必须有一个独一无二的名称;
#name 是对repository 的描述,支持像$releasever $basearch这样的变量;
#baseurl 是服务器设置中最重要的部分,只有设置正确,才能从上面获取软件. 它的格式是:
baseurl=url://server1/path/to/repository/
url://server2/path/to/repository/
url://server3/path/to/repository/
其中url 支持的协议有 http://, ftp://, file:// 三种. baseurl后可以跟多个url,你可以自己改为速度比较快的镜像站,但baseurl只能有一个,也就是说不能像如下格式:
baseurl=url://server1/path/to/repository/
baseurl=url://server2/path/to/repository/
baseurl=url://server3/path/to/repository/
其中url 指向的目录必须是这个repository header 目录的上一级,它也支持$releasever $basearch 这样的变量.
url 之后可以加上多个选项,如gpgcheck, exclude, failovermethod 等,比如:
##########################################################
[updates-released]
name=Fedora Core $releasever - $basearch - Released Updates
baseurl=http://download.atrpms.net/mirrors/fedoracore/updates/$releasever/$basearch
http://redhat.linux.ee/pub/fedora/linux/core/updates/$releasever/$basearch
http://fr2.rpmfind.net/linux/fedora/core/updates/$releasever/$basearch
enable=1
gpgcheck=1
exclude=gaim
failovermethod=priority
##########################################################
#其中gpgcheck,exclude 的含义和[main] 部分相同,但只对此服务器起作用,failovermethode 有两个选项roundrobin和priority,意思分别是有多个url可供选择时,yum 选择的次序,roundrobin是随机选择,如果连接失败则使用下一个,依次循环,priority则根据url的次序从第一个开始. 如果不指明,默认是roundrobin.
五 配置国内yum源
系统默认的yum 源速度往往不尽人意,为了达到快速安装的目的,在这里修改yum源为国内源.
上海交通大学yum源
a. 备份/etc/yum.repos.d/的CentOS-Base.repo文件为CentOS-Base.repo.backup;并复制一份改名为CenOS-sjtu.repo,内容为:
----------------------------------------------
# CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/updates/$basearch/
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/extras/$basearch/
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#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://ftp.sjtu.edu.cn/centos/$releasever/centosplus/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/contrib/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
----------------------------------------------
关于变量
$releasever:代表发行版的版本,从[main]部分的distroverpkg获取,如果没有,则根据redhat-release包进行判断.
$arch:cpu体系,如i686,athlon等
$basearch:cpu的基本体系组,如i686和athlon同属i386,alpha和alphaev6同属alpha.
b. 导入GPG KEY
yum 可以使用gpg 对包进行校验,确保下载包的完整性,所以我们先要到各个repository 站点找到gpg key,一般都会放在首页的醒目位置,一些名字诸如RPM-GPG-KEY-CentOS-6 之类的纯文本文件,把它们下载下来,然后用rpm --import RPM-GPG-KEY-CentOS-6 命令将key导入.
c. 执行yum 命令
其他国内yum源列表如下:
1. 企业贡献:
搜狐开源镜像站:http://mirrors.sohu.com/
网易开源镜像站:http://mirrors.163.com/
2. 大学教学:
北京理工大学:
http://mirror.bit.edu.cn (IPv4 only)
http://mirror.bit6.edu.cn (IPv6 only)
北京交通大学:
http://mirror.bjtu.edu.cn (IPv4 only)
http://mirror6.bjtu.edu.cn (IPv6 only)
http://debian.bjtu.edu.cn (IPv4+IPv6)
兰州大学:http://mirror.lzu.edu.cn/
厦门大学:http://mirrors.xmu.edu.cn/
清华大学:
http://mirrors.tuna.tsinghua.edu.cn/ (IPv4+IPv6)
http://mirrors.6.tuna.tsinghua.edu.cn/ (IPv6 only)
http://mirrors.4.tuna.tsinghua.edu.cn/ (IPv4 only)
天津大学:http://mirror.tju.edu.cn/
中国科学技术大学:
http://mirrors.ustc.edu.cn/ (IPv4+IPv6)
http://mirrors4.ustc.edu.cn/
http://mirrors6.ustc.edu.cn/
东北大学:
http://mirror.neu.edu.cn/ (IPv4 only)
http://mirror.neu6.edu.cn/ (IPv6 only)
电子科技大学:http://ubuntu.uestc.edu.cn/
六 使用第三方软件库
CentOS/RHEL默认的yum软件仓库非常有限,仅仅限于发行版本那几张盘里面的常规包和一些软件包的更新,利用RpmForge,可以增加非常多的第三方rpm软件包. RpmForge库现在已经拥有超过10000种CentOS的软件包,被CentOS社区认为是最安全也是最稳定的一个第三方软件库.
1 安装yum-priorities插件
这个插件是用来设置yum在调用软件源时的顺序的. 因为官方提供的软件源,都是比较稳定和被推荐使用的. 因此,官方源的顺序要高于第三方源的顺序. 如何保证这个顺序,就需要安装yum-priorities这插件了.
# yum -y install yum-priorities
2 安装完yum-priorities插件后需要设置/etc/yum.repos.d/ 目录下的.repo相关文件(如CentOS-Base.repo),在这些文件中插入顺序指令:priority=N (N为1到99的正整数,数值越小越优先)
一般配置[base],[addons],[updates],[extras]的priority=1,[CentOSplus],[contrib]的priority=2,其他第三的软件源为:priority=N (推荐N>10)
以CentOS-Base.repo 为例:
##############################################################
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=1
##############################################################
+---------------------------+
| 添加adobe软件仓并导入密钥 |
+---------------------------+
32位
# wget http://linuxdownload.adobe.com/linux/i386/adobe-release-i386-1.0-1.noarch.rpm
# rpm -ivh adobe-release-i386-1.0-1.noarch.rpm
64位
# wget http://linuxdownload.adobe.com/linux/x86_64/adobe-release-x86_64-1.0-1.noarch.rpm
# rpm -ivh adobe-release-x86_64-1.0-1.noarch.rpm
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
设置/etc/yum.repos.d/中的adobe-linux-x86_64.repo中的priority=10
现在可以安装adobe的flashplayer插件了
# yum install flash-plugin
+------------------+
| 安装atomic yum源 |
+------------------+
# wget http://www.atomicorp.com/installers/atomic #下载
# sh ./atomic #安装
# vi /etc/yum.repos.d/atomic.repo #修改atomic yum源优先级,priority=11
##############################################################
[atomic]
name=CentOS / Red Hat Enterprise Linux $releasever - atomicrocketturtle.com
mirrorlist=http://www.atomicorp.com/mirrorlist/atomic/centos-6-$basearch
#mirrorlist=http://www.atomicorp.com/channels/atomic/centos/6/mirrors-atomic
enabled=1
protect=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY.art.txt
priority=11
##############################################################
+----------------+
| 安装epel yum源 |
+----------------+
rpmfusion主要为桌面发行版提供大量rpm包,而EPEL则为服务器版本提供大量的rpm包,而且大多数rpm包在官方repository中是找不到的;
CentOS 5.*
32位系统
# wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm
64位系统:
# wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm
导入key:
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5
CentOS 6.*
32位系统:
# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# ipm -ivh epel-release-6-8.noarch.rpm
64位系统:
# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
导入key:
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
如果用比较新的软件,用epel-test.repo这个文件就行了
别忘了安装# yum install yum-priorities
# vi /etc/yum.repos.d/epel.repo #修改epel yum源优先级,priority=12
###############################################################
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
priority=12
#################################################################
+--------------------+
| 安装rpmforge软件源 |
+--------------------+
1 下载与安装相应rpmforge的rpm文件包,到http://pkgs.repoforge.org/rpmforge-release/ 查找对应版本的软件下载
32位# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm
64位# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
2 安装DAG的PGP Key
# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
或者导入本地的key
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-*
3 验证rpmforge的rpm文件包
# rpm -K rpmforge-release-0.5.3-1.el6.rf.*.rpm
4 安装rpmforge的rpm文件包
# rpm -i rpmforge-release-0.5.3-1.el6.rf.*.rpm
5 设置/etc/yum.repos.d/rpmforge.repo文件中源的级别
# cat rpmforge.repo
########################################################
### Name: RPMforge RPM Repository for RHEL 6 - dag
### URL: http://rpmforge.net/
[rpmforge]
name=RHEL $releasever - RPMforge.net - dag
baseurl=http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist=http://apt.sw.be/redhat/el6/en/mirrors-rpmforge
#mirrorlist=file:///etc/yum.repos.d/mirrors-rpmforge
enabled=1
protect=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck=1
priority=13
########################################################
+---------------------+
| 安装rpmfusion yum源 |
+---------------------+
含有各种音视频软件,但稳定性不如rpmforge
32位
# rpm -ivh http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm
# rpm -ivh http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm
64位
# rpm -ivh http://download1.rpmfusion.org/free/el/updates/6/x86_64/rpmfusion-free-release-6-1.noarch.rpm
# rpm -ivh http://download1.rpmfusion.org/nonfree/el/updates/6/x86_64/rpmfusion-nonfree-release-6-1.noarch.rpm
# vi /etc/yum.repos.d/rpmfusion-free-updates.repo #修改rpmfusion yum源优先级,priority=13
#################################################################
[rpmfusion-free-updates-testing]
name=RPM Fusion for EL 6 - Free - Test Updates
#baseurl=http://download1.rpmfusion.org/free/el/updates/testing/6/$basearch/
mirrorlist=http://mirrors.rpmfusion.org/mirrorlist?repo=free-el-updates-testing-6&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmfusion-free-el-6
priority=14
#################################################################
安装完毕执行
# yum clean all
# yum makecache
然后就可以使用新的yum源管理软件
//////////////////////下面是一个yum配置的脚本程序,可以运行于centos6.x////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#! /bin/bash
# created by longbin
# 2015-08-06
## yum and yum plugins installation scripts
PLAT_ARCH=$(uname -i | tr 'A-Z' 'a-z')
## check whether system is centos or not
function check_system_distributor() {
## get system distributor ID: centos ?
LINUX_DISTRIBUTOR=$(cat /etc/issue |tr 'A-Z' 'a-z'|awk ' /release/ {print $1}' | sed -n "1p")
LINUX_DISTRIBUTOR=${LINUX_DISTRIBUTOR:=$(lsb_release -i |tr 'A-Z' 'a-z'|awk '/distributor/ {print $3}')}
LINUX_DISTRIBUTOR=${LINUX_DISTRIBUTOR:=$(cat /etc/*release |tr 'A-Z' 'a-z'|awk '/\/ {print $1}'|sed -n '1p')}
LINUX_DISTRIBUTOR=${LINUX_DISTRIBUTOR:=$(cat /etc/*release |tr 'A-Z' 'a-z'|awk '/distrib_id=/ {print $1}'|sed 's/distrib_id=//'|sed -n '1p')}
echo "checking system distributor and release ID ..."
if [[ "${LINUX_DISTRIBUTOR}" == "centos" ]] ;then
echo -e "\tCurrent OS Distributor: ${LINUX_DISTRIBUTOR}"
else
echo -e "\tCurrent OS is not centos"
echo -e "\tCurrent OS Distributor: ${LINUX_DISTRIBUTOR}"
exit 1
fi
}
## check whether system is centos 6.5 or 6.6
function check_system_release_version() {
## get system release version: 6.5/6.6 ?
LINUX_RELEASE_VERSION=$(cat /etc/issue | awk '/release/ {print $3}'| sed -n '1p')
LINUX_RELEASE_VERSION=${LINUX_RELEASE_VERSION:=$(lsb_release -r | tr 'A-Z' 'a-z' | awk '/release/ {print $2}')}
LINUX_RELEASE_VERSION=${LINUX_RELEASE_VERSION:=$(cat /etc/*release |tr 'A-Z' 'a-z'|awk '/\/ {print $3}'|sed -n '1p')}
LINUX_RELEASE_VERSION=${LINUX_RELEASE_VERSION:=$(cat /etc/*release |tr 'A-Z' 'a-z'|awk '/distrib_release=/ {print $1}'|sed 's/distrib_release=//'|sed -n '1p')}
case ${LINUX_RELEASE_VERSION:0:5} in
6.*)
echo -e "\tCurrent OS Version: ${LINUX_RELEASE_VERSION}"
;;
*)
echo "Only support centos version, eg: 6.5/6.6 ..."
exit 1
;;
esac
echo "checked OK, preparing to setup softwares ..."
}
function check_user_UID() {
sudo ls > /dev/null
if [ "x$?" == "x1" ] ;then
echo -e "\tThere is a configuration/permission problem."
echo -e "\tPlease ensure that you have the permission"
exit 1
fi
if [ "x${UID}" == "x0" ] ;then
SUDO=''
else
SUDO=sudo
fi
}
function check_yum_install_env() {
check_system_distributor
check_system_release_version
check_user_UID
trap 'echo -e "\nAborted by user, exit";exit' INT
if [ "x$(which yum 2>/dev/null)" == "x" ] ;then
echo "yum not exists, please install yum manully"
exit 1
fi
}
function yum_plugins_installation() {
echo "Preparing to install yum plugins ..."
# ${SUDO} yum install yum-*
# ${SUDO} yum install axel
${SUDO} yum install yum-presto
${SUDO} yum install yum-fastestmirror
${SUDO} yum install yum-metadata-parser
${SUDO} yum install yum-downloadonly
${SUDO} yum install yum-priorities
}
function yum_axel_plugin_install() {
${SUDO} yum install axel
# if [ "x${PLAT_ARCH}" == "xx86_64" ] ;then
# ${SUDO} rpm -ivh http://pkgs.repoforge.org/axel/axel-2.4-1.el6.rf.x86_64.rpm
# else
# ${SUDO} rpm -ivh http://pkgs.repoforge.org/axel/axel-2.4-1.el6.rf.i686.rpm
# fi
# pushd /etc/yum/pluginconf.d/
# ${SUDO} wget http://cnfreesoft.googlecode.com/svn/trunk/axelget/axelget.conf
${SUDO} wget http://www.ha97.com/code/axelget.conf -P /etc/pluginconf.d/
if [ "$?" != 0 ] ;then
local tmp_file=$(mktemp)
${SUDO} cat > ${tmp_file} << EOF
[main]
enabled=1
onlyhttp=1
enablesize=54000
cleanOnException=1
EOF
${SUDO} mv ${tmp_file} /etc/yum/pluginconf.d/axelget.conf
fi
# popd
# pushd /usr/lib/yum-plugins/
# ${SUDO} wget http://cnfreesoft.googlecode.com/svn/trunk/axelget/axelget.py
${SUDO} wget http://www.ha97.com/code/axelget.py -P /usr/lib/yum-plugins/
if [ "$?" != 0 ] ;then
local tmp_file=$(mktemp)
${SUDO} cat > ${tmp_file} << EOF
from yum.plugins import PluginYumExit, TYPE_CORE, TYPE_INTERACTIVE
from urlparse import urljoin
import os,time
requires_api_version = '2.3'
plugin_type = (TYPE_CORE, TYPE_INTERACTIVE)
enablesize=300000
trymirrornum=-1
maxconn=10
httpdownloadonly=False
cleanOnException=0
def init_hook(conduit):
global enablesize,trymirrornum,maxconn,cleanOnException,httpdownloadonly
enablesize = conduit.confInt('main','enablesize',default=30000)
trymirrornum = conduit.confInt('main','trymirrornum',default=-1)
maxconn = conduit.confInt('main','maxconn',default=10)
httpdownloadonly=conduit.confBool('main','onlyhttp',default=False)
cleanOnException=conduit.confInt('main','cleanOnException',default=0)
return
def predownload_hook(conduit):
global enablesize,cleanOnException,httpdownloadonly
preffermirror=""
PkgIdx=0
TotalPkg=len(conduit.getDownloadPackages())
for po in (conduit.getDownloadPackages()):
PkgIdx+=1
if hasattr(po, 'pkgtype') and po.pkgtype == 'local':
continue
totsize = long(po.size)
ret = False
if totsize <= enablesize:
conduit.info(2, "Package %s download size %d less than %d,Skip plugin!" % (po.repo.id,totsize,enablesize))
continue
else:
conduit.info(2, "[%d/%d]Ok,we will try to use axel to download this big file:%d" % (PkgIdx,TotalPkg,totsize))
local = po.localPkg()
if os.path.exists(local):
if not os.path.exists(local+".st"):
fstate=os.stat(local)
if totsize == fstate.st_size:
conduit.info(2,"Target already exists,skip to next file!")
continue
localall = "%s %s" % (local,local+".st")
rmcmd = "rm -f %s" % (localall)
curmirroridx = 0
conduit.info(2,"Before we start,clean all the key files")
os.system(rmcmd)
connnum = totsize / enablesize
if connnum*enablesize maxconn:
connnum = maxconn
mirrors=[]
mirrors[:0]=po.repo.urls
if preffermirror != "":
mirrors[:0] = [preffermirror]
for url in mirrors:
if url.startswith("ftp://") and httpdownloadonly:
print "Skip Ftp Site:",url
continue
if url.startswith("file://"):
print "Skip Local Site:",url
continue
curmirroridx += 1
if (curmirroridx > trymirrornum) and (trymirrornum != -1):
conduit.info(2, "Package %s has tried %d mirrors,Skip plugin!" % (po.repo.id,trymirrornum))
break
remoteurl = "%s/%s" % (url,po.remote_path)
syscmd = "axel -a -n %s %s -o %s" % (connnum,remoteurl,local)
conduit.info(2, "Execute axel cmd:\n%s" % syscmd)
os.system(syscmd)
time.sleep(2)
if os.path.exists(local+".st"):
conduit.info(2,"axel exit by exception,let's try another mirror")
if cleanOnException:
conduit.info(2,"because cleanOnException is set to 1,we do remove key file first")
os.system(rmcmd)
continue
elif not os.path.exists(local):#this mirror may not update yet
continue
else:
ret = True
preffermirror=url
break
if not ret:
conduit.info (2,"try to run rm cmd:%s" % rmcmd)
os.system(rmcmd)
EOF
${SUDO} mv ${tmp_file} /usr/lib/yum-plugins/axelget.py
fi
# popd
}
# modify varible value of file callback function
function modify_varible_value_of_file_cb() {
if [ "$#" -lt 3 ] ;then
echo "too less arguments"
exit 1
fi
# echo $*
local filename=$1
local variable=$2
local value=$3
local res=$(cat ${filename}| sed -n "/^${variable}/p")
if [ "x${res}" == "x" ] ;then
#append variable and value to file
${SUDO} sed -i "/^enable[d]\?[ ]\?=[ ]\?1/ a ${variable}=${value}" ${filename}
else
#modify variable and value to file
${SUDO} sed -i "/^${variable}[ ]\?=/ s;${variable}.*$;${variable}=${value};" ${filename}
fi
}
function check_yum_conf_enable_plugins() {
local yum_conf=$(cat /etc/yum.conf| sed -n '/^plugins[ ]\?=[ ]\?1/p')
if [ "x${yum_conf}" != "x" ] ;then
return
else
# yum_conf_enable_plugins /etc/yum.conf
modify_varible_value_of_file_cb /etc/yum.conf plugins 1
fi
}
function backup_yum_repos_d_files() {
local backup_dir=/etc/yum.repos.d/repos.old.$(date +%Y%m%d%H%M%S)
${SUDO} mkdir -p ${backup_dir}
if [ "x$?" != "x0" ] ;then
return
fi
# pushd /etc/yum.repos.d
for file in $(ls /etc/yum.repos.d/ | sed -n '/repo$/p') ;
do
if [ -f "/etc/yum.repos.d/${file}" ] ;then
${SUDO} cp /etc/yum.repos.d/${file} ${backup_dir}
fi
done
# popd
}
function create_local_repo_DVD() {
if [ -f CentOS-6.6-x86_64-bin-DVD1.iso ] ;then
${SUDO} mkdir /media/_local_repo_DVD1
${SUDO} mount -o loop -t iso9660 CentOS-6.6-x86_64-bin-DVD1.iso /media/_local_repo_DVD1
fi
if [ -f CentOS-6.6-x86_64-bin-DVD2.iso ] ;then
${SUDO} mkdir /media/_local_repo_DVD2
${SUDO} mount -o loop -t iso9660 CentOS-6.6-x86_64-bin-DVD2.iso /media/_local_repo_DVD2
fi
local tmp_file=$(mktemp)
${SUDO} cat > ${tmp_file} << EOF
[_local_repo_DVD]
name=CentOS-\$releasever - Media
baseurl=file:/var/lib/yum/plugins/local
file:///media/CentOS/
file:///mnt/cdrom/
file:///media/cdrecorder/
file:///media/_local_repo_DVD1
file:///media/_local_repo_DVD2
enabled=0
priority=9
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
EOF
${SUDO} mv ${tmp_file} /etc/yum.repos.d/_local_repo_DVD.repo
}
function create_maintain_script() {
return #no need to create the script
local tmp_file=$(mktemp)
${SUDO} cat > ${tmp_file} << EOF
#! /bin/bash
read -p "backup or restore ? " select
if [[ "x\${select}" == "xbk" ]] ;then
for file in \$(ls /etc/yum.repos.d/ | sed -n '/repo$/p')
do
sudo mv \${file} \${file}.backup
done
elif [[ "x\${select}" == "xrs" ]] ;then
for file in \$(ls /etc/yum.repos.d/ | sed -n '/backup$/p')
do
sudo mv \${file} \${file%.backup*}
done
else
echo "Invalid option "
fi
EOF
${SUDO} mv ${tmp_file} /etc/yum.repos.d/_backup_restore.sh
}
# add adobe repo
function yum_add_adobe_repo() {
if [ "x${PLAT_ARCH}" == "xx86_64" ] ;then
#64bit#
${SUDO} rpm -ivh http://linuxdownload.adobe.com/linux/x86_64/adobe-release-x86_64-1.0-1.noarch.rpm
else
#32bit#
${SUDO} rpm -ivh http://linuxdownload.adobe.com/linux/i386/adobe-release-i386-1.0-1.noarch.rpm
fi
${SUDO} rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
# set adobe-linux-x86_64.repo priority=10
local repo_file=/etc/yum.repos.d/adobe-linux-${PLAT_ARCH}.repo
modify_varible_value_of_file_cb ${repo_file} priority 10
${SUDO} yum install flash-plugin
}
# add atomic repo
function yum_add_atomic_repo() {
${SUDO} wget http://www.atomicorp.com/installers/atomic #download
${SUDO} chmod a+x ./atomic
yes " " | sudo sh ./atomic #install
${SUDO} rm -f ./atomic
}
# add epel repo
function yum_add_epel_repo() {
# if [ "${PLAT_ARCH}" == "xx86_64" ] ;then
# #64bit:#
# ${SUDO} rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# else
# #32bit#
# ${SUDO} rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# fi
${SUDO} yum install epel-release
${SUDO} rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
}
# add rpmforge repo
function yum_add_rpmforge_repo() {
# download from http://pkgs.repoforge.org/rpmforge-release/
if [ "x${PLAT_ARCH}" == "xx86_64" ] ;then
#64bit#
${SUDO} wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
else
#32bit#
${SUDO} wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm
fi
${SUDO} rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
${SUDO} rpm -ivh rpmforge-release-0.5.3-1.el6.rf.*.rpm
${SUDO} rm -f rpmforge-release-0.5.3-1.el6.rf*.rpm
}
# add rpmfusion repo which includes many multimedia libs
function yum_add_rpmfusion_repo() {
if [ "x${PLAT_ARCH}" == "xx86_64" ] ;then
#64bit
${SUDO} rpm -ivh http://download1.rpmfusion.org/free/el/updates/6/x86_64/rpmfusion-free-release-6-1.noarch.rpm
${SUDO} rpm -ivh http://download1.rpmfusion.org/nonfree/el/updates/6/x86_64/rpmfusion-nonfree-release-6-1.noarch.rpm
else
#32bit
${SUDO} rpm -ivh http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm
${SUDO} rpm -ivh http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm
fi
}
function yum_add_nux_dextop_repo() {
if [ "x${PLAT_ARCH}" == "xx86_64" ] ;then
#64bit
${SUDO} rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm
else
#32bit
${SUDO} rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/i386/nux-dextop-release-0-2.el6.nux.noarch.rpm
fi
# ${SUDO} rm -f nux-dextop-release*.rpm
modify_varible_value_of_file_cb nux-dextop.repo enable 1
}
function setup_yum_repos_priority() {
# pushd /etc/yum.repos.d/
REPO_FILE_LIST=" CentOS-Base.repo atomic.repo epel.repo epel-testing.repo nux-dextop.repo rpmforge.repo rpmfusion-free-updates.repo "
repo_priority_num=1
for file in ${REPO_FILE_LIST}
do
file=/etc/yum.repos.d/${file}
if [ -f "${file}" ] ;then
echo "updating ${file} ..."
modify_varible_value_of_file_cb ${file} priority XXX
else
continue
fi
for ((i=0; i<5; i++)) ;
do
let prn=${repo_priority_num}+${i}
# echo ${repo_priority_num} ${prn}
${SUDO} sed "1, /^priority=XXX/ {/^priority=XXX/ s/priority=.*$/priority=${prn}/}" -i ${file}
done
let repo_priority_num+=5
done
# popd
}
function rebuild_yum_cache() {
${SUDO} yum clean all
${SUDO} yum makecache
}
function install_and_setup_yum_plugins() {
yum_plugins_installation
# yum_axel_plugin_install
}
function enable_and_backup_repos() {
check_yum_conf_enable_plugins
backup_yum_repos_d_files
}
function add_extra_repos() {
create_local_repo_DVD
# create_maintain_script
yum_add_adobe_repo
# yum_add_atomic_repo
yum_add_epel_repo
yum_add_nux_dextop_repo
yum_add_rpmforge_repo
yum_add_rpmfusion_repo
yum_axel_plugin_install
}
function setup_priority_and_rebuild_cache() {
setup_yum_repos_priority
rebuild_yum_cache
}
check_yum_install_env
install_and_setup_yum_plugins
enable_and_backup_repos
add_extra_repos
setup_priority_and_rebuild_cache
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
=========================================================================
YUM错误conflicts with file from package的解决办法
YUM一堆错误,是64位的包和32位的包冲突.
YUM错误conflicts with file from package的解决办法,先卸载有冲突的软件包,如下是 yum -y remove subversion 然后再重新YUM就OK了.
--------------------------------------------------------------------------
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Check Error:
file /usr/share/emacs/site-lisp/psvn.el from install of subversion-1.4.6-jason.1.i386 conflicts with file from package subversion-1.4.2-4.el5_3.1.x86_64
file /usr/share/locale/es/LC_MESSAGES/subversion.mo from install of subversion-1.4.6-jason.1.i386 conflicts with file from package subversion-1.4.2-4.el5_3.1.x86_64
file /usr/share/locale/it/LC_MESSAGES/subversion.mo from install of subversion-1.4.6-jason.1.i386 conflicts with file from package subversion-1.4.2-4.el5_3.1.x86_64
file /usr/share/locale/ja/LC_MESSAGES/subversion.mo from install of subversion-1.4.6-jason.1.i386 conflicts with file from package subversion-1.4.2-4.el5_3.1.x86_64
file /usr/share/locale/ko/LC_MESSAGES/subversion.mo from install of subversion-1.4.6-jason.1.i386 conflicts with file from package subversion-1.4.2-4.el5_3.1.x86_64
file /usr/share/locale/nb/LC_MESSAGES/subversion.mo from install of subversion-1.4.6-jason.1.i386 conflicts with file from package subversion-1.4.2-4.el5_3.1.x86_64
file /usr/share/locale/zh_CN/LC_MESSAGES/subversion.mo from install of subversion-1.4.6-jason.1.i386 conflicts with file from package subversion-1.4.2-4.el5_3.1.x86_64
file /usr/share/xemacs/site-packages/lisp/psvn.el from install of subversion-1.4.6-jason.1.i386 conflicts with file from package subversion-1.4.2-4.el5_3.1.x86_64
Error Summary
-------------
-------------------------------------------------------------------------
正当高兴的时候,发现yum安装webmin的时候还是有错误:
-------------------------------------------------------------------------
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
FATAL - 2010-11-28 15:51:02 - Fatal Error Occurred: Something went wrong during installation: 0
FATAL - 2010-11-28 15:51:03 - Cannot continue installation.
FATAL - 2010-11-28 15:51:03 - Attempting to remove virtualmin repository configuration,so the installation can be
FATAL - 2010-11-28 15:51:03 - re-attempted after any problems have been resolved.
FATAL - 2010-11-28 15:51:03 - Removing temporary directory and files.
FATAL - 2010-11-28 15:51:03 - If you are unsure of what went wrong,you may wish to review the log
FATAL - 2010-11-28 15:51:03 - in /root/virtualmin-install.log
------------------------------------------------------------------------
看日志发现,yum更新的时候有重复的32位和64位的包:
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
dovecot x86_64 1.0.7-7.el5 base 1.7 M
httpd i386 2.2.16-jason.1 utterramblings 3.0 M
httpd x86_64 1:2.2.3-43.3.vm virtualmin 1.2 M
mailman x86_64 3:2.1.9-4.el5 base 9.8 M
mod_dav_svn x86_64 1.4.2-4.el5_3.1 base 70 k
mod_dav_svn i386 1.4.6-jason.1 utterramblings 201 k
mod_perl x86_64 2.0.4-6.el5 base 4.0 M
mod_perl i386 2.0.4-7.jason.2 utterramblings 5.4 M
系统是64位的,所以很明显utterramblings 的yum源32位是有问题的. 我们需要删除这个utterramblings源.
# cd /etc/yum.repos.d/
# mv utterrambling.repo utterrambling.repo.del
然后我们yum重新安装virtualmin,终于一切正常了
yum-3.2.29-40.el6.centos.noarch.rpm
yum-metadata-parser-1.1.2-16.el6.i686.rpm
yum-plugin-aliases-1.1.30-14.el6.noarch.rpm
yum-plugin-changelog-1.1.30-14.el6.noarch.rpm
yum-plugin-downloadonly-1.1.30-14.el6.noarch.rpm
yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
yum-plugin-security-1.1.30-14.el6.noarch.rpm
yum-plugin-tmprepo-1.1.30-14.el6.noarch.rpm
yum-plugin-verify-1.1.30-14.el6.noarch.rpm
yum-plugin-versionlock-1.1.30-14.el6.noarch.rpm
yum-presto-0.6.2-1.el6.noarch.rpm
yum-utils-1.1.30-14.el6.noarch.rpm