RabbitMQ安装以及集群部署

本次记录安装RabbitMQ的过程,只针对MAC下单机版安装、单机集群安装方法以及配置haproxy负载均衡。

  • RabbitMQ单机版本安装
  • RabbitMQ单机集群安装方法(适合开发练习)
  • RabbitMQ配置haproxy负载均衡
  • RabbitMQ集群测试(待续)
  • 参考文档

 

  • RabbitMQ单机版本安装
消息发送原理:
应用程序和Rabbit Server之间会创建一个TCP连接,一旦TCP打开,并通过了认证,认证就是你试图连接Rabbit之前发送的Rabbit服务器连接信息和用户名和密码,有点像程序连接数据库,使用Java有两种连接认证的方式,后面代码会详细介绍,一旦认证通过你的应用程序和Rabbit就创建了一条AMQP信道(Channel)。
信道是创建在“真实”TCP上的虚拟连接,AMQP命令都是通过信道发送出去的,每个信道都会有一个唯一的ID,不论是发布消息,订阅队列或者介绍消息都是通过信道完成的。为什么不通过TCP直接发送命令?
对于操作系统来说创建和销毁TCP会话是非常昂贵的开销,假设高峰期每秒有成千上万条连接,每个连接都要创建一条TCP会话,这就造成了TCP连接的巨大浪费,而且操作系统每秒能创建的TCP也是有限的,因此很快就会遇到系统瓶颈。
如果我们每个请求都使用一条TCP连接,既满足了性能的需要,又能确保每个连接的私密性,这就是引入信道概念的原因。

 

RabbitMQ基础概念:
ConnectionFactory(连接管理器)、Channel(信道)、Exchange(交换器)、Queue(队列)、RoutingKey(路由键)、BindingKey(绑定键)。
  • ConnectionFactory(连接管理器):应用程序与Rabbit之间建立连接的管理器,程序代码中使用;
  • Channel(信道):消息推送使用的通道;
  • Exchange(交换器):用于接受、分配消息;
  • Queue(队列):用于存储生产者的消息;
  • RoutingKey(路由键):用于把生成者的数据分配到交换器上;
  • BindingKey(绑定键):用于把交换器的消息绑定到队列上;

 

 

 MAC下配置 brew  命令行: brew install rabbitmq 会帮助安装依赖的各个环境, 如Erlang等, 方便安装和卸载。

基础命令:

启动 : ./rabbitmq-server -detached (后台启动)

查看状态:./rabbitmqctl status

查看web管理界面:http://localhost:15672/#/

停止:./rabbitmqctl stop 

命令结果集:

