同一台机器做rabbitmq集群配置
yum install rabbitmq-server-3.6.6-1.el7.noarch.rpm
让guest用户可以在127.0.0.1外的机器上登陆
vi /etc/rabbitmq/rabbitmq.config
[{rabbit, [{loopback_users, []}]}].
启动mq
sudo ./rabbitmq-server -detached
管理rabbitmq的节点
先停止运行的mq服务,Rabbitmq默认的节点名称是rabbitmq,然后启动
RABBITMQ_NODE_PORT=5672 RABBITMQ_SERVER_START_ARGS=”-rabbitmq_management listener [{port,15672}]” RABBITMQ_NODENAME=rabbit rabbitmq-server -detached
添加节点hare,访问端口5673,管理端口15673,并启动
RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS=”-rabbitmq_management listener [{port,15673}]” RABBITMQ_NODENAME=hare rabbitmq-server -detached
停止节点hare
rabbitmqctl -n hare stop_app
两个节点建立集群
rabbitmqctl -n hare join_cluster rabbit@localhost
rabbitmqctl -n hare start_app
rabbitmqctl -n hare stop
设置队列的工作模式
rabbitmqctl -n rabbit set_policy ha-allqueue “^” ‘{“ha-mode”:”all”,”ha-sync-mode”:”automatic”}’
rabbitmqctl -n hare set_policy ha-allqueue “^” ‘{“ha-mode”:”all”,”ha-sync-mode”:”automatic”}’
可通过如下命令确认哪些salve在同步:
rabbitmqctl list_queues name slave_pids synchronised_slave_pids
手动同步queue:
rabbitmqctl sync_queue name
取消queue同步:
rabbitmqctl cancel_sync_queue name
至此rabbitmq的两个节点已经完全同步,为了让应用访问更方便,通常在前面增加haproxy做负载均衡。
make TARGET=linux2628 prefix=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
nohup /usr/local/haproxy/sbin/haproxy -f /etc/haproxy/haproxy.cfg >/dev/null &
/etc/haproxy/haproxy.cfg的文件内容如下:
listen rabbitmq_cluster
bind 0.0.0.0:5670
mode tcp
timeout client 3h
timeout server 3h
timeout connect 3h
balance roundrobin
server rabbit localhost:5672 check inter 5000 rise 2 fall 3
server hare localhost:5673 check inter 5000 rise 2 fall 3
欢迎转载,请注明出处:亲亲宝宝