Ubuntu APT source setup simple method

1. Why do WE need to build APT source

Here’s why:

1. When the company Intranet is offline, Ubuntu cannot be downloaded through APT source

2, some source countries can not be accessed normally, need to climb the wall

Based on the above reasons, we need to build our own APT source

Second, the preparation conditions

  1. You need a computer with Internet access, preferably github, Google, etc
  2. You need an Ubuntu machine with a large disk

Third, APT environment construction

3.1. Install apt-Mirror software

sudo apt-get install apt-mirror
Copy the code

3.2. Modify mirror.list configuration file

sudo mkdir -p /var/www/html
sudo vi /etc/apt/mirror.list
Copy the code

My configuration file is as follows:

############# config ##################
#To set a data store directory, the path must exist in advance
# set base_path    /var/spool/apt-mirror
set base_path /var/www/html

#Example Set the image storage location
# set mirror_path  $base_path/mirror

#Set the temporary download index location
# set skel_path    $base_path/skel

#Set the location of log, URLs and MD5 verification information
# set var_path     $base_path/var

#Configure the location to delete expired source scripts (not deleted by default to facilitate the installation of older versions of software)
# set cleanscript $var_path/clean.sh

#Set the default architecture, I386 / AMD64, download the same architecture as the native by default
# set defaultarch  <running host architecture>
set defaultarch amd64

#Set the location of the script to run after download
# set postmirror_script $var_path/postmirror.sh

#Set whether to execute the downloaded script. Default is 1(but there is no postmirror.sh script by default)
# set run_postmirror 0

#Set the number of download threads
set nthreads     20

#Whether to replace the wavy line in the URL with %7E (HTML code), otherwise the download will be skipped
set _tilde 0
#
############# end config ##############

#Ubuntu APT software source
#deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
#deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
#deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
#deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
#deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

#clean http://mirrors.ustc.edu.cn ubuntu

#Nvidia - docker2 source
#Deb (ARCH)/https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/$ 
#Using nvidia-Docker2 source address directly will cause problems, you need to modify the followingDeb HTTP: / / https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64 /#Deb (ARCH)/https://nvidia.github.io/libnvidia-container/experimental/ubuntu18.04/$Deb HTTP: / / https://nvidia.github.io/nvidia-container-runtime/stable/ubuntu18.04/amd64 /#Deb (ARCH)/https://nvidia.github.io/nvidia-container-runtime/experimental/ubuntu18.04/$Deb HTTP: / / https://nvidia.github.io/nvidia-docker/ubuntu18.04/amd64 /
#Docker - ce source
deb https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu bionic stable

#Source of ros
deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ bionic main

#Vscode source
#deb [arch=amd64,arm64,armhf] http://packages.microsoft.com/repos/code stable main

#Bazel sourceDeb [arch = amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8 clean https://nvidia.github.io ubuntu clean https://mirrors.tuna.tsinghua.edu.cn ubuntu clean http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu clean http://packages.microsoft.com/repos/codeCopy the code

3.3. Download the image software

sudo apt-miiror
Copy the code

The image download process takes a long time and requires patience. The execution process is as follows:

root@HANZHIWEI02:~# apt-mirror

Downloading 57 index files using 20 threads… Begin time: Fri Jan 28 14:20:18 2022 [20]… [19]… [18]… [17]… [16]… [15]… [14]… [13]… [12]… [11]… [10]… [9]… [8]… [7]… [6]… [5]… [4]… [3]… [2]… [1]… [0]… End time: Fri Jan 28 14:20:29 2022

Processing translation indexes: [TTTTTT]

Downloading 0 translation files using 0 threads… Begin time: Fri Jan 28 14:20:29 2022 [0]… End time: Fri Jan 28 14:20:29 2022

Processing DEP-11 indexes: [DDDDDD]

Downloading 0 dep11 files using 0 threads… Begin time: Fri Jan 28 14:20:29 2022 [0]… End time: Fri Jan 28 14:20:29 2022

Processing indexes: [PPPPPP]

Download 707 Archive Files using 20 threads Downloading… Begin time: Fri Jan 28 14:20:30 2022 [20]… [19]… [18]… [17]… [16]… [15]… [14]… [13]… [12]… [11]… [10]… [9]… [8]… [7]… [6]… [5]… [4]… [3]… [2]… [1]… [0]… End time: Fri Jan 28 14:31:46 2022

