【RabbitMQ】14 集群搭建
多服务器单实例 —— 参考博客:
https://www.cnblogs.com/lixioayi/articles/9993658.html
首先要找到cookie文件,所有实例要保持cookie一致(启动运行过的RabbitMQ会生成):
[root@localhost ~]# find / -name .erlang.cookie /var/lib/rabbitmq/.erlang.cookie [root@localhost ~]#
里面查看就是一堆字母:
[root@localhost ~]# cat /var/lib/rabbitmq/.erlang.cookie RMSWWJGQNKZKNEILPSHS[root@localhost ~]#
然后选定主从关系,统一使用主实例的Cookie
cookie是一个只读文件,那就用SCP直接传输覆盖吧(从机记得先关闭服务)
[root@localhost ~]# scp /var/lib/rabbitmq/.erlang.cookie root@192.168.2.110:/var/lib/rabbitmq/ The authenticity of host '192.168.2.110 (192.168.2.110)' can't be established. ECDSA key fingerprint is SHA256:hkKgDGf17aUrVAPXT5ZPL0/TjONX7nTeB5vrsSzXihE. ECDSA key fingerprint is MD5:91:9e:04:92:71:6f:00:d9:d1:9b:3b:6e:74:88:a7:d4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.2.110' (ECDSA) to the list of known hosts. root@192.168.2.110's password: .erlang.cookie 100% 20 58.1KB/s 00:00 [root@localhost ~]#
对每一个Cookie控制读写权限:
chmod 600 /var/lib/rabbitmq/.erlang.cookie
然后开启每台机器的服务
service rabbitmq-server start
其中 2 和 3 从机 关闭应用,不是关闭服务
rabbitmqctl stop_app
然后2和3都加入到1中去
rabbitmqctl join_cluster rabbit@centos6-1
启动2和3的应用
rabbitmqctl start_app