RabbitMQ集群搭建

准备三个节点,系统为CentOS7

Node IP
rabbitmq01 172.50.0.64
rabbitmq02 172.50.0.65
rabbitmq03 172.50.0.66

这里把node1作为master节点。

1、修改各节点hosts

# vim /etc/hosts
172.50.0.64     rabbitmq01
172.50.0.65     rabbitmq02
172.50.0.66     rabbitmq03

2、在各节点安装rabbitmq-server,并启动服务

# yum install -y rabbitmq-server
# systemctl start rabbitmq-server
# systemctl enable rabbitmq-server

3、启用各节点RabbitMQ Web管理插件,监听15672端口

# rabbitmq-plugins list            
# rabbitmq-plugins enable rabbitmq_management      
	The following plugins have been enabled:
	  mochiweb
	  webmachine
	  rabbitmq_web_dispatch
	  amqp_client
	  rabbitmq_management_agent
	  rabbitmq_management
	Plugin configuration has changed. Restart RabbitMQ for changes to take effect.

# systemctl start rabbitmq-server
# netstat -tnlp 

4、用浏览器访问

http://172.16.100.186:15672/
默认账号和密码都是guest;

5、将master节点的cookie文件复制到各slave节点

# scp /var/lib/rabbitmq/.erlang.cookie node2:/var/lib/rabbitmq/
# scp /var/lib/rabbitmq/.erlang.cookie node3:/var/lib/rabbitmq/

6、停止slave上的app,并将slave节点加入到集群

# rabbitmqctl stop_app
# rabbitmqctl join_cluster rabbit@node1
# rabbitmqctl start_app

7、将各slave加入集群后,查看集群状态

# rabbitmqctl cluster_status
Cluster status of node 'rabbit@rabbitmq01' ...
[{nodes,[{disc,['rabbit@rabbitmq01','rabbit@rabbitmq02',
                'rabbit@rabbitmq03']}]},
 {running_nodes,['rabbit@rabbitmq02','rabbit@rabbitmq03',
                 'rabbit@rabbitmq01']},
 {cluster_name,<<"rabbit@rabbitmq01">>},
 {partitions,[]}]
...done.

8、使用haproxy创建LB集群,在haproxy server上单独创建一个配置文件

# vim /etc/rabbitmq.cfg
listen rabbitmq :5672
        mode tcp
        balance roundrobin
        server rabbit01 172.50.0.64:5672 check inter 5000
        server rabbit02 172.50.0.65:5672 check inter 5000
        server rabbit03 172.50.0.66:5672 check inter 5000

listen rabbitmqui :15672
        mode http
        balance roundrobin
        server rabbit01 172.50.0.64:15672 check inter 5000
        server rabbit02 172.50.0.65:15672 check inter 5000
        server rabbit03 172.50.0.66:15672 check inter 5000

# haproxy -f /etc/rabbitmq.cfg

9、用浏览器访问haproxy server的地址和端口
http://172.16.100.186:15672/

posted @ 2017-03-09 22:13  KeithTt  阅读(397)  评论(0编辑  收藏  举报