rabbitmq主备模式部署

醉酒当歌 提交于 2020-01-20 22:37:26

192.168.15.240 主机名rabbitmq240
192.168.15.241 主机名rabbitmq241
vip: 192.168.15.1
vip: 192.168.15.2

1.两台机器安装
yum -y install erlang.x86_64
ln -s /usr/local/erlang/bin/erl /usr/bin/erl
ln -s /usr/local/erlang/bin/epmd /usr/bin/epmd
yum -y install rabbitmq.x86_64
2.配置主机名,
echo "192.168.15.240 rabbitmq240" >> /etc/hosts
echo "192.168.15.241 rabbitmq241" >> /etc/hosts
3.master 192.168.15.240操作
/usr/local/rabbitmq/sbin/rabbitmq-server -detached
生成文件:~/.erlang.cookie
        cat ~/.erlang.cookie
在master上启动代理:python -m SimpleHTTPServer 7890,备机上执行:wget http://192.168.15.240:7890/.erlang.cookie获取文件
确保master和slave该文件一致,否则加不进集群。
权限也要一致
chmod 400 .erlang.cookie
4.在slave上 192.168.15.241
/usr/local/rabbitmq/sbin/rabbitmq-server -detached
/usr/local/rabbitmq/sbin/rabbitmqctl stop_app
/usr/local/rabbitmq/sbin/rabbitmqctl join_cluster rabbit@rabbitmq240
/usr/local/rabbitmq/sbin/rabbitmqctl start_app

常用命令:
关闭启动mq
/etc/init.d/rabbitmq-server stop
/etc/init.d/rabbitmq-server start
检测集群状态
/usr/local/rabbitmq/sbin/rabbitmqctl cluster_status
删除节点
/usr/local/rabbitmq/sbin/rabbitmqctl forget_cluster_node  rabbit@rabbitmq241
-----------------------------------------------------------------------------------------------------------
vip配置如下:
/etc/rc.d/init.d/realserver

#!/bin/bash
# chkconfig: - 95 50
# description: Config realserver lo and apply noarp 

VIPS="192.168.15.1 192.168.15.1"
OLD_VIPS=`/sbin/ip a show dev lo |grep 'global'|awk '{print $4}'`

. /etc/rc.d/init.d/functions
start() {
      for VIP in $VIPS 
      do
      ifconfig lo:`echo $VIP|awk -F. '{print $3"-"$4}'` $VIP netmask 255.255.255.255 broadcast $VIP
      /sbin/route add -host $VIP dev lo:`echo $VIP|awk -F. '{print $3"-"$4}'`
      done
      echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
      echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
      echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
      echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
      echo "RealServer Start:                          [ OK ]"
}

stop() {
      for VIP  in $OLD_VIPS
      do
      ifconfig lo:`echo $VIP|awk -F. '{print $3"-"$4}'` down
      route del  $VIP  >/dev/null 2>&1
      done
      echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
      echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
      echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
      echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
      echo "RealServer Stoped:                         [ OK ]"
}


case "$1" in
    start)
         start
         ;;
    stop)
         stop
         ;;
    restart)
         stop
         start
         ;;
*)
      echo "Usage: $0 {start|stop|restart}"
      exit 1
esac

exit 0

执行sh checkvip.sh

realserver_num=$(/sbin/ip a |grep inet |grep lo: |grep brd |wc -l)

if [ ! -f /etc/init.d/realserver ];then
        exit
fi


if [ ${realserver_num} -lt 3 ];then
        /etc/init.d/realserver restart
fi

设置定时任务

*/5 * * * * sh /home/scottbing/tools/checkvip.sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!