Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9350571
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: 服务器与存储

2012-03-07 10:17:52

穷人的劳斯莱斯——spread+wackamole

各位看官之前肯定用过一些HA的软件,诸如heartbeat+lvs,zxtm之流,heartbeat很好很强大,最强大的在于不要钱,缺点在于没法做成AA,zxtm更强大,可以AA,可惜他要钱,接下来我们的主角隆重登场:spread+wackamole ,他既不要钱也能做AA,堪称穷人的劳斯莱斯。

spread 主要实现集群之间机器的健康检查(心跳),wackamole结合spread的检测结果及自身的配置文件来确定对外服务的ip绑定在集群内的哪台服务器上,当然这辆”劳斯莱斯”只是做网络方面的检测和ip的切换,服务层面的监控还是需要外挂的脚本实现。

安装篇:


安装的顺序为先装spread再装wackamole,下载地址如下:

spread:

wackamole:
安装前需要在/etc/hosts下添加该集群服务器的ip及主机名,接着编译安装spread,编译参数如下:

tar xzf spread-src-4.0.0.tar.gz cd spread-src-4.0.0 ./configure --prefix=/usr --sysconfdir=/etc make make install
完成之后需要ldconfig下,让其lib库生效,否则编译wackamole时将无法通过
接着上wackamole
tar xzf wackamole-2.1.4-last.tar.gz cd wackamole-2.1.4 ./configure --prefix=/usr --sysconfdir=/etc --with-perl make make install

搞定收工

配置篇:

spread的配置文件在/etc下面,文件名为spread.conf

Spread_Segment Bcast:4803 { hostname1         ip1 hostname2         ip2 } EventPriority =  ERROR EventLogFile = /your/path/spread.log RuntimeDir = /var/run/spread DaemonUser = nobody DaemonGroup = nobody

配置文件超级简单,只需要定义集群内的服务器,启动用户和事件日志文件的位置就行了

按照国际惯例附送启动文件一个:

#!/bin/bash # # spread        This starts and stops spread # # chkconfig: 345 90 10 # description: This starts the spread daemon # # processname: spread # config: /etc/spread.conf # pidfile:/var/run/spread.pid DAEMON=/usr/sbin/spread CONFIG=/etc/spread.conf LOG=/your/path/spread.log HOST=`uname -n` NAME="spread" RETVAL=0 #Source function library. . /etc/rc.d/init.d/functions start() { echo -n "Starting $NAME..." daemon $($DAEMON -c $CONFIG -n $HOST 2>&1 > $LOG &)&; RETVAL=$? [ "$RETVAL" = 0 ] && touch /var/lock/subsys/$NAME echo }   stop() { echo -n "Stopping $NAME..." killproc $DAEMON [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/$NAME echo }   case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status $NAME RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|status}" RETVAL=1 esac   exit $RETVAL

接下来是wackamole的配置文件,位置在/etc/wackamole.conf

Spread = 4803@127.0.0.1 SpreadRetryInterval = 5s Group = groupname Control = /var/run/wack.it Prefer { eth0:vip1/nm } VirtualInterfaces { { eth0:vip1/nm } { eth0:vip2/nm }   } Arp-Cache = 10s Notify { eth0:network/nm eth0:server{n}ip/nm arp-cache } balance { AcquisitionsPerRound = all interval = 4s } mature = 5s

也很简单,定义了spread的端口,groupname, vip(其中prefer定义了本机优先绑定的vip),notify中定义的是网络地址及集群内的其他服务器地址

启动文件如下:

#!/bin/bash # # wackamole This starts and stops wackamole # # chkconfig: 345 95 05 # description: This starts the wackamole daemon # # requires: spread # processname: wackamole # config: /etc/wackamole.conf # pidfile:/var/run/wackamole.pid   DAEMON=/usr/sbin/wackamole CONFIG=/etc/wackamole.conf NAME="wackamole" RETVAL=0   #Source function library. . /etc/rc.d/init.d/functions   start() { echo -n "Starting $NAME..." daemon $DAEMON -c $CONFIG RETVAL=$? [ "$RETVAL" = 0 ] && touch /var/lock/subsys/$NAME echo }   stop() { echo -n "Stopping $NAME..." killproc $DAEMON [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/$NAME echo }   case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status $NAME RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|status}" RETVAL=1 esac   exit $RETVAL

剩下的就是开启服务啦,先启动spread,再启动wackamole,至此完成了网络层面的高可用性,剩下的就是写些脚本去监控服务的状态,如有问题,手动调用wackamole的命令来触发vip的切换,这样,一个高可用的服务就全部完成啦

PS:
wackamole下我们常用的命令为wackatrl,用法如下:
wackatrl: invalid option — h
Usage:
-c : use filename instead of wackamole.conf
-f : tell the local instance to simulate failure
-s : tell the local instance to simulate success
-l : display the current VIF assignments

阅读(641) | 评论(0) | 转发(0) |
0

上一篇:Linux Virtual Server

下一篇:Lvs+heartbeat

给主人留下些什么吧!~~