Offline Package Installation I

When I was working on the upgrade DS k8s installer issue, I ran into the problem that I need to install ansible, docker and kubeadm offline. In the production environment, we may not have internet access, that means we need to prepare the rpms and dependencies needed and create a self-contained installer.

Download missing rpms without installing

Note: This method is (by-design) sensitive to the existence of already-installed packages. It will only download actual dependencies you need for that particular box, not all.

First let's install the yum-plugin-downloadonly:

yum install -y yum-plugin-downloadonly
yum install --downloadonly --downloaddir=<directory> <package:version>

For example, I want to get missing rpms for vim editor, reside them in /root/vim folder

mkdir -p /root/vim
yum install --downloadonly --downloaddir=/root/vim vim

...
Total download size: 7.0 M
Installed size: 23 M
Background downloading packages, then exiting:
(1/4): vim-common-7.4.160-5.el7.x86_64.rpm                                                     | 5.9 MB  00:00:00     
(2/4): vim-enhanced-7.4.160-5.el7.x86_64.rpm                                                   | 1.0 MB  00:00:00     
(3/4): vim-filesystem-7.4.160-5.el7.x86_64.rpm                                                 |  10 kB  00:00:00     
(4/4): gpm-libs-1.20.7-5.el7.x86_64.rpm                                                        |  32 kB  00:00:00     
----------------------------------------------------------------------------------------------------------------------
Total                                                                                  39 MB/s | 7.0 MB  00:00:00     
exiting because "Download Only" specified

List the target folder:

total 7168
-rw-r--r-- 1 root root   32988 Jan 26  2018 gpm-libs-1.20.7-5.el7.x86_64.rpm
-rw-r--r-- 1 root root   10500 Oct 30 21:22 vim-filesystem-7.4.160-5.el7.x86_64.rpm
-rw-r--r-- 1 root root 6197920 Oct 30 21:22 vim-common-7.4.160-5.el7.x86_64.rpm
-rw-r--r-- 1 root root 1087684 Oct 30 21:24 vim-enhanced-7.4.160-5.el7.x86_64.rpm

Another way is using yumdownloader that is from yum-utils. The difference is if the package is already installed completely, yumdownloader will download the outermost rpm but --downloadonly will do nothing.

yum install -y yum-utils
yumdownloader --resolve --destdir=/root/vim vim

Loaded plugins: product-id
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.160-5.el7 will be installed
--> Processing Dependency: vim-common = 2:7.4.160-5.el7 for package: 2:vim-enhanced-7.4.160-5.el7.x86_64
--> Processing Dependency: libgpm.so.2()(64bit) for package: 2:vim-enhanced-7.4.160-5.el7.x86_64
--> Running transaction check
---> Package gpm-libs.x86_64 0:1.20.7-5.el7 will be installed
---> Package vim-common.x86_64 2:7.4.160-5.el7 will be installed
--> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.160-5.el7.x86_64
--> Running transaction check
---> Package vim-filesystem.x86_64 2:7.4.160-5.el7 will be installed
--> Finished Dependency Resolution
(1/4): gpm-libs-1.20.7-5.el7.x86_64.rpm                                                        |  32 kB  00:00:00     
(2/4): vim-enhanced-7.4.160-5.el7.x86_64.rpm                                                   | 1.0 MB  00:00:00     
(3/4): vim-filesystem-7.4.160-5.el7.x86_64.rpm                                                 |  10 kB  00:00:00     
(4/4): vim-common-7.4.160-5.el7.x86_64.rpm                                                     | 5.9 MB  00:00:00 

Download all rpms without installing

yum & yumdownloader

Usually what we really want is to resolve all dependencies and download them, yumdownloader or yum --downloadonly with --installroot option is the solution.

Keep in mind, that yumdownloader will use your yum database when resolving dependencies.

For example if you download bash, which needs glibc, it will resolve glibc and skip it, since it is installed. If you want to download all dependencies, use a different installroot instead.

mkdir -p /root/vim
mkdir -p /root/new_root
yumdownloader --installroot=/root/new_root --destdir=/root/vim/ --resolve vim

Let's check how many ansible related rpms are here, way to many then what we get from the first section methods.

ls -ltr /root/vim | wc -l
57

repotrack

This method can also resolve and download all dependencies, repotrack is from yum-utils, it will down all the dependencies for any architecture by default if it doesn't appear you specified the architecture which could account for the difference in what you see downloaded.

mkdir -p /root/vim
repotrack -p /root/vim vim-enhanced

if you check /root/vim, there are some i686 rpms, once you delete them and count again, 57 the same as we use yumdownloader above.

Note: actually repotrack has -a option to specify arch, but I am not able to figure it out, when I specify x86_64, it still download i686.

Install local rpms

Now the problem is how to install these rpms in correct order, install them one by one is obviously infeasible, the method that can resolve their dependencies and install automatically is welcome:

yum --disablerepo=* --skip-broken install -y /root/vim/*.rpm
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章