部署 rabbitmq 集群

由于 rabbitmqerlang 开发的所以依赖 erlang, 准备三台服务器并配置好主机名, 并以下信息写入三台服务器的 hosts.

1
2
3
mq1 192.168.1.11
mq2 192.168.1.12
mq3 192.168.1.13
1
2
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | bash
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | bash
1
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
1
yum install -y erlang rabbitmq-server
1
rabbitmq-plugins enable rabbitmq_management
1
rabbitmq-server -detached
1
2
3
rabbitmqctl stop_app
rabbitmqctl join_cluster --disc [email protected]
rabbitmqctl start_app

–ram 为内存节点

1
2
3
rabbitmqctl add_user jpuser 'G6JzIC3ifipGIMa'
rabbitmqctl set_user_tags jpuser administrator
rabbitmqctl set_permissions -p '/' jpuser '.*' '.*' '.*'
1
rabbitmqctl set_policy ha-all-queue "^" '{"ha-mode":"all","ha-sync-mode":"automatic"}'

设置 policy,以 ha. 开头的队列将会被镜像到集群其他所有节点,一个节点挂掉然后重启后会自动同步队列消息(生产环境采用这个方式)