160328、rabbitMQ集群部署示例

时间:2022-06-20 06:44:55

环境:
Centos 6.5 x86_64
MQ网址:http://www.rabbitmq.com/
SERVER101\SERVER102 SERVER103

一、单节点安装

#yum install erlang -y

#wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.3.5/rabbitmq-server-3.3.5-1.noarch.rpm

# yum install rabbitmq-server-3.3.5-1.noarch.rpm -y

#rabbitmq-plugins enable rabbitmq_management(安装web管理插件)

#rabbitmqctl set_user_tags guest administrator (赋予默认用户gues权限,需要启动rabbitmq)
二、分别配置三台主机hosts文件
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.101 server101
192.168.1.102 server102
192.168.1.103 server103

三、将SERVER101中的.erlang.cookie 复制到集群节点中
#chmod 777 /root/.erlang.cookie
#chmod 777 /var/lib/rabbitmq/.erlang.cookie
/var/lib/rabbitmq/.erlang.cookie
/root/.erlang.cookie

三、创建添加集群
1)分别启动各主机上mq
server 101#rabbitmq-server -detached

server 102#rabbitmq-server -detached

server 103#rabbitmq-server -detached
2)查看每个节点的集群状态
server101#rabbitmqctl cluster_status

server102#rabbitmqctl cluster_status

server103#rabbitmqctl cluster_status

3)将SERVER102以内存节点加入 SERVER101 集群
server102#rabbitmqctl stop_app

server102#rabbitmqctl join_cluster --ram rabbit@server101

server102#rabbitmqctl start_app

4)将SERVER103以内存节点加入SERVER101集群
server103#rabbitmqctl stop_app

server103#rabbitmqctl join_cluster --ram rabbit@server101

server103#rabbitmqctl start_app

5)集群部署完成 操作指令
1、查询集群状态
#rabbitmqctl cluster_status
2、 更改集群节点 (内存或磁盘) 执行如下命令前 需要停止MQ服务

① #rabbitmqctl stop_app
② #rabbitmqctl change_cluster_node_type disc(磁盘)
③ #rabbitmqctl change_cluster_node_type ram(内存)
④ #rabbitmqctl start_app
3、后台启动mq
#rabbitmq-server -detached
4、停止mq服务
#rabbitmqctl stop_app
4、 启动mq服务
#rabbitmqctl start_app
6)操作指令
1、启动rabbitmq:rabbitmq-server –detached
2、停止rabbitmq:rabbitmqctl stop
3、停止mq的服务:rabbitmqctl stop_app
4、将节点加入到集群:rabbitmqctl join_cluster rabbit@server101
5、启动节点服务:rabbitmqctl start_app