【yum】linux离线安装rpm包及其依赖和卸载包及其依赖

本文详细介绍了在CentOS系统中如何进行离线安装和卸载Docker的流程。首先,在可上网的主机上使用`yum`命令下载所需依赖包并保存,然后将这些包拷贝到离线服务器上,通过`rpm`命令进行安装。卸载时,使用`rpm`命令移除包及其依赖,或者使用`yum autoremove`删除包及其不必要的依赖。
摘要由CSDN通过智能技术生成

说明

  • 流程:对于同一版本CentOS,我们可以事先下载离线依赖包,后面用命令手动安装。
  • 准备条件:一台能正常上网的主机【最好和需要离线安装的主机是同一系统版本】
  • 下载离线包的这台主机不能先安装该包,否则无法下载,如果已经安装该包,那么必须先卸载需要离线的包及其依赖,方法见下面的yum卸载包及其依赖。

离线包安装流程

下载离线包

  • 登陆一台能正常通外网的服务器
  • 下载离线包使用的命令格式是:yum -y install --downloadonly --downloaddir=存放路径 包名
    • --downloadonly:下载不安装的意思
    • --downloaddir=存放路径:这是下载存放的路径,可以不要这行,但建议加上【不加这行下载的默认路径我不知道在哪,也懒的去查,你可以用 find 查询下载的包看出默认路径的。】
      注:下载离线包的主机务必不能先安装该包,如果已经安装,先卸载包及其依赖,方法见下面yum卸载包及其依赖。
  • 如:我下载docker的离线包,并放在/docker文件中为例
[root@ccx ~]# mkdir /docker
[root@ccx ~]# yum install docker-ce -y --downloaddir=/docker --downloadonly 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:20.10.7-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-20.10.7-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.4.1 for package: 3:docker-ce-20.10.7-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-20.10.7-3.el7.x86_64
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.7-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package containerd.io.x86_64 0:1.4.6-3.1.el7 will be installed
---> Package docker-ce-cli.x86_64 1:20.10.7-3.el7 will be installed
--> Processing Dependency: docker-scan-plugin(x86-64) for package: 1:docker-ce-cli-20.10.7-3.el7.x86_64
---> Package docker-ce-rootless-extras.x86_64 0:20.10.7-3.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-20.10.7-3.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-20.10.7-3.el7.x86_64
--> Running transaction check
---> Package docker-scan-plugin.x86_64 0:0.8.0-3.el7 will be installed
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================
 Package                          Arch          Version                          Repository               Size
===============================================================================================================
Installing:
 docker-ce                        x86_64        3:20.10.7-3.el7                  docker-ce-stable         27 M
Installing for dependencies:
 container-selinux                noarch        2:2.119.2-1.911c772.el7_8        extras                   40 k
 containerd.io                    x86_64        1.4.6-3.1.el7                    docker-ce-stable         34 M
 docker-ce-cli                    x86_64        1:20.10.7-3.el7                  docker-ce-stable         33 M
 docker-ce-rootless-extras        x86_64        20.10.7-3.el7                    docker-ce-stable        9.2 M
 docker-scan-plugin               x86_64        0.8.0-3.el7                      docker-ce-stable        4.2 M
 fuse-overlayfs                   x86_64        0.7.2-6.el7_8                    extras                   54 k
 fuse3-libs                       x86_64        3.6.1-4.el7                      extras                   82 k
 slirp4netns                      x86_64        0.4.3-4.el7_8                    extras                   81 k

Transaction Summary
===============================================================================================================
Install  1 Package (+8 Dependent packages)

Total download size: 107 M
Installed size: 438 M
Background downloading packages, then exiting:
(1/9): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm                             |  40 kB  00:00:00     
(2/9): docker-ce-20.10.7-3.el7.x86_64.rpm                                               |  27 MB  00:00:16     
(3/9): containerd.io-1.4.6-3.1.el7.x86_64.rpm                                           |  34 MB  00:00:21     
(4/9): docker-ce-rootless-extras-20.10.7-3.el7.x86_64.rpm                               | 9.2 MB  00:00:06     
(5/9): fuse3-libs-3.6.1-4.el7.x86_64.rpm                                                |  82 kB  00:00:00     
(6/9): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                                             |  81 kB  00:00:00     
(7/9): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm                                          |  54 kB  00:00:01     
(8/9): docker-scan-plugin-0.8.0-3.el7.x86_64.rpm                                        | 4.2 MB  00:00:02     
(9/9): docker-ce-cli-20.10.7-3.el7.x86_64.rpm                                           |  33 MB  00:00:21     
---------------------------------------------------------------------------------------------------------------
Total                                                                          2.8 MB/s | 107 MB  00:00:37     
exiting because "Download Only" specified
[root@ccx ~]# cd /docker/
[root@ccx docker]# ls
containerd.io-1.4.6-3.1.el7.x86_64.rpm                docker-scan-plugin-0.8.0-3.el7.x86_64.rpm
container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm  fuse3-libs-3.6.1-4.el7.x86_64.rpm
docker-ce-20.10.7-3.el7.x86_64.rpm                    fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
docker-ce-cli-20.10.7-3.el7.x86_64.rpm                slirp4netns-0.4.3-4.el7_8.x86_64.rpm
docker-ce-rootless-extras-20.10.7-3.el7.x86_64.rpm
[root@ccx docker]# 