4.1 GiB in 1406 files and 2 directories can be freed. Run /mnt/e/ubuntu-apt/var/clean.sh for this purpose.

Running the Post Mirror script … (/var/www/html/var/postmirror.sh)

Post Mirror script has completed. See above output for any possible errors.

3.4. Install nginx

sudo apt-get install nginx
Copy the code

3.5. Configure nginx services

sudo vi /etc/nginx/sites-available/default
Copy the code

My configuration file is as follows:

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or WordPress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {listen 80 default_server; Charset UTF-8;	# listen [::]:80 default_server;

	# SSL configuration
	#
	#listen 443 ssl default_server;
	#listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	#ssl_certificate /mnt/e/ubuntu-apt/key/server.crt;#ssl_certificate_key /mnt/e/ubuntu-apt/key/server.key; #ssl_session_timeout 5m; # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #ssl_ciphers AESGCM:ALL:! DH:! EXPORT:! RC4:+HIGH:! MEDIUM:! LOW:! aNULL:! eNULL; #ssl_prefer_server_ciphers on; #ssl_ciphers HIGH:! aNULL:! MD5;

	#Show directory
	autoindex on;
	
	#Directory where the image resides
	root /var/www/html;

	# Add index.php to the list if you are using PHP
	index index.html index.htm index.nginx-debian.html;

	# server_name _;Server_name < local IP address >; location / {		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
		#autoindex on;
                #autoindex_exact_size off;
                #autoindex_localtime on;
	}

	# pass PHP scripts to FastCGI server
	#
	#location ~ \.php$ {
	#	include snippets/fastcgi-php.conf;
	#
	#	# With php-fpm (or other unix sockets):
	#Fastcgi_pass Unix: / var/run/PHP/php7.0 - FPM. The sock.
	#	# With php-cgi (or other tcp sockets):
	#Fastcgi_pass 127.0.0.1:9000;
	#}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	#	deny all;
	#}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#	listen 80;
#	listen [::]:80;
#
#	server_name example.com;
#
#	root /var/www/example.com;
#	index index.html;
#
#	location / {
#		try_files $uri $uri/ = 404;
#	}
#}

Copy the code

3.6. Restart the nginx service

sudo service nginx restart
Copy the code

Open http://IP in the browser and the following page can be found, which indicates that the establishment is successful

4. Modify the Intranet APT source

After chapter 3, we have built a simple APT image source. Now we only need to modify the APT source on the Intranet computer to the source we built

Modify the /etc/apt/sources.list file

sudo vi  /etc/apt/sources.list
Copy the code

Put the following:

Deb repo.t3caic.com/repository/… Bionic main restricted universe multiverse deb repo.t3caic.com/repository/… Bionic ws-security main restricted universe multiverse deb repo.t3caic.com/repository/… Bionic – updates the main restricted universe multiverse deb repo.t3caic.com/repository/… Bionic – programs main restricted universe multiverse deb repo.t3caic.com/repository/… bionic-backports main restricted universe multiverse

# # docker deb/arch = amd64 mirrors.tuna.tsinghua.edu.cn/docker-ce/l… bionic stable

# nvidia – docker2 deb nvidia. Making. IO/libnvidia – c… / deb nvidia. Making. IO/libnvidia – c… / deb nvidia. Making. IO/nvidia – cont… / deb nvidia. Making. IO/nvidia – cont… / deb nvidia. Making. IO/nvidia – the dock… /

# ros deb mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ bionic main

# vscode deb [arch=amd64,arm64,armhf] packages.microsoft.com/repos/code stable main

# bazel deb [arch=amd64] storage.googleapis.com/bazel-apt stable jdk1.8

Replace it with the following:

  1. Add your own IP address to the URL
  2. httpsNeed to be replaced byhttpBecause SSL authentication is not enabled for the nginx service

Deb repo.t3caic.com/repository/… Bionic main restricted universe multiverse deb repo.t3caic.com/repository/… Bionic ws-security main restricted universe multiverse deb repo.t3caic.com/repository/… Bionic – updates the main restricted universe multiverse deb repo.t3caic.com/repository/… Bionic – programs main restricted universe multiverse deb repo.t3caic.com/repository/… bionic-backports main restricted universe multiverse

# # docker deb [arch = amd64] http:// < build > IP address/mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu bionic stable

