5

RHEL(Red Hat Enterprise Linux) 配置 YUM 源

 2 years ago
source link: https://wsgzao.github.io/post/yum/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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 日 - 初稿

阅读原文 - https://wsgzao.github.io/post/yum/

扩展阅读

RHEL/CentOS/OracleLinux 7.x 使用 EPEL 和 REMI 第三方 yum 源 - http://www.ha97.com/5649.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 6.X YUM 源

# 导入 GPG key
sudo rpm --import http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

# 修改 repo 文件添加 CentOS 6.X 的 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.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-plugin-downloadonly 插件
yum install -y yum-plugin-downloadonly

#YUM 只下载不安装
yum install --downloadonly --downloaddir=/tmp/puppet puppet

CentOS 7.X YUM 源

# 导入 GPG key
sudo rpm --import http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7

# 修改 repo 文件添加 CentOS 7.X 的 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/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-plugin-downloadonly 插件
yum install -y yum-plugin-downloadonly

#YUM 只下载不安装
yum install --downloadonly --downloaddir=/tmp/pacemaker pacemaker

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK