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
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 rpm but --downloadonly
will do nothing.
yum install -y yum-utils
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, 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 specifyx86_64
, it still downloadi686
.
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