使用HeartBeat实现高可用HA的配置。HA即(high available)高可用,又被叫做双机热备,用于关键性业务。简单理解就是,有2台机器 A 和 B,正常是 A 提供服务,B 待命闲置,当 A 宕机或服务宕掉,会切换至B机器继续提供服务。常见的实现高可用的开源软件有 heartbeat 和 keepalived。
hostname Master01 vim /etc/sysconfig/network 编辑配置文件:HOSTNAME=Master01
# vim /etc/sysconfig/network 编辑配置文件:HOSTNAME=Master01
10.60.196.179 Slave01# vim /etc/sysconfig/network 编辑配置文件:HOSTNAME=Slave01
# iptables -F # service iptables save # service iptables stop
# setenforce 0 # sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# yum install -y epel-release
# yum install -y heartbeat* libnet
# cd /usr/share/doc/heartbeat-3.0.4/ # cp authkeys ha.cf haresources /etc/ha.d/ # cd /etc/ha.d
# vim authkeys 更改或增加如下内容: auth 33 md5 Hello!然后修改其权限 # chmod 600 authkeys
# vim haresources加入下面一行:Master01 10.60.196.180/24/eth0:0 raysync
说明:master为主节点hostname,10.60.196.180为vip,/24为掩码为24的网段,eth0:0为vip的设备名,httpd为heartbeat监控的服务,也是两台机器对外提供的核心服务。改行指定在启动时,节点得到vip,并启动httpd,在停止时heartbeat首先停止httpd,然后释放vip。
respawn hacluster /usr/lib64/heartbeat/ipfail
logfile /var/log/ha-log:heartbeat的日志文件。
keepalive 2:心跳的时间间隔,默认时间单位为秒s。
deadtime 30:超出该时间间隔未收到对方节点的心跳,则认为对方已经死亡。
warntime 10:超出该时间间隔未收到对方节点的心跳,则发出警告并记录到日志中。
initdead 120:在某系统上,系统启动或重启之后需要经过一段时间网络才能正常工作,该选项用于解决这种情况产生的时间间隔,取值至少为deadtime的2倍。
udpport 694:设置广播通信使用的端口,694为默认使用的端口号。
ucast eth0 10.60.196.179:设置对方机器心跳检测的网卡和IP。
auto_failback on:heartbeat的两台主机分别为主节点和从节点。主节点在正常情况下占用资源并运行所有的服务,遇到故障时把资源交给从节点由从节点运行服务。在该选项设为on的情况下,一旦主节点恢复运行,则自动获取资源并取代从节点,否则不取代从节点。
respawn heartbeat /usr/lib/heartbeat/ipfail:指定与heartbeat一同启动和关闭的进程,该进程被自动监视,遇到故障则重新启动。最常用的进程是ipfail,该进程用于检测和处理网络故障,需要配合ping语句指定的ping node来检测网络连接。如果你的系统是64bit,请注意该文件的路径。
# cd /etc/ha.d # scp authkeys ha.cf haresources root@Slave01:/etc/ha.d
只需要更改一个地方如下:ucast eth0 10.60.196.179改为ucast eth0 10.60.196.180
配置完毕后,先Master01启动,后Slave01启动。
# service heartbeat start
vim /root/bin/routecheck.sh
ip route show |grep 10.60.196.180
ip route show|grep 10.60.196.254
if [[ $a == 0 ]] && [[ $b != 0 ]];then
route del default gw 10.60.196.254 && ip route add 0.0.0.0/0 via 10.60.196.254 dev eth0 src 10.60.196.180
if [[ $a != 0 ]] && [[ $c != 0 ]];then
ip route add 0.0.0.0/0 via 10.60.196.254 dev eth0
*/1 * * * * bash /root/bin/routecheck.sh > /dev/null
# description: setup RaySync service
# Author: lirou<lirou@rayvision.com>
. /etc/rc.d/init.d/functions
export LC_ALL=en_US.UTF-8
echo "Error Usage: service $(basename $0) [ start | stop | status | restart ]"
if [[ "x$BASE_DIR" == "x" ]];then
RAYSYNC_CONF=$BASE_DIR/config/config.ini
if ! [ -d $(dirname $RAYSYNC_CONF) ];then
install -d -m 755 $(dirname $RAYSYNC_CONF)
if [[ "x$PID_DIR" == "x" ]];then
mkdir -pv $PID_DIR &>/dev/null
#MONITOR_PID=$PID_DIR/monitor.pid
MONITOR_LOCKFILE=$PID_DIR/monitor.lock
RAYSYNC_SERVER_LOCKFILE=$PID_DIR/raysync-server.lock
RAYSYNC_PROXY_SERVER_LOCKFILE=$PID_DIR/raysync-proxy.lock
RAYSYNC_PROXY_SERVER_BIN_NAME=
if [[ "x$MONITOR_BIN_NAME" == "x" ]];then
if [[ "x$RAYSYNC_SERVER" == "x" ]];then
RAYSYNC_SERVER_BIN_NAME=RaySyncServer
if [[ "x$RAYSYNC_PROXY_SERVER" == "x" ]];then
RAYSYNC_PROXY_SERVER_BIN_NAME=RaySync-Proxy-Server
if ! [ -s $RAYSYNC_CONF ];then
echo "Error: don't have configure file in $RAYSYNC_CONF path."
if ! [ -f $MONITOR_LOCKFILE ]; then
# nohup ${BASE_DIR}/${MONITOR_BIN_NAME} &>/dev/null &
nohup ${BASE_DIR}/${MONITOR_BIN_NAME} >/dev/null 2>&1 &
if [[ "x$(ps aux | grep -i monitor | grep -v -i grep )" == "x" ]];then
echo -e "monitor setup fail" && failure
echo -e " monitor is running: " && success
if ! [ -f $RAYSYNC_SERVER_LOCKFILE ];then
nohup $BASE_DIR/RaySyncServer >/dev/null 2&>1 &
if [[ "x$(ps aux | grep RaySyncServer | grep -v -i 'grep' )" == "x" ]];then
echo -e "RaySyncServer setup fail" && failure
touch $RAYSYNC_SERVER_LOCKFILE
echo -e " RaySyncServer is running" && success
if ! [ -f $RAYSYNC_PROXY_SERVER_LOCKFILE ];then
#nohup $BASE_DIR/proxy/$RAYSYNC_PROXY_SERVER_BIN_NAME >/dev/null 2&>1
#echo "nohup $BASE_DIR/proxy/$RAYSYNC_PROXY_SERVER_BIN_NAME >/dev/null 2&>1"
if [[ "x$(ps aux | grep RaySync-Proxy-Server )" == "x" ]];then
echo -e "RaySync-Proxy-Server setup fail" && failure
touch $RAYSYNC_PROXY_SERVER_LOCKFILE
echo -e " RaySync-Proxy-Server is running" && success
if [ -f $MONITOR_LOCKFILE ];then
# killall $MONITOR_BIN_NAME
ps -ef|grep Ray|grep -v grep|awk '{print $2}'|xargs kill -9 >/dev/null 2&>1
echo -e "monitor stopped" && success
if [ -f $RAYSYNC_SERVER_LOCKFILE ];then
#kill $(echo $RAYSYNC_SERVER_PID)
# killall $RAYSYNC_SERVER_BIN_NAME
ps -ef|grep Ray|grep -v grep|awk '{print $2}'|xargs kill -9 >/dev/null 2&>1
rm -f $RAYSYNC_SERVER_LOCKFILE
echo -e "RaySyncServer stopped" && success
# result_Proxy=`ps -ef|grep ${RAYSYNC_PROXY_SERVER_BIN_NAME}|grep -v grep`
# if [ -f $RAYSYNC_PROXY_SERVER_LOCKFILE ] || [ $result_Proxy != "" ];then
if [ -f $RAYSYNC_PROXY_SERVER_LOCKFILE ];then
ps -ef|grep Ray|grep -v grep|awk '{print $2}'|xargs kill -2 >/dev/null 2&>1
echo ${RAYSYNC_PROXY_SERVER_BIN_NAME}
rm -f $RAYSYNC_PROXY_SERVER_LOCKFILE
echo -e "RaySync-Proxy-Server stopped" && success
if [ -f $MONITOR_LOCKFILE ];then
echo " monitor is running"
if [ -f $RAYSYNC_SERVER_LOCKFILE ];then
echo " RaySyncServer is running"
echo " RaySyncServer stopped"
if [ -f $RAYSYNC_PROXY_SERVER_LOCKFILE ];then
echo " RaySync-Proxy-Server is running"
echo " RaySync-Proxy-Server stopped"
echo "Error Usage: service $(basename $0) [ start | stop | status | restart ]"
以上是关于镭速 (Raysync) 文件传输软件的高可用安装部署详细介绍!