- 云原生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配置相同):
![](https://epubservercos.yuewen.com/27A31B/26581513401334806/epubprivate/OEBPS/Images/Figure-P32_132761.jpg?sign=1739199492-5oacLpfIxIsGgdsenhctZq9zjgOIEP9V-0-5356c6f5fe8fa9060459bf307cca3816)
所有Master节点配置KeepAlived,由于KeepAlived需要配置自身的IP地址和网卡名称,因此每个KeepAlived节点的配置不一样。
Master01节点的配置(注意每个节点的IP和网卡interface参数):
![](https://epubservercos.yuewen.com/27A31B/26581513401334806/epubprivate/OEBPS/Images/Figure-P33_132764.jpg?sign=1739199492-9Qkhvwq2pZ7DpuR9LzHAsuofRr7W20zA-0-c392e705ed16d6362fcf40da186159f1)
Master02节点的配置(注意更改加粗部分的配置):
![](https://epubservercos.yuewen.com/27A31B/26581513401334806/epubprivate/OEBPS/Images/Figure-P33_132765.jpg?sign=1739199492-5TevD6CDwdLculGZtHZUqenTLII6zPfW-0-f385c08d871ddce6bea2601c868e4dec)
Master03节点的配置(注意更改加粗部分的配置):
![](https://epubservercos.yuewen.com/27A31B/26581513401334806/epubprivate/OEBPS/Images/Figure-P34_132767.jpg?sign=1739199492-9rPcKSg70td772azGR15Ijjh9LHyOOPX-0-f1c8d5825a7a0c900a2fd7d477cd1cc3)
所有Master节点配置KeepAlived健康检查文件:
![](https://epubservercos.yuewen.com/27A31B/26581513401334806/epubprivate/OEBPS/Images/Figure-P34_132768.jpg?sign=1739199492-QYLDoGid79uL9UGRSobBY7DVhVT9MGZ1-0-b532ab784f98cac06dabfdf470cf208a)
启动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的状态,监听端口是否正常等。