利用yum下载的rpm包制作本地yum源

5 篇文章 0 订阅

1、利用yum-utils工具从网络上下载rpm安装包
安装yum-utils包
yum -y install yum-utils

下载rpm包
yumdownloader --destdir=/tmp/soft/createrepo --resolve createrepo

脚本:
单个软件包下载脚本
#!/bin/bash
#--------------------------------------------
# name        :  yumonlydownrpm.sh
# author      :  zhaikaiyun
# param       :  yunmane 需要下载的软件名 storagepath 存储路径
# example     :  sh yumonlydownrpm.sh vsftpd /tmp/soft
#--------------------------------------------

if [ $# != 2 ] ; then
 echo "param error"
 echo "example : sh yumonlydownrpm.sh vsftpd /tmp/soft"
 exit 1
fi
softname=$1
storagepath=$2
echo "inpara ${softname} ${storagepath}"
echo "mkdir $storagepath/$softname"
mkdir $storagepath/$softname
echo "yumdownloader --destdir=$storagepath/$softname --resolve $softname"
yumdownloader --destdir=$storagepath/$softname --resolve $softname

例如:
[root@k8smaster01 soft]# sh yumonlydownrpm.sh lrzsz /tmp/soft
inpara lrzsz /tmp/soft
mkdir /tmp/soft/lrzsz
yumdownloader --destdir=/tmp/soft/lrzsz --resolve lrzsz
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * elrepo: mirrors.neusoft.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be reinstalled
--> Finished Dependency Resolution
lrzsz-0.12.20-36.el7.x86_64.rpm                                                                                                                      |  78 kB  00:00:02     
You have new mail in /var/spool/mail/root
[root@k8smaster01 soft]# 

批量软件包下载脚本
#!/bin/bash
#--------------------------------------------
# name        :  yumonlydownrpmbatch.sh
# author      :  zhaikaiyun
# param       :  storagepath 存储路径
# example     :  sh yumonlydownrpmbatch.sh /tmp/soft
#--------------------------------------------

if [ $# != 1 ] ; then
 echo "param error"
 echo "example : sh yumonlydownrpmbatch.sh /tmp/soft"
 exit 1
fi
storagepath=$1
echo "inpara ${storagepath}"
cat list.txt |while read softname  
do  
  echo "mkdir $storagepath/$softname"
  mkdir $storagepath/$softname
  echo "yumdownloader --destdir=$storagepath/$softname --resolve $softname"
  yumdownloader --destdir=$storagepath/$softname --resolve $softname
done

[root@k8smaster01 tmp]# more list.txt 
pvsadm
ipset
jq
iptables
curl
sysstat
libseccomp
wget
vim
net-tools
git
lrzsz 其他主机使用本地yum源安装测试使用
httpd
vsftpd
iptables-services
yum-utils
createrepo


下载后的安装包目录:
[root@k8smaster01 soft]# ls -lrt
total 16
drwxr-xr-x 2 root root   54 Jan  4 17:06 kernel-lt
drwxr-xr-x 2 root root    6 Jan  4 17:07 pvsadm
drwxr-xr-x 2 root root   77 Jan  4 17:07 ipset
drwxr-xr-x 2 root root    6 Jan  4 17:07 jq
drwxr-xr-x 2 root root 4096 Jan  4 17:07 iptables
drwxr-xr-x 2 root root  126 Jan  4 17:07 curl
drwxr-xr-x 2 root root   45 Jan  4 17:07 sysstat
drwxr-xr-x 2 root root 4096 Jan  4 17:07 libseccomp
drwxr-xr-x 2 root root   44 Jan  4 17:07 wget
drwxr-xr-x 2 root root 4096 Jan  4 17:08 vim
drwxr-xr-x 2 root root   58 Jan  4 17:08 net-tools
drwxr-xr-x 2 root root 4096 Jan  4 17:08 git
drwxr-xr-x 2 root root   44 Jan  4 17:08 lrzsz
drwxr-xr-x 2 root root   49 Jan  4 17:08 httpd
drwxr-xr-x 2 root root   43 Jan  4 17:08 vsftpd
drwxr-xr-x 2 root root   95 Jan  4 17:08 iptables-services
drwxr-xr-x 2 root root   47 Jan  4 17:08 yum-utils
drwxr-xr-x 2 root root   47 Jan  4 17:08 createrepo
[root@k8smaster01 soft]#


2、通过createrepo生成对应的repodata目录(软件仓库),会自动创建成一个yum本地源
安装createrepo
yum install createrepo  -y   #安装createrepo包
[root@k8smaster01 soft]# yum -y install createrepo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * elrepo: mirrors.neusoft.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Package createrepo-0.9.9-28.el7.noarch already installed and latest version
Nothing to do
[root@k8smaster01 soft]#

createrepo /tmp/soft/  自行创建完毕,新机器配置yum的源指向这个新的源
createrepo --update /tmp/soft/ 更新软件仓库

[root@k8smaster01 kernel-lt]# createrepo /tmp/soft/
Spawning worker 0 with 47 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

语法:
createrepo [option] <directory>
参数选项说明
-u  --baseurl <url>
    指定Base URL的地址
-o --outputdir <url>
    指定元数据的输出位置
-x --excludes <packages>
    指定在形成元数据时需要排除的包
-i --pkglist <filename>
    指定一个文件,该文件内的包信息将被包含在即将生成的元数据中,格式为每个包信息独占一行,不含通配符、正则,以及范围表达式。
-n --includepkg
    通过命令行指定要纳入本地库中的包信息,需要提供URL或本地路径。
-q --quiet
    安静模式执行操作,不输出任何信息。
-g --groupfile <groupfile>
    指定本地软件仓库的组划分,范例如下:
createrepo -g comps.xml /path/to/rpms
    注意:组文件需要和rpm包放置于同一路径下。
-v --verbose
    输出详细信息。
-c --cachedir <path>
    指定一个目录,用作存放软件仓库中软件包的校验和信息。
    当createrepo在未发生明显改变的相同仓库文件上持续多次运行时,指定cachedir会明显提高其性能。
--update
    如果元数据已经存在,且软件仓库中只有部分软件发生了改变或增减,
    则可用update参数直接对原有元数据进行升级,效率比重新分析rpm包依赖并生成新的元数据要高很多。
-p --pretty
    以整洁的格式输出xml文件。
-d --database
    该选项指定使用SQLite来存储生成的元数据,默认项。


3、安装httpd服务
[root@k8smaster01 soft]# yum install httpd -y
将本地生成的软件仓库放在/var/www/html目录,将本地yum源提供给其他机器使用
[root@k8smaster01 soft]# pwd
/var/www/html/soft
[root@k8smaster01 soft]# ls -lrt
total 20
drwxrwxrwx 2 root root   54 Jan  4 17:13 kernel-lt
drwxrwxrwx 2 root root    6 Jan  4 17:13 pvsadm
drwxrwxrwx 2 root root    6 Jan  4 17:13 jq
drwxrwxrwx 2 root root   77 Jan  4 17:13 ipset
drwxrwxrwx 2 root root 4096 Jan  4 17:13 iptables
drwxrwxrwx 2 root root   45 Jan  4 17:13 sysstat
drwxrwxrwx 2 root root  126 Jan  4 17:13 curl
drwxrwxrwx 2 root root 4096 Jan  4 17:13 libseccomp
drwxrwxrwx 2 root root   44 Jan  4 17:13 wget
drwxrwxrwx 2 root root 4096 Jan  4 17:13 vim
drwxrwxrwx 2 root root   58 Jan  4 17:13 net-tools
drwxrwxrwx 2 root root 4096 Jan  4 17:13 git
drwxrwxrwx 2 root root   44 Jan  4 17:13 lrzsz
drwxrwxrwx 2 root root   49 Jan  4 17:13 httpd
drwxrwxrwx 2 root root   43 Jan  4 17:13 vsftpd
drwxrwxrwx 2 root root   47 Jan  4 17:13 yum-utils
drwxrwxrwx 2 root root   95 Jan  4 17:13 iptables-services
drwxrwxrwx 2 root root   47 Jan  4 17:13 createrepo
drwxrwxrwx 2 root root 4096 Jan  4 17:13 repodata
[root@k8smaster01 soft]#

4、登录k8snode01机器,将yum源指向本地yum源
[root@k8snode01 ~]# more /etc/yum.repos.d/soft.repo 
[soft]
name=base
baseurl=http://192.168.23.134/soft
gpgcheck=0
[root@k8snode01 ~]# 
然后先清除yum缓存
yum clean all

使用本地yum源进行软件安装
[root@k8snode01 ~]# rpm -qa|grep lrzsz
[root@k8snode01 ~]# yum install -y lrzsz
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================
 Package                                Arch                                    Version                                         Repository                             Size
============================================================================================================================================================================
Installing:
 lrzsz                                  x86_64                                  0.12.20-36.el7                                  soft                                   78 k

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

Total download size: 78 k
Installed size: 181 k
Downloading packages:
lrzsz-0.12.20-36.el7.x86_64.rpm                                                                                                                      |  78 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : lrzsz-0.12.20-36.el7.x86_64                                                                                                                              1/1 
  Verifying  : lrzsz-0.12.20-36.el7.x86_64                                                                                                                              1/1 

Installed:
  lrzsz.x86_64 0:0.12.20-36.el7                                                                                                                                             

Complete!
[root@k8snode01 ~]# 
 


 
 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值