liym 2019-11-27
centos7的rabbitmq升级到3.7.10集群
#卸载
[ ~]# systemctl stop rabbitmq-server
[ ~]# yum remove rabbitmq-server -y
[ yum.repos.d]# yum remove erlang* -y
[ ~]# rm -rf /var/lib/rabbitmq/
1 安装erlang
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
yum install erlang -y
查看版本:
erl
3.安装rabbitmq(当前目录为rabbitmq-server-3.7.10-1.el7.noarch.rpm包的目录下)
[ ~]#wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.10/rabbitmq-server-3.7.10-1.el7.noarch.rpm
[ ~]#yum install -y rabbitmq-server-3.7.10-1.el7.noarch.rpm
[ ~]# systemctl start rabbitmq-server
[ ~]# systemctl enable rabbitmq-server
############
[ yum.repos.d]# rabbitmqctl add_user admin admin
Creating user "admin" ...
[ yum.repos.d]# rabbitmqctl set_permissions admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/" ...
密码设置成admin
[ ~]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
mochiweb
webmachine
rabbitmq_web_dispatch
amqp_client
rabbitmq_management_agent
rabbitmq_management
Applying plugin configuration to started 6 plugins.
[ ~]# systemctl restart rabbitmq-server
[ ~]# netstat -lntup|grep 5672
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 15851/beam
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 15851/beam
tcp6 0 0 :::5672 :::* LISTEN 15851/beam
无法登录页面,参考:
https://blog.csdn.net/shenhonglei1234/article/details/82745601
vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.7.10/ebin/rabbit.app
将:{loopback_users, [<<”guest”>>]},
改为:{loopback_users, []},
原因:rabbitmq从3.3.0开始禁止使用guest/guest权限通过除localhost外的访问
====登录页面修改密码,重置角色,略
将node1上的.erlang.cookie传输到node2、node3,并保证权限一直
[ ~]# scp /var/lib/rabbitmq/.erlang.cookie 192.168.56.12:/var/lib/rabbitmq/
#[ ~]# scp /var/lib/rabbitmq/.erlang.cookie 192.168.56.13:/var/lib/rabbitmq/
先停止运行节点,然后以后台方式启动 RabbitMQ Server(node1和node2分别执行):
[ ~]# systemctl stop rabbitmq-server
[ ~]# rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
[ ~]# systemctl stop rabbitmq-server
[ ~]# rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
然后我们以node1作为集群中心,在node2上执行加入集群中心命令(节点类型为磁盘节点):
[ ~]# rabbitmqctl stop_app
[ ~]# rabbitmqctl reset
[ ~]# rabbitmqctl join_cluster
//默认是磁盘节点,如果是内存节点的话,需要加--ram参数
[ ~]# rabbitmqctl start_app
查看集群的状态(包含node1和node2节点):
[ ~]# rabbitmqctl cluster_status
Cluster status of node ‘‘ ...
[{nodes,[{disc,[‘‘,‘‘]}]},
{running_nodes,[‘‘,‘‘]},
{cluster_name,<<"">>},
{partitions,[]}]
#镜像模式
[ ~]# rabbitmqctl set_policy ha-all "^" ‘{"ha-mode":"all","ha-sync-mode":"automatic"}‘
Setting policy "ha-all" for pattern "^" to "{\"ha-mode\":\"all\",\"ha-sync-mode\":\"automatic\"}" with priority "0" ...
...done.