background

During project deployment, apt/ PIP packages need to be cached offline in advance. The laptop is then plugged into the deployment site as an APT/PIP source server.

Software to prepare

Apt-mirror: Synchronize apt package, because I don’t know the small version number of the field system, here directly pull down the Ubuntu Bionc library, about 230GB. Pip2pi: Synchronizes pYPI packets

steps

apt-mirror

The installation
sudo apt update
sudo apt install -y apt-mirror
Copy the code
configuration

Modify base_PATH, RUN_postmirror, and synchronization source

############# config ##################
#
set base_path    /var/www/html
#
# set mirror_path $base_path/mirror
# set skel_path    $base_path/skel
# set var_path     $base_path/var
# set cleanscript $var_path/clean.sh
set defaultarch  amd64
# set postmirror_script $var_path/postmirror.sh
#Postmirror. sh: postmirror.sh: postmirror.sh: postmirror.sh: postmirror.sh: postmirror.sh
set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# clean http://mirrors.tuna.tsinghua.edu.cn/ubuntu

# postgresql
deb http://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/apt/ bionic-pgdg main
deb https://packagecloud.io/timescale/timescaledb/ubuntu/ bionic main

Copy the code

Pit point

  1. Postgresql libraries require their own keys. Apt-mirror does not synchronize key information
  2. Timescaledb sets up the mirror library and adds GPG in advance otherwise the Release file is missing

See: packagecloud. IO/timescale/t…

Synchronization and Use

sudo apt-mirror
# Sync took all morning. And it is strongly recommended to execute in TMUx. Will SSH break by itself? It's very metaphysical
sudo apt install nginx
Copy the code

Delete the default soft links in /etc/nginx/sites-enable to prevent port 80 from being used in the conf.d directory, create xx.conf, and set the parameters as follows

server { listen 80; listen [::]:80; server_name mirror.xxx.cn; location / { alias /var/www/shared/; autoindex on; autoindex_exact_size off; autoindex_localtime on; }}Copy the code

/var/ WWW /shared/ = /shared/ = /var/ WWW /shared/

sudo ln -s .. /html/mirror/mirrors.tuna.tsinghua.edu.cn/ubuntu ubuntuCopy the code

Restart the nginx service

sudo service nginx restart
Copy the code

If all is well, a similar page appears

Intranet host configuration source

Tips: You can modify /etc/hosts to customize a DNS resolution rule. This rule is applicable when the internal source IP address environment frequently changes

Source. list can be set as follows:

deb [arch=amd64] http://mirror.xxx.cn/ubuntu/ bionic main restricted universe multiverse
deb [arch=amd64] http://mirror.xxx.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb [arch=amd64] http://mirror.xxx.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb [arch=amd64] http://mirror.xxx.cn/ubuntu/ bionic-security main restricted universe multiverse

Copy the code

For example, if [ARCH = AMd64] is not added here, apt Update fails to find i386 package information and cannot complete the index work, which will affect the installation of AMD64 package. After the above work is done, APT offline source is set up. It should be noted that there is no I386 source

pip2pi

Installation and Configuration

sudo apt update
sudo apt install python3
sudo apt install python3-pip
# Update PIP, old version has strange Bug in operation
pip3 install pip --upgrade
# installation
pip install pip2pi
Copy the code

Pip2tgz: download pypi dir2pi: create index for pypi dir2pi: create index for pypi dir2pi: Create index for pypi dir2pi: Create index for pypi dir2pi: Create index for pypi dir2pi: Create index for pypi dir2pi: Create index for pypi dir2pi

pip2tgz /var/www/html/pypi/packages -r requirements.txt ... Multiple files dir2pi/var/WWW/HTML/pypi/packagesCopy the code

The next step is the same as setting up APT, set up soft connection in /var/www/shared/ directory, restart Nginx service

use

Modify ~/. PIP /pip.conf of the Intranet host to use the newly constructed host as the pypI source

[global]
index-url = http://mirror.xxx.cn/simple
trusted-host = mirror.xxx.cn
Copy the code

At this point, the benefits of custom hosts files appear, one configuration, overall use

You may encounter the following situations

The other packages can be installed normally, and you are sure that the GEvent package has been indexed

The solution: Upgrade the PIP version of the Intranet host

python -m pip install  pip --upgrade
Copy the code

PIP packages can be found, don’t worry. Do not know the bug trigger condition, metaphysics,,

Reference source

Segmentfault.com/a/119000002… Juejin. Cn/post / 705850… Blog.csdn.net/zhifangyou7… Blog.csdn.net/xianjie0318…