#! /bin/bash
#安装Docker
#定义用户名
NEW_USER=rancher
#添加用户(可选)
sudo adduser $NEW_USER
#为新用户设置密码
echo rancher | sudo passwd $NEW_USER --stdin
#为新用户添加sudo权限
sudo echo "$NEW_USER ALL=(ALL) ALL" >> /etc/sudoers
#安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 bash-completion
#添加Docker源信息
sudo yum-config-manager --add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#缓存docker源
sudo yum makecache
#安装docker 19.03.7版本
sudo yum -y install docker-ce-19.03.7-3.el7 docker-ce-cli-19.03.7-3.el7 containerd.io
#把当前用户加入docker组
sudo usermod -aG docker $NEW_USER
#设置开机自启并运行docker服务
sudo systemctl enable --now docker
#安装yum-plugin-versionlock插件
yum -y install yum-plugin-versionlock
#锁定Docker软件包
yum versionlock add docker-ce-19.03.7-3.el7 docker-ce-cli-19.03.7-3.el7 containerd.io
#关闭虚拟内存
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
#系统内核调优
cat >> /etc/sysctl.d/kubernetes.conf<<EOF
# 开启路由功能
net.ipv4.ip_forward=1
# 避免cpu资源长期使用率过高导致系统内核锁
kernel.watchdog_thresh=30
# 开启iptables bridge
net.bridge.bridge-nf-call-iptables=1
# 调优ARP高速缓存
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
EOF
sysctl -p
#配置加速器
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"max-concurrent-downloads": 3,
"max-concurrent-uploads": 5,
"registry-mirrors": ["https://0bb06s1q.mirror.aliyuncs.com"],
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
EOF
#重启docker
systemctl daemon-reload
systemctl restart docker
systemctl enable docker.service
#查看docker版本信息
sudo docker info