环境为centos7,NAT连接模式
1、设置主机列表名:hostnamectl set-hostname xxx
192.168.159.136 master1
192.168.159.137 worker1
192.168.159.138 worker2
2、主机ip配置:vi /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE="ens33"
TYPE="Ethernet"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR="192.168.159.XXX" #通过ipconfig获取,如果ipconfig提示无法识别的命令,则yum install net-tools安装工具包
NETMASK="255.255.255.0"
GATEWAY="192.168.159.2" #route -n 命令获取
DNS1="192.168.159.2" #cat /etc/resolv.conf 命令获取
重启网卡:systemctl restart network
3、配置文件修改: vi /etc/hosts
192.168.159.136 master1
192.168.159.137 worker1
192.168.159.138 worker2
测试是否成功,相互ping一下,ping master1、ping worker1、ping worker2
4、主机安全配置:
1)关闭firewalld: systemctl stop firewalld
设置为开机禁用: systemctl disable firewalld
确认是否运行:firewall-cmd --state
not running
2)SELinux配置:sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
做出以上修改,一定要重启系统才能生效
或者直接进入到 文件中修改 vi /etc/selinux/config
查看修改后结果:输入 getenfore ,回车后Disabled
5、主机时间同步设置
由于最小化安装系统,需要单独安装ntpdate:yum -y install ntpdate
命令:crontab -e 后回车输入(使用阿里时钟源每隔1小时同步一次):
0 */1 * * * ntpdate time1.aliyun.com
或者直接输入命令:ntpdate time1.aliyun.com
6、永久关闭swap分区:
使用kubeadm部署必须关闭swap分区,修改配置文件后需要重新启动操作系统。
vi /etc/fstab
将/dev/mapper/centos-swap swap前面加上#注释掉
重启前执行free -m 查看分区是否真实存在
重启(reboot)后再次执行 free -m,swap为0时表示执行成功
7、添加网桥过滤:
在 /etc/sysctl.d/目录下添加k8s.conf文件(命令:vi /etc/sysctl.d/k8s.conf),文件内容为:
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness = 0
加载br_netfilter模块:modprobe br_netfilter
查看是否加载:lsmod | grep br_netfilter
加载网桥配置文件: sysctl -p /etc/sysctl.d/k8s.conf
7、开启ipvs:
1)安装ipset及ipvsadm,命令:yum -y install ipset ipvsadm
2)在所有节点执行如下脚本:
添加需要加载的模块:
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF
3)设置权限:chmod 755 /etc/sysconfig/modules/ipvs.modules
使生效:sh /etc/sysconfig/modules/ipvs.modules
验证: lsmod | grep ip_vs_rr