CentOS7.8 offline installation of Docker24.0.2, offline installation of gcc and g++ environment

background

Sometimes it is required to operate in the intranet environment during operation and maintenance, that is, the server cannot connect to the Internet, so it cannot be yuminstalled online through the source. . At this time, the required software is generally installed in the following three ways:

  1. Download the source package to compile and install;
  2. Download the compiled installation package for the corresponding platform and unzip it;
  3. Download rpmthe package and install it locally.

Docker

system environment

[root@etl opt]# uname -a
Linux etl 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@etl opt]# cat /proc/version
Linux version 3.10.0-1127.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Mar 31 23:36:51 UTC 2020
[root@etl opt]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

Download the installation package

Download the compiled installation package for the corresponding platform and decompress it.

Download address: https://download.docker.com/linux/static/stable/x86_64/docker-24.0.2.tgz

Install Docker

# 解压
[root@etl opt]# tar -xvf docker-24.0.2.tgz 
docker/
docker/docker-proxy
docker/containerd-shim-runc-v2
docker/ctr
docker/docker
docker/docker-init
docker/runc
docker/dockerd
docker/containerd

[root@etl opt]# cp docker/* /usr/bin/

confirm installation

Check Dockerthe version to make sure it is installed.

[root@etl opt]# docker info
Client:
 Version:    24.0.2
 Context:    default
 Debug Mode: false

Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info

[root@etl opt]# docker version
Client:
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:50:49 2023
 OS/Arch:           linux/amd64
 Context:           default
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Configure Docker to start automatically at boot

Write a service script to manage Dockerthe service and configure Dockerit to start automatically at boot.

[root@etl opt]# vi /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
 
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
 
[Install]
WantedBy=multi-user.target

Commonly Used Management Commands

Including start, view status, stop, restart commands. After starting, you can pull the image and run the container.

[root@etl opt]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/etc/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: https://docs.docker.com

619 04:25:55 etl systemd[1]: [/etc/systemd/system/docker.service:34] Invalid section header '[root@SXCTC-TYMH local]# sy... docker'
Hint: Some lines were ellipsized, use -l to show in full.

[root@etl opt]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /etc/systemd/system/docker.service.

[root@etl opt]# systemctl list-unit-files | grep docker
docker.service                                enabled 

[root@etl opt]# systemctl start docker

[root@etl opt]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2023-06-19 04:27:52 EDT; 4s ago
     Docs: https://docs.docker.com
619 04:27:52 etl systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

[root@etl opt]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

[root@etl opt]# docker info
Client:
 Version:    24.0.2
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 24.0.2
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1677a17964311325ed1c31e2c0a3589ce6d5c30d
 runc version: v1.1.7-0-g860f061
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-1127.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.682GiB
 Name: etl
 ID: 0eee62aa-0908-4f69-a442-6333e558b82b
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

gcc and g++

[root@etl opt]# gcc -v
-bash: gcc: 未找到命令

[root@etl opt]# g++ -v
-bash: g++: 未找到命令

In an offline environment, if you need to compile and install source code, such as Nginx, Redisetc., you need to have gccand g++these basic environments. The following is an offline installation of and with rpmthe package .gccg++

gccDownload link with g++the rpmpackage: https://pan.baidu.com/s/1I4kn_vF9KX0dZF9cr4JFnw?pwd=ruks Extraction code: ruks

gcc

Enter /opt/gccthe directory and execute the following command to install gcc:

rpm -ivh *.rpm --nodeps --force

Among them --nodeps, means to ignore the dependency check, --forcemeans to force the installation.

[root@etl gcc]# rpm -ivh *.rpm --nodeps --force
准备中...                          ################################# [100%]
正在升级/安装...
   1:glibc-common-2.17-105.el7        ################################# [ 11%]
   2:glibc-2.17-105.el7               警告:/etc/nsswitch.conf 已建立为 /etc/nsswitch.conf.rpmnew 

################################# [ 22%]

   3:mpfr-3.1.1-4.el7                 ################################# [ 33%]
   4:libmpc-1.0.1-3.el7               ################################# [ 44%]
   5:cpp-4.8.5-4.el7                  ################################# [ 56%]
   6:kernel-headers-3.10.0-327.el7    ################################# [ 67%]
   7:glibc-headers-2.17-105.el7       ################################# [ 78%]
   8:glibc-devel-2.17-105.el7         ################################# [ 89%]
   9:gcc-4.8.5-4.el7                  ################################# [100%]

# 查看版本,确认已安装
[root@etl gcc]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 

g++

Enter /opt/g++the directory and execute the following command to install g++:

rpm -ivh *.rpm --nodeps --force

Among them --nodeps, means to ignore the dependency check, --forcemeans to force the installation.

[root@etl g++]# rpm -ivh *.rpm --nodeps --force
准备中...                          ################################# [100%]
正在升级/安装...
   1:libstdc++-devel-4.8.5-4.el7      ################################# [ 50%]
   2:gcc-c++-4.8.5-4.el7              ################################# [100%]

# 查看版本,确认已安装
[root@etl g++]# g++ -v
使用内建 specs。
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 

small summary

When your server cannot connect to the internet. This could be due to network restrictions, security policies, or other reasons. In this case, you need to manually download the offline installation package downloaded on a machine with Internet access, Docker 24.0.2and install it on the target server.

Additionally, offline installations GCCand G++environments may be required:

  1. GCCWhen it is not possible to download and install and over a network connection G++.
  2. When you need to compile and build C or C++ code in an environment without a network connection.

To install GCC and G++ environment offline, in addition to the above rpm, you can also follow the steps below:

  1. On a computer with an Internet connection, download the offline installation packages for GCC and G++ (usually in tar.gz or tar.xz format).
  2. Transfer the offline installation package to the target computer.
  3. Unzip the offline installation package on the target computer.
  4. Enter the decompressed directory, and run the following commands to configure and install:
./configure
make
sudo make install

This will configure, compile and install the GCCand G++environment. GCCAfter the installation is complete, you can use and G++compile and build Cor code on the target computer C++, such as we often install in source code Nginx, Redis.

Reference


If you have any questions or any bugs are found, please feel free to contact me.

Your comments and suggestions are welcome!

Guess you like

Origin blog.csdn.net/u013810234/article/details/131754417