前言
本文章讲述如何基于 TFTP 的方式搭建 YUM 仓库, 那么 YUM 仓库使用场景还是挺广泛的, 如果公司服务器数量较大的话, 可以在本地搭建 YUM 仓库, 在客户端创建 repo 文件指向 YUM 仓库, 那么当客户端 yum 安装软件的时候直接从本地 YUM 仓库中下载 rpm 包, 而 YUM 仓库可以定时的向互联网的 repo 仓库同步 rpm 包
YUM 仓库构建
本地光盘提供基础软件包 Base
yum 缓存提供 update 软件包
yum 缓存提供常? 软件包: nginx,zabbix,docker,saltstack
环境准备
系统 | IP | 角色 | 主机名 |
---|---|---|---|
centos7.4 | 10.0.0.171 | yum 仓库服务端 | yum_server_171 |
centos7.4 | 10.0.0.172 | yum 仓库服务端 | yum_client_172 |
服务端配置
1. 基础环境准备
- #1. 关闭防火墙
- [root@yum_server_171 ~]# systemctl stop firewalld
- [root@yum_server_171 ~]# systemctl disable firewalld
- #2. 关闭 selinux
- [root@yum_server_171 ~]# sed -i.ori 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
- [root@yum_server_171 ~]# setenforce 0
- [root@yum_server_171 ~]# getenforce
- Disabled
- #3. 安装 ftp 服务, 启动并加? 开机启动
- [root@yum_server_171 ~]# yum install vsftpd -y
- [root@yum_server_171 ~]# systemctl start vsftpd
- [root@yum_server_171 ~]# systemctl enable vsftpd
- #4. 开启 yum 缓存功能
- [root@yum_server_171 ~]# VIM /etc/yum.conf
- [main]
- cachedir=/var/cache/yum/$basearch/$releasever
- keepcache=1
- debuglevel=2
- ....
- # 清理所有 yum 缓存
- [root@yum_server_171 ~]# yum clean all
2. 提供基础的 base 源
- # 创建一个用于存放基础 base 的 rpm 包目录
- [root@yum_server_171 ~]# mkdir /var/ftp/centos74 -p
- # 挂载 iOS 镜像并拷贝该镜像中的 rpm 包至存放目录
- [root@yum_server_171 ~]# mount /dev/cdrom /mnt/
- [root@yum_server_171 ~]# cp /mnt/Packages/*.rpm /var/ftp/centos74/
- [root@yum_server_171 ~]# ls /var/ftp/centos74/ |wc -L
- 82
3. 提供第三方源
有些软件包需要添加对应的官方仓库, 例如 zabbix,saltstack, 需提前添加好对应软件包的 repo 仓库, 文中我就以 zabbix,saltstack 演示.
- # 创建一个用于存放第三放源的 rom 包目录
- [root@yum_server_171 ~]# mkdir /var/ftp/ops -p
- # 添加 zabbix repo 源
- [root@yum_server_171 ~]# rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
- # 添加 saltstack repo 源
- [root@yum_server_171 ~]# yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm
- [root@yum_server_171 ~]# sed -i "s/repo.saltstack.com/mirrors.aliyun.com\/saltstack/g" /etc/yum.repos.d/salt-latest.repo
- # 下载第三方 rpm 包
- [root@yum_server_171 ~]# yum -y install nginx docker zabbix-agent zabbix-server-MySQL salt-mastet salt-minion
- # 复制已缓存的 Nginx docker zabbix saltstack 及依赖包等, 到? 定义 YUM 仓库? 录中
- [root@yum_server_171 ~]# find /var/cache/yum/x86_64/7/ -iname "*.rpm" -exec cp -r {
- } /var/ftp/ops/ \;
- [root@yum_server_171 ~]# ll /var/ftp/ops/ |wc -l
- 99
4. 安装 createrepo 并创建 repo 仓库
- # 安装 createrepo, 用于仓库信息的生成
- [root@yum_server_171 ~]# yum -y install createrepo
- # 生成仓库信息
- [root@yum_server_171 ~]# createrepo /var/ftp/ops/
- [root@yum_server_171 ~]# createrepo /var/ftp/centos74/
注意: 如果此仓库每次新增软件包则需要重新? 成? 次 (createrepo)
5. 在浏览器输入 ftp://10.0.0.171/, 可访问到 ftp 的内容 (根据实际地址为准)
客户端使? yum 源
1. 备份原有仓库
[root@yum_client_172 ~]# gzip /etc/yum.repos.d/*
2. 配置并使用 base 基础源
- [root@yum_client_172 ~]# VIM /etc/yum.repos.d/centos7.repo
- [centos74]
- name=centos74_base
- baseurl=ftp://10.0.0.171/centos74
- gpgcheck=0
3. 客户端指向本地 ops 源 (第三方源)
- [root@yum_client_172 ~]# VIM /etc/yum.repos.d/ops.repo
- [ops]
- name=ops_repo
- baseurl=ftp://10.0.0.171/ops
- gpgcheck=0
4. 生成 yum 缓存并查看 repo 仓库列表
- [root@yum_client_172 ~]# yum makecache
- [root@yum_client_172 ~]# yum repolist
- Loaded plugins: fastestmirror
- Loading mirror speeds from cached hostfile
- repo id repo name status
- centos74 centos74_base 3,894
- ops ops_repo 98
- repolist: 3,992
5. 客户端 yum 安装 rpm 包
[root@yum_client_172 ~]# yum install nginx -y
可以看到安装 nginx 的过程中, 是从我们刚刚搭建的 yum 仓库中下载
来源: http://www.bubuko.com/infodetail-2945118.html