openstack——Rabbitmq集群部署
一、前期准备
1.条件:准备3台Linux系统虚拟机,保持系统版本一致,确保配置好yum源,及网络源
2.3台虚拟机做静态解析
[root@yun1 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.127.135 yun1 192.168.127.136 yun2 192.168.127.137 yun3 192.168.127.138 yun4
3.设置无密钥登陆
4.配置防火墙规则
- 将INPUT规则链设置为只允许指定网段的主机访问本机的rabbitmq服务监听端口5672,rabbitmq的web监听端口15672,拒绝来自其他所有主机的流量:
iptables -I INPUT -s 192.168.127.0/24 -p tcp --dport 5672 -j ACCEPT iptables -I INPUT -s 192.168.127.0/24 -p tcp --dport 15672 -j ACCEPT iptables -A INPUT -p tcp --dport 5672 -j REJECT iptables -A INPUT -p tcp --dport 15672 -j REJECT
二、安装过程
- 所有node虚拟机安装rabbitmq和erlang软件包
yum install -y erlang rabbitmq-server.noarch systemctl enable rabbitmq-server.service systemctl start rabbitmq-server.service systemctl status rabbitmq-server.service
- 查看监听端口5672
[root@yun1 ~]# netstat -lantp | grep 5672
- rabbitmq配置文件
vim /etc/rabbitmq/rabbitmq.config
- node1:修改guest密码为admin(默认用户为:guest 密码为:guest)
[root@yun1 ~]# rabbitmqctl change_password guest admin Changing password for user "guest" ...
- node1:添加一个openstack的用户,并设置密码为admin。并设置权限和成为管理员
[root@yun1 ~]# rabbitmqctl add_user openstack admin Creating user "openstack" ... [root@yun1 ~]# rabbitmqctl set_permissions openstack ".*" ".*" ".*" Setting permissions for user "openstack" in vhost "/" ... [root@yun1 ~]# rabbitmqctl set_user_tags openstack administrator Setting tags for user "openstack" to [administrator] ...
- node1:编辑rabbitmq变量文件
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=192.168.127.135
- node1:将rabbitmq变量文件拷贝到其他两个节点,之后并修改相应节点的ip
"/etc/rabbitmq/rabbitmq-env.conf" 4L, 286C 已写入 [root@yun1 ~]# scp /etc/rabbitmq/rabbitmq-env.conf yun2:/etc/rabbitmq/ rabbitmq-env.conf 100% 286 0.3KB/s 00:00 [root@yun1 ~]# scp /etc/rabbitmq/rabbitmq-env.conf yun3:/etc/rabbitmq/ rabbitmq-env.conf
- 查看rabbitmq插件
[root@yun1 ~]# /usr/lib/rabbitmq/bin/rabbitmq-plugins list
- 所有node开启rabbitmq的web管理页面
rabbitmq-plugins enable rabbitmq_management systemctl restart rabbitmq-server.service systemctl status rabbitmq-server.service
- node1发送缓存文件erlang.cookie到其他节点配置集群
[root@yun2 ~]# rabbitmqctl cluster_status #查看rabbitmq的状态 Cluster status of node rabbit@yun2 ... [{nodes,[{disc,[rabbit@yun2]}]}, {running_nodes,[rabbit@yun2]}, {cluster_name,<<"rabbit@yun2">>}, {partitions,[]}, {alarms,[{rabbit@yun2,[]}]}]
[root@yun1 ~]# cat /var/lib/rabbitmq/.erlang.cookie IRWFJQZPVRHYOTK
[root@yun1 ~]# scp /var/lib/rabbitmq/.erlang.cookie yun2:/var/lib/rabbitmq/.erlang.cookie .erlang.cookie 100% 20 0.0KB/s 00:00 [root@yun1 ~]# scp /var/lib/rabbitmq/.erlang.cookie yun3:/var/lib/rabbitmq/.erlang.cookie .erlang.cookie
- node2和node3停止应用,并以ram的方式加入node1节点,之后重启应用
[root@yun3 ~]# systemctl restart rabbitmq-server.service [root@yun3 ~]# rabbitmqctl stop_app Stopping node rabbit@yun3 .. [root@yun3 ~]# rabbitmqctl join_cluster --ram rabbit@yun1 Clustering node rabbit@yun3 with rabbit@yun1 ... Error: unable to connect to nodes [rabbit@yun1]: nodedown DIAGNOSTICS =========== attempted to contact: [rabbit@yun1] rabbit@yun1: * unable to connect to epmd (port 4369) on yun1: address (cannot connect to host/port) current node details: - node name: 'rabbitmq-cli-25@yun3' - home dir: /var/lib/rabbitmq - cookie hash: wCM6VjtONuseC1mVH1gL4A== [root@yun2 ~]# rabbitmqctl start_app Starting node rabbit@yun2 ...
- node1检查集群状态
[root@yun1 ~]# rabbitmqctl cluster_status Cluster status of node rabbit@yun1 ... [{nodes,[{disc,[rabbit@yun1]},{ram,[rabbit@yun3,rabbit@yun2]}]}, {running_nodes,[rabbit@yun3,rabbit@yun2,rabbit@yun1]}, {cluster_name,<<"rabbit@yun1">>}, {partitions,[]}, {alarms,[{rabbit@yun3,[]},{rabbit@yun2,[]},{rabbit@yun1,[]}]}]
- 登陆验证
http://192.168.127.135:15672/
注意:
- 保证集群中至少有一个磁盘类型的节点以防止数据丢失,在更改节点类型时尤其要注意。
- 若整个集群被停掉了,应保证最后一个down掉的节点被最先启动,若不能则要使用forget_cluster_node命令将其移除集群。
- 若集群节点中几乎同时以不可控的方式down了此时在其中一个节点使用forter_boot命令重启节点。