博客
关于我
LVS+heartbeat 高可用LINUX服务器
阅读量:806 次
发布时间:2023-02-06

本文共 3021 字,大约阅读时间需要 10 分钟。

LVS高可用配置 - Heartbeat安装与配置指南

1. 环境准备

在开始配置之前,请确保以下环境条件已满足:

  • 操作系统:CentOS 7.6及以上版本
  • 网络:所有节点间应有互联,且IP配置正确无误
  • 用户权限:建议使用root用户执行所有操作
  • 存储空间:至少需要100MB的存储空间用于安装依赖软件

2. 安装依赖软件

安装Heartbeat和相关工具包:

yum -y install libnet* heartbeat* ipvsadm

3. 配置Heartbeat

3.1 复制默认配置文件

将Heartbeat的默认配置文件复制到/etc/ha.d/目录:

cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/cp /usr/share/doc/heartbeat-ldirectord-2.1.3/ldirectord.cf /etc/ha.d/

3.2 修改配置文件

编辑/etc/ha.d/ha.cf文件:

vim /etc/ha.d/ha.cf

添加或修改以下参数:

logfacility local0keepalive 2deadtime 30warntime 10udpport 694ucast eth0 192.168.50.8auto_failback onnode lvs.abc.comnode lvs1.abc.comping 192.168.50.8ping_group group1 192.168.50.8 192.168.50.9ping_group group1 192.168.60.8 192.168.60.9respawn hacluster /usr/lib/heartbeat/ipfailapiauth ipfail gid=haclient uid=hacluster

3.3 验证authkeys文件

编辑/etc/ha.d/authkeys文件:

vim /etc/ha.d/authkeys

确保文件中的验证信息与主从节点一致,并设置文件权限为600:

chmod 600 /etc/ha.d/authkeys

3.4 修改ldirectord.cf

编辑/etc/ha.d/ldirectord.cf文件:

vim /etc/ha.d/ldirectord.cf

添加或修改以下内容:

checktimeout 3checkinterval 1autoreload yeslogfile "/var/log/ldirectord.log"fallback 127.0.0.1:80service httpscheduler wrrprotocol tcpchecktype negotiatecheckport 80request test.htmlreceive "Test Page"

4. 编写资源脚本

创建/etc/ha.d/lvs文件:

vim /etc/ha.d/lvs

添加以下内容:

#!/bin/bash# description: start LVS of DirectorServer# Written by: NetSeek http://www.linuxtone.orgGW=192.168.50.80WEB_VIP=192.168.50.80WEB_RIP1=192.168.50.5WEB_RIP2=192.168.50.6WEB_RIP3=1.1.1.18WEB_RIP4=1.1.1.19case "$1" instart)echo "start LVS of DirectorServer"/sbin/ifconfig eth0:0 $WEB_VIP broadcast $WEB_VIP netmask 255.255.255.255 up/sbin/route add -host $WEB_VIP dev eth0:0/sbin/ipvsadm -A -t $WEB_VIP:80 -s wrr -p 3/sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP1:80 -g -w 1/sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP2:80 -g -w 2/sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP3:80 -g -w 1/sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP4:80 -g -w 1touch /var/lock/subsys/ipvsadm > /dev/null 2>&1 &/sbin/arping -I eth0 -c 5 -s $WEB_VIP $GW > /dev/null 2>&1 &echo "ipvsadm started";;stop)echo "stop LVS of DirectorServer"/sbin/ipvsadm -C/sbin/ipvsadm -Z/sbin/ifconfig eth0:0 down/sbin/route del $WEB_VIP > /dev/null 2>&1 &rm -rf /var/lock/subsys/ipvsadm > /dev/null 2>&1 &/sbin/arping -I eth0 -c 5 -s $WEB_VIP $GW > /dev/null 2>&1 &echo "ipvsadm stopped";;status)if [ ! -e /var/lock/subsys/ipvsadm ]; thenecho "ipvsadm is stopped"exit 1fiipvsadm -lnecho "..........ipvsadm is OK."fi;;*)echo "Usage: $0 {start|stop|status}"exit 1esacexit 0

5. 设置服务启动

设置Heartbeat和ipvsadm的自启动:

chkconfig heartbeat onchkconfig ipvsadm on

6. 复制配置文件到从节点

从节点的配置文件可以通过scp从主节点复制:

scp root@192.168.50.9:/etc/ha.d/* /etc/ha.d/

7. 启动Heartbeat

在所有节点上执行以下命令:

systemctl start heartbeatsystemctl enable heartbeat

8. 测试与验证

8.1 查看Heartbeat状态

tail -F /var/log/ha-logtail -F /var/log/messages

8.2 查看LVS状态

ipvsadm -L -n -stats

8.3 访问测试页面

通过浏览器访问:

  • http://192.168.50.5/test.html
  • http://192.168.50.6/test.html

9. 故障恢复

在主节点或从节点发生故障时,Heartbeat会自动切换到其他节点提供服务。

转载地址:http://ptufk.baihongyu.com/

你可能感兴趣的文章
Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime(93)解决
查看>>
Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
查看>>
Node 裁切图片的方法
查看>>
node+express+mysql 实现登陆注册
查看>>
Node+Express连接mysql实现增删改查
查看>>
node, nvm, npm,pnpm,以前简单的前端环境为什么越来越复杂
查看>>
Node-RED中Button按钮组件和TextInput文字输入组件的使用
查看>>
vue3+Ts 项目打包时报错 ‘reactive‘is declared but its value is never read.及解决方法
查看>>
Node-RED中Switch开关和Dropdown选择组件的使用
查看>>
Node-RED中使用exec节点实现调用外部exe程序
查看>>
Node-RED中使用function函式节点实现数值计算(相加计算)
查看>>
Node-RED中使用html节点爬取HTML网页资料之爬取Node-RED的最新版本
查看>>
Node-RED中使用JSON数据建立web网站
查看>>
Node-RED中使用json节点解析JSON数据
查看>>
Node-RED中使用node-random节点来实现随机数在折线图中显示
查看>>
Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
查看>>
Node-RED中使用node-red-contrib-image-output节点实现图片预览
查看>>
Node-RED中使用node-red-node-ui-iframe节点实现内嵌iframe访问其他网站的效果
查看>>
Node-RED中使用Notification元件显示警告讯息框(温度过高提示)
查看>>
Node-RED中使用range范围节点实现从一个范围对应至另一个范围
查看>>