使用Keepalived实现简单的GrayLog高可用

简介: 使用Keepalived实现简单的GrayLog高可用

如下图所示,使用Keepalived实现简单的GrayLog高可用

(图片点击放大查看)

Node1:192.168.31.64

Node2:192.168.31.66

虚拟VIP——192.168.31.65

具体步骤如下

1、yum安装keepalived

yum -y install keepalived

(图片点击放大查看)

2、配置keepalived.conf

cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf-default
echo -n |  tee /etc/keepalived/keepalived.conf
vim /etc/keepalived/keepalived.conf
global_defs {
  # Keepalived process identifier
  router_id graylog
}
# Script to check whether graylog is running or not
vrrp_script check_graylog {
  script "/etc/keepalived/check_graylog.sh"
  interval 3
  weight 50
  fall 2
}
# Virtual interface - The priority specifies the order in which the assigned interface to take over in a failover
vrrp_instance VI_Graylog {
  state MASTER
  interface ens33
  virtual_router_id 80
  priority 110
  # The virtual ip address shared between the two GrayLog Web Server which will float
  virtual_ipaddress {
    192.168.31.65/24 dev ens33
  }
  track_script {
    check_graylog
  }
  authentication {
    auth_type PASS
    auth_pass Keepalived2023
  }
  notify_master "/etc/keepalived/master.sh"
  notify_backup "/etc/keepalived/backup.sh"
  notify_fault "/etc/keepalived/fault.sh"
}

(图片点击放大查看)

(图片点击放大查看)

备节点修改如下位置

scp /etc/keepalived/keepalived.conf root@192.168.31.66:/etc/keepalived/keepalived.conf
vim /etc/keepalived/keepalived.conf
state BACKUP
priority 80

(图片点击放大查看)

3、编写notify脚本

vim /etc/keepalived/master.sh
添加如下行
#!/bin/bash
LOGFILE=/var/log/keepalived-state.log
date >> $LOGFILE
echo "[MASTER]" >> $LOGFILE
webhook_url="https://oapi.dingtalk.com/robot/send?access_token=4f851XXXXXXXXcaf25e6eabad63f88aXX"
NodeIP=`(hostname -I)`
set_payload_file(){
cat  > /opt/payload_result.json << \EOF
{       
"msgtype": "actionCard",
"actionCard": {
"title":"当前节点已切换成Master节点",
"text":"
##### 当前节点已切换成Master节点 \n
>  ##### <font color=#67C23A> 【Master节点IP】</font> :<font color=#FF0000> templateIP </font> \n
"
}
}
EOF
}
set_payload_file
sed -i "s^templateIP^$NodeIP^g" /opt/payload_result.json
response=$(curl -sS -H "Content-Type: application/json" -X POST -d @/opt/payload_result.json "${webhook_url}")
if [ $? -eq 0 ]; then
   echo "Alert sent successfully"
else
   echo "Failed to send alert: ${response}"
fi

(图片点击放大查看)

vim /etc/keepalived/backup.sh 
添加如下行
#!/bin/bash
LOGFILE=/var/log/keepalived-state.log
date >> $LOGFILE
echo "[BACKUP]" >> $LOGFILE 
vim /etc/keepalived/fault.sh 
添加如下行
#!/bin/bash
LOGFILE=/var/log/keepalived-state.log
date >> $LOGFILE
echo "[FAULT]" >> $LOGFILE

(图片点击放大查看)

4、编写track_script

vim /etc/keepalived/check_graylog.sh
添加如下行
#!/bin/bash
Graylog_PID=`ps -ef | grep '/bin/graylog-server' | grep -v grep | awk '{print $2}'`
if [ -z $Graylog_PID ]; then
  exit 1
else 
  exit 0
fi

(图片点击放大查看)

chmod a+x /etc/keepalived/*.sh
scp /etc/keepalived/*.sh root@192.168.31.66:/etc/keepalived/

(图片点击放大查看)

5、启动keepalived

firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept' --permanent
firewall-cmd --reload
systemctl enable keepalived
systemctl start keepalived
systemctl status keepalived

(图片点击放大查看)

(图片点击放大查看)

这时Node1为主节点

6、Keepalived高可用测试验证

手动关闭主节点的graylog-server服务

这时虚拟VIP会漂移到备节点

(图片点击放大查看)

再启动主节点的graylog-server服务

这时Node1为切回Master 这时虚拟VIP会漂移到主节点

(图片点击放大查看)

本文参考如下链接完成

https://linuxhandbook.com/load-balancing-setup/
https://www.linuxtechi.com/setup-highly-available-nginx-keepalived-linux/
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/load_balancer_administration/keepalived_install_example1#doc-wrapper
https://www.redhat.com/sysadmin/advanced-keepalived
https://www.howtoforge.com/how-to-setup-highly-available-nginx-with-keepalived-on-centos-8/
https://www.atlantic.net/dedicated-server-hosting/how-to-vrrp-keepalived-configuration/
https://tobru.ch/keepalived-check-and-notify-scripts/
https://docs.oracle.com/en/operating-systems/oracle-linux/6/admin/section_hxz_zdw_pr.html
相关文章
|
6月前
|
负载均衡 Linux 网络安全
Keepalived 实现 Kibana 的高可用
Keepalived 实现 Kibana 的高可用
|
6月前
【优化篇】使用Keepalived实现简单的GrayLog高可用
【优化篇】使用Keepalived实现简单的GrayLog高可用
71 0
|
3月前
|
运维 负载均衡 监控
Nginx加Keepalived实现高可用
使用Nginx和Keepalived来实现高可用性的方案,对于确保关键服务的稳定性和可靠性来说是非常有效的。此配置涉及多个步骤,包括各个服务的安装、设置及测试,目标是在主服务器故障时能无缝切换,以确保服务的持续可用。正确的配置和充分的测试是实现高可用性的保证,这也要求管理员对这些工具和它们背后的原理有深入的了解。
73 1
nginx+keepalived实现高可用
如果通过keepalived实现高可用
|
负载均衡 NoSQL 关系型数据库
Nginx+keepalived实现高可用集群
大型企业架构一般是用户先访问到四层负载均衡,在由四层负载均衡转发至七层服务在均衡,七层负载均衡再转发至后端服务器,四层负载均衡只起到一个分流的作用,根据用户访问的端口,比如说80端口就会跳转至七层的对应的集群,两台四层负载均衡配置是一模一样的,形成高可用,七层的配置也是一模一样的,当有1500个请求需要响应时,四层负载均衡就会平均将1500个请求分给急群中的lb,每个lb响应500个请求,减轻单点的压力。
1707 0
Nginx+keepalived实现高可用集群
|
负载均衡 JavaScript 应用服务中间件
Nginx负载均衡配置+keepalived高可用
Nginx负载均衡配置+keepalived高可用
3374 0
|
网络架构
Keepalived 介绍、安装、配置(高可用)
1、keepalived的工作原理是VRRP(Virtual Router Redundancy Protocol)虚拟路由冗余协议。 2、VRRP路由器是指运行VRRP的路由器,是物理实体,虚拟路由器是指VRRP协议创建的,是逻辑概念。
1218 0
|
监控 关系型数据库 MySQL