下载完毕以后就可以将这些包全部拷贝到需要离线安装的文件中了。
如果服务器很多的话,可以写个批量拷贝文件的脚本,然后把下面安装离线包的命令放在后面,一并就解压了哦。

安装离线包

  • 方法很简单:在存放需要安装的软件包目录下,执行下面一行代码即可了
    rpm -ivhU * --nodeps --force
    • -ivhU:先安装并升级,这个U建议加上,因为有些命令安装是有升级的服务的,如果不加U就失败了【比如java】【如何确定哪些包有升级的包,直接在通外网的服务器上yum安装该服务,看过程即可】
    • --nodeps --force:忽略软件包的依赖关系,忽略软件包及文件的冲突并强行安装
  • 如,我以安装docker为例:
[root@ccx docker]# ls
containerd.io-1.4.6-3.1.el7.x86_64.rpm                docker-scan-plugin-0.8.0-3.el7.x86_64.rpm
container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm  fuse3-libs-3.6.1-4.el7.x86_64.rpm
docker-ce-20.10.7-3.el7.x86_64.rpm                    fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
docker-ce-cli-20.10.7-3.el7.x86_64.rpm                slirp4netns-0.4.3-4.el7_8.x86_64.rpm
docker-ce-rootless-extras-20.10.7-3.el7.x86_64.rpm
[root@ccx docker]# 
[root@ccx docker]# rpm -ivhU * --nodeps --force
Preparing...                          ################################# [100%]
Updating / installing...
   1:docker-scan-plugin-0:0.8.0-3.el7 ################################# [ 11%]
   2:docker-ce-cli-1:20.10.7-3.el7    ################################# [ 22%]
   3:container-selinux-2:2.119.2-1.911################################# [ 33%]
   4:containerd.io-1.4.6-3.1.el7      ################################# [ 44%]
   5:slirp4netns-0.4.3-4.el7_8        ################################# [ 56%]
   6:fuse3-libs-3.6.1-4.el7           ################################# [ 67%]
   7:fuse-overlayfs-0.7.2-6.el7_8     ################################# [ 78%]
   8:docker-ce-rootless-extras-0:20.10################################# [ 89%]
   9:docker-ce-3:20.10.7-3.el7        ################################# [100%]
[root@ccx docker]# 
[root@ccx docker]# systemctl restart docker
[root@ccx docker]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@ccx docker]# 

rpm卸载包

用rpm安装的包是不能通过yum卸载的,只能通过rpm卸载,命令:rpm -e --nodeps package【如果不加–nodeps,就会因为有依赖导致卸载报错】
如上,安装了9个,就需要rpm -e 包名【复制粘贴上面的包名】重复9次【需要去掉后缀】。

[root@ccx ~]# rpm -e --nodeps fuse-overlayfs
[root@ccx ~]# rpm -e --nodeps containerd.io
[root@ccx ~]# rpm -e --nodeps docker-scan-plugin
[root@ccx ~]# rpm -e --nodeps container-selinux
[root@ccx ~]# rpm -e --nodeps fuse3-libs
[root@ccx ~]# rpm -e --nodeps docker-ce-cli
[root@ccx ~]# rpm -e --nodeps slirp4netns
[root@ccx ~]# rpm -e --nodeps docker-ce
[root@ccx ~]# rpm -e --nodeps docker-ce-rootless-extras # 这个卸载报错是因为卸载docker-ce的时候一并给卸载了】
error: package docker-ce-rootless-extras is not installed

卸载完毕重新去下载的时候,发现又是9个包了

Total download size: 107 M
Installed size: 438 M
Background downloading packages, then exiting:
(1/9): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm                             |  40 kB  00:00:00     
(2/9): docker-ce-20.10.7-3.el7.x86_64.rpm                                               |  27 MB  00:00:13     
(3/9): containerd.io-1.4.6-3.1.el7.x86_64.rpm                                           |  34 MB  00:00:18     
(4/9): docker-ce-rootless-extras-20.10.7-3.el7.x86_64.rpm                               | 9.2 MB  00:00:04     
(5/9): fuse3-libs-3.6.1-4.el7.x86_64.rpm                                                |  82 kB  00:00:00     
(6/9): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm                                          |  54 kB  00:00:00     
(7/9): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                                             |  81 kB  00:00:00     
(8/9): docker-scan-plugin-0.8.0-3.el7.x86_64.rpm                                        | 4.2 MB  00:00:02     
(9/9): docker-ce-cli-20.10.7-3.el7.x86_64.rpm                                           |  33 MB  00:00:15     
---------------------------------------------------------------------------------------------------------------
Total                                                                          3.7 MB/s | 107 MB  00:00:29     
exiting because "Download Only" specified

