该脚本目标是在ubuntu1604 上进行初始化工作,其他版本需要做相应调整

#dns 配置
echo "nameserver 10.26.100.1" >  /etc/resolvconf/resolv.conf.d/base
resolvconf -u

 修改source.list
root@ubuntu:~# vim /etc/apt/sources.list


deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse 




#更新安装必备
apt-get update  
apt-get upgrade
apt-get install -y apt-transport-https curl
#关闭swap => K8S中不支持swap分区
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
swapoff -a
#关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#修改时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#添加密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
#安装docker
apt-get install docker.io -y
#启动docker
systemctl enable docker
systemctl start docker
#systemctl status docker
#查看docker状态
docker version

#内核优化
cat >> /etc/sysctl.conf<<EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
EOF

sysctl -p
文档更新时间: 2020-09-07 10:29   作者:月影鹏鹏