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 missing dependencies you need for that particular box, not all rpms.
First let’s install the yum-plugin-downloadonly:
1 | yum install -y yum-plugin-downloadonly |
1 | yum install --downloadonly --downloaddir=<directory> <package:version> |
For example, I want to get missing rpms for vim editor, reside them in /root/vim folder
1 | mkdir -p /root/vim |
List the target folder:
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 level rpm but --downloadonly will do nothing.
1 | yum install -y yum-utils |
1 | yumdownloader --resolve --destdir=/root/vim vim |
Download all rpms without installing
yum & yumdownloader
Usually what we really want is to resolve all dependencies and download them, even though some required rpms have already installed in box, 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.
1 | mkdir -p /root/vim |
This is what I need for a self-contained offline installer.
Let’s check how many vim related rpms are here, way too many then what we get from the first section.
1 | ls -ltr /root/vim | wc -l |
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.
1 | mkdir -p /root/vim |
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
repotrackhas-aoption to specify arch, but I am not able to use it, when I specifyx86_64, it still downloadsi686.
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, both command like:
1 | yum --disablerepo=* --skip-broken install -y /root/vim/*.rpm |
and
1 | rpm --force -ivh /root/vim/*.rpm |
may work but it’s not a good way, you may encounter rpm version upgrade issue and duplicate problem. Now from my knowledge create a local yum repository is clean and elegant, please refer my blog Set up and Use Local Yum Repository.