zhouguangfengdeMacBook-Pro:sbin feng$ ls
cuttlefish        rabbitmq-defaults    rabbitmq-diagnostics    rabbitmq-env        rabbitmq-plugins    rabbitmq-server        rabbitmqadmin        rabbitmqctl
zhouguangfengdeMacBook-Pro:sbin feng$ ./rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
zhouguangfengdeMacBook-Pro:sbin feng$ ./rabbitmqctl status
Status of node rabbit@localhost ...
[{pid,16051},{running_applications,[{rabbitmq_management,"RabbitMQ Management Console","3.7.5"},{rabbitmq_management_agent,"RabbitMQ Management Agent","3.7.5"},{rabbitmq_mqtt,"RabbitMQ MQTT Adapter","3.7.5"},{rabbitmq_stomp,"RabbitMQ STOMP plugin","3.7.5"},{rabbitmq_amqp1_0,"AMQP 1.0 support for RabbitMQ","3.7.5"},{amqp_client,"RabbitMQ AMQP Client","3.7.5"},{rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.7.5"},{rabbit,"RabbitMQ","3.7.5"},{rabbit_common,"Modules shared by rabbitmq-server and rabbitmq-erlang-client","3.7.5"},{ranch_proxy_protocol,"Ranch Proxy Protocol Transport","1.5.0"},{cowboy,"Small, fast, modern HTTP server.","2.2.2"},{ranch,"Socket acceptor pool for TCP protocols.","1.5.0"},{ssl,"Erlang/OTP SSL application","8.2.6"},{public_key,"Public key infrastructure","1.5.2"},{asn1,"The Erlang ASN1 compiler version 5.0.5","5.0.5"},{recon,"Diagnostic tools for production use","2.3.2"},{jsx,"a streaming, evented json parsing toolkit","2.8.2"},{cowlib,"Support library for manipulating Web protocols.","2.1.0"},{os_mon,"CPO  CXC 138 46","2.4.4"},{xmerl,"XML parser","1.3.16"},{crypto,"CRYPTO","4.2.2"},{sasl,"SASL  CXC 138 11","3.1.2"},{amqp10_common,"Modules shared by rabbitmq-amqp1.0 and rabbitmq-amqp1.0-client","3.7.5"},{inets,"INETS  CXC 138 49","6.5.1"},{mnesia,"MNESIA  CXC 138 12","4.15.3"},{lager,"Erlang logging framework","3.5.1"},{goldrush,"Erlang event stream processor","0.1.9"},{compiler,"ERTS  CXC 138 10","7.1.5"},{syntax_tools,"Syntax tools","2.1.4"},{stdlib,"ERTS  CXC 138 10","3.4.5"},{kernel,"ERTS  CXC 138 10","5.4.3"}]},{os,{unix,darwin}},{erlang_version,"Erlang/OTP 20 [erts-9.3.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:64] [hipe] [kernel-poll:true] [dtrace]\n"},{memory,[{connection_readers,0},{connection_writers,0},{connection_channels,0},{connection_other,32472},{queue_procs,67296},{queue_slave_procs,0},{plugins,2195128},{other_proc,27648040},{metrics,203960},{mgmt_db,294896},{mnesia,84800},{other_ets,2473304},{binary,209024},{msg_index,30064},{code,29314811},{atom,1131721},{other_system,14138316},{allocated_unused,17768616},{reserved_unallocated,0},{strategy,rss},{total,[{erlang,77823832},{rss,90247168},{allocated,95592448}]}]},{alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"127.0.0.1"},{stomp,61613,"::"},{mqtt,1883,"::"},{http,15672,"::"}]},{vm_memory_calculation_strategy,rss},{vm_memory_high_watermark,0.4},{vm_memory_limit,3435973836},{disk_free_limit,50000000},{disk_free,168907264000},{file_descriptors,[{total_limit,156},{total_used,4},{sockets_limit,138},{sockets_used,0}]},{processes,[{limit,1048576},{used,413}]},{run_queue,0},{uptime,75},{kernel,{net_ticktime,60}}]
zhouguangfengdeMacBook-Pro:sbin feng$ ./rabbitmqctl stop
Stopping and halting node rabbit@localhost ...
zhouguangfengdeMacBook-Pro:sbin feng$ 

 

RabbitMQ默认Port Access:参考http://www.rabbitmq.com/clustering.html#selinux-ports

http: RabbitMQ默认web管理界面端口

amqp:RabbitMQ默认客户端通信端口

 

 

  • RabbitMQ单机集群安装(适合开发练习)

由于在一个机器启动多个服务,会存在端口冲突问题,启动的时候需要设置不同的端口和节点名称。这里启动三个节点(rabbit_node_one、rabbit_node_two、rabbit_node_three)组合一个集群。

1、分别启动三个节点:

rabbit_node_one: 使用默认端口

RABBITMQ_NODE_PORT=5672 RABBITMQ_NODENAME=rabbit_node_one ./rabbitmq-server -detached

 rabbit_node_two:

RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}] -rabbitmq_stomp tcp_listeners [61614] -rabbitmq_mqtt tcp_listeners [1884]" RABBITMQ_NODENAME=rabbit_node_two ./rabbitmq-server -detached

rabbit_node_three:
RABBITMQ_NODE_PORT=5674 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15674}] -rabbitmq_stomp tcp_listeners [61615] -rabbitmq_mqtt tcp_listeners [1885]" RABBITMQ_NODENAME=rabbit_node_three ./rabbitmq-server -detached

 

2、集群配置: rabbit_node_one 为主节点

配置rabbit_node_two 为持久化节点 从节点:

./rabbitmqctl -n rabbit_node_two stop_app
./rabbitmqctl -n rabbit_node_two reset
./rabbitmqctl -n rabbit_node_two join_cluster rabbit_node_one
./rabbitmqctl -n rabbit_node_two start_app

rabbit_node_three 为内存节点 从节点::
./rabbitmqctl -n rabbit_node_three stop_app
./rabbitmqctl -n rabbit_node_three reset
./rabbitmqctl -n rabbit_node_three join_cluster rabbit_node_one --ram
./rabbitmqctl -n rabbit_node_three start_app

查询集群状态:
./rabbitmqctl cluster_status -n rabbit_node_one

 

命令结果集:

zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ RABBITMQ_NODE_PORT=5672 RABBITMQ_NODENAME=rabbit_node_one ./rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}] -rabbitmq_stomp tcp_listeners [61614] -rabbitmq_mqtt tcp_listeners [1884]" RABBITMQ_NODENAME=rabbit_node_two ./rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ RABBITMQ_NODE_PORT=5674 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15674}] -rabbitmq_stomp tcp_listeners [61615] -rabbitmq_mqtt tcp_listeners [1885]" RABBITMQ_NODENAME=rabbit_node_three ./rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ps aux | grep rabbitmq
zhouguangfeng    22499   0.1  0.9  5981744  79132   ??  S    10:42上午   0:04.65 /usr/local/Cellar/erlang/20.3.6/lib/erlang/erts-9.3.1/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 1280000 -K true -- -root /usr/local/Cellar/erlang/20.3.6/lib/erlang -progname erl -- -home /Users/zhouguangfeng -- -pa /usr/local/Cellar/rabbitmq/3.7.5/ebin -noshell -noinput -s rabbit boot -sname rabbit_node_three -boot /usr/local/opt/erlang/lib/erlang/bin/start_clean -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"127.0.0.1",5674}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit lager_log_root "/usr/local/var/log/rabbitmq" -rabbit lager_default_file "/usr/local/var/log/rabbitmq/rabbit_node_three.log" -rabbit lager_upgrade_file "/usr/local/var/log/rabbitmq/rabbit_node_three_upgrade.log" -rabbit enabled_plugins_file "/usr/local/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/Cellar/rabbitmq/3.7.5/plugins" -rabbit plugins_expand_dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_three-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_three" -rabbitmq_management listener [{port,15674}] -rabbitmq_stomp tcp_listeners [61615] -rabbitmq_mqtt tcp_listeners [1885] -kernel inet_dist_listen_min 25674 -kernel inet_dist_listen_max 25674 -noshell -noinput
zhouguangfeng    22167   0.0  0.9  5978272  79400   ??  S    10:42上午   0:05.36 /usr/local/Cellar/erlang/20.3.6/lib/erlang/erts-9.3.1/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 1280000 -K true -- -root /usr/local/Cellar/erlang/20.3.6/lib/erlang -progname erl -- -home /Users/zhouguangfeng -- -pa /usr/local/Cellar/rabbitmq/3.7.5/ebin -noshell -noinput -s rabbit boot -sname rabbit_node_one -boot /usr/local/opt/erlang/lib/erlang/bin/start_clean -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"127.0.0.1",5672}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit lager_log_root "/usr/local/var/log/rabbitmq" -rabbit lager_default_file "/usr/local/var/log/rabbitmq/rabbit_node_one.log" -rabbit lager_upgrade_file "/usr/local/var/log/rabbitmq/rabbit_node_one_upgrade.log" -rabbit enabled_plugins_file "/usr/local/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/Cellar/rabbitmq/3.7.5/plugins" -rabbit plugins_expand_dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_one-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_one" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672 -noshell -noinput
zhouguangfeng    22719   0.0  0.0  4295984    528 s001  U+   10:42上午   0:00.00 grep rabbitmq
zhouguangfeng    22315   0.0  1.0  5974940  79984   ??  S    10:42上午   0:05.42 /usr/local/Cellar/erlang/20.3.6/lib/erlang/erts-9.3.1/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 1280000 -K true -- -root /usr/local/Cellar/erlang/20.3.6/lib/erlang -progname erl -- -home /Users/zhouguangfeng -- -pa /usr/local/Cellar/rabbitmq/3.7.5/ebin -noshell -noinput -s rabbit boot -sname rabbit_node_two -boot /usr/local/opt/erlang/lib/erlang/bin/start_clean -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"127.0.0.1",5673}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit lager_log_root "/usr/local/var/log/rabbitmq" -rabbit lager_default_file "/usr/local/var/log/rabbitmq/rabbit_node_two.log" -rabbit lager_upgrade_file "/usr/local/var/log/rabbitmq/rabbit_node_two_upgrade.log" -rabbit enabled_plugins_file "/usr/local/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/Cellar/rabbitmq/3.7.5/plugins" -rabbit plugins_expand_dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_two-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_two" -rabbitmq_management listener [{port,15673}] -rabbitmq_stomp tcp_listeners [61614] -rabbitmq_mqtt tcp_listeners [1884] -kernel inet_dist_listen_min 25673 -kernel inet_dist_listen_max 25673 -noshell -noinput
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl -n rabbit_node_two stop_app
Stopping rabbit application on node rabbit_node_two@zhouguangfengdeMacBook-Pro ...
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl -n rabbit_node_two reset
Resetting node rabbit_node_two@zhouguangfengdeMacBook-Pro ...
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl -n rabbit_node_two join_cluster rabbit_node_one
Clustering node rabbit_node_two@zhouguangfengdeMacBook-Pro with rabbit_node_one
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl -n rabbit_node_two start_app
Starting node rabbit_node_two@zhouguangfengdeMacBook-Pro ...completed with 6 plugins.
Resetting node rabbit_node_three@zhouguangfengdeMacBook-Pro ...
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl cluster_status -n rabbit_node_one
Cluster status of node rabbit_node_one@zhouguangfengdeMacBook-Pro ...
[{nodes,[{disc,['rabbit_node_one@zhouguangfengdeMacBook-Pro','rabbit_node_two@zhouguangfengdeMacBook-Pro']}]},{running_nodes,['rabbit_node_two@zhouguangfengdeMacBook-Pro','rabbit_node_one@zhouguangfengdeMacBook-Pro']},{cluster_name,<<"rabbit_node_one@zhouguangfengdeMacBook-Pro">>},{partitions,[]},{alarms,[{'rabbit_node_two@zhouguangfengdeMacBook-Pro',[]},{'rabbit_node_one@zhouguangfengdeMacBook-Pro',[]}]}]
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl -n rabbit_node_three reset
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl -n rabbit_node_three join_cluster rabbit_node_one --ram
Clustering node rabbit_node_three@zhouguangfengdeMacBook-Pro with rabbit_node_one
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl -n rabbit_node_three start_app
Starting node rabbit_node_three@zhouguangfengdeMacBook-Pro ...completed with 6 plugins.
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl cluster_status -n rabbit_node_one
Cluster status of node rabbit_node_one@zhouguangfengdeMacBook-Pro ...
[{nodes,[{disc,['rabbit_node_one@zhouguangfengdeMacBook-Pro','rabbit_node_two@zhouguangfengdeMacBook-Pro']},{ram,['rabbit_node_three@zhouguangfengdeMacBook-Pro']}]},{running_nodes,['rabbit_node_three@zhouguangfengdeMacBook-Pro','rabbit_node_two@zhouguangfengdeMacBook-Pro','rabbit_node_one@zhouguangfengdeMacBook-Pro']},{cluster_name,<<"rabbit_node_one@zhouguangfengdeMacBook-Pro">>},{partitions,[]},{alarms,[{'rabbit_node_three@zhouguangfengdeMacBook-Pro',[]},{'rabbit_node_two@zhouguangfengdeMacBook-Pro',[]},{'rabbit_node_one@zhouguangfengdeMacBook-Pro',[]}]}]
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ 

 

 访问web页面: http://localhost:15672/#/  http://localhost:15673/#/  http://localhost:15674/#/

  

 

