RabbitMQ的安装及集群搭建方法

2020-08-21 10:38:40 浏览数 (1)

RabbitMQ安装

1 安装erlang 下载地址:http://www.erlang.org/downloads 博主这里采用的是otp_src_19.1.tar.gz (200MB )

代码语言:javascript复制
[root@hidden util]# tar zxvf  otp_src_19.1.tar.gz
[root@hidden util]# cd otp_src_19.1 
[root@hidden otp_src_19.1]# ./configure --prefix=/opt/erlang
[root@hidden otp_src_19.1]# make 
[root@hidden otp_src_19.1]# make install

修改/etc/profile文件,添加下面的环境变量:

代码语言:javascript复制
ERLANG_HOME=/opt/erlang
export PATH=$PATH:$ERLANG_HOME/bin
export ERLANG_HOME

最后执行source /etc/profile让文件生效。

2 安装simpleJson 下载地址:https://pypi.python.org/pypi/simplejson/ 博主这里采用的是simplejson-3.10.0.tar.gz

代码语言:javascript复制
[root@hidden util]# tar zxvf simplejson-3.10.0.tar.gz
[root@hidden util]# cd simplejson-3.10.0
[root@hidden simplejson-3.10.0]# python setup.py install

3 安装rabbitmq 下载地址:http://www.rabbitmq.com/releases/rabbitmq-server/ 博主这里用的版本就有很多了,比如2.7.0, 3.4.0, 3.4.1, 3.4.2, 3.4.3, 3.5.7, 3.6.0等等,不过都是用的rabbitmq-server-generic-unix-..*.tar.gz的版本。 这里以3.5.7举例:

代码语言:javascript复制
[root@hidden util]# tar zvxf rabbitmq-server-generic-unix-3.5.7.tar.gz -C /opt
[root@hidden util]# cd /opt
[root@hidden util]# mv rabbitmq_server-3.5.7 rabbitmq

修改/etc/profile文件,添加下面的环境变量:

代码语言:javascript复制
export PATH=$PATH:/opt/rabbitmq/sbin

最后执行source /etc/profile让文件生效。 运行:rabbitmq-server -detached 之后运行rabbitmqctl status查看rabbitmq是否正常启动:

代码语言:javascript复制
[root@zhuzhonghua2-fqawb rabbitmq]# rabbitmqctl status
Status of node 'rabbit@zhuzhonghua2-fqawb' ...
[{pid,25020},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.5.7"},
      {rabbitmq_management_agent,"RabbitMQ Management Agent","3.5.7"},
      {rabbit,"RabbitMQ","3.5.7"},
      {mnesia,"MNESIA  CXC 138 12","4.14.1"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.5.7"},
      {webmachine,"webmachine","1.10.3-rmq3.5.7-gite9359c7"},
      {mochiweb,"MochiMedia Web Server","2.7.0-rmq3.5.7-git680dba8"},
      {os_mon,"CPO  CXC 138 46","2.4.1"},
      {amqp_client,"RabbitMQ AMQP Client","3.5.7"},
      {inets,"INETS  CXC 138 49","6.3.3"},
      {xmerl,"XML parser","1.3.12"},
      {sasl,"SASL  CXC 138 11","3.0.1"},
      {stdlib,"ERTS  CXC 138 10","3.1"},
      {kernel,"ERTS  CXC 138 10","5.1"}]},
 {os,{unix,linux}},
 {erlang_version,
     "Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:64] [hipe] [kernel-poll:true]n"},
 {memory,
     [{total,60110136},
      {connection_readers,0},
      {connection_writers,0},
      {connection_channels,0},
      {connection_other,5664},
      {queue_procs,1028160},
      {queue_slave_procs,1576056},
      {plugins,8008840},
      {other_proc,6115560},
      {mnesia,197760},
      {mgmt_db,14219256},
      {msg_index,58288},
      {other_ets,1181200},
      {binary,633896},
      {code,17650127},
      {atom,711593},
      {other_system,8723736}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,3301929779},
 {disk_free_limit,50000000},
 {disk_free,35754786816},
 {file_descriptors,
     [{total_limit,924},{total_used,6},{sockets_limit,829},{sockets_used,1}]},
 {processes,[{limit,1048576},{used,195}]},
 {run_queue,0},
 {uptime,139660}]

RabbitMQ集群搭建方法

这里展示的是多机集群的部署,如果机器受限,可以选择单机集群部署,详细可以参考《RabbitMQ单机多实例配置》。 这里选用三台主机,主机名分别是hidden1, hidden2, hidden3 1 在这三台机器中安装rabbitmq-server, 参考上面。

2 读取其中一个节点的cookie, 并复制到其他节点(节点之间通过cookie确定相互是否可通信)。 cookie存放在/var/lib/rabbitmq/.erlang.cookie或者$HOME/.erlang.cookie中。

3 逐个启动节点 rabbitmq-server -detached

4 查看各节点的状态: rabbitmqctl status, rabbitmqctl cluster_status

5 配置各节点的hosts文件( vim /etc/hosts) xxx.xxx.xxx.xxx hidden1 xxx.xxx.xxx.xxx hidden2 xxx.xxx.xxx.xxx hidden3

6 建立集群 以hidden1为主节点,在hidden2上: rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl join_cluster rabbit@hidden1 rabbitmqctl start_app hidden3上的操作与hidden2的雷同。 最后通过rabbitmqctl cluster_status查看集群的状态信息:

代码语言:javascript复制
[{nodes,[{disc,[rabbit@hidden1,'rabbit@hidden2','rabbit@hidden3']}]},
 {running_nodes,[rabbit@hidden1,'rabbit@hidden2','rabbit@hidden3']},
 {cluster_name,<<"rabbit@hidden1">>},
 {partitions,[]}]

7 在访问web(http://xxx.xxx.xxx.xxx:15672)时, 如果在Overview中的Nodes部分看到“Node statistics not available”的信息,说明在该节点上web管理插件还未启用。直接运行rabbitmq-plugins enable rabbitmq_management即可。

0 人点赞