【rabbitmq知识体系】centos7下rabbitmq3.7.2集群配置(续)

参考资料

https://www.cnblogs.com/me-sa/p/erlang-epmd.html

erlang虚拟机

查询官网后得知,rabbitmq是一个基于erlang语言的应用程序。
在 Erlang中有两个概念:节点(node)和应用程序(application)。

节点(node)

node为运行Erlang虚拟机的一个实例。

应用程序(application)

多个Erlang应用程序(application)可以运行在同一个节点(node)之上。

erlang节点特点

节点(node)之间可进行通信(无论是否运行在同一台服务器)。
简单来说:
1.一个运行在节点A上的应用程序(application)可以调用节点B上应用程序的方法,就好像调用本地函数一样。
2.如果要关闭整个RabbitMQ节点可以使用stop参数,它会和本地节点通信并指示其干净得关闭:/sbin/rabbitmqctl stop。
比如:
默认node名称是rabbit@server,如果主机名是server.example.com,那么node名称就是 rabbit@server.example.com

/sbin/rabbitmqctl -n rabbit@server.example.com stop

3.rabbitmqctl关闭RabbitMQ应用程序,如果只想关闭应用程序,同时保持Erlang节点运行则可以使用 stop_app。
rabbitmqctl也可以指定关闭不同得节点(包括远程节点),只需传入参数也可以指定关闭不同的节点(包括远程节点),且只需传入参数 -n node(依赖于下面要提到的epmd)。

/sbin/rabbitmqctl -n rabbit@server.example.com stop_app

empd

rabbitmq顶层架构

集群整体架构

单点整体架构

启动参数解析

上面提到的整体架构可能有点抽象,看下启动参数

/usr/lib64/erlang/erts-9.3.3.6/bin/beam.smp -W w -A 64 
-P 1048576
-t 5000000
-stbt db
-zdbbl 128000
-K true
--
-root /usr/lib64/erlang #erlang虚拟机目录
-progname erl
--
-home /var/lib/rabbitmq #rabbitmq家目录
--
-pa /usr/lib/rabbitmq/lib/rabbitmq_server-3.7.2/ebin
-noshell
-noinput
-s rabbit boot
-sname rabbit@lxg53
-boot start_sasl
-conf /etc/rabbitmq/rabbitmq #rabbitmq配置文件
-conf_dir /var/lib/rabbitmq/config #rabbitmq配置文件目录
-conf_script_dir /usr/lib/rabbitmq/bin
-conf_schema_dir /var/lib/rabbitmq/schema
-kernel inet_default_connect_options [{nodelay,true}] #kerner程序的配置
-sasl errlog_type error
-sasl sasl_error_logger false
-rabbit lager_log_root "/data/rabbitmq/log" #rabbitmq程序的日志配置
-rabbit lager_default_file "/data/rabbitmq/log/rabbit@lxg53.log" #rabbitmq程序的日志配置
-rabbit lager_upgrade_file "/data/rabbitmq/log/rabbit@lxg53_upgrade.log" #rabbitmq程序的日志配置
-rabbit enabled_plugins_file "/etc/rabbitmq/enabled_plugins" #rabbitmq程序的插件配置
-rabbit plugins_dir "/usr/lib/rabbitmq/plugins:/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.2/plugins" #rabbitmq程序的插件目录
-rabbit plugins_expand_dir "/data/rabbitmq/mnesia/rabbit@lxg53-plugins-expand"
-os_mon start_cpu_sup false #rabbitmq程序的配置
-os_mon start_disksup false
-os_mon start_memsup false
-mnesia dir "/data/rabbitmq/mnesia/rabbit@lxg53"
-kernel inet_dist_listen_min 25672
-kernel inet_dist_listen_max 25672

rabbitmq相关应用程序

