[Advanced Operation and Maintenance Knowledge] One-click deployment of yum local warehouse

Using yum local warehouse can improve download speed, can be used offline, realize software version consistency and software security, etc. This article will introduce how to make yum local warehouse and achieve one-click deployment. The principle of yum local warehouse is to The required software packages are downloaded from the Internet to a local machine or a server in the network, and through certain configurations, the server can provide software packages from the local repository. When you need to install software, you can obtain the necessary software packages from the local repository for installation.

I encapsulated all operations into scripts and implemented one-click deployment of the yum local warehouse.

Configure the virtual machine first.

c626d1489cbc431bb092919da8315fd3.png

Warehouse deployment script

[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 <<EOF
server {
    listen 80 default_server;
    root /share;
    index index.html index.htm;
    autoindex on;
    autoindex_exact_size on;
    autoindex_localtime on;
}
EOF

# 准备yum仓库存储目录
mkdir /share/packages
chown -R nginx:nginx /share/packages

# 安装createrepo
yum -y install createrepo 

# 复制rpm包到本地yum仓库
cp -a /mnt/Packages/* /share/packages/

# 构建yum仓库
createrepo /share/packages/

# 启动nginx服务,并将服务加入开机启动项中
systemctl start nginx
systemctl enable nginx

One-click deployment of yum warehouse

[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.

View yum local repository

[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

129dd23d0f1546f9aa31d4014ea0b6c4.png

2daa31d3e1f0495e9a8487960fb337b8.png

Configure the yum source on the client for test downloading

[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!

Frequently asked questions about yum local warehouse

When using the yum local warehouse, the installed software may lack dependencies. At this time, we need to install our dependencies, put the dependency packages into the local warehouse, and then refresh the local warehouse cache.

Perform the following operations on the yum warehouse side to recreate the yum warehouse

createrepo /share/packages/

The client performs the following operations to refresh the local warehouse cache

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

 My name is Koten. I have 10 years of operation and maintenance experience. I continue to share operation and maintenance tips. Thank you for reading and paying attention!

 

Guess you like

Origin blog.csdn.net/qq_37510195/article/details/130694200