使用centos7镜像创建三台云主机来搭建rabbitmq集群。使用普通集群模式,其中一台做磁盘节点,另外两台做内存节点,最后启动rabbitmq服务
- 创建三个节点,分别为mq1,mq2,mq3
- 修改hosts文件,改名 (三个节点)
- 关闭防火墙,selinux (三个节点)
systemctl stop firewalld
setenforce 0
getenforce
- 配置好yum源,然后安装 (三个节点都进行以下操作)
yum install -y rabbitmq-server
ln -s /usr/lib/rabbitmq/bin/* /usr/bin/
5.分别查看三个节点并添加管理服务(都进行以下操作)
[root@mq1 ~]# cd /usr/lib/rabbitmq/bin/
[root@mq1 bin]# ls
rabbitmqctl rabbitmq-env rabbitmq-server
rabbitmq-defaults rabbitmq-plugins
[root@mq1 bin]# rabbitmq-plugins list #查看插件安装情况
Configured: E = explicitly enabled; e = implicitly enabled
| Status: [failed to contact rabbit@mq2 - status not shown]
|/
[ ] amqp_client 3.6.5
[ ] cowboy 1.0.3
[ ] cowlib 1.0.1
[ ] mochiweb 2.13.1
[ ] rabbitmq_amqp1_0 3.6.5
[ ] rabbitmq_auth_backend_ldap 3.6.5
[ ] rabbitmq_auth_mechanism_ssl 3.6.5
[ ] rabbitmq_consistent_hash_exchange 3.6.5
[ ] rabbitmq_event_exchange 3.6.5
[ ] rabbitmq_federation 3.6.5
[ ] rabbitmq_federation_management 3.6.5
[ ] rabbitmq_jms_topic_exchange 3.6.5
[ ] rabbitmq_management 3.6.5
[ ] rabbitmq_management_agent 3.6.5
[ ] rabbitmq_management_visualiser 3.6.5
[ ] rabbitmq_mqtt 3.6.5
[ ] rabbitmq_recent_history_exchange 1.2.1
[ ] rabbitmq_sharding 0.1.0
[ ] rabbitmq_shovel 3.6.5
[ ] rabbitmq_shovel_management 3.6.5
[ ] rabbitmq_stomp 3.6.5
[ ] rabbitmq_top 3.6.5
[ ] rabbitmq_tracing 3.6.5
[ ] rabbitmq_trust_store 3.6.5
[ ] rabbitmq_web_dispatch 3.6.5
[ ] rabbitmq_web_stomp 3.6.5
[ ] rabbitmq_web_stomp_examples 3.6.5
[ ] sockjs 0.3.4
[ ] webmachine 1.10.3
[root@mq1 bin]# 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.
6.启动rabbitmq服务,使用netstat -ntpl进行查看,有如下三个端口15672,25672,5672 开放说明正常。(三节点)
[root@mq1 bin]# systemctl start rabbitmq-server.service或 systemctl start rabbitmq-server
[root@mq1 bin]# netstat -ntpl 或 netstat -an | grep 5672
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 1339/beam
tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 1312/epmd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 922/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 843/master
tcp6 0 0 :::5672 :::* LISTEN 1339/beam
tcp6 0 0 :::4369 :::* LISTEN 1312/epmd
tcp6 0 0 :::22 :::* LISTEN 922/sshd
tcp6 0 0 ::1:25 :::* LISTEN 843/master
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN
参数注解:
15672和25672是rabbitmq的管理端口
5672是生产者、消费者通信的端口
7.检查三台的集群状态(三个节点)
[root@mq1 ~]# rabbitmqctl cluster_status
Cluster status of node rabbit@mq1 ... //目前相互独立,没有形成集群
[{nodes,[{disc,[rabbit@mq1]}]},
{running_nodes,[rabbit@mq1]},
{cluster_name,<<"rabbit@mq1">>},
{partitions,[]},
{alarms,[{rabbit@mq1,[]}]}]
8.停止rabbitmq服务(三个节点)
[root@mq3 bin]# systemctl stop rabbitmq-server
8.在三台服务器上构建Erlang的集群环境(保证三台服务器里的cookie一样)
[root@mq2 bin]# chmod u+w /var/lib/rabbitmq/.erlang.cookie
[root@mq1 bin]# vi /var/lib/rabbitmq/.erlang.cookie
YORXFZTNBWJOSQJRFGLLe
9.开启rabbitmq服务(三节点)
[root@mq1 bin]# systemctl start rabbitmq-server
[root@mq2 bin]# systemctl start rabbitmq-server
[root@mq3 bin]# systemctl start rabbitmq-server
10.将mq2、mq3作为内存节点与mq1磁盘节点连接起来。
[root@mq2 bin]# rabbitmqctl stop_app #停止
Stopping rabbit application on node rabbit@mq2
[root@mq2 bin]# rabbitmqctl join_cluster --ram rabbit@mq1 ###将mq2连接到mq1,成为一个集群
Clustering node rabbit@mq2 with rabbit@mq1
[root@mq2 bin]# rabbitmqctl start_app #启动
Starting node rabbit@mq2
[root@mq2 bin]# rabbitmqctl cluster_status
Cluster status of node rabbit@mq2
[{nodes,[{disc,[rabbit@mq1]},{ram,[rabbit@mq2]}]},
{running_nodes,[rabbit@mq1,rabbit@mq2]},
{cluster_name,<<"rabbit@mq1">>},
{partitions,[]},
{alarms,[{rabbit@mq1,[]},{rabbit@mq2,[]}]}]
[root@mq3 bin]# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@mq3
[root@mq3 bin]# rabbitmqctl join_cluster --ram rabbit@mq1
Clustering node rabbit@mq3 with rabbit@mq1
[root@mq3 bin]# rabbitmqctl cluster_status
Cluster status of node rabbit@mq3
[{nodes,[{disc,[rabbit@mq1]},{ram,[rabbit@mq3,rabbit@mq2]}]},
{alarms,[{rabbit@mq2,[]},{rabbit@mq1,[]}]}]
11.打开浏览器访问http://192.168.200.7:15672/
用户名:guest 密码:guest
注:如果登不上 检查网络 把WLAN或其他禁止