# 1.修改内核参数
# 临时禁用swap
swapoff -a
# 编辑 fstab,在 swap 相关行前面加“#”注释掉,关闭swap分区
sed -i '/swap/ s/^/#/' /etc/fstab
# 禁用防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
# 调整内核参数
cat > /etc/sysctl.d/k8s.conf << EOF
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv6.conf.all.forwarding=1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
#modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
# 2.安装 Docker
# 参考资料:https://docs.docker.com/engine/install/centos/
yum install -y yum-utils
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 修改 docker repo,添加 extras
echo "
[centos-extras]
name=Centos extras - base
baseurl=http://mirror.centos.org/centos/7/extras/x86_64
enabled=1
gpgcheck=1
gpgkey=http://centos.org/keys/RPM-GPG-KEY-CentOS-7
" >>/etc/yum.repos.d/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 设置 Docker 参数
cat >/etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"registry-mirrors": ["https://ajmumh9n.mirror.aliyuncs.com"]
}
EOF
# 启用服务
systemctl daemon-reload && systemctl restart docker && systemctl enable docker