高可用集群-heartbeat

heartbeat最核心的包括两个。部分,心跳监测部分和资源接管部分,心跳监测 可以通过网络链路和串口进行,而且支持冗余链路,它们之间相互发送报文来告诉对方自己当前的状态, 如果在挃定的时间内未收到对方发送的报文,那举就认为对方失效,这时需启劢资源接管模块来接管运行 在对方主机上的资源戒者服务

在这里插入图片描述

准备工作

  1. 修改主机名,永久生效
vim /etc/sysconfig/network

内容如下:

hostnamectl set-hostname hb31.cn
  1. 解析
vim /etc/hosts

内容如下:

192.168.1.31   hb31.cn
192.168.1.32   hb32.cn
  1. 关防火墙,关掉selinux
iptables -F 
getenforce  Permissive 

安装nfs 服务

在192.168.1.20 上安装nfs服务端

yum install -y  nfs-utils
yum install -y rpcbind

systemctl start rpcbind
systemctl start nfs-server
mkdir /wwwdir
echo "heartbeat     http     ha"  > /wwwdir/index.html 
chmod 777 -R /wwwdir/ 

在/etc/exports 添加如下内容

/wwwdir   192.168.1.0/24(rw) 
systemctl restart nfs-server

安装apache

在hb31 和hb32 上安装apache

yum install httpd

安装heartbeat

https://www.linuxidc.com/Linux/2019-02/157123.htm 参考

安装依赖

yum install gcc gcc-c++ autoconf automake libtool glib2-devel libxml2-devel bzip2 bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel asciidoc  -y 
 

创建用户组

groupadd haclient
useradd -g haclient hacluster

安装cluster-glue

tar xf 0a7add1d9996.tar.bz2
cd Reusable-Cluster-Components-glue--0a7add1d9996/
./autogen.sh
./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'
make && make install
echo $? 
cd ..

编译安装resource-agents

tar xf resource-agents-3.9.6.tar.gz
cd resource-agents-3.9.6/
./autogen.sh
./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'
make && make install
echo $?
cd ..

编译安装heartbeat

tar xf 958e11be8686.tar.bz2
cd Heartbeat-3-0-958e11be8686/
./bootstrap
export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'
make && make install
echo $?

生成配置文件

cd /usr/local/heartbeat/etc/ha.d/
cp /root/Heartbeat-3-0-958e11be8686/doc/{ha.cf,haresources,authkeys} .
chkconfig --add heartbeat
chkconfig heartbeat on
chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys
mkdir -pv /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/
cp /usr/lib/ocf/lib/heartbeat/ocf-* /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/
ln -sv /usr/local/heartbeat/lib64/heartbeat/plugins/* /usr/local/heartbeat/lib/heartbeat/plugins/

配置

Heartbeat的配置主要涉及到ha.cf、haresources、authkeys这三个文件。
ha.cf: 主配置文件,
haresource: 用来配置要让Heartbeat托管的服务,
authkey: 是用来指定Heartbeat的认证方式。

  1. 配置ha.cf----主配置文件
# vim /usr/local/heartbeat/etc/ha.d/ha.cf (注:前面数字是行号)
24 debugfile /var/log/ha-debug           ##用于记录heartbeat的调试信息
29 logfile /var/log/ha-log                ##用于记录heartbeat的日志信息
34 logfacility local0                    ##设置heartbeat的日志,这里用的是系统日志
48 keepalive 2                              ##设定心跳(监测)时间时间为2秒
56 deadtime 30         ##指定若备用节点在30秒内未收到主节点心跳信号,则接管主服务器资源
61 warntime 10           ##指定心跳延迟的时间为10秒,10秒内备节点不能接收主节点心跳信号,
                                  即往日志写入警告日志,但不会切换服务
71 initdead 60         ##系统启动或重启后预留的忽略时间段,取值至少为deadtime的两倍
76 udpport  694                         ##广播/单播通讯使用的Udp端口
91 #bcast ens32   # Linux             ##使用网卡eno32发送心跳检测
113 #mcast eth0 225.0.0.1 694 1 0    ##采用网卡eth0的Udp多播来组织心跳,一般在备用节点
Bcast、ucast和mcast分别代表广播、单播和多播,是组织心跳的的方式,任选其一
121 ucast ens33 192.168.1.32   ##采用网卡eth32的udp单播来组织心跳,后面跟的IP地址为双机对方IP地址
157 auto_failback on                 ##定义当主节点恢复后,是否将服务自动切回
211 node hb31.cn                     ##主节点名称
212 node hb32.cn                     ##备用节点名称
220 ping 192.168.2.1                ##通过ping网关检测心跳是否正常,仅用来测试网络
253 respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail   ##指定和heartbeat一起启动、关闭的进程
  1. 配置haresources资源文件
    Haresources文件用于指定双机系统的主节点、集群IP、子网掩码、广播地址及启动服务集群资源,文件每一行可包含一个或多个资源脚本名,资源间使用空格隔开,参数间使用两个冒号隔开,主节点和备份节点中资源文件haresources要完全一样.
    一般格式为:
    node-name network
    node-name表示主节点的主机名,必须和ha.cf文件中指定的节点名一致。network用于设定集群的
    IP地址、子网掩码和网络设备标识等。resource-group用于指定需Heartbeat托管的服务(即这些
    服务可由Heartbeat来启动和关闭)。
    注意:这里指定的IP地址就是集群对外服务的IP地址
    如要托管这些服务,必须将服务写成可通过start/stop来启动或关闭的脚本,放到/etc/init.d/
    或/etc/ha.d/resource.d/目录下,Heartbeat会根据脚本名称自动去/etc/init.d或者
    /etc/ha.d/resource.d目录下找到相应脚本进行启动或关闭操作。
# vim /usr/local/heartbeat/etc/ha.d/haresources (注:前面数字为行号)
44 hb31.cn IPaddr::192.168.1.111/24/ens33 Filesystem::192.168.1.20:/wwwdir::/var/www/html::nfs  httpd
  1. 配置authkeys
#vim /usr/local/heartbeat/etc/ha.d/authkeys 
auth 3
3 md5 Hello!

chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys
  1. 编写httpd启动脚本
# vim /usr/local/heartbeat/etc/ha.d/resource.d/httpd 
!/bin/bash
/bin/systemctl $1 httpd     
chmod 755 !$
  1. 复制配置文件至备机
scp –rp /usr/local/heartbeat/etc/ha.d/* root@192.168.1.32:/usr/local/heartbeat/etc/ha.d/

chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys

修改
ha.cf 中的ucast 配置

测试

两机器启动heartbeat服务:

/etc/init.d/heartbeat restart

在这里插入图片描述在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值