Linux运维_Bash脚本_二进制文件部署Docker-CE-26.1.4

Linux运维_Bash脚本_二进制文件部署Docker-CE-26.1.4

Bash (Bourne Again Shell) 是一个解释器,负责处理 Unix 系统命令行上的命令。它是由 Brian Fox 编写的免费软件,并于 1989 年发布的免费软件,作为 Sh (Bourne Shell) 的替代品。

您可以在 Linux 和 MacOS 机器上使用 Bash,甚至可以通过适用于 Linux 的 Windows 子系统在 Windows 10 机器上使用。

使用方法

  • 下载源码包:

shadow-4.2.1.tar.xz

docker-26.1.4.tgz (Binary)

docker-rootless-extras-26.1.4.tgz (Binary)

buildx-v0.16.2.linux-amd64 (Binary)

  • 放于指定路径:

这里 Bash Shell 脚本的全局变量 STORAGE 指定的存放源码包的路径 /home/goufeng 可进行修改。

  • 执行 Bash Shell 脚本:

输入 /[路径名]/[脚本名].sh 即可进行自动编译部署,过程中提示输入 (y/n) 输入 y 则进行下一步,这样分阶段确认的原因是为了确保能够看到上一个源码编译结果中可能的错误和提示。

完整脚本

shell 复制代码
#! /bin/bash
# Create By GF 2024-08-06 01:34

# --------------------------------------------------
# Install First: 
# * None

# --------------------------------------------------
# Download Site:
# Docker-CE 二进制(Binary)可执行文件: https://mirrors.aliyun.com/docker-ce/linux/static/
# buildx 二进制(Binary)可执行文件: https://github.com/docker/buildx/releases

# ------------------- Dependency -------------------
# Need File: shadow-4.2.1.tar.xz
# --------------- Docker-CE - 26.1.4 ---------------
# Need File: docker-26.1.4.tgz (Binary)
# ------- Docker-CE - 26.1.4 Rootless Extras -------
# Need File: docker-rootless-extras-26.1.4.tgz (Binary)
# --------------- Docker-CE - Plugins --------------
# Need File: buildx-v0.16.2.linux-amd64 (Binary)

# ##################################################
STORAGE=/home/goufeng

# ############################################ Dependency ############################################

