keepalived安装-集群部署

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

  • 11
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑要上天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值