# nvidia – docker2 deb the IP address of the < build > http:// / nvidia lot. IO/libnvidia – container/stable/ubuntu18.04 / (ARCH)/debhttp: / / the IP address of the < build > / nvidia lot. IO/libnvidia – container/experimental/ubuntu18.04 / (ARCH)/deb The IP address of the http:// < build > / nvidia lot. IO/libnvidia – container/experimental/ubuntu18.04 / (ARCH)/debhttp: / / the IP address of the < build > / nvidia git Hub. IO/libnvidia – container/experimental/ubuntu18.04 / (ARCH)/deb The IP address of the http:// < build > / nvidia lot. IO/nvidia – container – the runtime/stable/ubuntu18.04 / (ARCH)/debhttp: / / the IP address of the < build > / nvidia lot. IO/nvidia – container – the runtime/experimental/ubuntu18.04 / (ARCH)/deb The IP address of the http:// < build > / nvidia lot. IO/nvidia – container – the runtime/experimental/ubuntu18.04 / (ARCH)/debhttp: / / the IP address of the < build > / nvidi Atul gawande ithub. IO/nvidia – container – the runtime/experimental/ubuntu18.04 / (ARCH)/deb /nvidia-docker/ubuntu18.04/$(ARCH) /

# ros deb http:// < build > IP address/mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ bionic main

# vscode deb [arch = amd64, arm64 armhf] http:// < build > IP address/packages.microsoft.com/repos/code stable main

# bazel deb [arch = amd64] http:// < build > IP address/storage.googleapis.com/bazel-apt stable jdk1.8

After the above steps, the computers isolated on the Intranet can install the required APT by accessing the service computers on the Internet.

V. Setup and deployment of rosDEP offline source

5.1. Solve rosdeP init problem

The following problems may occur when rosdep init is executed offline on the Intranet:

hanzhiwei@T4-046:~$ sudo rosdep init

ERROR: always download a default sources list from: raw.githubusercontent.com/ros/rosdist… Website may be down.

Solution 1:

  1. Download 20-default.list

  2. The 20 – default. The list files in the/etc/ros/rosdep/sources. List. D directory, if the directory does not exist can be built

Solution 2:

  1. Download 20-default.list

  2. According to the source of apt way, in nginx/var/www/html/raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d directory

  3. /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py

    DEFAULT_SOURCES_LIST_URL = ‘raw.githubusercontent.com/ros/rosdist… ‘

    Is amended as:

    DEFAULT_SOURCES_LIST_URL = The IP address of the ‘http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list’

    Can be

5.2 Solve the rosdeP Update problem

Perform rosdep update in the Intranet environment to report the following problems:

hanzhiwei@T4-046:~$ rosdep update

reading in sources list data from /etc/ros/rosdep/sources.list.d ERROR: Unable to process the source/raw.githubusercontent.com/ros/rosdist… Error: < urlopen error [Errno 0] > (raw.githubusercontent.com/ros/rosdist…). ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]: The < urlopen error [Errno 0] error > (raw.githubusercontent.com/ros/rosdist…). ERROR: unable to process the source/raw.githubusercontent.com/ros/rosdist… Error: < urlopen error [Errno 0] > (raw.githubusercontent.com/ros/rosdist…). ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml]: The < urlopen error [Errno 0] error > (raw.githubusercontent.com/ros/rosdist…).