# Function:  编译安装(Compile Install) Shadow - 4.2.1 (Binary)
# ##################################################
function Compile_Install_Shadow_4_2_1() {

    if ! command -v newuidmap > /dev/null 2>&1; then
    
        local VERIFY
        local STEP_UNZIPPED=0
        local STEP_CONFIGURED=0
        local STEP_INSTALLED=0
    
        # ------------------------------------------
        read -p "[Confirm] Compile and Install ( shadow-4.2.1 )? (y/n)>" VERIFY
        if [[ "$VERIFY" != "y" ]]; then exit 1; fi

        # ------------------------------------------
        tar -Jxvf $STORAGE/shadow-4.2.1.tar.xz && STEP_UNZIPPED=1
        
        # ------------------------------------------
        # 指令说明:
        # ..........................................
        # * sed -i 's/groups$(EXEEXT) //' src/Makefile.in:
        #   This sed is used to suppress the installation of the groups program as the version from the Coreutils package installed during LFS is preferred.
        #   此 sed 用于抑制组程序的安装, 因为首选 LFS 期间安装的 Coreutils 包中的版本。
        # ..........................................
        # * find man -name Makefile.in -exec ... {} \;:
        #   This command is used to suppress the installation of the groups man pages so the existing ones installed from the Coreutils package are not replaced.
        #   此命令用于禁止安装组手册页, 这样就不会替换从 Coreutils 软件包安装的现有手册页。
        # ..........................................
        # * sed -i -e 's@#ENCRYPT_METHOD DES@ENCRYPT_METHOD SHA512@' -e 's@/var/spool/mail@/var/mail@' etc/login.defs:
        #   Instead of using the default 'DES' method, this command modifies the installation to use the more secure 'SHA512' method of hashing passwords, which also allows passwords longer than eight characters.
        #   It also changes the obsolete /var/spool/mail location for user mailboxes that Shadow uses by default to the /var/mail location.
        #   此命令修改安装以使用更安全的哈希密码 "SHA512" 方法, 而不是使用默认的 "DES" 方法, 该方法还允许使用长度超过八个字符的密码。
        #   它还将 Shadow 默认使用的用户邮箱的过时 /var/spool/mail 位置更改为 /var/mail 位置。
        # ..........................................
        # * sed -i 's/1000/999/' etc/useradd:
        #   Make a minor change to make the default useradd consistent with the LFS groups file.
        #   稍作更改, 使默认 useradd 与 LFS 组文件一致。
        # ..........................................
        sed -i 's/groups$(EXEEXT) //' src/Makefile.in &&
        find man -name Makefile.in -exec sed -i 's/groups\.1 / /' {} \; &&
        
        sed -i -e 's@#ENCRYPT_METHOD DES@ENCRYPT_METHOD SHA512@' \
               -e 's@/var/spool/mail@/var/mail@' etc/login.defs &&
        
        sed -i 's/1000/999/' etc/useradd
        
        # ------------------------------------------
        # 选项说明:
        # ..........................................
        # * --with-group-name-max-length=32:
        #   The maximum user name is 32 characters. Make the maximum group name the same.
        #   用户名的最大长度为 32 个字符。使最大组名相同。
        # ..........................................
        cd $STORAGE/shadow-4.2.1 && ./configure --prefix=/opt/shadow-4.2.1 \
                                                --with-group-name-max-length=32 &&
        STEP_CONFIGURED=1
        
        # ------------------------------------------
        make && make install && STEP_INSTALLED=1
        
        # ------------------------------------------
        if [[ $STEP_INSTALLED == 1 ]]; then
            if [[ ! -d "/usr/local" ]]; then mkdir /usr/local; fi
            if [[ ! -d "/usr/local/bin" ]]; then mkdir /usr/local/bin; fi
            # ......................................
            # Skip # ln -sf /opt/shadow-4.2.1/bin/chage     /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/chfn      /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/chsh      /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/expiry    /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/faillog   /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/gpasswd   /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/lastlog   /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/login     /usr/local/bin/
            ln -sf /opt/shadow-4.2.1/bin/newgidmap /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/newgrp    /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/newgrp    /usr/local/bin/sg
            ln -sf /opt/shadow-4.2.1/bin/newuidmap /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/passwd    /usr/local/bin/
            # Skip # ln -sf /opt/shadow-4.2.1/bin/su        /usr/local/bin/
        fi
        
        # ------------------------------------------
        # 可选操作:
        # ..........................................
        # * mv -v /usr/bin/passwd /bin:
        #   The passwd program may be needed during times when the /usr filesystem is not mounted so it is moved into the root partition.
        #   当 /usr 文件系统未被挂载时, 可能需要使用 passwd 程序, 以便将其移动到根分区。
        # ..........................................
        # Skip # mv -v /usr/bin/passwd /bin
        
        # ------------------------------------------
        cd $STORAGE && rm -rf $STORAGE/shadow-4.2.1 && return 0
    else
    
        echo "[Caution] Command: ( newuidmap ) Already Exists."
        # ------------------------------------------
        return 0
    fi
}

# ######################################## Docker-CE - 26.1.4 ########################################

