
前言
YUM(全稱為 Yellow dog Updater, Modified)是一個在Fedora中的Shell前端軟件包管理器。基于RPM包管理,能夠從指定的服務器自動下載RPM包并且安裝,可以自動處理依賴性關系,并且一次安裝所有依賴的軟體包,無須繁瑣地一次次下載和安裝。文章以RHEL(Red Hat Enterprise Linux)配置YUM源為例分享YUM常用命令技巧以及如何搭建ISO本地源和CentOS YUM源。
YUM是一個安裝,卸載和搜索軟件包的工具
更新記錄
2016年03月25日 - 初稿
閱讀原文 - http://wsgzao.github.io/post/yum/
擴展閱讀
Configuring Yum and Yum Repositories - https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Configuring_Yum_and_Yum_Repositories.html
YUM常用命令
列舉平時做常用的幾組YUM命令
#清除緩存目錄
yum clean all
#更新緩存
yum makecache
#使用YUM查找軟件包
yum search telnet
#用YUM安裝軟件包
yum install telnet
#用YUM刪除軟件包
yum remove telnet
#安裝更新軟件
yum update
yum update telnet
本地YUM源
無論直接加載ISO還是拷貝文件來搭建本地YUM源都是很簡單的
#通過ISO鏡像掛載或者復制文件
mount -o loop rhel-server-6.3-x86_64-dvd.iso /mnt
mkdir /tmp/repo
cp -r /mnt/* /tmp/repo
#編輯本地YUM源文件
cd /etc/yum.repos.d/
#清除老配置,rm -rf *
vi local.repo
[rhel6.3]
name=rhel6.3
baseurl=file:///tmp/repo
enabled=1
gpgcheck=0
#清除yum緩存并更新
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服務端
#安裝apache
yum install httpd*
#編輯apache配置文件
cd /etc/httpd/conf
cp httpd.conf httpd.conf.bak
#刪除測試啟動服務
rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html
#拷貝文件到目錄或者修改httpd.conf中的DocumentRoot
cp -r /tmp/repo /var/www/html
cd /var/www/html
chmod -R 755 repo/
#重啟apache服務 并設置服務自啟動
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客戶端
cd /etc/yum.repos.d
#清除老配置,rm -rf *
vi http.repo
[rhel6.3]
name=rhel6.3
baseurl=http://172.28.70.160/repo
enabled=1
gpgcheck=0
#清除yum配置緩存并更新
yum clean all
yum makecache
CentOS YUM源
#修改repo文件添加CentOS的YUM源
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.163.com/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.163.com/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.163.com/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