• 【yum自动解决包依赖】linux离线安装rpm包及其依赖和卸载包及其依赖


    问题描述:

    在公司的Linux服务器需要安装一些软件,但是服务器无法连接外网,如果一个一个找软件包下载,需要解决的依赖太多,比较费事。

    流程:

    对于同一版本CentOS,我们可以事先下载离线依赖包,后面用命令手动安装。

    准备条件:

    一台能正常上网的主机【最好和需要离线安装的主机是同一系统版本】
    下载离线包的这台主机不能先安装该包,否则无法下载,如果已经安装该包,那么必须先卸载需要离线的包及其依赖,方法见下面的yum卸载包及其依赖。

    离线包安装流程

    下载离线包

    1. 登陆一台能正常通外网的服务器
    2. 下载离线包使用的命令格式是:
    yum -y install --downloadonly --downloaddir=存放路径 包名
    --downloadonly:下载不安装的意思
    --downloaddir=存放路径:这是下载存放的路径,可以不要这行,但建议加上
    
    【不加这行下载的默认路径我不知道在哪,也懒的去查,你可以用 find 查询下载的包看出默认路径的。】
    
    • 1
    • 2
    • 3
    • 4
    • 5
    1. 注:下载离线包的主机务必不能先安装该包,如果已经安装,先卸载包及其依赖,方法见下面yum卸载包及其依赖。
    2. 下载完毕以后就可以将这些包全部拷贝到需要离线安装的文件中了。
    3. 如果服务器很多的话,可以写个批量拷贝文件的脚本,然后把下面安装离线包的命令放在后面,一并就解压了哦。

    在这里插入图片描述

    安装离线包

    1. 方法很简单:在存放需要安装的软件包目录下,执行下面一行代码即可了
    rpm -ivhU * --nodeps --force
    
    • 1

    -ivhU:先安装并升级,这个U建议加上,因为有些命令安装是有升级的服务的,如果不加U就失败了【比如java】【如何确定哪些包有升级的包,直接在通外网的服务器上yum安装该服务,看过程即可】
    –nodeps --force:忽略软件包的依赖关系,忽略软件包及文件的冲突并强行安装

    rpm卸载包

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

    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]#
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
  • 相关阅读:
    dll文件缺失,ps,pr无法打开,游戏运行不了如何解决
    Redis 切片集群的数据倾斜分析
    ElementPlus· banner轮播图实现
    vConsole调试工具的三种使用方式
    SRE 排障利器,接口请求超时试试 httpstat
    java面向对象进阶之static
    风控建模还在用IV特征分箱“老方法”,何不试下这个更有效的实操
    kubeadm部署k8s教程(5)---容器挂载本地磁盘
    大学生想做兼职应该怎么找,适合大学生的线上线下靠谱兼职推荐
    设计模式——面向对象设计原则
  • 原文地址:https://blog.csdn.net/zhuan_long/article/details/126120770