# Function:  二进制文件部署(Binary File Deploy) Docker-CE - 26.1.4
# ##################################################
function Binary_File_Deploy_Docker_CE_26_1_4() {

    if [[ ! -f "/opt/sandbox-docker-ce/bin/docker" ]]; then
    
        local VERIFY
        local STEP_UNZIPPED=0
        local STEP_DEPLOYED=0
    
        # ------------------------------------------
        read -p "[Confirm] Binary File Deploy ( docker-ce-26.1.4 )? (y/n)>" VERIFY
        if [[ "$VERIFY" != "y" ]]; then exit 1; fi
        
        # ------------------------------------------
        # Create Group for docker-ce-26.1.4.
        local GROUP_NAME=$(cat /etc/group | grep -o docker)
        # ..........................................
        local GROUPADD_EXISTS=0
        # ..........................................
        if [[ -f "/usr/bin/groupadd" ]];  then GROUPADD_EXISTS=$(($GROUPADD_EXISTS + 1)); fi
        if [[ -f "/usr/sbin/groupadd" ]]; then GROUPADD_EXISTS=$(($GROUPADD_EXISTS + 1)); fi
        # ..........................................
        if [[ -z "$GROUP_NAME" && $GROUPADD_EXISTS -ge 1 ]]; then groupadd docker && usermod -aG docker $USER; fi

        # ------------------------------------------
        tar -zxvf $STORAGE/docker-26.1.4.tgz && STEP_UNZIPPED=1
        
        # ------------------------------------------
        if [[ ! -d "/opt/sandbox-docker-ce/bin" ]]; then mkdir -p /opt/sandbox-docker-ce/bin; fi
        # ..........................................
        cp -v $STORAGE/docker/ctr                     /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker/containerd              /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker/containerd-shim-runc-v2 /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker/docker                  /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker/docker-init             /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker/docker-proxy            /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker/dockerd                 /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker/runc                    /opt/sandbox-docker-ce/bin/

        # ------------------------------------------
        chmod +x /opt/sandbox-docker-ce/bin/ctr                     
        chmod +x /opt/sandbox-docker-ce/bin/containerd              
        chmod +x /opt/sandbox-docker-ce/bin/containerd-shim-runc-v2 
        chmod +x /opt/sandbox-docker-ce/bin/docker                  
        chmod +x /opt/sandbox-docker-ce/bin/docker-init             
        chmod +x /opt/sandbox-docker-ce/bin/docker-proxy            
        chmod +x /opt/sandbox-docker-ce/bin/dockerd                 
        chmod +x /opt/sandbox-docker-ce/bin/runc                    
        
        # ------------------------------------------
        cp -v /opt/sandbox-docker-ce/bin/ctr                     /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/containerd              /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/containerd-shim-runc-v2 /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/docker                  /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/docker-init             /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/docker-proxy            /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/dockerd                 /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/runc                    /usr/local/bin/ &&
        STEP_DEPLOYED=1
        
        # ------------------------------------------
        if [[ "$STEP_DEPLOYED" == 1 ]]; then
            cd $STORAGE && rm -rf $STORAGE/docker
        fi
        
        # ------------------------------------------
        return 0
    else
    
        echo "[Caution] Binary: ( /opt/sandbox-docker-ce/bin/docker ) Already Exists."
        # ------------------------------------------
        return 0
    fi
}

# ################################ Docker-CE - 26.1.4 Rootless Extras ################################

