#! /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 -ased -i 's/.*swap.*/#&/' /etc/fstab#系统内核调优cat >> /etc/sysctl.d/kubernetes.conf<<EOF# 开启路由功能net.ipv4.ip_forward=1# 避免cpu资源长期使用率过高导致系统内核锁kernel.watchdog_thresh=30# 开启iptables bridgenet.bridge.bridge-nf-call-iptables=1# 调优ARP高速缓存net.ipv4.neigh.default.gc_thresh1=4096net.ipv4.neigh.default.gc_thresh2=6144net.ipv4.neigh.default.gc_thresh3=8192EOFsysctl -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#重启dockersystemctl daemon-reloadsystemctl restart dockersystemctl enable docker.service#查看docker版本信息sudo docker info