当前位置: 首页 > article >正文

yumdownloader介绍和使用示例

有时候公司的服务器外网权限控制的很严,不允许连接到外网。安装系统离线源之外的工具使用yum会直接报错,例如:

yum install autossh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.t-2.net
 * extras: centos.t-2.net
 * updates: centos.t-2.net
No package autossh available.
Error: Nothing to do

如果使用离线rpm安装的话,有很多依赖需要下载安装。

yumdownloader神器的出现完美的解决这这个问题,安装:

# yum install yum-utils -y

使用:

yumdownloader --resolve --destdir=/data/mypackages/ xxx
  • -–destdir:默认情况下,Yumdownloader 将会下载软件包到当前工作目录下.为了将软件下载到一个特定的目录下,我们使用  参数:
  • --resolve:解析所有依赖

示例1:安装httpd

1)使用yumdownloader下载依赖:

# yumdownloader --resolve --destdir=/root/mypackages/ httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
--> Running transaction check
---> Package httpd.i686 0:2.4.6-98.tl2.7.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-98.tl2.7.1 for package: httpd-2.4.6-98.tl2.7.1.i686
--> Processing Dependency: libaprutil-1.so.0 for package: httpd-2.4.6-98.tl2.7.1.i686
--> Processing Dependency: libapr-1.so.0 for package: httpd-2.4.6-98.tl2.7.1.i686
---> Package httpd.x86_64 0:2.4.6-98.tl2.7.1 will be installed
--> Running transaction check
---> Package apr.i686 0:1.4.8-7.tl2 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be updated
---> Package apr-util.i686 0:1.5.2-6.tl2.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.tl2.1 will be an update
---> Package httpd-tools.x86_64 0:2.4.6-98.tl2.7.1 will be installed
--> Finished Dependency Resolution
No Presto metadata available for tlinux
(1/6): apr-1.4.8-7.tl2.i686.rpm                                                                                                                                     | 108 kB  00:00:00     
(2/6): apr-util-1.5.2-6.tl2.1.i686.rpm                                                                                                                              |  93 kB  00:00:00     
(3/6): apr-util-1.5.2-6.tl2.1.x86_64.rpm                                                                                                                            |  92 kB  00:00:00     
(4/6): httpd-2.4.6-98.tl2.7.1.x86_64.rpm                                                                                                                            | 2.7 MB  00:00:00     
(5/6): httpd-tools-2.4.6-98.tl2.7.1.x86_64.rpm                                                                                                                      |  94 kB  00:00:00     
(6/6): httpd-2.4.6-98.tl2.7.1.i686.rpm 

# ll
total 5972
-rw-r--r-- 1 root root  110256 Nov 17  2020 apr-1.4.8-7.tl2.i686.rpm
-rw-r--r-- 1 root root   95376 Jun  5  2023 apr-util-1.5.2-6.tl2.1.i686.rpm
-rw-r--r-- 1 root root   93924 Jun  5  2023 apr-util-1.5.2-6.tl2.1.x86_64.rpm
-rw-r--r-- 1 root root 2838832 May  6  2023 httpd-2.4.6-98.tl2.7.1.i686.rpm
-rw-r--r-- 1 root root 2845720 May  6  2023 httpd-2.4.6-98.tl2.7.1.x86_64.rpm
-rw-r--r-- 1 root root   96368 May  6  2023 httpd-tools-2.4.6-98.tl2.7.1.x86_64.rpm

2)使用createrepo制作离线源

cd /root
createrepo mypackages                         #将mypackages目录制作成仓库

vim /etc/yum.repos.d/httpd.repo
[httpd]
name=httpd
baseurl=file:///root/mypackages/
gpgcheck=0
enabled=1

示例2:安装ansible

假设两台服务器A和B,A安装了ansible,B不允许联外网,无法使用yum安装,可以使用如下方式:

1)在A服务器上使用yumdownloader下载ansible依赖:

