RabbitMQ 镜像集群
安装 erlang
cd /usr/local/src/ wget https://github.com/rabbitmq/erlang-rpm/releases/download/v26.2.5/erlang-26.2.5-1.el8.x86_64.rpm rpm -ivh erlang-26.2.5-1.el8.x86_64.rpm
#安装 rabbitmq
cd /usr/local/src/ wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.13.3/rabbitmq-server-3.13.3-1.el8.noarch.rpm rpm -ivh rabbitmq-server-3.13.3-1.el8.noarch.rpm
#开启自启动
chkconfig rabbitmq-server on
#服务命令
#查看状态 /sbin/service rabbitmq-server status #启动 /sbin/service rabbitmq-server start #停止 /sbin/service rabbitmq-server stop
#开启web管理页面(不开启的话没有web页面)
rabbitmq-plugins enable rabbitmq_management
#安装 mqtt 插件
rabbitmq-plugins enable rabbitmq_mqtt
#安装延迟队列插件
cd /usr/local/src/ wget https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/v3.13.0/rabbitmq_delayed_message_exchange-3.13.0.ez cp rabbitmq_delayed_message_exchange-3.13.0.ez /usr/lib/rabbitmq/lib/rabbitmq_server-3.13.3/plugins cd /usr/lib/rabbitmq/lib/rabbitmq_server-3.13.3/plugins rabbitmq-plugins enable rabbitmq_delayed_message_exchange
#添加账号 https://juejin.cn/post/7059382641396547615
rabbitmqctl add_user username password rabbitmqctl set_user_tags username administrator rabbitmqctl set_permissions -p / username ".*" ".*" ".*"
集群搭建
#设置 erlang cookie 一致性
cd /var/lib/rabbitmq/
vim .erlang.cookie
#将所有服务器上设置一致的
#修改权限
# 修改用户组 chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie # 仅只有所有者可读 chmod 400 /var/lib/rabbitmq/.erlang.cookie
#修改hostname
vim /etc/hosts
# master 172.*.*.2 app1
#slave 172.*.*.3 app2
#修改主机名
#修改主机名( master ) hostnamectl set-hostname app1 #修改主机名( slave) hostnamectl set-hostname app2
#修改节点名称
vim /etc/rabbitmq/rabbitmq.conf #master 使用这行 NODENAME=rabbit@app1 #slave 使用这行 #NODENAME=rabbit@app2
slave 设置 cluster 节点
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@app1
rabbitmqctl start_app