一、前期准备
(1)条件:准备3台linux系统,确保配置好源,及epel源
yun1,yun2,yun3
(2)三台机器能够静态解析彼此
(3)设置可以无密钥登陆
ssh-keygen
ssh-copy-id yun2
ssh-copy-id yun3
二、安装过程:
(1)所有node安装rabbtimq和erlang软件包:
yum install -y erlang rabbitmq-server.noarch
systemctl enable rabbitmq-server.service
systemctl start rabbitmq-server.service
systemctl status rabbitmq-server.service
查看监听端口:
netstat -lantp | grep 5672
配置文件:
vim /etc/rabbitmq/rabbitmq.config
(2)node1:修改guest密码为admin(默认用户为:guest 密码为:guest)
rabbitmqctl change_password guest admin
(3)node1:添加一个openstack的用户,并设密码为admin。并设置权限和成为管理员
node1:
rabbitmqctl add_user openstack admin
rabbitmqctl set_permissions openstack ".*" ".*" ".*"
rabbitmqctl set_user_tags openstack administrator
(4)node1:编辑rabbittmq变量文件
vim /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_NODE_PORT=5672
ulimit -S -n 4096
RABBITMQ_SERVER_ERL_ARGS="+K true +A30 +P 1048576 -kernel inet_default_connect_options [{nodelay,true},{raw,6,18,<<5000:64/native>>}] -kernel inet_default_listen_options [{raw,6,18,<<5000:64/native>>}]"
RABBITMQ_NODE_IP_ADDRESS=172.16.254.60
(5)node1:将rabbittmq变量文件拷贝到其他两节点,之后并修改相应节点的ip
scp /etc/rabbitmq/rabbitmq-env.conf con2:/etc/rabbitmq/
scp /etc/rabbitmq/rabbitmq-env.conf con3:/etc/rabbitmq/
查看rabbitmq插件
/usr/lib/rabbitmq/bin/rabbitmq-plugins list
(6)所有node 开启rabbitmq的web管理页面
/usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management mochiweb webmachine rabbitmq_web_dispatch amqp_client rabbitmq_management_agent
或者:rabbitmq-plugins enable rabbitmq_management
systemctl restart rabbitmq-server.service
systemctl status rabbitmq-server.service
(7)node1发送erlang.cookie到其他节点配置集群
rabbitmqctl status
scp /var/lib/rabbitmq/.erlang.cookie con2:/var/lib/rabbitmq/.erlang.cookie
scp /var/lib/rabbitmq/.erlang.cookie con3:/var/lib/rabbitmq/.erlang.cookie
(8)node2和node3停止应用,并以ram的方式加入node1节点,之后重启应用
systemctl restart rabbitmq-server.service
rabbitmqctl stop_app
rabbitmqctl join_cluster --ram rabbit@con1
rabbitmqctl start_app
(9)node1检查集群状态
[root@con1 conf]# rabbitmqctl cluster_status
Cluster status of node rabbit@con1 ...
[{nodes,[{disc,[rabbit@con1]},{ram,[rabbit@con3,rabbit@con2]}]},
{running_nodes,[rabbit@con3,rabbit@con2,rabbit@con1]},
{cluster_name,<<"rabbit@con1">>},
{partitions,[]},
{alarms,[{rabbit@con3,[]},{rabbit@con2,[]},{rabbit@con1,[]}]}]
(10)登陆验证:http://172.16.254.60:15672/#/ guest/admin
其他命令:
(1)添加管理员:
rabbitmqctl add_user mqadmin mqadmin
rabbitmqctl set_user_tags mqadmin administrator
rabbitmqctl set_permissions -p / mqadmin ".*" ".*" ".*"
(2)更改节点类型(内存型或磁盘型)
rabbitmqctl stop_app
rabbitmqctl change_cluster_node_type disc 或 rabbitmqctl change_cluster_node_type ram
rabbitmqctl start_app
(3)从集群移除节点(或者重置节点)
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status
(4)从某个节点移除集群中其他节点
rabbitmqctl forget_cluster_node rabbit@node3
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status
1. 保证集群中至少有一个磁盘类型的节点以防数据丢失,在更改节点类型时尤其要注意。
2. 若整个集群被停掉了,应保证最后一个 down 掉的节点被最先启动,若不能则要使用 forget_cluster_node 命令将其移出集群
3. 若集群中节点几乎同时以不可控的方式 down 了此时在其中一个节点使用 force_boot 命令重启节点