可以看到集群中三个节点已经正常启动,rabbit_node_three 设置为RAM内存节点,其他为磁盘节点(Disk and RAM Nodes)。RabbitMQ要求在集群中至少有一个磁盘节点,所有其他节点可以是内存节点,当节点加入或者离开集群时,必须要将该变更通知到至少一个磁盘节点。如果集群中唯一的一个磁盘节点崩溃的话,集群仍然可以保持运行,但是无法进行其他操作(增删改查),直到节点恢复。

 

测试集群节点down掉情况:对rabbit_node_two 进行kill操作 和 恢复操作, 查询集群情况

zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl cluster_status -n rabbit_node_one
Cluster status of node rabbit_node_one@zhouguangfengdeMacBook-Pro ...
[{nodes,[{disc,['rabbit_node_one@zhouguangfengdeMacBook-Pro','rabbit_node_two@zhouguangfengdeMacBook-Pro']},{ram,['rabbit_node_three@zhouguangfengdeMacBook-Pro']}]},
 {running_nodes,['rabbit_node_three@zhouguangfengdeMacBook-Pro','rabbit_node_two@zhouguangfengdeMacBook-Pro','rabbit_node_one@zhouguangfengdeMacBook-Pro']},{cluster_name,<<"rabbit_node_one@zhouguangfengdeMacBook-Pro">>},{partitions,[]},{alarms,[{'rabbit_node_three@zhouguangfengdeMacBook-Pro',[]},{'rabbit_node_two@zhouguangfengdeMacBook-Pro',[]},{'rabbit_node_one@zhouguangfengdeMacBook-Pro',[]}]}]
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ps aux | grep rabbitmq
zhouguangfeng    41776   0.0  0.0  4295984    536 s001  U+   11:05上午   0:00.00 grep rabbitmq
zhouguangfeng    22499   0.0  0.7  5988224  58552   ??  S    10:42上午   0:12.23 /usr/local/Cellar/erlang/20.3.6/lib/erlang/erts-9.3.1/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 1280000 -K true -- -root /usr/local/Cellar/erlang/20.3.6/lib/erlang -progname erl -- -home /Users/zhouguangfeng -- -pa /usr/local/Cellar/rabbitmq/3.7.5/ebin -noshell -noinput -s rabbit boot -sname rabbit_node_three -boot /usr/local/opt/erlang/lib/erlang/bin/start_clean -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"127.0.0.1",5674}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit lager_log_root "/usr/local/var/log/rabbitmq" -rabbit lager_default_file "/usr/local/var/log/rabbitmq/rabbit_node_three.log" -rabbit lager_upgrade_file "/usr/local/var/log/rabbitmq/rabbit_node_three_upgrade.log" -rabbit enabled_plugins_file "/usr/local/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/Cellar/rabbitmq/3.7.5/plugins" -rabbit plugins_expand_dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_three-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_three" -rabbitmq_management listener [{port,15674}] -rabbitmq_stomp tcp_listeners [61615] -rabbitmq_mqtt tcp_listeners [1885] -kernel inet_dist_listen_min 25674 -kernel inet_dist_listen_max 25674 -noshell -noinput
zhouguangfeng    22315   0.0  0.7  5984200  61532   ??  S    10:42上午   0:15.88 /usr/local/Cellar/erlang/20.3.6/lib/erlang/erts-9.3.1/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 1280000 -K true -- -root /usr/local/Cellar/erlang/20.3.6/lib/erlang -progname erl -- -home /Users/zhouguangfeng -- -pa /usr/local/Cellar/rabbitmq/3.7.5/ebin -noshell -noinput -s rabbit boot -sname rabbit_node_two -boot /usr/local/opt/erlang/lib/erlang/bin/start_clean -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"127.0.0.1",5673}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit lager_log_root "/usr/local/var/log/rabbitmq" -rabbit lager_default_file "/usr/local/var/log/rabbitmq/rabbit_node_two.log" -rabbit lager_upgrade_file "/usr/local/var/log/rabbitmq/rabbit_node_two_upgrade.log" -rabbit enabled_plugins_file "/usr/local/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/Cellar/rabbitmq/3.7.5/plugins" -rabbit plugins_expand_dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_two-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_two" -rabbitmq_management listener [{port,15673}] -rabbitmq_stomp tcp_listeners [61614] -rabbitmq_mqtt tcp_listeners [1884] -kernel inet_dist_listen_min 25673 -kernel inet_dist_listen_max 25673 -noshell -noinput
zhouguangfeng    22167   0.0  0.7  5984748  56532   ??  S    10:42上午   0:13.23 /usr/local/Cellar/erlang/20.3.6/lib/erlang/erts-9.3.1/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 1280000 -K true -- -root /usr/local/Cellar/erlang/20.3.6/lib/erlang -progname erl -- -home /Users/zhouguangfeng -- -pa /usr/local/Cellar/rabbitmq/3.7.5/ebin -noshell -noinput -s rabbit boot -sname rabbit_node_one -boot /usr/local/opt/erlang/lib/erlang/bin/start_clean -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"127.0.0.1",5672}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit lager_log_root "/usr/local/var/log/rabbitmq" -rabbit lager_default_file "/usr/local/var/log/rabbitmq/rabbit_node_one.log" -rabbit lager_upgrade_file "/usr/local/var/log/rabbitmq/rabbit_node_one_upgrade.log" -rabbit enabled_plugins_file "/usr/local/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/Cellar/rabbitmq/3.7.5/plugins" -rabbit plugins_expand_dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_one-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/var/lib/rabbitmq/mnesia/rabbit_node_one" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672 -noshell -noinput
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ kill -9 22315
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl cluster_status -n rabbit_node_one
Cluster status of node rabbit_node_one@zhouguangfengdeMacBook-Pro ...
[{nodes,[{disc,['rabbit_node_one@zhouguangfengdeMacBook-Pro','rabbit_node_two@zhouguangfengdeMacBook-Pro']},{ram,['rabbit_node_three@zhouguangfengdeMacBook-Pro']}]},
 {running_nodes,['rabbit_node_three@zhouguangfengdeMacBook-Pro','rabbit_node_one@zhouguangfengdeMacBook-Pro']},{cluster_name,<<"rabbit_node_one@zhouguangfengdeMacBook-Pro">>},{partitions,[]},{alarms,[{'rabbit_node_three@zhouguangfengdeMacBook-Pro',[]},{'rabbit_node_one@zhouguangfengdeMacBook-Pro',[]}]}]
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl -n rabbit_node_two start_app
Starting node rabbit_node_three@zhouguangfengdeMacBook-Pro ...
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl cluster_status -n rabbit_node_one
Cluster status of node rabbit_node_one@zhouguangfengdeMacBook-Pro ...
[{nodes,[{disc,['rabbit_node_one@zhouguangfengdeMacBook-Pro','rabbit_node_two@zhouguangfengdeMacBook-Pro']},{ram,['rabbit_node_three@zhouguangfengdeMacBook-Pro']}]},
 {running_nodes,['rabbit_node_three@zhouguangfengdeMacBook-Pro','rabbit_node_two@zhouguangfengdeMacBook-Pro','rabbit_node_one@zhouguangfengdeMacBook-Pro']},{cluster_name,<<"rabbit_node_one@zhouguangfengdeMacBook-Pro">>},{partitions,[]},{alarms,[{'rabbit_node_three@zhouguangfengdeMacBook-Pro',[]},{'rabbit_node_one@zhouguangfengdeMacBook-Pro',[]}]}]
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ 

 可以看到rabbit_node_two节点down之后,集群正常工作。 当节点恢复之后,主动加入集群。

 

  • RabbitMQ配置haproxy负载均衡