# Function:  二进制文件部署(Binary File Deploy) Docker-CE - 26.1.4 Rootless Extras
# ##################################################
function Binary_File_Deploy_Docker_CE_26_1_4_Rootless_Extras() {

    # Require: newuidmap # ---> from shadow-4.2.1.tar.xz.
    
    # Install: After Deployment is Completed, Non root User Running "dockerd-rootless-setuptool.sh".

    if [[ ! -f "/opt/sandbox-docker-ce/bin/dockerd-rootless-setuptool.sh" ]]; then
    
        local VERIFY
        local STEP_UNZIPPED=0
        local STEP_DEPLOYED=0
    
        # ------------------------------------------
        read -p "[Confirm] Binary File Deploy ( docker-ce-26.1.4-rootless-extras )? (y/n)>" VERIFY
        if [[ "$VERIFY" != "y" ]]; then exit 1; fi

        # ------------------------------------------
        tar -zxvf $STORAGE/docker-rootless-extras-26.1.4.tgz && STEP_UNZIPPED=1
        
        # ------------------------------------------
        if [[ ! -d "/opt/sandbox-docker-ce/bin" ]]; then mkdir -p /opt/sandbox-docker-ce/bin; fi
        # ..........................................
        cp -v $STORAGE/docker-rootless-extras/dockerd-rootless.sh           /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker-rootless-extras/dockerd-rootless-setuptool.sh /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker-rootless-extras/rootlesskit                   /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker-rootless-extras/rootlesskit-docker-proxy      /opt/sandbox-docker-ce/bin/
        cp -v $STORAGE/docker-rootless-extras/vpnkit                        /opt/sandbox-docker-ce/bin/
        
        # ------------------------------------------
        chmod +x /opt/sandbox-docker-ce/bin/dockerd-rootless.sh           && \
        chmod +x /opt/sandbox-docker-ce/bin/dockerd-rootless-setuptool.sh && \
        chmod +x /opt/sandbox-docker-ce/bin/rootlesskit                   && \
        chmod +x /opt/sandbox-docker-ce/bin/rootlesskit-docker-proxy      && \
        chmod +x /opt/sandbox-docker-ce/bin/vpnkit                        &&
        
        # ------------------------------------------
        cp -v /opt/sandbox-docker-ce/bin/dockerd-rootless.sh           /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/dockerd-rootless-setuptool.sh /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/rootlesskit                   /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/rootlesskit-docker-proxy      /usr/local/bin/ && \
        cp -v /opt/sandbox-docker-ce/bin/vpnkit                        /usr/local/bin/ &&
        STEP_DEPLOYED=1

        # ------------------------------------------
        if [[ "$STEP_DEPLOYED" == 1 ]]; then
            cd $STORAGE && rm -rf $STORAGE/docker-rootless-extras
        fi
        
        # ------------------------------------------
        return 0
    else
    
        echo "[Caution] Script: ( /opt/sandbox-docker-ce/bin/dockerd-rootless-setuptool.sh ) Already Exists."
        # ------------------------------------------
        return 0
    fi
}

# ####################################### Docker-CE - Plugins ########################################

# Function:  二进制文件部署(Binary File Deploy) Docker-CE - Plugins: buildx-0.16.2-Linux-Amd64
# ##################################################
function Binary_File_Deploy_Docker_CE_Plugins_buildx_0_16_2_Linux_Amd64() {

    if [[ ! -f "/opt/sandbox-docker-ce/cli-plugins/buildx" ]]; then
    
        local VERIFY
        local STEP_DEPLOYED=0
    
        # ------------------------------------------
        read -p "[Confirm] Binary File Deploy ( docker-ce-plugins: buildx-0.16.2-linux-amd64 )? (y/n)>" VERIFY
        if [[ "$VERIFY" != "y" ]]; then exit 1; fi
        
        # ------------------------------------------
        if [[ ! -d "$HOME/.docker/cli-plugins" ]]; then mkdir -p $HOME/.docker/cli-plugins; fi
        
        # ------------------------------------------
        if [[ ! -d "/opt/sandbox-docker-ce/cli-plugins" ]]; then mkdir -p /opt/sandbox-docker-ce/cli-plugins; fi
        # ..........................................
        cp -v $STORAGE/buildx-v0.16.2.linux-amd64 /opt/sandbox-docker-ce/cli-plugins/buildx
        
        # ------------------------------------------
        chmod 755 /opt/sandbox-docker-ce/cli-plugins/buildx
        
        # ------------------------------------------
        cp -v /opt/sandbox-docker-ce/cli-plugins/buildx $HOME/.docker/cli-plugins && 
        STEP_DEPLOYED=1
        
        # ------------------------------------------
        return 0
    else
    
        echo "[Caution] Binary: ( /opt/sandbox-docker-ce/cli-plugins/buildx ) Already Exists."
        # ------------------------------------------
        return 0
    fi
}