Solutions are as follows:

  1. Download the following contents and put them in the corresponding directory under nginx/var/www/html according to APT source construction mode

    Raw.githubusercontent.com/ros/rosdist…

    Raw.githubusercontent.com/ros/rosdist…

    Raw.githubusercontent.com/ros/rosdist…

    Raw.githubusercontent.com/ros/rosdist…

    Raw.githubusercontent.com/ros/rosdist…

    Raw.githubusercontent.com/ros/rosdist…

    Raw.github.com/ros/rosdist…

  2. Modify the contents of file 20-default.list

    sudo vi /etc/ros/rosdep/sources.list.d/20-default.list
    Copy the code

    Include the following:

    # OS – specific listings first yaml raw.githubusercontent.com/ros/rosdist… osx

    # generic yaml raw.githubusercontent.com/ros/rosdist… Yaml raw.githubusercontent.com/ros/rosdist… Yaml raw.githubusercontent.com/ros/rosdist… Gbpdistro raw.githubusercontent.com/ros/rosdist… fuerte

    # newer distributions (Groovy, Hydro, …) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

    Is amended as:

    # os-specific listings first yaml The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

    # generic yaml http:// < build > IP address/raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml yaml The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml yaml The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml gbpdistro The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

    # newer distributions (Groovy, Hydro, …) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

  3. Modify the rep3.py file

    Sudo vi/usr/lib/python2.7 / dist - packages/rosdep2 / rep3 pyCopy the code

    Include the following:

    REP3_TARGETS_URL = ‘raw.github.com/ros/rosdist… ‘

    Is amended as:

    REP3_TARGETS_URL = ‘http://, the IP address of the < build > / raw.github.com/ros/rosdistro/master/releases/targets.yaml’

  4. Modify the __init__.py file

    Sudo vi/usr/lib/python2.7 / dist - packages/rosdistro/set pyCopy the code

    Include the following:

    DEFAULT_INDEX_URL = ‘raw.githubusercontent.com/ros/rosdist… ‘

    Is amended as:

    DEFAULT_INDEX_URL = ‘http://, the IP address of the < build > / raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml’

  5. If rosdep update is executed, the following error will be found

    root@T4-046:~# rosdep update

    reading in sources list data from /etc/ros/rosdep/sources.list.d Warning: running ‘rosdep update’ as root is not recommended. You should run ‘sudo rosdep fix-permissions’ and invoke ‘rosdep update’ again without sudo. Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml Query rosdistro index The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml Add distro “ardent” ERROR: error loading sources list: HTTP Error 404: Not Found the IP address of the < build > (http:// / raw.githubusercontent.com/ros/rosdistro/master/ardent/distribution.yaml)

  6. This is because the index – v4. Yaml file and part of the file to download, according to the error and the index – v4. Yaml files the interpretation of the contents, found that still need to download the following files, and on the nginx under/var/WWW/HTML directory

    Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist… Raw.githubusercontent.com/ros/rosdist…

  7. After downloading the above files, perform rosdep update to complete related operations. The execution process is as follows

    root@T4-046:~# rosdep update

    reading in sources list data from /etc/ros/rosdep/sources.list.d Warning: running ‘rosdep update’ as root is not recommended. You should run ‘sudo rosdep fix-permissions’ and invoke ‘rosdep update’ again without sudo. Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml Hit The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml Query rosdistro index The IP address of the http:// < build > / raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml Add distro “ardent Add” distro “bouncy” Add distro “crystal” Add distro “dashing” Add distro “eloquent” Add distro “foxy” Add distro “galactic” Add distro “groovy” Add distro “hydro” Add distro “indigo” Add distro “jade” Add distro “kinetic” Add distro “lunar” Add distro “melodic” Add distro “noetic” Add distro “rolling” updated cache in /root/.ros/rosdep/sources.cache

5.3 directory structure under nginx

Nginx directory structure is as follows for reference only:

└ ─ ─ var

└ ─ ─ WWW └ ─ ─ HTML ├ ─ ─ raw.github.com │ └ ─ ─ ros │ └ ─ ─ rosdistro │ └ ─ ─ master │ └ ─ ─ the releases │ └ ─ ─ the targets. The yaml └ ─ ─ Raw.githubusercontent.com └ ─ ─ ros └ ─ ─ rosdistro └ ─ ─ master ├ ─ ─ ardent │ └ ─ ─ distribution. The yaml ├ ─ ─ bouncy │ └ ─ ─ Distribution. The yaml ├ ─ ─ crystal │ └ ─ ─ distribution. The yaml ├ ─ ─ dashing │ └ ─ ─ distribution. The yaml ├ ─ ─ eloquent │ └ ─ ─ ├── bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ bass ├─ ├── ─ Bass ├── ─ Bass ├── ─ Bass ├── ── ── ── ── ── ── ── ─ Distribution. The yaml ├ ─ ─ kinetic │ └ ─ ─ distribution. The yaml ├ ─ ─ lunar │ └ ─ ─ distribution. The yaml ├ ─ ─ melodic │ └ ─ ─ Yaml ├── bass exercises ── bass exercises. Yaml Bass Exercises ── bass exercises └ ─ ─ rosdep ├ ─ ─ base. Yaml ├ ─ ─ osx – homebrew. Yaml ├ ─ ─ python. The yaml ├ ─ ─ ruby. The yaml └ ─ ─ sources. List. D └ ─ ─ 20 – default. The list

Reference documentation

T.zoukankan.com/superbi-p-1… www.cnblogs.com/zhjblogs/p/…