如果没有特殊说明,以下操作每台服务器上都要执行
一、关闭防火墙
[root@k8s-5-146 ~]# systemctl stop firewalld
[root@k8s-5-146 ~]# systemctl disable firewalld
二、禁用SELINUX
[root@k8s-5-146 ~]# setenforce 0
[root@k8s-5-146 ~]# cat /etc/selinux/config
SELINUX=disabled
三、添加host解析
[root@k8s-5-146 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 k8s-5-146.k8s.host #每天机器解析自己的服务器名到127.0.0.1
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# 每台服务器都添加以下内容
192.168.5.146 k8s-5-146.k8s.host
192.168.5.147 k8s-5-147.k8s.host
192.168.5.148 k8s-5-148.k8s.host
四、添加br_netfilter 模块
由于开启内核 ipv4 转发需要加载 br_netfilter 模块,所以加载下该模块:
[root@k8s-5-146 ~]# modprobe br_netfilter
五、配置网桥
bridge-nf 使得 netfilter 可以对 Linux 网桥上的 IPv4/ARP/IPv6 包过滤。比如,设置
net.bridge.bridge-nf-call-iptables=1
后,二层的网桥在转发包时也会被 iptables的 FORWARD 规则所过滤。常用的选项包括:
- net.bridge.bridge-nf-call-arptables:是否在 arptables 的 FORWARD 中过滤网桥的 ARP 包
- net.bridge.bridge-nf-call-ip6tables:是否在 ip6tables 链中过滤 IPv6 包
- net.bridge.bridge-nf-call-iptables:是否在 iptables 链中过滤 IPv4 包
- net.bridge.bridge-nf-filter-vlan-tagged:是否在 iptables/arptables 中过滤打了 vlan 标签的包。
[root@k8s-5-146 ~]# vim /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
[root@k8s-5-146 ~]# sysctl -p /etc/sysctl.d/k8s.conf
六、安装 ipvs
[root@k8s-5-146 ~]# 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
[root@k8s-5-146 ~]# chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
上面脚本创建了的
/etc/sysconfig/modules/ipvs.modules
文件,保证在节点重启后能自动加载所需模块。使用lsmod | grep -e ip_vs -e nf_conntrack_ipv4
命令查看是否已经正确加载所需的内核模块。
七、安装 ipset 软件包 和管理工具
[root@k8s-5-146 ~]# yum install ipset
[root@k8s-5-146 ~]# yum install ipvsadm
八、同步服务器时间
[root@k8s-5-146 ~]# yum install chrony -y
[root@k8s-5-146 ~]# systemctl enable chronyd
[root@k8s-5-146 ~]# systemctl start chronyd
[root@k8s-5-146 ~]# chronyc sources
210 Number of sources = 4
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^+ ntp2.aas.ru 1 10 377 21m -3839us[-4877us] +/- 122ms
^+ time.cloudflare.com 3 10 377 512 -1258us[-2388us] +/- 106ms
^+ ntp.xtom.nl 2 10 277 468 +737us[ -398us] +/- 109ms
^* sv1.ggsrv.de 2 10 377 261 -3826us[-4986us] +/- 113ms
九、关闭 swap 分区
[root@k8s-5-146 ~]# swapoff -a
# 修改/etc/fstab文件,注释掉 SWAP 的自动挂载
[root@k8s-5-146 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Mar 5 22:06:53 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=9686e40d-a343-41b3-bcaa-a02da3954665 /boot xfs defaults 0 0
# /dev/mapper/centos-swap swap swap defaults 0 0 ###注释掉这一行
## 使用free -m确认 swap 已经关闭,如果Swap 全部为0,意味着已经关闭
[root@k8s-5-146 ~]# free -m
total used free shared buff/cache available
Mem: 1821 195 789 9 836 1413
Swap: 0 0 0
## swappiness 参数调整,修改/etc/sysctl.d/k8s.conf添加内容 vm.swappiness=0
[root@k8s-5-146 ~]# cat /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
# 执行sysctl -p /etc/sysctl.d/k8s.conf使修改生效。
[root@k8s-5-146 ~]# sysctl -p /etc/sysctl.d/k8s.conf
十、安装docker
参考文档
安装Docker