function main() {

    # ----------------- Dependency -----------------
    Compile_Install_Shadow_4_2_1
    # ------------- Docker-CE - 26.1.4 -------------
    Binary_File_Deploy_Docker_CE_26_1_4
    # ----- Docker-CE - 26.1.4 Rootless Extras -----
    # Skip # Binary_File_Deploy_Docker_CE_26_1_4_Rootless_Extras # ---> Optional (Non root User Running "dockerd-rootless-setuptool.sh").
    # ------------- Docker-CE - Plugins ------------
    Binary_File_Deploy_Docker_CE_Plugins_buildx_0_16_2_Linux_Amd64

    # Docker-CE Configure File 1: docker.service
    # ----------------------------------------------
    #     # "docker.service" is Located by Default in "/etc/systemd/system" or "/lib/systemd/system".

    #     [Unit]
    #     Description=Docker Application Container Engine
    #     Documentation=https://docs.docker.com
    #     After=network-online.target docker.socket firewalld.service
    #     Wants=network-online.target
    #     Requires=docker.socket
    #      
    #     [Service]
    #     Type=notify
    #     ExecStart=/usr/local/bin/dockerd
    #     ExecReload=/bin/kill -s HUP $MAINPID
    #     LimitNOFILE=1048576
    #     LimitNPROC=infinity
    #     LimitCORE=infinity
    #     TasksMax=infinity
    #     TimeoutStartSec=0
    #     Delegate=yes
    #     KillMode=process
    #     Restart=on-failure
    #     StartLimitBurst=3
    #     StartLimitInterval=60s
    #      
    #     [Install]
    #     WantedBy=multi-user.target
    
    # Docker-CE Configure File 2: docker.socket
    # ----------------------------------------------
    #     # "docker.socket" is Located by Default in "/etc/systemd/system" or "/lib/systemd/system".
    #     
    #     [Unit]
    #     Description=Docker Socket for the API
    #     PartOf=docker.service
    #      
    #     [Socket]
    #     ListenStream=/run/docker.sock
    #     SocketMode=0660
    #     SocketUser=root
    #     SocketGroup=root
    #      
    #     [Install]
    #     WantedBy=sockets.target

    # Docker-CE Configure File 3: daemon.json (Path: /etc/docker/daemon.json)
    # ----------------------------------------------
    #     {
    #         "data-root": "/data/docker",
    #         "exec-root": "/var/run/docker",
    #         "iptables": true,
    #         "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:4243"],
    #         "exec-opts": ["native.cgroupdriver=systemd"],
    #         "log-driver": "json-file",
    #         "log-level": "warn",
    #         "log-opts": {
    #             "max-size": "500m",
    #             "max-file": "3"
    #         },
    #         "insecure-registries" : ["demo.local.hub:5000"],
    #         "bip": "192.168.100.1/24",
    #         "default-address-pools": [
    #             {
    #                 "scope": "local",
    #                 "base": "172.17.0.0/16",
    #                 "size": 24
    #             }
    #         ],
    #         "registry-mirrors": ["https://registry.docker-cn.com"],
    #         "storage-driver": "overlay2",
    #         "live-restore": true,
    #         "max-concurrent-downloads": 5
    #     }
}

main

总结

以上就是关于 Linux运维 Bash脚本 二进制文件部署Docker-CE-26.1.4 的全部内容。

更多内容可以访问我的代码仓库:

https://gitee.com/goufeng928/public

https://github.com/goufeng928/public

相关推荐
IT 古月方源几秒前
关于 VRRP的详解
运维·网络·tcp/ip·网络安全·智能路由器
檀越剑指大厂1 分钟前
【Linux系列】sed命令的深入解析:如何使用sed删除文件内容
linux·运维·服务器
~央千澈~28 分钟前
docker 是什么?docker初认识之如何部署docker-优雅草后续将会把产品发布部署至docker容器中-因此会出相关系列文章-优雅草央千澈
docker·vim·镜像
不爱学英文的码字机器29 分钟前
深入理解 Linux 文件时间戳:atime、mtime 和 ctime 的概念及应用
linux·运维·服务器
qq1778036231 小时前
电商矩阵运营服务器怎么选
服务器·线性代数·矩阵·电商平台
迷迭所归处1 小时前
Linux系统 —— 进程控制系列 - 进程的等待:wait 与 waitpid
linux·运维·服务器
周先森的怣忈1 小时前
RHCE(第二部分)-----第三章:shell条件测试
linux·rhce
Charlie__ZS2 小时前
Docker安装
运维·docker·容器
AIGCnn2 小时前
jetson 无显示器配置WIFI
linux·jetson
yulingfeng592 小时前
Centos7 yum 报错“Could not resolve host: mirrorlist.centos.org; Unknown error“
linux·运维·centos