前言
YUM(全称为 Yellow dog Updater, Modified)是一个在Fedora中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载和安装。文章以RHEL(Red Hat Enterprise Linux)配置YUM源为例分享YUM常用命令技巧以及如何搭建ISO本地源和CentOS YUM源。
YUM是一个安装,卸载和搜索软件包的工具
更新记录
2016年04月01日 - 更新rhel7.1配置CentOS 7 YUM源
2016年03月25日 - 初稿
阅读原文 - http://wsgzao.github.io/post/yum/
扩展阅读
RHEL/CentOS/OracleLinux 7.x使用EPEL和REMI第三方yum源 - http://www.ha97.com/5649.html
YUM常用命令
列举平时做常用的几组YUM命令
1 2 3 4 5 6 7 8 9 10 11 12 13
| yum clean all
yum makecache
yum search telnet
yum install telnet
yum remove telnet
yum update yum update telnet
|
本地YUM源
无论直接加载ISO还是拷贝文件来搭建本地YUM源都是很简单的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| mount -o loop rhel-server-6.3-x86_64-dvd.iso /mnt mkdir /tmp/repo cp -r /mnt/* /tmp/repo
cd /etc/yum.repos.d/
vi local.repo
[rhel6.3] name=rhel6.3 baseurl=file:///tmp/repo enabled=1 gpgcheck=0
yum clean all yum makecache
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager Updating certificate-based repositories. Unable to read consumer identity rhel6.3 | 4.0 kB 00:00 ... rhel6.3/filelists_db | 3.7 MB 00:00 ... rhel6.3/primary_db | 3.1 MB 00:00 ... rhel6.3/other_db | 1.6 MB 00:00 ... rhel6.3/group_gz | 204 kB 00:00 ... Metadata Cache Created
|
搭建YUM服务器
选择ftp或http等方式多可以,偷懒必须要简单有效
YUM服务端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| yum install httpd*
cd /etc/httpd/conf cp httpd.conf httpd.conf.bak
rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html
cp -r /tmp/repo /var/www/html cd /var/www/html chmod -R 755 repo/
service httpd restart chkconfig httpd on chkconfig --list | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
|
YUM客户端
1 2 3 4 5 6 7 8 9 10 11 12 13
| cd /etc/yum.repos.d
vi http.repo
[rhel6.3] name=rhel6.3 baseurl=http://172.28.70.160/repo enabled=1 gpgcheck=0
yum clean all yum makecache
|
CentOS 6.X YUM源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| sudo rpm --import http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
cd /etc/yum.repos.d/ cp rhel-source.repo rhel-source.repo.bak vi rhel-source.repo
[base] name=CentOS-$releasever-Base baseurl=http://centos.ustc.edu.cn/centos/6/os/x86_64/ gpgcheck=1 gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
[updates] name=CentOS-$releasever-Updates baseurl=http://centos.ustc.edu.cn/centos/6/os/x86_64/ gpgcheck=1 gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
[extras] name=CentOS-$releasever-Extras baseurl=http://centos.ustc.edu.cn/centos/6/os/x86_64/ gpgcheck=1 gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
[centosplus] name=CentOS-$releasever-Plus baseurl=http://centos.ustc.edu.cn/centos/6/os/x86_64/ gpgcheck=1
yum clean all yum makecache yum repolist
yum install -y yum-plugin-downloadonly
yum install --downloadonly --downloaddir=/tmp/puppet puppet
|
CentOS 7.X YUM源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| sudo rpm --import http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
cd /etc/yum.repos.d/ cp rhel-source.repo rhel-source.repo.bak vi rhel-source.repo
[base] name=CentOS-$releasever-Base baseurl=http://centos.ustc.edu.cn/centos/7/os/x86_64/ gpgcheck=1 gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
[updates] name=CentOS-$releasever-Updates baseurl=http://centos.ustc.edu.cn/centos/7/os/x86_64/ gpgcheck=1 gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
[extras] name=CentOS-$releasever-Extras baseurl=http://centos.ustc.edu.cn/centos/7/os/x86_64/ gpgcheck=1 gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
[centosplus] name=CentOS-$releasever-Plus baseurl=http://centos.ustc.edu.cn/centos/7/os/x86_64/ gpgcheck=1
yum clean all yum makecache yum repolist
yum install -y yum-plugin-downloadonly
yum install --downloadonly --downloaddir=/tmp/pacemaker pacemaker
|