1、配置RabbitMQ镜像功能

 使用Rabbit镜像功能,需要基于RabbitMQ策略来实现,策略是用来控制和修改群集范围的某个vhost队列行为和Exchange行为

zhouguangfengdeMacBook-Pro:~ zhouguangfeng$ cd /usr/local/Cellar/rabbitmq/3.7.5/sbin/
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ls
cuttlefish        rabbitmq-diagnostics    rabbitmq-plugins    rabbitmqadmin        run.sh
rabbitmq-defaults    rabbitmq-env        rabbitmq-server        rabbitmqctl
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$ ./rabbitmqctl set_policy -p hrsystem ha-allqueue "^" '{"ha-mode":"all"}' -n rabbit_node_one
Setting policy "ha-allqueue" for pattern "^" to "{"ha-mode":"all"}" with priority "0" for vhost "hrsystem" ...
zhouguangfengdeMacBook-Pro:sbin zhouguangfeng$

 

这行命令创建一个名称为hrsystem的vhost,策略名称为ha-allqueue,策略模式为 all 即复制到所有节点,包含新增节点,策略正则表达式为 “^” 表示所有匹配所有队列名称。

详情参考:http://www.rabbitmq.com/ha.html

 

2、安装haproxy,使用mac下安装工具brew : brew install haproxy 

查看安装版本和目录:

zhouguangfengdeMacBook-Pro:/ zhouguangfeng$ haproxy -version
HA-Proxy version 1.8.12-8a200c7 2018/06/27
Copyright 2000-2018 Willy Tarreau <willy@haproxy.org>zhouguangfengdeMacBook-Pro:/ zhouguangfeng$ cd /usr/local/Cellar/haproxy/1.8.12/
.brew/                       INSTALL_RECEIPT.json         README                       homebrew.mxcl.haproxy.plist  
CHANGELOG                    LICENSE                      bin/                         share/                       
zhouguangfengdeMacBook-Pro:/ zhouguangfeng$ cd /usr/local/Cellar/haproxy/1.8.12/bin/
zhouguangfengdeMacBook-Pro:bin zhouguangfeng$ ls
haproxy    run.sh
zhouguangfengdeMacBook-Pro:bin zhouguangfeng$

 

配置haproxy.cfg 并启动:

zhouguangfengdeMacBook-Pro:bin zhouguangfeng$ cd /usr/local/etc/
zhouguangfengdeMacBook-Pro:bin zhouguangfeng$ mkdir haproxy
zhouguangfengdeMacBook-Pro:bin zhouguangfeng$ cd haproxy/
zhouguangfengdeMacBook-Pro:haproxy zhouguangfeng$ vim haproxy.cfg  -- 内容如下
haproxy.cfg
zhouguangfengdeMacBook-Pro:haproxy zhouguangfeng$ cat haproxy.cfg 
globallog 127.0.0.1   local0 # 日志daemon      # 后台运行maxconn 256 # 最大连接数defaultsmode http    # 默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OKstats enablestats uri /haproxy-statsstats refresh 10smonitor-uri /haproxy-testbalance roundrobin option httpclose  # 每次请求完毕后主动关闭http通道 option forwardfor # 如果后端服务器需要获得客户端真实ip需要配置的参数,可以从Http Header中获得客户端iptimeout connect 5000ms # 连接超时时间timeout client 50000ms # 客户端连接超时时间timeout server 50000ms # 服务器端连接超时时间####################################################################
# listen http_front# bind 0.0.0.0:1080           #监听端口  #stats refresh 30s           #统计页面自动刷新时间  #stats uri /haproxy?stats            #统计页面url  #listen private_monitoring :8100#stats realm Haproxy Manager #统计页面密码框上提示文本  #stats auth guest:guest      #统计页面用户名和密码设置  listen private_monitoring  # haproxy 监控 bind 0.0.0.0:8100 #监听端口mode httpoption httplog # 采用http日志格式stats enablestats uri /stats #设置haproxy监控地址为http://localhost:8100/stats
    stats refresh 30s #统计页面自动刷新时间stats auth guest:guest #添加用户名密码认证#####################我把RabbitMQ的管理界面也放在HAProxy后面了###############################
listen rabbitmq_admin bind 0.0.0.0:8004server rabbit_node_one 127.0.0.1:15672server rabbit_node_two 127.0.0.1:15673server rabbit_node_three 127.0.0.1:15674
####################################################################
listen rabbitmq_cluster bind 0.0.0.0:6672option tcplogmode tcptimeout client  3htimeout server  3hoption          clitcpkabalance roundrobin      #负载均衡算法(#banlance roundrobin 轮询,balance source 保存session值,支持static-rr,leastconn,first,uri等参数)#balance url_param userid#balance url_param session_id check_post 64#balance hdr(User-Agent)#balance hdr(host)#balance hdr(Host) use_domain_only#balance rdp-cookie#balance leastconn#balance source //ipserver   rabbit_node_one 127.0.0.1:5672 check inter 5s rise 2 fall 3   #check inter 2000 是检测心跳频率,rise 2是2次正确认为服务器可用,fall 3是3次失败认为服务器不可用server   rabbit_node_two 127.0.0.1:5673 check inter 5s rise 2 fall 3server   rabbit_node_three 127.0.0.1:5674 check inter 5s rise 2 fall 3
zhouguangfengdeMacBook-Pro:haproxy zhouguangfeng$ pwd
/usr/local/etc/haproxy
zhouguangfengdeMacBook-Pro:haproxy zhouguangfeng$ ls
haproxy.cfg
zhouguangfengdeMacBook-Pro:haproxy zhouguangfeng$ cd /usr/local/Cellar/haproxy/1.8.12/
.brew/                       INSTALL_RECEIPT.json         README                       homebrew.mxcl.haproxy.plist  
CHANGELOG                    LICENSE                      bin/                         share/                       
zhouguangfengdeMacBook-Pro:haproxy zhouguangfeng$ cd /usr/local/Cellar/haproxy/1.8.12/bin/
zhouguangfengdeMacBook-Pro:bin zhouguangfeng$ ls
haproxy    run.sh
zhouguangfengdeMacBook-Pro:bin zhouguangfeng$ cat run.sh 
#!/bin/sh./haproxy -f /usr/local/etc/haproxy/haproxy.cfg -d
zhouguangfengdeMacBook-Pro:bin zhouguangfeng$ ./run.sh 
[WARNING] 187/111607 (50864) : config : log format ignored for proxy 'private_monitoring' since it has no log address.
[WARNING] 187/111607 (50864) : config : monitor-uri will be ignored for proxy 'rabbitmq_cluster' (needs 'mode http').
[WARNING] 187/111607 (50864) : config : log format ignored for proxy 'rabbitmq_cluster' since it has no log address.
[WARNING] 187/111607 (50864) : config : 'stats' statement ignored for proxy 'rabbitmq_cluster' as it requires HTTP mode.
[WARNING] 187/111607 (50864) : config : 'option forwardfor' ignored for proxy 'rabbitmq_cluster' as it requires HTTP mode.
Available polling systems :kqueue : pref=300,  test result OKpoll : pref=200,  test result OKselect : pref=150,  test result OK
Total: 3 (3 usable), will use kqueue.Available filters :[SPOE] spoe[COMP] compression[TRACE] trace
Using kqueue() as the polling mechanism.    

 

