How to install all dependent packages offline

Keywords: Python yum pip RPM

When we deploy something in an environment without public network, it is often a headache, because we may need a variety of dependency packages, which also have many dependencies. If we don't package and download all the dependency packages at one time, we can understand what Russian dolls are in the process of downloading..

1, os dependency package

1. Prepare a mirror that is basically consistent with the kernel version of the production deployment environment, and install the mini install version as the local environment

# cat /proc/version
Linux version 3.10.0-693.el7.x86_64 ( (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Aug 22 21:09:27 UTC 2017

2. Configure the yum source of the local environment and ensure that it can be connected to the public network. Generally, Alibaba's Yum source can be configured

# cd /etc/yum.repos.d/
# mkdir bak
# mv ./*repo bak
# curl -o /etc/yum.repos.d/CentOS-Base.repo
# yum clean all
# yum makecache

3. Download all the required dependency packages to the local directory via yum

# yum install --downloadonly --downloaddir= <target_dir> <package-name>

Note: to ensure that the production deployment environment can deploy its own local yum source, we need to download createrepo additionally

# yum install --downloadonly --downloaddir=/myrpm createrepo

4. Package all the above dependent packages to the production deployment environment and build the local yum source

1) Manually install createrepo through rpm

Follow the prompts to install the required dependency package
# rpm -ihv createrepo-0.9.9-28.el7.noarch.rpm

2) Build local yum source

#Create index directory of local rpm package repodata
# createrepo /myrpm/
Spawning worker 0 with 197 pkgs
Spawning worker 1 with 197 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

#If you update other dependent packages later, you don't need to rebuild, just update the index directory
# createrepo --update /myrpm/
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

#Configure yum source profile
# cd /etc/yum.repos.d/
# mkdir bak
# mv ./*repo bak
# cat local_yum.repo

#Clear yum cache
yum clean all

5. Deploy the installation through the local yum source

yum install <package-name>

2, python library installation

1. When downloading python dependency packages, you should pay attention to the consistency of python and pip versions in both environments

# /app/python/bin/virtualenv /clean_env
New python executable in /clean_env/bin/python2.7
Not overwriting existing python script /clean_env/bin/python (you must use /clean_env/bin/python2.7)
Installing setuptools, pip, wheel...done.

# source /clean_env/bin/activate
(clean_env) # python --version
Python 2.7.9
(clean_env) # pip --version
pip 20.2b1 from /clean_env/lib/python2.7/site-packages/pip (python 2.7)

2. Libraries and their dependent packages needed for local environment Download

#requirements.txt Under the file are all the libraries we need to install
(clean_env) # pip download -d <target-dir>  --trusted-host -r requirements.txt
(clean_env) # pip download -d <target-dir>  --trusted-host <package-name>

3. Package and upload all python packages to the production deployment environment

4. Production environment specifies package directory installation Library

# pip install --no-index --find-links=/root/python20/opsinsight/ -r requirements.txt
# pip install --no-index --find-links=/root/python20/opsinsight/ <package-name>

Posted by chacha102 on Thu, 04 Jun 2020 05:19:28 -0700