In order to install the package in an environment isolated from the external network, you need to use yum to download the package first, then create a local yum repository, and finally add it to the yum configuration.
Download package
yum install --downloadonly --downloaddir=path/of/local wget git #It should be noted that if the package is already installed, this step cannot be downloaded.
Create a local repository
To create a warehouse, you need a small tool: createrepo
rpm -ivh deltarpm-3.6-3.el7.x86_64.rpm rpm -ivh python-deltarpm-3.6-3.el7.x86_64.rpm rpm -ivh libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm createrepo /path/of/localrepo
release repository
To publish a repository is to add a configuration file to /etc/yum.repos.d/, the content of the file is as follows
#Note that gpgcheck must be 0 #enable should be 1 [my-media] name=CentOS-$releasever - myrepo baseurl = file: /// path/of/localrepo gpgcheck=0 enabled=1
At the same time, you should also remove /etc/yum.repos.d/CentOS.repo and /etc/yum.repos.d/epel.repo, otherwise the local package may not be found during installation.
After completing the above steps, you can use yum install happily.
full tool script
For the convenience of use, the following script is made, when using
#download bash mkrepo.sh download wget git nginx #create repository bash mkrepo.sh init #Publish repository #Package the above directory, copy it to the target machine, and start publishing bash mkrepo.sh publish #clear warehouse bash mkrepo.sh unpublis
mkrepo.sh script
#!/usr/bin/env bash basedir=$(dirname $0) cd ${basedir} x=file://$(pwd) DIR="${x//\//\/}" case "$1" in "download" ) str="" for ((i=2;i<=$#;i++)) do echo ${!i} str="$str ${!i}" done if [ -z "$str" ]; then echo "no pakages specified"; exit 1; be yum install --downloadonly --downloaddir=$(pwd) $str ;; "init" ) rpm -ivh deltarpm-3.6-3.el7.x86_64.rpm rpm -ivh python-deltarpm-3.6-3.el7.x86_64.rpm rpm -ivh libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm createrepo $(pwd) rpm -e createrepo-0.9.9-28.el7.noarch rpm -e libxml2-python-2.9.1-6.el7_2.3.x86_64 rpm -e python-deltarpm-3.6-3.el7.x86_64 rpm -e deltarpm-3.6-3.el7.x86_64 ;; "publish" ) sed -r "s/^baseurl.*$/baseurl=$DIR/" zc.repo > /etc/yum.repos.d/zc.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak ;; "unpublish" ) rm /etc/yum.repos.d/zc.repo mv /etc/yum.repos.d/CentOS-Base.repo.bak /etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/epel.repo.bak /etc/yum.repos.d/epel.repo ;; * ) echo "Usage:" echo " bash $basedir/$0 command <params>" echo "commands include: " echo " download pakagenames. names seperated by blankspace" echo " init , create a local rpm repo" echo " publish, add this repo to rpm repos" echo " unpublist, remove this repo from rpm repos" ;; esac