访问:统计页面 http://localhost:8100/stats  用户和密码是上述配置的guest

访问RabbitMQ统一管理页面:http://localhost:8004/#/ 用户和密码是初始化密码 guest和guest

 

  • 参考文档: 

Clustering Guide:http://www.rabbitmq.com/clustering.html

RabbitMQ单机集群搭建:https://blog.csdn.net/Java_HuiLong/article/details/73718714

RabbitMQ分布式集群架:https://blog.csdn.net/WoogeYu/article/details/51119101

RabbitMQ3.6.3集群搭建+HAProxy1.6做负载均衡:https://www.cnblogs.com/lion.net/p/5725474.html

RabbitMQ集群及负载均衡搭建:https://blog.csdn.net/zpwmail/article/details/78066862

HAProxy Configuration Manual :http://cbonte.github.io/haproxy-dconv/1.8/configuration.html

 

转载于:https://www.cnblogs.com/xiaoxing/p/9258345.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/366591.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

r 保留之前曲线_生存曲线居然能够批量绘制了

生信分析第三步&#xff1a;生存曲线批量绘制各位解螺旋的小伙伴大家好&#xff0c;我是先锋宇&#xff0c;欢迎大家来到每周日的先锋宇专栏&#xff0c;经过前两期推文的学习&#xff0c;很多小伙伴都私信我说从先锋宇助教的专栏很接地气&#xff0c;自己能够开始慢慢处理数据…

基于vue自动化表单实践

背景 B端系统表单较多&#xff0c;且表单可能含有较多字段字段较多的表单带来了大片HTML代码在大片HTML中&#xff0c;混杂着参数绑定、事件处理等逻辑&#xff0c;不利于维护技术栈 Vue&#xff0c;Element(默认表单布局)适合中后台项目快速开发 目标 通过json配置快速生成表单…

天津科技大学计算机学院复试分数线,2021天津科技大学研究生复试分数线

2021天津科技大学研究生复试分数线已经公布&#xff0c;包含学术学位、专业学位、专项计划复试分数线&#xff0c;供大家参考&#xff0c;如意了在此祝广大考研学子都能顺利上岸。一、2021年天津科技大学研究生分数线1&#xff0e;专业分数线各学院严格执行《2021年全国硕士研究…

使用Eclipse Hibernate插件逐步为POJO域Java类和hbm自动生成代码

概述&#xff1a; 在本教程中&#xff0c;我们将使用Eclipse Hibernate工具自动生成域对象和相应的hbm xml文件。 如果您正在处理大型或中型项目&#xff0c;并且开始时有超过5个以上的表&#xff0c;则可能会发现此插件是自动生成映射域对象java文件和相应* .hbm.xml的绝佳工具…

idea本地跑如何看gc日志_线上故障如何快速排查?来看这套技巧大全

简介&#xff1a;有哪些常见的线上故障&#xff1f;如何快速定位问题&#xff1f;本文详细总结工作中的经验&#xff0c;从服务器、Java应用、数据库、Redis、网络和业务六个层面分享线上故障排查的思路和技巧。较长&#xff0c;同学们可收藏后再看。前言线上定位问题时&#x…

从零打造在线版H5页面生成器

想必你一定使用过易企秀或其它微场景生成工具制作过炫酷的h5页面&#xff0c;除了感叹其神奇之处有没有想过其实现方式呢&#xff1f;从设计者的角度来看待问题&#xff0c;会有不一样的收获&#xff0c;本文将从零开始&#xff0c;使用node技术来设计实现一款精简版的易企秀 G…

使用Struts2,Hibernate和MySQL BLOB开发个人迷你相册应用程序–第1部分

概述&#xff1a; 在本研讨会中&#xff0c;我们将开发一个Web应用程序&#xff0c;可用于创建漂亮的照片库。 您可以将其托管在Web服务器中&#xff0c;也可以在自己的PC中使用以维护和管理照片集。 使用本教程&#xff0c;您将能够了解与Struts2和Hibernate相关的以下重要内容…

基于 Webpack2、Vue2、iView2 的可视化脚手架 iView Cli 发布 2.0 版本

谷歌今天发布了一系列“性感”的软件&#xff0c;我们也发布了一款大家期待已久的开发者工具&#xff0c;同样很性感 &#xff1a;) iView 2.0 已经发布有两个月了&#xff0c;在 2.0 发布后&#xff0c;npm 下载量、issues 数量都提升了很多&#xff08;可以 watch 下项目&…

在OSGi中为Karaf构建Camel-CXF REST服务–组播和聚合