第二种手段:查询日志。
结合启动参数、日志后可以看出,rabbitmq相关的erlang程序包括:

  • rabbitmq_management
  • amqp_client
  • rabbitmq_web_dispatch
  • cowboy #http server
  • cowlib
  • rabbitmq_management_agent #基于cowboy的插件
  • rabbit
  • mnesia
  • rabbit_common
  • os_mon
    2017-12-23 13:21:40.187 [info] <0.18635.0> RabbitMQ is asked to stop...
    2017-12-23 13:21:40.410 [info] <0.18635.0> Stopping RabbitMQ applications and their dependencies in the following order:
    rabbitmq_management
    amqp_client
    rabbitmq_web_dispatch
    cowboy
    cowlib
    rabbitmq_management_agent
    rabbit
    mnesia
    rabbit_common
    os_mon
    2017-12-23 13:21:40.410 [info] <0.18635.0> Stopping application 'rabbitmq_management'
    2017-12-23 13:21:40.414 [info] <0.33.0> Application rabbitmq_management exited with reason: stopped
    2017-12-23 13:21:40.414 [info] <0.18635.0> Stopping application 'amqp_client'
    2017-12-23 13:21:40.416 [info] <0.33.0> Application amqp_client exited with reason: stopped
    2017-12-23 13:21:40.416 [info] <0.18635.0> Stopping application 'rabbitmq_web_dispatch'
    2017-12-23 13:21:40.419 [info] <0.33.0> Application rabbitmq_web_dispatch exited with reason: stopped
    2017-12-23 13:21:40.419 [info] <0.18635.0> Stopping application 'cowboy'
    2017-12-23 13:21:40.421 [info] <0.33.0> Application cowboy exited with reason: stopped
    2017-12-23 13:21:40.421 [info] <0.18635.0> Stopping application 'cowlib'
    2017-12-23 13:21:40.421 [info] <0.33.0> Application cowlib exited with reason: stopped
    2017-12-23 13:21:40.421 [info] <0.18635.0> Stopping application 'rabbitmq_management_agent'
    2017-12-23 13:21:40.424 [info] <0.33.0> Application rabbitmq_management_agent exited with reason: stopped
    2017-12-23 13:21:40.424 [info] <0.18635.0> Stopping application 'rabbit'
    2017-12-23 13:21:40.424 [info] <0.944.0> Peer discovery backend rabbit_peer_discovery_classic_config does not support registration, skipping unregistration.
    2017-12-23 13:21:40.424 [info] <0.1300.0> stopped TCP Listener on [::]:5672
    2017-12-23 13:21:40.425 [info] <0.1039.0> Closing all connections in vhost 'bbs' on node 'rabbit@lxg54' because the vhost is stopping
    2017-12-23 13:21:40.426 [info] <0.1039.0> Closing all connections in vhost 'fsp_metrics' on node 'rabbit@lxg54' because the vhost is stopping
    2017-12-23 13:21:40.426 [info] <0.1236.0> Stopping message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/2EO163IWD87C0LGDYBMCOU9AZ/msg_store_persistent'
    2017-12-23 13:21:40.426 [info] <0.1183.0> Stopping message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/CJ961M2R0VKA2HG0XCI215CBA/msg_store_persistent'
    2017-12-23 13:21:40.426 [info] <0.1130.0> Stopping message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/msg_store_persistent'
    2017-12-23 13:21:40.426 [info] <0.1077.0> Stopping message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/BILT8EMIAEYFVG7TLIG4764T5/msg_store_persistent'
    2017-12-23 13:21:40.426 [info] <0.1039.0> Closing all connections in vhost '/' on node 'rabbit@lxg54' because the vhost is stopping
    2017-12-23 13:21:40.426 [info] <0.1039.0> Closing all connections in vhost 'fsp-asynctask-service' on node 'rabbit@lxg54' because the vhost is stopping
    2017-12-23 13:21:40.482 [info] <0.1130.0> Message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/msg_store_persistent' is stopped
    2017-12-23 13:21:40.482 [info] <0.1127.0> Stopping message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/msg_store_transient'
    2017-12-23 13:21:40.483 [info] <0.1236.0> Message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/2EO163IWD87C0LGDYBMCOU9AZ/msg_store_persistent' is stopped
    2017-12-23 13:21:40.483 [info] <0.1077.0> Message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/BILT8EMIAEYFVG7TLIG4764T5/msg_store_persistent' is stopped
    2017-12-23 13:21:40.483 [info] <0.1183.0> Message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/CJ961M2R0VKA2HG0XCI215CBA/msg_store_persistent' is stopped
    2017-12-23 13:21:40.483 [info] <0.1074.0> Stopping message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/BILT8EMIAEYFVG7TLIG4764T5/msg_store_transient'
    2017-12-23 13:21:40.483 [info] <0.1233.0> Stopping message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/2EO163IWD87C0LGDYBMCOU9AZ/msg_store_transient'
    2017-12-23 13:21:40.483 [info] <0.1180.0> Stopping message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/CJ961M2R0VKA2HG0XCI215CBA/msg_store_transient'
    2017-12-23 13:21:40.626 [info] <0.1127.0> Message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/msg_store_transient' is stopped
    2017-12-23 13:21:40.626 [info] <0.1233.0> Message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/2EO163IWD87C0LGDYBMCOU9AZ/msg_store_transient' is stopped
    2017-12-23 13:21:40.626 [info] <0.1180.0> Message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/CJ961M2R0VKA2HG0XCI215CBA/msg_store_transient' is stopped
    2017-12-23 13:21:40.627 [info] <0.1074.0> Message store for directory '/var/lib/rabbitmq/mnesia/rabbit@lxg54/msg_stores/vhosts/BILT8EMIAEYFVG7TLIG4764T5/msg_store_transient' is stopped
    2017-12-23 13:21:40.631 [info] <0.18635.0> Stopping application 'mnesia'
    2017-12-23 13:21:40.631 [info] <0.33.0> Application rabbit exited with reason: stopped
    2017-12-23 13:21:40.634 [info] <0.33.0> Application mnesia exited with reason: stopped
    2017-12-23 13:21:40.634 [info] <0.18635.0> Stopping application 'rabbit_common'
    2017-12-23 13:21:40.634 [info] <0.33.0> Application rabbit_common exited with reason: stopped
    2017-12-23 13:21:40.634 [info] <0.18635.0> Stopping application 'os_mon'
    2017-12-23 13:21:40.636 [info] <0.33.0> Application os_mon exited with reason: stopped
    2017-12-23 13:21:40.636 [info] <0.18635.0> Successfully stopped RabbitMQ and its dependencies

