rabbitmq-cluster搭建

一、前期准备:
准备3台linux系统,配置好公司源,或者官网下载相应的网络源
1、条件:准备3台linux系统,确保能连到download.yunwei.edu
2、编写yum源下载脚本:
#vim yum-repo.sh

wget -O /etc/yum.repos.d/Centos7-Base-yunwei.repo download.yunwei.edu/shell/Centos7-Base-yunwei.repo
wget -O /etc/yum.repos.d/epel-yunwei.repo download.yunwei.edu/shell/epel-yunwei.repo
wget -O /etc/yum.repos.d/rdo-release-yunwei.repo download.yunwei.edu/shell/rdo-release-yunwei.repo
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Cloud download.yunwei.edu/shell/RPM-GPG-KEY-CentOS-SIG-Cloud
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 download.yunwei.edu/shell/RPM-GPG-KEY-EPEL-7

3、将系统自带网络源移走,执行yum-repo.sh

# sh yum-repo.sh
4、DNS能够解析此三台主机

二、安装过程:
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

2、查看监听端口:
# netstat -lantp | grep 5672
3、配置文件:
vim /etc/rabbitmq/rabbitmq.config

4、node1:修改guest密码为admin(默认用户为:guest 密码为:guest)
# rabbitmqctl change_password guest admin

5、node1:添加一个openstack的用户,并设密码为admin。并设置权限和成为管理员
1)node1:
# rabbitmqctl add_user openstack admin
# rabbitmqctl set_permissions openstack ".*" ".*" ".*"
# rabbitmqctl set_user_tags openstack administrator

2)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

 


3)node1:将rabbittmq变量文件拷贝到其他两节点,之后并修改相应节点的ip
# scp /etc/rabbitmq/rabbitmq-env.conf con2:/etc/rabbitmq/
# scp /etc/rabbitmq/rabbitmq-env.conf con3:/etc/rabbitmq/

4)查看rabbitmq插件
# /usr/lib/rabbitmq/bin/rabbitmq-plugins list或者
# 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@node1
# rabbitmqctl start_app

9、node1检查集群状态
# rabbitmqctl cluster_status
Cluster status of node rabbit@node1 ...
[{nodes,[{disc,[rabbit@node1]},{ram,[rabbit@node3,rabbit@node2]}]},
{running_nodes,[rabbit@node3,rabbit@node2,rabbit@node1]},
{cluster_name,<<"rabbit@node1">>},
{partitions,[]},
{alarms,[{rabbit@node3,[]},{rabbit@node2,[]},{rabbit@node1,[]}]}]

10、登陆验证:http://172.16.254.60:15672/#/
默认账户guest
默认密码guest(如果改了密码以更改后的密码为准)

 

三、其他命令:
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 命令重启节点

上一篇:运维少年系列 - python and cisco(2)


下一篇:Photoshop设计制作出绚丽的飞翔金色叠加光束