请查看我在Karaf的OSGi中构建普通CXF服务&#xff08;不使用Camel&#xff09;的其他文章 。 这是有关如何 创建一个CXF REST服务 使用骆驼多播&#xff08;并并行化&#xff09;传入的请求 来自两个不同服务的源数据 汇总响应并 最后将合并结果作为JSON返回给最终用户。…

cgcs2000大地坐标系地图_为什么要从北京54和西安80统一到CGCS2000?测绘人必知!...

导 读北京54坐标和西安80坐标&#xff0c;使用了很多年&#xff0c;为何要统一成CGCS2000坐标&#xff1f;启用CGCS2000坐标有何重大意义&#xff1f;概述北京54坐标系和西安1980坐标系的建立极大的促进了新中国测绘的发展,然而随着空间大地测量技术的兴起,这两种经典的局部大地…

Amazon Elastic Map Reduce使用Apache Mahout计算建议

Apache Mahout是一个“可扩展的机器学习库”&#xff0c;其中包含各种单节点和分布式推荐算法的实现。 在我的上一篇博客文章中&#xff0c; 我描述了如何在单个节点上实现在线推荐系统来处理数据。 如果数据太大而无法放入内存&#xff08;> 100M首选项数据点&#xff09;怎…

基于element-ui实现table可配置化

写在前面 感谢 饿了么前端团队提供组件化框架elememt-ui&#xff0c;本文基础组件使用element-ui。 大背景 在开发一些系统过程中&#xff0c;使用table作数据展示在所难免。先来看看el-table组件。 非常简单易用的组件&#xff0c;根据提供的data数据&#xff0c;配置table…

麟龙指标通达信指标公式源码_通达信指标公式源码波段极限副图源码

做价值的传播者&#xff0c;一路同行&#xff0c;一起成长问题&#xff1a;怎样才能每天都收到这类文章&#xff01;答案&#xff1a;只需点击上方《通达信公式指标》{买卖公式}AA:(2*CHIGHLOW)/4;BB:AA-REF(C,12);CC:EMA(BB,13);DD:EMA(CC,2);EE:EMA(BB,34);FF:EMA(BB,55);GG:…

计算机系统备份的原则和策略,计算机系统数据备份机制与策略

计算机系统数据备份机制与策略20年第5 05期华中电力第 l卷 8计算机系统数据备份机制与策略耿煜(樊学院机械系&#xff0c;北襄樊襄湖 4 15 ) 4 03摘要&#xff1a;针对当今计算环境中不断增长的数据量&#xff0c;系统地分析、论述了完整的数据备份机制&#xff0c;出了相应的策…

[译] 帮助你成为一名成功的 Web 开发工程师的 21 步

前言 随着 Web 开发的蓬勃发展&#xff0c;许多人都在问这样一个问题&#xff1a;我如何才能成为一名 Web 开发者&#xff1f;我认为这个问题不应该这样问&#xff0c;而应该是&#xff1a;我如何才能成为一名成功的 Web 开发者&#xff1f;这样的问题是很有必要的&#xff0c;…

循环卷积和周期卷积的关系_基于单口RAM读写的卷积电路(下)

这是迟到很久的卷积电路verilog设计的下篇。。。你看我还有机会吗。。。上回我们给出系统的层次结构、卷积计算模块以及用于数据缓存的fifo模块&#xff0c;今天我们首先回顾一下上一次的关键内容。系统结构回顾RTL代码文件可以分为结构如下所示 ~|--top_conv_tb.v|--top_conv.…

浅析 PHP 中的 Generator

浅析 PHP 中的 Generator Miss Wang php开发案例 前天 何为 Generator 从 PHP 5.5 开始&#xff0c;PHP 加入了一个新的特性&#xff0c;那就是 Generator&#xff0c;中文译为生成器。生成器可以简单地用来实现对象的迭代&#xff0c;让我们先从官方的一个小例子说起。 xrange…

注意安全!XSS 和 XSRF

[Tips] 本文是从 jianshu 平台重新修改编辑后移植来的&#xff0c;比上一版本做了些修订。 最近在看一些关于网络安全的问题&#xff0c;当然许多是跟前端相关的&#xff0c;包括且不局限于xss和xsrf 了&#xff0c;那么小编就结合最近的学习实践谈一些粗浅的认识。&#xff08…

go分析和kegg分析_干货预警:3分钟搞定GO/KEGG功能富集分析(2)

在 3分钟了解GO/KEGG功能富集分析 一文中给大家讲解了GO和KEGG的基本概念和内涵,并且给大家介绍了DAVID这一神奇网站。今天我们就把GO/KEGG功能富集分析的详细教程按部就班地呈现给大家,有请小猎豹。 多图预警,轻点图片,查看高清大图 1 Step1: 打开DAVID官网:https://dav…

如何在本地开发环境调试微信 JS-SDK

以下篇幅将会描述不同前提下对应的调试策略&#xff0c;当然也有可能不是最优解&#xff0c;望斧正 →_→ 前言 何谓「安全域名限制」&#xff1f; 以微信 JS-SDK 的使用为例&#xff0c;每个公众号被限制最多可设置三个安全域名&#xff0c;且必须能被腾讯服务器所验证&#…