1、准备两台linux,并安装好rabbitmq
2、修改 /etc/hosts 映射文件
vim /etc/hosts
172.25.228.171 iZ2ze0bf211t8e5fsndtk8Z iZ2ze0bf211t8e5fsndtk8Z
172.26.218.199 iZ2ze0bf211t8e5fsndtk6Z iZ2ze0bf211t8e5fsndtk6Z
[root@iZ2ze0bf211t8e5fsndtk8Z opt]# reboot 重启服务器
3、相互通信,cookie必须保持一致,同步 rabbitmq的cookie 文件:跨服务器拷贝 .erlang.cookie (隐藏文件,使用 ls -all 显示)
[root@iZ2ze0bf211t8e5fsndtk8Z ~]# scp /var/lib/rabbitmq/.erlang.cookie 8.141.57.87:/var/lib/rabbitmq
The authenticity of host '8.141.57.87 (8.141.57.87)' can't be established.
ECDSA key fingerprint is SHA256:Tr2gDM5EjZR8roGoEDtwVm9EXTSe/FyFUtgNbAz1Ing.
ECDSA key fingerprint is MD5:ae:45:05:a7:bf:cd:98:a5:e4:d7:d9:09:e3:42:e5:dc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '8.141.57.87' (ECDSA) to the list of known hosts.
root@8.141.57.87's password:
.erlang.cookie
[root@iZ2ze0bf211t8e5fsndtk8Z ~]# cat /var/lib/rabbitmq/.erlang.cookie
XZYFVUOIYZCWNSXYGLCO[root@iZ2ze0bf211t8e5fsndtk8Z ~]#
修改cookie文件,要重启服务器,reboot
4、停止防火墙,启动rabbitmq服务
[root@iZ2ze0bf211t8e5fsndtk6Z ~]# systemctl stop firewalld
[root@iZ2ze0bf211t8e5fsndtk6Z ~]# systemctl start rabbitmq-server
5、加入集群节点
[root@iZ2ze0bf211t8e5fsndtk6Z ~]# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@iZ2ze0bf211t8e5fsndtk6Z ...
[root@iZ2ze0bf211t8e5fsndtk6Z ~]# rabbitmqctl join_cluster rabbit@iZ2ze0bf211t8e5fsndtk8Z
Clustering node rabbit@iZ2ze0bf211t8e5fsndtk6Z with rabbit@iZ2ze0bf211t8e5fsndtk8Z
[root@iZ2ze0bf211t8e5fsndtk6Z ~]# rabbitmqctl start_app
Starting node rabbit@iZ2ze0bf211t8e5fsndtk6Z ...
6、查看节点状态
[root@B ~]# rabbitmqctl cluster_status
日常练习:与集群搭建无关系
[root@iZ2ze0bf211t8e5fsndtk8Z etc]# chmod a+w hosts
chmod: changing permissions of ‘hosts’: Operation not permitted
[root@iZ2ze0bf211t8e5fsndtk8Z etc]# lsattr hosts
----i--------e-- hosts
[root@iZ2ze0bf211t8e5fsndtk8Z etc]# chattr -ia hosts
-bash: /usr/bin/chattr: Permission denied
[root@iZ2ze0bf211t8e5fsndtk8Z etc]# lsattr /usr/bin/chattr
-------------e-- /usr/bin/chattr
[root@iZ2ze0bf211t8e5fsndtk8Z etc]# chattr -i hosts
-bash: /usr/bin/chattr: Permission denied
[root@iZ2ze0bf211t8e5fsndtk8Z etc]# cd /usr/bin
[root@iZ2ze0bf211t8e5fsndtk8Z bin]# ll
[root@iZ2ze0bf211t8e5fsndtk8Z bin]# chattr -i /etc/hosts
[root@iZ2ze0bf211t8e5fsndtk8Z bin]#