- 云原生Kubernetes全栈架构师实战
- 杜宽
- 517字
- 2023-09-15 17:43:39
1.4 高可用组件安装
本书采用KeepAlived和HAProxy实现高可用,所以需要安装KeepAlived和HAProxy。KeepAlived和HAProxy的节点可以和Master在同一个节点,也可以在不同的节点。
如果读者是在公有云搭建高可用集群,可以采用公有云的负载均衡替代KeepAlived和HAProxy。
提示
如果读者想要搭建只有一个Master节点的集群,可以不安装高可用组件。
所有Master节点通过yum安装HAProxy和KeepAlived:
# yum install keepalived haproxy -y
所有Master节点配置HAProxy(详细配置可参考HAProxy官方文档,所有Master节点的HAProxy配置相同):
所有Master节点配置KeepAlived,由于KeepAlived需要配置自身的IP地址和网卡名称,因此每个KeepAlived节点的配置不一样。
Master01节点的配置(注意每个节点的IP和网卡interface参数):
Master02节点的配置(注意更改加粗部分的配置):
Master03节点的配置(注意更改加粗部分的配置):
所有Master节点配置KeepAlived健康检查文件:
启动HAProxy和KeepAlived:
# systemctl daemon-reload # systemctl enable --now haproxy # systemctl enable --now keepalived
如果是用HAProxy和KeepAlived实现的高可用,则需要测试VIP是否是正常的:
# 所有节点进行ping测试 # ping 10.0.0.236 -c 4 PING 10.0.0.236 (10.0.0.236) 56(84) bytes of data. 64 bytes from 10.0.0.236: icmp_seq=1 ttl=64 time=0.464 ms 64 bytes from 10.0.0.236: icmp_seq=2 ttl=64 time=0.063 ms 64 bytes from 10.0.0.236: icmp_seq=3 ttl=64 time=0.062 ms 64 bytes from 10.0.0.236: icmp_seq=4 ttl=64 time=0.063 ms --- 10.0.0.236 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3106ms rtt min/avg/max/mdev = 0.062/0.163/0.464/0.173 ms # 所有节点进行telnet测试 # telnet 10.0.0.236 16443 Trying 10.0.0.236... Connected to 10.0.0.236. Escape character is '^]'. Connection closed by foreign host.
如果ping不通且telnet没有出现,则认为VIP不可用。如果VIP不可用,不可再继续往下执行,需要排查VIP的问题,比如防火墙和SELinux、HAProxy和Keepalived的状态,监听端口是否正常等。