(1)下载erlang源码包
wget http://www.erlang.org/download/otp_src_R13B04.tar.gz
(2)解压缩erlang源码包
tar -zxvf otp_src_R13B04.tar.gz
(3)安装
./configure --prefix=/usr/local/erlang
./make
./make install
如果抛出如下错误
No curses library functions found
请先安装 curses library
yum -y install ncurses-devel
然后将erlang执行目录加入PATH路径
export PATH=$PATH:/usr/local/erlang/bin
(4)测试erlang环境是否安装成功
[root@ptr165 rabbitmq_server-3.2.0]# erl -sname test Erlang R13B04 (erts-5.7.5) [source] [64-bit] [smp:16:16] [rq:16] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.7.5 (abort with ^G) (test@ptr164)1>如果出现上面的路径,erlang环境安装成功。
(1)下载rabbit包
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.2.0/rabbitmq-server-generic-unix-3.2.0.tar.gz
(2)解压到当前目录
tar -zxvf rabbitmq-server-generic-unix-3.2.0.tar.gz
(3)启动rabbitmq-server
cd rabbitmq_server-3.2.0
sbin/rabbitmq-server
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmq-server RabbitMQ 3.2.0. Copyright (C) 2007-2013 GoPivotal, Inc. ## ## Licensed under the MPL. See http://www.rabbitmq.com/ ## ## ########## Logs: sbin/../var/log/rabbitmq/[email protected] ###### ## sbin/../var/log/rabbitmq/[email protected] ########## Starting broker... completed with 0 plugins.如果出现这样的输出说明rabbitmq安装成功
(1)控制台启动方式:sbin/rabbitmq-server
通过控制台方式启动,可以CTRL-C命令关掉rabbitmq
(2)后台启动方式:sbin/rabbitmq-server -detached
可以通过rabbitmqctl stop命令关掉rabbitmq
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl stop Stopping and halting node rabbit@ptr165 ... ...done.(3)指定rabbitmq节点的名字启动
默认情况下,rabbitmq节点的名字是rabbit@HOSTNAME
rabbit@ptr165默认端口是5672
当我们运行rabbitmqctl stop命令时,由于没有指定节点名称,默认指向rabbit@HOSTNAME
我们可以通过指定不同的名字和端口
RABBITMQ_NODE_PORT=5673 RABBITMQ_NODENAME=rabbit1 sbin/rabbitmq-server -detached此时运行rabbitmqctl命令时,要指定节点名称
sbin/rabbitmqctl -n rabbit1@ptr164 status Status of node rabbit1@ptr164 ...关闭rabbitmq
sbin/rabbitmqctl -n rabbit1@ptr164 stop Stopping and halting node rabbit1@ptr164 ... ...done.一台单机上可以运行多个node节点。
(4)启动rabbitmq的管理插件
我们前面启动的rabbitmq没有启动任何插件
Starting broker... completed with 0 plugins.首先启动rabbitmq
然后运行命令
sbin/rabbitmq-plugins enable rabbitmq_management
重新启动rabbitmq-server
sbin/rabbitmq-server RabbitMQ 3.2.0. Copyright (C) 2007-2013 GoPivotal, Inc. ## ## Licensed under the MPL. See http://www.rabbitmq.com/ ## ## ########## Logs: sbin/../var/log/rabbitmq/[email protected] ###### ## sbin/../var/log/rabbitmq/[email protected] ########## Starting broker... completed with 6 plugins.
可以在浏览器中输入:http://192.168.1.164:15672/
我们测试用的两台机器分别为192.168.1.164和192.168.1.165。
(1)配置hostname
在两台机器的host分别配置vi /etc/hosts
122.11.45.165 ptr165 122.11.45.164 ptr164
~/.erlang.cookie,可以为任意值。
(3)分别启动rabbitmq
[root@ptr164 rabbitmq_server-3.2.0]# sbin/rabbitmq-server -detached
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmq-server -detached
(4)创建cluster
我们以rabbit@ptr164为主,将rabbit@ptr165加入到集群中
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl stop_app
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl join_cluster --ram rabbit@ptr164
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl start_app
查看集群状态
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl cluster_status
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl cluster_status Cluster status of node rabbit@ptr165 ... [{nodes,[{disc,[rabbit@ptr164]},{ram,[rabbit@ptr165]}]}, {running_nodes,[rabbit@ptr164,rabbit@ptr165]}, {partitions,[]}] ...done.
[root@ptr164 rabbitmq_server-3.2.0]# sbin/rabbitmqctl cluster_status Cluster status of node rabbit@ptr164 ... [{nodes,[{disc,[rabbit@ptr164]},{ram,[rabbit@ptr165]}]}, {running_nodes,[rabbit@ptr165,rabbit@ptr164]}, {partitions,[]}] ...done.两个节点得到相同的输出,其中rabbit@ptr164节点形式是disc,rabbit@ptr165节点形式是ram。这和执行join_cluster命令是的选项--ram是一致的。
(5)改变节点形式
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl stop_app Stopping node rabbit@ptr165 ... ...done. [root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl change_cluster_node_type disc Turning rabbit@ptr165 into a disc node ... ...done. [root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl start_app Starting node rabbit@ptr165 ... ...done.
[root@ptr164 rabbitmq_server-3.2.0]# sbin/rabbitmqctl cluster_status Cluster status of node rabbit@ptr164 ... [{nodes,[{disc,[rabbit@ptr164,rabbit@ptr165]}]}, {running_nodes,[rabbit@ptr165,rabbit@ptr164]}, {partitions,[]}] ...done.
两个节点都是disc的形式
(6)从cluster中分离
[root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl stop_app Stopping node rabbit@ptr165 ... ...done. [root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl reset Resetting node rabbit@ptr165 ... ...done. [root@ptr165 rabbitmq_server-3.2.0]# sbin/rabbitmqctl start_app Starting node rabbit@ptr165 ...
通过查看集群状态发现,两个节点都成了孤立的节点
Cluster status of node rabbit@ptr165 ... [{nodes,[{disc,[rabbit@ptr165]}]}, {running_nodes,[rabbit@ptr165]}, {partitions,[]}] ...done.