Yum全称是Yellowdogupdatermodified,在安装软件时用的最多也是最方便的,最大的好处是:可以自动解决安装软件包的依赖关系。
1.yum服务器
使用yum来进行软件包安装时,需要制定yum服务器,
这是
[base] #代表容器的名字,中括号一定存在,名字可以随其的定义 name=CentOS-$releasever - Base - 163.com #说明一下容器的意义 mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os #列出容器可以使用的镜像站点,此项可以注释掉 baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/ #这是最重要的配置,是容器的实际网址 enable=1 #启动这个容器,不启动设置为0 gpgcheck=1 #是否开启查阅rpm文件的数字证书 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 #数字证书的公钥文件所在的位置
$releasever:表示你的系统的版本,变量会自动的检测你的版本 $basearch:表示CPU的架构,是x86_64,还是i386系列 yum服务器配置总结: 1.通过baseurl=来指定服务器的地址有三种方式: file:/// #yum源在本地,后面为一个目录的绝对路径 http:// #网络地址, ftp:// #ftp地址 无论哪种方式,网址或目录下一个有一个repodata目录,这是最重要,也是地址设置时的方法。yum服务器之所以可以工作就是由于该目录下面的几个重要的文件
2.repodata目录的信息
comps.xml filelists.sqlite.bz2 filelists.xml.gz #所有rpm包生成的文件列表 other.sqlite.bz2 other.xml.gz #额外的文件信息,包含rpm包的改变日志信息 primary.sqlite.bz2 primary.xml.gz #当前yum仓库内每一个rpm包的名字及彼此的依赖关系,以及每一个rpm包能够生成的文件 repomd.xml #保留时间戳,检查rpm文件是否改变
3.yum的配置文件
[root@zhu1 ~]# vim /etc/yum.conf [main] cachedir=/var/cache/yum #yum的缓存目录 keepcache=0 #是否保存缓存文件 debuglevel=2 #调试级别 logfile=/var/log/yum.log #日志文件 distroverpkg=redhat-release #秘钥文件 tolerant=1 #在进行安装软件时,当有的软件已安装,则忽略此现象,而不会终止其他软件的安装 exactarch=1 #是否精确匹配,安装指定平台的包 obsoletes=1 #是否检查垃圾文件的包 gpgcheck=1 #是否启用验证 plugins=1 #是否支持插件 bugtracker_url=http://bugs.centos.org/yum5bug # 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 #定义yum源文件的位置 ~
4.yum常用命令
1.查看可以安装的软件包有
yum list #查看可以安装的软件包清单 [root@zhu1 ~]# yum list | grep vsftpd vsftpd.i386 2.0.5-28.el5 base
2.查看已经安装的软件包
[root@zhu1 ~]# yum list installed
3.查看所有已安装但不在yum仓库内的软件包
[root@zhu1 ~]# yum list extras
4.查看本机上可以升级的软件包
[root@zhu1 ~]# yum list updates
5.查询软件包的名称,可根据部分关键字
[root@zhu1 ~]# yum search vsftpd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * addons: mirrors.grandcloud.cn * base: mirrors.grandcloud.cn * extras: mirrors.grandcloud.cn * updates: mirrors.grandcloud.cn =========================================== Matched: vsftpd =========================================== vsftpd.i386 : vsftpd - 非常安全 Ftp 守护进程
6.查询软件包的详细信息相当于rpm-qi
[root@zhu1 ~]# yum info vsftpd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * addons: mirrors.grandcloud.cn * base: mirrors.grandcloud.cn * extras: mirrors.grandcloud.cn * updates: mirrors.grandcloud.cn Installed Packages Name : vsftpd Arch : i386 Version : 2.0.5 Release : 28.el5 Size : 289 k Repo : installed Summary : vsftpd - 非常安全 Ftp 守护进程 URL : http://vsftpd.beasts.org/ License : GPL Description: vsftpd 是一个非常安全 FTP 守护进程。它是完全从零开始 : 编写的。
7.根据文件查所属软件
[root@zhu1 ~]# yum provides /etc/vsftpd/vsftpd.conf Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * addons: mirrors.grandcloud.cn * base: mirrors.grandcloud.cn * extras: mirrors.grandcloud.cn * updates: mirrors.grandcloud.cn vsftpd-2.0.5-28.el5.i386 : vsftpd - 非常安全 Ftp 守护进程 Repo : base Matched from: Filename : /etc/vsftpd/vsftpd.conf vsftpd-2.0.5-28.el5.i386 : vsftpd - 非常安全 Ftp 守护进程 Repo : installed Matched from: Other : Provides-match: /etc/vsftpd/vsftpd.conf
8.安装
[root@zhu1 ~]# yum -y install vsftpd
9.卸载
[root@zhu1 ~]# yum -y remove vsftpd
10.更新
[root@zhu1 ~]# yum update httpd
11.列出可更新的软件包
[root@zhu1 ~]# yum check-update
12.列出容器个数
[root@zhu1 ~]# yum repolist all Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * addons: mirrors.grandcloud.cn * base: mirrors.grandcloud.cn * extras: mirrors.grandcloud.cn * updates: mirrors.grandcloud.cn repo id repo name status addons CentOS-5 - Addons - 163.com enabled: 0 base CentOS-5 - Base - 163.com enabled: 2,770 centosplus CentOS-5 - Plus - 163.com disabled contrib CentOS-5 - Contrib - 163.com disabled extras CentOS-5 - Extras - 163.com enabled: 276 updates CentOS-5 - Updates - 163.com enabled: 508 repolist: 3,554
13.清除yum缓存信息
[root@zhu1 ~]# yum clean all Loaded plugins: fastestmirror Cleaning up Everything Cleaning up list of fastest mirrors
15.yum安装开发组
用yum安装开发组 (RHEL6.x) yum -y groupinstall "DesktopPlatform Development" "Development tools" "Server Platform Development" (RHEL5.x) yum -y groupinstall "Development tools " "Development Libraries"
16.
[root@zhu1 ~]# yum --help Loaded plugins: fastestmirror usage: yum [options] COMMAND List of Commands: check-update Check for available package updates clean Remove cached data deplist List a package's dependencies downgrade downgrade a package erase Remove a package or packages from your system groupinfo Display details about a package group groupinstall Install the packages in a group on your system grouplist List available package groups groupremove Remove the packages in a group from your system help Display a helpful usage message info Display details about a package or group of packages install Install a package or packages on your system list List a package or groups of packages localinstall Install a local RPM makecache Generate the metadata cache provides Find what package provides the given value reinstall reinstall a package repolist Display the configured software repositories resolvedep Determine which package provides the given dependency search Search package details for the given string shell Run an interactive yum shell update Update a package or packages on your system upgrade Update packages taking obsoletes into account options: -h, --help show this help message and exit -t, --tolerant be tolerant of errors -C run entirely from cache, don't update cache -c [config file] config file location -R [minutes] maximum command wait time -d [debug level] debugging output level --showduplicates show duplicates, in repos, in list/search commands -e [error level] error output level -q, --quiet quiet operation -v, --verbose verbose operation -y answer yes for all questions --version show Yum version and exit --installroot=[path] set install root --enablerepo=[repo] enable one or more repositories (wildcards allowed) --disablerepo=[repo] disable one or more repositories (wildcards allowed) -x [package], --exclude=[package] exclude package(s) by name or glob --disableexcludes=[repo] disable exclude from main, for a repo or for everything --obsoletes enable obsoletes processing during updates --noplugins disable Yum plugins --nogpgcheck disable gpg signature checking --disableplugin=[plugin] disable plugins by name --enableplugin=[plugin] enable plugins by name --skip-broken skip packages with depsolving problems --color=COLOR control whether color is used Plugin Options:
5.常用的yum源
1.
[root@zhu1 yum.repos.d]# yum repolist all Loaded plugins: fastestmirror Determining fastest mirrors repolist: 0 [root@zhu1 yum.repos.d]# ll 总计 4 -rw-r--r-- 1 root root 87 09-28 03:27 zhu [root@zhu1 yum.repos.d]# mv zhu zhu.repo [root@zhu1 yum.repos.d]# yum repolist all Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile zhu | 1.1 kB 00:00 zhu/primary | 983 kB 00:04 zhu 2770/2770 repo id repo name status zhu zhu enabled: 2,770 repolist: 2,770 [root@zhu1 yum.repos.d]# nl zhu.repo 1 [zhu] 2 name=zhu 3 baseurl=http://debian.ustc.edu.cn/centos/5/os/i386/ 4 enable=1 5 gpgcheck=0
2.利用宏变量
[root@zhu1 yum.repos.d]# yum repolist all Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile zhu | 1.1 kB 00:00 zhu/primary | 983 kB 00:04 zhu 2770/2770 repo id repo name status zhu zhu enabled: 2,770 repolist: 2,770 [root@zhu1 yum.repos.d]# nl zhu.repo 1 [zhu] 2 name=zhu 3 baseurl=http://debian.ustc.edu.cn/centos/$releasever/os/$basearch/ 4 enable=1 5 gpgcheck=0
yum源总结
#主要的开源镜像站点资源 #国内高校的开源镜像站 中国科学技术大学(debian.ustc.edu.cn) 上海交通大学(ftp.stju.edu.cn) 大连理工大学(mirror.dlut.edu.cn) 北京交通大学(mirror.bjtu.edu.cn) 北京理工大学(mirror.bit.edu.cn) 东北大学(mirror.neu.edu.cn) 厦门大学(mirrors.xmu.edu.cn) 兰州大学(mirror.lzu.edu.cn) 西安电子科技大学(linux.xidian.edu.cn) 哈尔滨工业大学(run.hit.edu.cn) 天津大学(mirror.tju.edu.cn) 东软信息学院(mirrors.neusoft.edu.cn) 电子科技大学(mirrors.stuhome.net) #美国各大学的镜像站 卡内基梅隆大学CMU(http://www.club.cc.cmu.edu/pub) 麻省理工学院MIT(http://mirrors.mit.edu/) 哥伦比亚大学(http://mirror.cc.columbia.edu/) 俄勒冈州立大学(http://ftp.osuosl.org/pub) 伊利诺伊大学厄巴纳-香槟分校(http://cosmos.cites.illinois.edu/) 杜克大学(http://archive.linux.duke.edu/) 约翰·霍普金斯大学 (http://mirrors.acm.jhu.edu/) #企业贡献 搜狐开源镜像站:http://mirrors.sohu.com/ 网易开源镜像站:http://mirrors.163.com/
搜狐:
# CentOS-Base.repo # # 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 - sohu.com mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os baseurl=http://mirrors.sohu.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 #released updates [updates] name=CentOS-$releasever - Updates - sohu.com mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates baseurl=http://mirrors.sohu.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 #packages used/produced in the build but not released [addons] name=CentOS-$releasever - Addons - sohu.com mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons baseurl=http://mirrors.sohu.com/centos/$releasever/addons/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - sohu.com mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras baseurl=http://mirrors.sohu.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - sohu.com mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus baseurl=http://mirrors.sohu.com/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - sohu.com mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib baseurl=http://mirrors.sohu.com/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
163
# CentOS-Base.repo # # 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 - 163.com baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #released updates [updates] name=CentOS-$releasever - Updates - 163.com baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #packages used/produced in the build but not released [addons] name=CentOS-$releasever - Addons - 163.com baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - 163.com baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - 163.com baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5