1.服务器信息
| 服务器版本 | 服务器IP | 介质版本 | 安装用户 | 
| CentOS Linux release 7.9.2009 (Core) | 192.168.10.244 | keepalived-2.2.8.tar.gz nginx-1.26.1 | root | 
| CentOS Linux release 7.9.2009 (Core) | 192.168.10.245 | keepalived-2.2.8.tar.gz nginx-1.26.1 | root | 
2.服务器基础配置
参考:Linux常规基础配置_linux基础配置-CSDN博客
3.nginx安装
参考:基于CentOS7.9搭建LNMP_centos7.9 安装lnmp-CSDN博客
nginx网页改造
节点1:
[root@logstash html]# pwd
/usr/share/nginx/html
[root@logstash html]# ls
50x.html  index.html
[root@logstash html]# cat index.html 
this is 192.168.10.244
[root@logstash html]# 

节点2:
[root@kibana html]# pwd
/usr/share/nginx/html
[root@kibana html]# ls
50x.html  index.html
[root@kibana html]# cat index.html 
this is 192.168.10.245
[root@kibana html]# 

4.keepalived安装配置
参考:Keepalived安装-单节点-CSDN博客
5.keepalived集群配置
节点1集群配置
keepalived.conf
global_defs {
   router_id LVS_MASTER    #名称标记为master,名字随便取
   vrrp_gna_interval 0
}
#加入周期性检测nginx服务脚本的相关配置
vrrp_script check_nginx {
#心跳执行的脚本,检查nginx是否启动
  script "/etc/keepalived/check_nginx.sh"
#检测脚本执行的时间间隔,单位是秒
  interval 2
}
vrrp_instance VI_1 {
#指定当前节点为MASTER节点,只能有一个MASTER(当然也可以不定义为MASTER),其余只能是BACKUP
    state MASTER
#绑定此虚拟路由使用的网卡名称,可以使用ifconfig或ip addr命令查看
    interface ens32
#指定虚拟路由id,虚拟路由的唯一标识,范围是0-255,master和backup节点需要指定一样的,相同id为一组
    virtual_router_id 99
#指定当前节点的优先级,master节点要大于backup节点
    priority 200
#指定发送vrrp通告的间隔,单位是秒
    advert_int 1
    virtual_ipaddress {
#指定虚拟ip,来源于需求方或自己自定义
        192.168.10.240
    }
   track_script {
#添加跟踪(执行脚本)
    check_nginx   
    }
}
check_nginx.sh
#!/bin/bash
A=$(ps -C nginx --no-header | wc -l)
if [ $A -eq 0 ];then
 exit 1
fi
节点2集群配置
keepali



















