#!/bin/bash
# 二进制包安装docker-xy.xy.x-ce
# 变量
unamer=`uname -r |cut -d'.' -f1-2`
Max_Space=$(df|grep "^/dev"|sort -rn -k2|head -1|awk '{print $6}')
Registry="mirror.eastraycloud.com:8665"
#判断当前系统类型
Unamer=$(uname -v|awk '{print $1}'|awk -F - '{print $2}')
#Unamer=`cat /proc/version|awk -F "(" '{print $4}'|awk '{print $1}'`
#Unamer=`cat /etc/os-release |grep ID|head -1|awk -F "=" '{print $2}'|sed 's/\"//g'`
if [ "$Unamer" = "Ubuntu" ]; then
Service=/lib/systemd/system/docker.service
else
Service=/usr/lib/systemd/system/docker.service
fi
# docker-compose安装
Docker_Compose() {
cp -f ../docker-compose/* /usr/local/bin/
chmod u+x /usr/local/bin/docker-compose
}
# 解压安装docker
Docker_Install (){
tar zxf ../docker-ce/docker-*-ce.tgz -C $Max_Space
mv $Max_Space/docker/* /usr/bin/
Docker_Data=$Max_Space/docker
}
# 设置容器日志大小限制
Docker_log_limits() {
mkdir /etc/docker
cat > /etc/docker/daemon.json<<EOF
{
"log-driver":"json-file",
"log-opts": {"max-size":"500m", "max-file":"3"},
"default-address-pools":[{"base":"172.80.0.0/16","size":24},{"base":"172.90.0.0/16","size":24}],
"registry-mirrors":["https://docker.nju.edu.cn"]
}
EOF
}
# 启动docker并设置自动启动
Docker_Start() {
cat >$Service <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
OOMScoreAdjust=-1000
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
## "--ip-forward=true --iptables=false"
##ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock --insecure-registry=$Registry --data-root $Docker_Data
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
EOF
# 启动docker服务
systemctl start docker
# 设置docker开机自启动
systemctl enable docker
}
Docker() {
Docker_Compose
Docker_Install
Docker_log_limits
Docker_Start
}
Docker
标签:shell,Space,Unamer,目录,awk,print,docker,Docker
From: https://blog.csdn.net/qq_15753385/article/details/142971317