containerd一键部署脚本

                                              作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.containerd一键部署脚本内容


#!/bin/bash
# auther: Jason Yin
# blog: https://www.cnblogs.com/yinzhengjie


CONTAINERD_VERSION=1.6.36
CONTAINERD_FILENAME=cri-containerd-cni-${CONTAINERD_VERSION}-linux-amd64.tar.gz
CONTAINERD_URL=https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION}/${CONTAINERD_FILENAME}
CONTAINERD_BASEDIR=/usr/local/bin/
CONTAINERD_SCRIPTS=/usr/lib/systemd/system/
CONTAINERD_CONFIG=/etc/containerd
RUNC_VERSION=1.1.15
RUNC_FILENAME=runc.amd64
RUN_URL=https://github.com/opencontainers/runc/releases/download/v${RUNC_VERSION}/${RUNC_FILENAME}
RUNC_BASEDIR=/usr/sbin
DOWNLOAD=./download


function prepare(){
  if [ ! -f ${DOWNLOAD}/$1 ]; then
    wget -T 3  -t 2 $2 -O ${DOWNLOAD}/$1
  fi

  if [ $? != 0 ];then
   rm -f ${DOWNLOAD}/$1
   echo "不好意思,由于网络波动原因,无法下载${1}软件包,程序已退出!请稍后再试......"
   exit 100
 fi

}

function InstallContainerd(){
   prepare ${CONTAINERD_FILENAME}  ${CONTAINERD_URL}
   
   tar xf ${DOWNLOAD}/${CONTAINERD_FILENAME} -C ${CONTAINERD_BASEDIR} usr/local/bin/{containerd,ctr,containerd-shim-runc-v2}  --strip-components=3
   tar xf ${DOWNLOAD}/${CONTAINERD_FILENAME} -C ${CONTAINERD_SCRIPTS} etc/systemd/system/containerd.service --strip-components=3
   
   if [ ! -f ${CONTAINERD_CONFIG} ] ;then 
      install -d ${CONTAINERD_CONFIG}
   fi

   containerd config default > /etc/containerd/config.toml
   
   sed -ri 's#(SystemdCgroup = )false#\1true#' /etc/containerd/config.toml 
   sed -i 's#registry.k8s.io/pause:3.6#registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6#' /etc/containerd/config.toml
   systemctl enable --now containerd

   prepare ${RUNC_FILENAME} ${RUN_URL}

   cp ${DOWNLOAD}/${RUNC_FILENAME} ${RUNC_BASEDIR}/runc
   chmod +x ${RUNC_BASEDIR}/runc

   tput setaf 3
   ctr version
   echo 
   runc -v
   echo 
   echo "安装成功,欢迎使用尹正杰二进制contianed安装脚本,欢迎下次使用!"
   tput setaf 2


}



function UninstallContainerd(){
  rm -f ${RUNC_BASEDIR}/runc /etc/containerd/config.toml \
     ${CONTAINERD_BASEDIR}/{containerd,ctr,containerd-shim-runc-v2} \
     ${CONTAINERD_SCRIPTS}/containerd.service

  tput setaf 5
  echo "卸载成功,欢迎再次使用尹正杰二进制containerd安装脚本哟~"
  tput setaf 7

}


function main(){
   case $1 in
     install|i)
      InstallContainerd
      ;;
      remove|r)
      UninstallContainerd
      ;;
     *)
       echo "Invalid parameter, Usage: $0 install|remove"
       ;;
   esac
}

main $1                   

二.脚本使用演示

1.安装脚本

[root@docker101 ~]# ./install-containerd.sh i
Client:
  Version:  v1.6.36
  Revision: 88c3d9bc5b5a193f40b7c14fa996d23532d6f956
  Go version: go1.22.7

Server:
  Version:  v1.6.36
  Revision: 88c3d9bc5b5a193f40b7c14fa996d23532d6f956
  UUID: f218dfb6-2c52-4c72-b269-01ca949716c1

runc version 1.1.15
commit: v1.1.15-0-gbc20cb44
spec: 1.0.2-dev
go: go1.22.3
libseccomp: 2.5.5

安装成功,欢迎使用尹正杰二进制contianed安装脚本,欢迎下次使用!
[root@docker101 ~]# 

2.卸载containerd

[root@docker101 ~]# ./install-containerd.sh r
卸载成功,欢迎再次使用尹正杰二进制containerd安装脚本哟~
[root@docker101 ~]# 
posted @ 2024-09-29 23:09  尹正杰  阅读(60)  评论(0编辑  收藏  举报