RabbitMQ集群安装

rabbit是基于erlang编写的,所以需要先安装erlang环境。
首先在四台主机上安装erlang、rabbitmq-server;
读取其中一台节点上的erlang cookie,并复制到其他节点(节点之间通过cookie确定相互是否可通信);
逐个启动节点:rabbitmq-server -detached
查看各节点的状态: rabbitmqctl status, rabbitmqctl cluster_status
将其他节点加入集群。

设置host

//不重启 临时修改hostname
hostname rabbitmq-node1~4

//永久设置hostname
vim /etc/hostname
rabbitmq-node1
vim /etc/sysconfig/network
HOSTNAME=rabbitmq-node1

//在/etc/hosts中添加
10.30.128.67    rabbitmq-node1    
10.30.128.68    rabbitmq-node2    
10.30.128.69    rabbitmq-node3    
10.30.128.70    rabbitmq-node4

安装erlang

下载otp_src_19.2.tar.gz

yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel    ncurses-devel
yum -y install xz perl unixODBC unixODBC-devel

mkdir -p /apache/RabbitMQ/erlang/
cd /apache/RabbitMQ/erlang/
wget http://erlang.org/download/otp_src_19.2.tar.gz
tar xvf otp_src_19.2.tar.gz
cd otp_src_19.2
./configure 
make 
make install
//输入erl出现如下界面即表示安装完成
[root@rabbitmq-node1 otp_src_19.2]# erl
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.2  (abort with ^G)
1> 

安装rabbitmq3.6.6

下载rabbitmq-server-generic-unix-3.6.6.tar.xz

cd /apache/RabbitMQ
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.6/rabbitmq-server-generic-unix-3.6.6.tar.xz
xz -d rabbitmq-server-generic-unix-3.6.6.tar.xz
tar xvf rabbitmq-server-generic-unix-3.6.6.tar

vi /etc/profile
export PATH=$PATH:/apache/RabbitMQ/rabbitmq_server-3.6.6/sbin
source /etc/profile

组成集群

首先使用参数-detached运行各节点,运行后才能集群

rabbitmqctl stop
rabbitmq-server -detached

设置erlang cookie
Rabbitmq的集群是依赖于erlang的集群来工作的,所以必须先构建起erlang的集群环境。Erlang的集群中各节点是通过一个magic cookie来实现的,这个cookie存放在 /root/.erlang.cookie 中,文件是400的权限。所以必须保证各节点cookie保持一致,否则节点之间就无法通信。我们是删除其中三台的/root/.erlang.cookie,然后将另一台的/root/.erlang.cookie拷贝到这三台上。文件权限是 400

scp /root/.erlang.cookie root@10.30.128.68:/root

组成集群,在node2 3 4上分别运行:

rabbitmqctl stop_app
rabbitmqctl reset 
rabbitmqctl join_cluster rabbit@rabbitmq-node1
//默认是磁盘节点,如果是内存节点的话,需要加--ram参数
rabbitmqctl start_app
[root@rabbitmq-node1 rabbitmq]# rabbitmqctl cluster_status -n rabbit
Cluster status of node 'rabbit@rabbitmq-node1' ...
[{nodes,[{disc,['rabbit@rabbitmq-node1','rabbit@rabbitmq-node2',
                'rabbit@rabbitmq-node3','rabbit@rabbitmq-node4']}]},
 {running_nodes,['rabbit@rabbitmq-node4','rabbit@rabbitmq-node2',
                 'rabbit@rabbitmq-node3','rabbit@rabbitmq-node1']},
 {cluster_name,<<"rabbit@rabbitmq-node1">>},
 {partitions,[]},
 {alarms,[{'rabbit@rabbitmq-node4',[]},
          {'rabbit@rabbitmq-node2',[]},
          {'rabbit@rabbitmq-node3',[]},
          {'rabbit@rabbitmq-node1',[]}]}]
[root@DockerHost rabbitmq]#

rabbitmqctl rabbitmq管理工具
rabbitmq-plugins rabbitmq插件管理工具
rabbitmq-server rabbitmq服务

参考:官方安装指南
RabbitMQ nodes and CLI tools (e.g. rabbitmqctl) use a cookie to determine whether they are allowed to communicate with each other. For two nodes to be able to communicate they must have the same shared secret called the Erlang cookie. The cookie is just a string of alphanumeric characters. It can be as long or short as you like. Every cluster node must have the same cookie.
Erlang VM will automatically create a random cookie file when the RabbitMQ server starts up. The easiest way to proceed is to allow one node to create the file, and then copy it to all the other nodes in the cluster.
On Unix systems, the cookie will be typically located in /var/lib/rabbitmq/.erlang.cookie or $HOME/.erlang.cookie.

阅读 5.6k

推荐阅读
从入门到放弃
用户专栏

小白coder的成长记录

0 人关注
2 篇文章
专栏主页