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,一经查实,立即删除!

相关文章

前端通过spark-md5.js计算本地文件md5

背景&#xff1a;说到本人第一次使用spark-md5.js还是差不多一年以前的时候了&#xff0c;当时后台老大说要搞一个文件分片上传的功能。我当时就心想&#xff1a;what&#xff1f;啥是文件分片上传&#xff0c;完全没听过好吗&#xff1f;至于我当时内心那个慌就不多描述了&…

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

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

关于窗口的一些小脚本

一般窗口分为两种情况 &#xff1a; 1、window.open 浏览器样式窗口 ⑴ 属性&#xff1a;window.open(index.html, newpage, height800, width60, top20, left50, toolbarno, menubarno, scrollbarsno, resizableno, locationno, statusno) 参数&#xff1a;window.open 弹出新…

基于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…

【第七次JAVA课,java语法基础】课件总结

没上课&#xff0c;不写总结&#xff01; 空着&#xff0c;会专门写篇总结java的io和nio的随笔。 转载于:https://www.cnblogs.com/limitCM/p/9997971.html

计算机技术与分析化学论文,分析化学(论文).doc

分析化学(论文)分析化学在生活中的应用化学化工学院 胡成摘 要&#xff1a;通过简单介绍有关分析化学在食品安全、药品检测、化妆品研究和环境监测的应用&#xff0c;阐明分析化学在人类生活中的重要作用。关 键 词&#xff1a;分析化学 食品安全 药品检测 化妆品研究 环境监测…

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

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

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

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

Activity并行网关和排他网关

说一说activiti中的排他网关和并行网关 activiti工作流中我们经常用到的网关有两种&#xff1a; 1. Exclusive Gateway 排他网关 排他网关.png 排他网关&#xff08;也叫异或&#xff08;XOR&#xff09;网关&#xff0c;或更技术性的叫法 基于数据的排他网关&#xff09;&…

ValueError: too many values to unpack

Error msg: 执行: python manage,py makemigrations 报错:Value: too many values to unpack 问题: django第一次数据库迁移之后, apps中的model位置改变了, 导致之前生成的迁移文件检测不到原来的位置 解决: 删除所有的迁移文件重新迁移, 或者将之前的迁移文件的路径修改正确 …

安徽省计算机二级考试vfp试题,安徽省计算机二级VFP考试理论模拟试题附答案

《安徽省计算机二级VFP考试理论模拟试题附答案》由会员分享&#xff0c;可在线阅读&#xff0c;更多相关《安徽省计算机二级VFP考试理论模拟试题附答案(19页珍藏版)》请在人人文库网上搜索。1、一、单项选择题(每题1分&#xff0c;共40分) 1. 计算机能够自动工作&#xff0c;主…

你不懂js系列学习笔记-异步与性能- 02

第二章&#xff1a;回调 原文&#xff1a;You-Dont-Know-JS 主要理解 “回调地狱&#xff08;callback hell&#xff09;”痛苦的点到底是哪&#xff0c;以及尝试拯救回调。 1. 首先从实际生活中模拟 我相信大多数读者都曾经听某个人说过&#xff08;甚至你自己就曾这么说&…

c# 计算空格宽度像素_关于C#中换算像素和毫米的说明

在C#中是以像素作为尺寸单位的&#xff0c;像素是一种相对的尺寸概念&#xff0c;与毫米的转换跟当前显示器的分辨率有关&#xff0c;在不同分辨率下转换的系数也不同。借助C#中的GDI可以实现像素与毫米的换算&#xff1a;一、根据Win32 API定义函数获取显示器设备信息&#xf…

使用Apache Commons Net SMTP以Java(和Android)发送邮件:STARTTLS,SSL

最近我正在做一个Android实验&#xff0c;我想使用SMTP服务器通过android应用程序通过身份验证和加密来发送电子邮件。 好吧&#xff0c; 我发现Android上的javax.mail并不是一个很好的选择 &#xff0c;因为它取决于awt类&#xff08;我猜是传统&#xff09;&#xff1b; 有些…

列名无效

数据库增加新&#xff0c;视图没有更新转载于:https://www.cnblogs.com/Neil-Peng/p/9283355.html

天津天河计算机技术有限公司,“天河一号”超级计算机落户天津,命名为“天河”,取天津与“银河团队...

注意问题&#xff1a;一、对语句排序试题一般应注意以下几个问题&#xff1a;1.揣摩语段的整体意义&#xff0c;理清选项内容所提供的信息和表达内容的主旨。2.分析选项内容与整体语段的语境联系。3.进行对比分析&#xff0c;排除干扰项。该类试题几个选项在语句的数量或内容上…

tan和cot的梗_cot和tan的关系

各位家长好&#xff0c;我是51学霸(51xueba.cn)专栏作者&#xff0c;甜老师全文共计521字&#xff0c;建议阅读2分钟cot和tan的关联&#xff1a;tanαcotα1。在三角函数中&#xff0c;cotθcosθ/sinθ&#xff0c;当θ≠kπ&#xff0c;k∈Z时&#xff0c;cotθ1/tanθ&#…