yumdownloader介绍和使用示例
2023-12-13 03:44:08
有时候公司的服务器外网权限控制的很严,不允许连接到外网。安装系统离线源之外的工具使用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
文章来源:https://blog.csdn.net/liuxiao723846/article/details/134840647
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!