【运维知识进阶篇】一键部署yum本地仓库

使用yum本地仓库有提升下载速度,可以离线使用,实现软件版本一致性与软件安全性等等好处,本篇文章来介绍下如何制作yum本地仓库,实现一键部署,yum本地仓库的原理是将需要的软件包从互联网上下载到一个本机或网络内的服务器上,并通过一定的配置使得这个服务器可以提供来自本地仓库的软件包。当需要安装软件时,可以从本地仓库中获取必要的软件包进行安装。

我将所有的操作封装进了脚本,实现了一键部署yum本地仓库。

先配置好虚拟机。

【运维知识进阶篇】一键部署yum本地仓库_第1张图片

仓库部署脚本

[root@Ansible ~]# cat /bash/yum-repo-deploy.sh 
#!/bin/bash

# 挂载CDROM并授权
mount -t iso9660 /dev/sr0 /mnt/ -o loop,ro 
chmod -R +r /mnt/

# 安装epel源
yum -y install epel-release

# 安装nginx
yum -y install nginx

# 创建目录,准备Nginx默认站点
mkdir /share
chown -R nginx:nginx /share

# 删除Nginx默认站点,并在其目录中创建yum.conf文件进行yum仓库目录索引
rm /etc/nginx/conf.d/default.conf
cat > /etc/nginx/conf.d/yum.conf <

一键部署yum仓库

[root@Ansible ~]# sh /bash/yum-repo-deploy.sh 
......
Spawning worker 0 with 4070 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

查看yum本地仓库

[root@Ansible ~]# ls /share/
packages/ test.txt 
[root@Ansible ~]# ls /share/packages/
......
yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
yum-plugin-tmprepo-1.1.31-54.el7_8.noarch.rpm
yum-plugin-verify-1.1.31-54.el7_8.noarch.rpm
yum-plugin-versionlock-1.1.31-54.el7_8.noarch.rpm
yum-utils-1.1.31-54.el7_8.noarch.rpm
zenity-3.28.1-1.el7.x86_64.rpm
zip-3.0-11.el7.x86_64.rpm
zlib-1.2.7-18.el7.x86_64.rpm
zlib-devel-1.2.7-18.el7.x86_64.rpm
zsh-5.0.2-34.el7_8.2.x86_64.rpm
zziplib-0.13.62-12.el7.x86_64.rpm

【运维知识进阶篇】一键部署yum本地仓库_第2张图片

【运维知识进阶篇】一键部署yum本地仓库_第3张图片

客户端配置yum源,进行测试下载

[root@Web01 ~]# mv /etc/yum.repos.d/* /opt/
[root@Web01 ~]# cat /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=http://10.0.0.61/packages
enabled=1
[root@Web01 ~]# yum -y install tree
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================
 Package  Arch       Version           Repository
                                                  Size
=======================================================
Installing:
 tree     x86_64     1.6.0-10.el7      local      46 k

Transaction Summary
=======================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm      |  46 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : tree-1.6.0-10.el7.x86_64            1/1 
  Verifying  : tree-1.6.0-10.el7.x86_64            1/1 

Installed:
  tree.x86_64 0:1.6.0-10.el7                           

Complete!

yum本地仓库常见问题

使用yum本地仓库可能会出现安装的软件缺少依赖的情况,此时我们需要去安装我们的依赖,将依赖包放入本地仓库中,再进行本地仓库缓存刷新

yum仓库端进行如下操作,重新创建yum仓库

createrepo /share/packages/

客户端进行如下操作,刷新本地仓库缓存

yum clean all
yum makecache
yum repolist #查看yum源中是否有软件包

 我是koten,10年运维经验,持续分享运维干货,感谢大家的阅读和关注!

你可能感兴趣的:(进阶运维知识,运维知识分享,运维,服务器,linux,yum本地仓库,yum)