Heartbeat v3 + ttser
DRBD是一种块设备,可以被用于高可用(HA)之中.它类似于一个网络RaiD-1功能.当你将数据写入本地 文件系统时,数据还将会被发送到网络中另一台主机上.以相同的形式记录在一个文件系统中. 本地(主节点)与远程主机(备节点)的数据可以保证实时同步.当本地系统出现故障时,远程主机上还会保留有一份相同的数据,可以继续使用.
Heartbeat:heartbeat是一种主要提供高可用的软件
Ttserver:ttserver是一种高并发的分布式持久存储系统,具体可以自己Google一下
准备工作
机器包括space142和space143
space142上的两个IP分别为10.0.0.1和192.168.20.180;
space142上的两个IP分别为10.0.0.2和192.168.20.181;
漂移IP(VIP)为192.168.20.183;
10.0.0.x网段用于DRBD通信。
分别在两台机器上配置/etc/hosts文件
- #vim /etc/hosts
10.0.0.1 space142
192.168.20.180 space142
10.0.0.2 space143
192.168.20.181 space143
ttsserver安装和配置
具体可以参看我的其他文章
- #cp /usr/local/tokyotyrant/bin/ttserver /etc/init.d/
- #vim /etc/init.d/ttserver #修改相关的变量
prog="ttservctl"
cmd="/usr/local/tokyotyrant/bin/ttserver"
basedir="/data/ttserver1"
port="1978"
pidfile="$basedir/pid"
logfile="$basedir/log"
ulogdir="$basedir/ulog"
ulimsiz="256m"
sid=1
#mhost="remotehost1"
#mport="1978"
#rtsfile="$basedir/rts"
dbname="$basedir/casket.tch#bnum=1000000"
retval=0
/etc/init.d/ttserver脚本被用做资源脚本被heartbeat调用
安装和配置DRBD
分别在space142、space143上安装DRBD
- #wget Http://oss.linbit.com/drbd/8.3/drbd-8.3.10.tar.gz
- #tar zxvf drbd-8.3.10.tar.gz
- #cd drbd-8.3.10
- #./configure
- #make rpm
- #make km-rpm
- #cd /usr/src/redhat/RPMS/x86_64
- #rpm -ivh drbd*
- #modprobe drbd
- #lsmod |grep drbd
DRBD配置如下:
- #vim /etc/drbd.conf
disk {
on-io-error detach;
#size 1G;
}
net {
}
on space142 {
device /dev/drbd0;
disk /dev/sdb1;
address 10.0.0.1:7898;
meta-disk internal;
}
on space143 {
device /dev/drbd0;
disk /dev/sdb1;
address 10.0.0.2:7898;
meta-disk internal;
}
}
初始化DRBD资源
- #drbdadm create-md r0
- #mkfs.ext3 /dev/drbd0
- #/etc/init.d/drbd start && chkconfig drbd off
- #mkdir /data
/data目录用来挂载drbd设备
安装和配置Heartbeat V3
1)安装heartbeat前准备,安装Cluster Glue
- #groupadd haclient
- #useradd -g haclient hacluster
- #wget http://hg.linux-ha.org/glue/arcHive/glue-1.0.7.tar.bz2
- #tar jxvf glue-1.0.7.tar.bz2
- #cd Reusable-Cluster-Components-glue--glue-1.0.7/
- #./autogen.sh
- #./configure
- #make
- #make install
2)安装resource-agents
- #wget https://download.GitHub.com/ClusterLabs-resource-agents-agents-1.0.4-0-GC06b6f3.tar.gz
- #tar -jvxf ClusterLabs-resource-agents-agents-1.0.4-0-gc06b6f3.tar.gz
- #cd Cluster-Resource-Agents-agents-1.0.4
- #./autogen.sh
- #./configure
- #make
- #make install
3)安装heartbeat
- #wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/STABLE-3.0.4.tar.bz2
- #tar jxvf STABLE-3.0.4.tar.bz2
- #cd Heartbeat-3-0-STABLE-3.0.4/
- #./bootstrap
- #./configure
- #make
- #make install
4)配置ha.cf和authkeys
- # vim /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 30
udpport 694
mcast eth1 239.0.0.1 694 1 0 # 使用多播方式进行相互通信
auto_failback on
node space142
node space143
compression bz2
compression_threshold 2
crm respawn
# 以下两行是pacemaker-mgmt提供的hb_gui 连接所必须的,2.1.4时没有
配置authkeys
- # vi /etc/ha.d/authkeys
auth 1
1 sha1 0366577bdaed36f08b5f1c29431812dc
5)资源配置
利用crm命令进入crm shell进行配置
primitive ClusterIP ocf:heartbeat:IPaddr2 \
params ip="192.168.20.183" cidr_netmask="32" \
op monitor interval="30s"
primitive drbd ocf:linbit:drbd \
params drbd_resource="r0" drbdconf="/etc/drbd.conf" \
op monitor interval="60s" \
op start interval="0" timeout="240s" \
op stop interval="0" timeout="100s"
primitive fs ocf:heartbeat:Filesystem \
params device="/dev/drbd0" directory="/data" fstype="ext3" \
op start interval="0" timeout="240s" \
op stop interval="0" timeout="100s"
primitive ttserver lsb:ttservctl
group group_ttserver ClusterIP fs ttserver \
meta target-role="Started" is-managed="true"
ms ms_drbd drbd \
meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
colocation ttserver-on-drbd inf: group_ttserver ms_drbd:Master
order ttserver-after-drbd inf: ms_drbd:promote group_ttserver:start
property $id="cib-bootstrap-options" \
stonith-enabled="false" \
dc-version="1.0.10-da7075976b5ff0bee71074385f8fd02f296ec8a3" \
cluster-infrastructure="Heartbeat"
1、drbd常用操作
#watch -n 1 cat /proc/drbd 查看drbd的状态
主从切换:先umount drbd设备。再用drbdadm primary all切换为主,drbdadm primary all切换为从
2、heartbeat常用操作
查看heartbeat资源状态,crm_mon可以查看资源使用情况:
#crm_mon
============
Last updated: Thu Apr 7 14:15:44 2011
Stack: Heartbeat
Current DC: space143 (fdec6bb1-a091-44a6-a542-af6afc3030a5) - partition with quorum
Version: 1.0.10-da7075976b5ff0bee71074385f8fd02f296ec8a3
2 nodes configured, unknown expected votes
2 Resources configured.
============
Online: [ space142 space143 ]
Master/Slave Set: ms_drbd
Masters: [ space143 ]
Slaves: [ space142 ]
Resource Group: group_ttserver
ClusterIP (ocf::heartbeat:IPaddr2): Started space143
fs (ocf::heartbeat:Filesystem): Started space143
ttserver (lsb:ttservctl): Started space143
资源切换
如果资源挂载space142,通过以下命令可以把资源手动的切换到space143
相关文章