# yumdownloader --resolve ansible
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base                                                                                                                                                                | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                    | 3.5 kB  00:00:00     
epel                                                                                                                                                                | 4.7 kB  00:00:00     
extras                                                                                                                                                              | 3.4 kB  00:00:00     
tlinux                                                                                                                                                              | 4.0 kB  00:00:00     
updates                                                                                                                                                             | 3.4 kB  00:00:00     
--> Running transaction check
---> Package ansible.noarch 0:2.9.27-2.tl2 will be installed
--> Finished Dependency Resolution
ansible-2.9.27-2.tl2.noarch.rpm                                                                                                                                     |  17 MB  00:00:01     
[root@VM-18-54-centos /data/knowliu/ansible_dep]# ll
total 17416
-rw-r--r-- 1 root root 17832116 Feb  6  2023 ansible-2.9.27-2.tl2.noarch.rpm

注:只下载了ansible-2.9.27-2.tl2.noarch.rpm,以来貌似没有下载。

2)将ansible-2.9.27-2.tl2.noarch.rpm上传到服务器B,然后执行安装:

# rpm -ivh ansible-2.9.27-2.tl2.noarch.rpm 
error: Failed dependencies:
        python-httplib2 is needed by ansible-2.9.27-2.tl2.noarch
        python-paramiko is needed by ansible-2.9.27-2.tl2.noarch
        python2-jmespath is needed by ansible-2.9.27-2.tl2.noarch
        sshpass is needed by ansible-2.9.27-2.tl2.noarch

3)在A服务器上,继续使用yumdownloader下载以上的包:

# yumdownloader python-httplib2
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
python-httplib2-0.9.2-1.el7.noarch.rpm                                                                                                                              | 115 kB  00:00:00 

# yumdownloader python-paramiko
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
python-paramiko-2.1.1-9.tl2.noarch.rpm                                                                                                                              | 268 kB  00:00:00

# yumdownloader python2-jmespath
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
python2-jmespath-0.9.4-2.el7.noarch.rpm                                                                                                                             |  41 kB  00:00:00

# yumdownloader sshpass
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
sshpass-1.06-2.el7.x86_64.rpm                                                                                                                                       |  21 kB  00:00:00

4)在B服务器上执行依赖安装:

rpm -ivh python-httplib2-0.9.2-1.el7.noarch.rpm
rpm -ivh python-paramiko-2.1.1-9.tl2.noarch.rpm
rpm -ivh python2-jmespath-0.9.4-2.el7.noarch.rpm
rpm -ivh sshpass-1.06-2.el7.x86_64.rpm 
rpm -ivh ansible-2.9.27-2.tl2.noarch.rpm


http://www.kler.cn/a/160121.html

相关文章:

  • Mac 使用mac 原生工具将mp4视频文件提取其中的 mp3 音频文件
  • SpringCloud 微服务消息队列灰度方案 (RocketMQ 4.x)
  • 微信小程序——01开发前的准备和开发工具
  • 【缺陷检测】Anomaly Detection via Reverse Distillation from One-Class Embedding
  • linux设置主机名
  • Android中桌面小部件的开发流程及常见问题和解决方案
  • leetcode:用栈实现队列(先进先出)
  • mysql中year函数有什么用
  • 二叉树的右视图[中等]
  • MySQL电商管理系统练习题及答案
  • 【动手学深度学习】(十一)卷积层
  • 指针(三)
  • 使用Java网络编程,窗口,线程,IO,内部类等实现多人在线聊天1.0
  • 是否曾经想过关闭Microsoft账户,那么你来对地方了
  • QGraphicsView实现简易地图7『异步加载-多瓦片-无底图』
  • Linux--程序地址空间
  • 慎用!3个容易被打的Python恶搞脚本
  • Java中的并发编程:深入理解CountDownLatch
  • 从零开始学习 JavaScript APl(七):实例解析关于京东案例头部案例和放大镜效果!
  • 跳水比赛(C++)
  • 使用sqoop操作HDFS与MySQL之间的数据互传
  • Hello World
  • redis中使用pipeline
  • Qt Rsa 加解密方法使用(pkcs1, pkcs8, 以及文件存储和内存存储密钥)
  • 对于多台232modbus仪表低成本通讯的modbus转profinet网关
  • 微服务开发:断路器详解