1、Keepalived软件前期用来管理并监控LVS集群系统中各个服务节点的状态;
2、后期加入了实现高可用的VRRP功能。因此可以为lvs负载均衡提供高可用功能,也可以为其他服务提供高可用。。
实验镜像:Centos 8.1.1911
草图:(待补)
1、两个real server 安装配置
在keepalived Master上测试无问题。
[root@HA1 ~]# curl http://192.168.94.140 this is real 1 server [root@HA1 ~]# curl http://192.168.94.141 this is real 2 server [root@HA1 ~]#
2、安装keepalived、ipvsadm
yum install ipvsadm keepalived -y
使用keepalived即可完成real server的添加。
配置文件在/etc/keepalived下
[root@HA1 keepalived]# pwd /etc/keepalived [root@HA1 keepalived]# ls keepalived.conf [root@HA1 keepalived]# cp keepalived.conf keepalived.conf.bak [root@HA1 keepalived]# echo "" > keepalived.conf [root@HA1 keepalived]#
3、keepalived文件配置
MASTER
! Configuration File for keepalived # 全局 global_defs { notification_email { root@localhost } notification_email_from keepalived@server.com smtp_connect_timeout 3 smtp_server 127.0.0.1 router_id LVS_DEVEL } # 一个keepalived服务器,MASTER为主的进行服务提供 vrrp_instance VI_1 { interface ens33 state MASTER priority 101 virtual_router_id 51 garp_master_delay 1 authentication { auth_type PASS auth_pass password } # VIP 地址 virtual_ipaddress { 192.168.94.200 dev ens33 label ens33:0 } } # VIP 关联两个real server virtual_server 192.168.94.200 80 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 50 protocol TCP # 两个real server 都故障,提供服务的地址 sorry_server 192.168.94.138 80 # 定义real server 1 real_server 192.168.94.140 80 { weight 1 # real server 存活检测,检测url的code HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } # 定义real server 2 real_server 192.168.94.141 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
把配置文件复制到HA2上
BACKUP
! Configuration File for keepalived # 全局 global_defs { notification_email { root@localhost } notification_email_from keepalived@server.com smtp_connect_timeout 3 smtp_server 127.0.0.1 router_id LVS_DEVEL } # 一个keepalived服务器,MASTER为主的进行服务提供 vrrp_instance VI_1 { interface ens33 state BACKUP priority 100 virtual_router_id 51 garp_master_delay 1 authentication { auth_type PASS auth_pass password } # VIP 地址 virtual_ipaddress { 192.168.94.200 dev ens33 label ens33:0 } } # VIP 关联两个real server virtual_server 192.168.94.200 80 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 50 protocol TCP # 两个real server 都故障,提供服务的地址 sorry_server 192.168.94.139 80 # 定义real server 1 real_server 192.168.94.140 80 { weight 1 # real server 存活检测,检测url的code HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } # 定义real server 2 real_server 192.168.94.141 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
1、高可用
两个节点(MASTER、BACKUP)都启动服务。
查看地址ifconfig –a
VIP只会启动在MASTER上,当MASTER服务故障后,则BACKUP提供服务。
2、real server 资源管理
real server 节点故障后,keepalived会自动在ipvs中进行删除。再上线后也会重新加进来。
我的配置文件可能有点问题,测试的时候有些奇怪,有时间在检查吧。
读书和健身总有一个在路上