1. # 关闭防火墙
    2. systemctl stop firewalld && systemctl disable firewalld
    3. # 关闭selinux
    4. sed -i 's/enforcing/disabled/' /etc/selinux/config && setenforce 0
    5. # 关闭swap
    6. swapoff -a && sed -ri 's/.*swap.*/#&/' /etc/fstab
    7. # 根据规划设置主机名
    8. hostnamectl set-hostname <hostname>
    9. # 在master添加hosts
    10. cat >> /etc/hosts << EOF
    11. 192.168.31.253 master.k8s.io k8svip
    12. 192.168.31.252 master01.k8s.io k8smaster01
    13. 192.168.31.182 master02.k8s.io k8smaster02
    14. 192.168.31.80 node01.k8s.io k8snode01
    15. 192.168.31.126 node01.k8s.io k8snode02
    16. EOF
    17. # 将桥接的IPv4流量传递到iptables的链
    18. cat > /etc/sysctl.d/k8s.conf << EOF
    19. net.bridge.bridge-nf-call-ip6tables = 1
    20. net.bridge.bridge-nf-call-iptables = 1
    21. EOF
    22. sysctl --system # 生效
    23. # 时间同步
    24. yum install ntpdate -y
    25. ntpdate time.windows.com
    26. # 更改源
    27. cat <<EOF > /etc/yum.repos.d/kubernetes.repo
    28. [kubernetes]
    29. name=Kubernetes
    30. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
    31. enabled=1
    32. gpgcheck=1
    33. repo_gpgcheck=1
    34. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
    35. EOF