rabbitmq核心概念

Broker

简单来说就是消息队列服务器的实体,类似于 JMS 规范中的 JMS provider。它用于接收和分发消息,有时候也称为 Message Broker 或者更直白的称为 RabbitMQ Server。

cluster

一群broker组成的集群,其中一个是disc节点,其他的为ram节点。

Virtual Host

和 Web 服务器中的虚拟主机(Virtual Host)是类似的概念,出于多租户和安全因素设计的,可以将 RabbitMQ Server 划分成多个独立的空间,彼此之间互相独立,这样就可以将一个 RabbitMQ Server 同时提供给多个用户使用,每个用户在自己的空间内创建 Exchange 和 Queue。

Exchange

交换机用于接收消息,这是消息到达 Broker 的第一站,然后根据交换机的类型和路由规则(Routing Key),将消息分发到特定的队列中去。常用的交换机类型有:direct (point-to-point)、topic (publish-subscribe) 和 fanout (multicast)。

Queue

生产者发送的消息就是存储在这里,在 JMS 规范里,没有 Exchange 的概念,消息是直接发送到 Queue,而在 AMQP 中,消息会经过 Exchange,由 Exchange 来将消息分发到各个队列中。消费者可以直接从这里取走消息。

Binding

绑定的作用就是把 Exchange 和 Queue 按照路由规则绑定起来,路由规则可由下面的 Routing Key 指定。

Routing Key

路由关键字,Exchange 根据这个关键字进行消息投递。

Producer/Publisher

消息生产者或发布者,产生消息的程序。

Consumer/Subscriber

消息消费者或订阅者,接收消息的程序。

Connection

生产者和消费者和 Broker 之间的连接,一个 Connection 实际上就对应着一条 TCP 连接。

Channel

由于 TCP 连接的创建和关闭开销非常大,如果每次访问 Broker 都建立一个 Connection,在消息量大的时候效率会非常低。Channel 是在 Connection 内部建立的逻辑连接,相当于一次会话,如果应用程序支持多线程,通常每个线程都会创建一个单独的 Channel 进行通讯,各个 Channel 之间完全隔离,但这些 Channel 可以公用一个 Connection。