yum卸载包及其依赖

  • 我们知道卸载包的命令是:yum remove package【方法并不会卸载其依赖】
  • 卸载包及其依赖的命令是:yum autoremove package
  • 如下,我以卸载docker及其依赖为例
[root@ccx docker]# yum autoremove docker-ce
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:20.10.7-3.el7 will be erased
--> Processing Dependency: docker-ce for package: docker-ce-rootless-extras-20.10.7-3.el7.x86_64
--> Running transaction check
---> Package docker-ce-rootless-extras.x86_64 0:20.10.7-3.el7 will be erased
--> Finished Dependency Resolution
--> Finding unneeded leftover dependencies
---> Marking docker-ce-cli to be removed - no longer needed by docker-ce
---> Marking container-selinux to be removed - no longer needed by docker-ce
---> Marking containerd.io to be removed - no longer needed by docker-ce
---> Marking fuse-overlayfs to be removed - no longer needed by docker-ce-rootless-extras
---> Marking slirp4netns to be removed - no longer needed by docker-ce-rootless-extras
---> Marking docker-scan-plugin to be removed - no longer needed by docker-ce-cli
---> Marking fuse3-libs to be removed - no longer needed by fuse-overlayfs
Found and removing 7 unneeded dependencies
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be erased
---> Package containerd.io.x86_64 0:1.4.6-3.1.el7 will be erased
---> Package docker-ce-cli.x86_64 1:20.10.7-3.el7 will be erased
---> Package docker-scan-plugin.x86_64 0:0.8.0-3.el7 will be erased
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be erased
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be erased
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================
 Package                         Arch         Version                            Repository               Size
===============================================================================================================
Removing:
 docker-ce                       x86_64       3:20.10.7-3.el7                    @docker-ce-stable       115 M
Removing for dependencies:
 container-selinux               noarch       2:2.119.2-1.911c772.el7_8          @extras                  41 k
 containerd.io                   x86_64       1.4.6-3.1.el7                      @docker-ce-stable       129 M
 docker-ce-cli                   x86_64       1:20.10.7-3.el7                    @docker-ce-stable       156 M
 docker-ce-rootless-extras       x86_64       20.10.7-3.el7                      @docker-ce-stable        24 M
 docker-scan-plugin              x86_64       0.8.0-3.el7                        @docker-ce-stable        13 M
 fuse-overlayfs                  x86_64       0.7.2-6.el7_8                      @extras                 116 k
 fuse3-libs                      x86_64       3.6.1-4.el7                        @extras                 270 k
 slirp4netns                     x86_64       0.4.3-4.el7_8                      @extras                 169 k

Transaction Summary
===============================================================================================================
Remove  1 Package (+8 Dependent packages)

Installed size: 438 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : docker-ce-rootless-extras-20.10.7-3.el7.x86_64                                              1/9 
  Erasing    : 3:docker-ce-20.10.7-3.el7.x86_64                                                            2/9 
  Erasing    : containerd.io-1.4.6-3.1.el7.x86_64                                                          3/9 
  Erasing    : docker-scan-plugin-0.8.0-3.el7.x86_64                                                       4/9 
  Erasing    : 1:docker-ce-cli-20.10.7-3.el7.x86_64                                                        5/9 
  Erasing    : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                         6/9 
  Erasing    : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                          7/9 
  Erasing    : fuse3-libs-3.6.1-4.el7.x86_64                                                               8/9 
  Erasing    : slirp4netns-0.4.3-4.el7_8.x86_64                                                            9/9 
  Verifying  : containerd.io-1.4.6-3.1.el7.x86_64                                                          1/9 
  Verifying  : fuse3-libs-3.6.1-4.el7.x86_64                                                               2/9 
  Verifying  : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                         3/9 
  Verifying  : slirp4netns-0.4.3-4.el7_8.x86_64                                                            4/9 
  Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                          5/9 
  Verifying  : 3:docker-ce-20.10.7-3.el7.x86_64                                                            6/9 
  Verifying  : 1:docker-ce-cli-20.10.7-3.el7.x86_64                                                        7/9 
  Verifying  : docker-ce-rootless-extras-20.10.7-3.el7.x86_64                                              8/9 
  Verifying  : docker-scan-plugin-0.8.0-3.el7.x86_64                                                       9/9 

Removed:
  docker-ce.x86_64 3:20.10.7-3.el7                                                                             

Dependency Removed:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8      containerd.io.x86_64 0:1.4.6-3.1.el7                 
  docker-ce-cli.x86_64 1:20.10.7-3.el7                    docker-ce-rootless-extras.x86_64 0:20.10.7-3.el7     
  docker-scan-plugin.x86_64 0:0.8.0-3.el7                 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8                
  fuse3-libs.x86_64 0:3.6.1-4.el7                         slirp4netns.x86_64 0:0.4.3-4.el7_8                   

Complete!
[root@ccx docker]#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

҉人间无事人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值