zoukankan      html  css  js  c++  java
  • RabbitMQ集群搭建

    注意:集群控制台页面管理中,

    千!万!不!要!随便点击任何一个点的reset和集群reset!!

    这样在生产环境有一段时间内断开原有连接,无法连接丢失大量数据的危险!!

    注意:目前还没有做集群的镜像队列和负载均衡无镜像下队列、消息等只保存在集群单点,容易丢失数据!!

    掌握技术,考虑问题,要足够深入,细致,全面!!

    注意:目前单机版集群,重启机器后需要按下面的操作重新建立集群,且集群没有布置成服务,开机启动等。

    参考:

    单机集群:

    首先参考朱忠华的书里面,带插件的单机集群搭建、配置!!然后参照下面实际操作!!

    安装Java进行程序测试注意:在一个控制台Shell配置好java,source /etc/profile之后,再打开另一个控制台Shell,可能这个Shell还沿用旧的PATH路径配置,造成版本是java1.7,与程序版本不兼容。需要在这个Shell中再source /etc/profile一下!!

    注意安装配置Java时,Java路径要配在PATH所有路径的前面:export PATH=$JAVA_HOME/bin:$PATH,否则可能先找到其他路径下的Java,造成版本错误!! 

    下面链接的文章仅供参考,并没有按他的做法搭建成功(端口冲突启动失败了!!

    https://blog.csdn.net/Java_HuiLong/article/details/73718714

    需要注意的是Web管理插件端口及其他端口冲突问题!!

    https://blog.csdn.net/u013256816/article/details/53264715

    多机集群:https://blog.csdn.net/u013256816/article/details/53524766

    更改主机名:(需要修改完后重启Linux)

    https://blog.csdn.net/qi49125/article/details/77539913

    这样主机名确实永久改变了,然而rabbitmq识别的主机名仍然是localhost!所以下面的Clustering配置,

    @主机名,仍然要写localhost才能创建集群成功!!

    单机集群注意要点:

    1.rabbitmq识别的主机名仍然是localhost,所以要@localhost,如上所述

    2.配置完集群后,启动各节点的rabbitmq_management插件(前提是集群配置时该插件端口设置不冲突!),需要加上-n rabbit1@localhost这样的参数,并且需要在各自节点的sbin目录

    也就是节点目录要和-n rabbit1@localhost参数匹配,不能在这个节点目录配置启动另一个节点的插件!!而查看集群状态时则在任何一个节点的目录都行。

    3.集群创建用户,也要像2中一样,指定-n rabbit1@localhost这样的参数,才能创建成功。并且在一个节点上创建的用户,在其他节点上也有,无需挨个创建,这在各节点的控制台可以看到

    这里在任何一个节点目录创建均可,并且-n rabbit1@localhost参数不需要和节点目录对应,比如可以在节点3目录创建节点1的用户并赋予权限,3个节点均可共享,vhost配置可以在控制台直接设定

    发现集群控制台是单点登录的,一个节点的一个账号退出,其他节点同一个账号登录的均退出,都需要重新登录。

    实际操作:

    [root@node1 sbin]# pwd
    /usr/local/rabbitmq/sbin
    [root@node1 sbin]# RABBITMQ_NODE_PORT=5672 RABBITMQ_NODENAME=rabbit1 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15672}]" ./rabbitmq-server -detached
    Warning: PID file not written; -detached was passed.
    [root@node1 sbin]# cd /usr/local/rabbitmq2/sbin
    [root@node1 sbin]# RABBITMQ_NODE_PORT=5673 RABBITMQ_NODENAME=rabbit2 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}]" ./rabbitmq-server -detached
    Warning: PID file not written; -detached was passed.
    [root@node1 sbin]# cd /usr/local/rabbitmq3/sbin
    [root@node1 sbin]# RABBITMQ_NODE_PORT=5674 RABBITMQ_NODENAME=rabbit3 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15674}]" ./rabbitmq-server -detached
    Warning: PID file not written; -detached was passed.
    [root@node1 sbin]# cd /usr/local/rabbitmq2/sbin
    [root@node1 sbin]# ./rabbitmqctl -n rabbit2@node1 stop_app
    Stopping rabbit application on node rabbit2@node1
    Error: unable to connect to node rabbit2@node1: nodedown

    DIAGNOSTICS
    ===========

    attempted to contact: [rabbit2@node1]

    rabbit2@node1:
    * connected to epmd (port 4369) on node1
    * epmd reports node 'rabbit2' running on port 25673
    * TCP connection succeeded but Erlang distribution failed

    * Hostname mismatch: node "rabbit2@localhost" believes its host is different. Please ensure that hostnames resolve the same way locally and on "rabbit2@localhost"


    current node details:
    - node name: 'rabbitmq-cli-81@localhost'
    - home dir: /root
    - cookie hash: ct+K59z4oWF/n8u2DG4BFA==

    [root@node1 sbin]# ./rabbitmqctl -n rabbit2@localhost stop_app
    Stopping rabbit application on node rabbit2@localhost
    [root@node1 sbin]# hostname
    node1
    [root@node1 sbin]# ./rabbitmqctl -n rabbit2@localhost reset
    Resetting node rabbit2@localhost
    [root@node1 sbin]# ./rabbitmqctl -n rabbit2@localhost join_cluster rabbit1@localhost
    Clustering node rabbit2@localhost with rabbit1@localhost
    [root@node1 sbin]# ./rabbitmqctl -n rabbit2@localhost start_app
    Starting node rabbit2@localhost
    [root@node1 sbin]# cd /usr/local/rabbitmq3/sbin
    [root@node1 sbin]# ./rabbitmqctl -n rabbit3@localhost stop_app
    Stopping rabbit application on node rabbit3@localhost
    [root@node1 sbin]# ./rabbitmqctl -n rabbit3@localhost reset
    Resetting node rabbit3@localhost
    [root@node1 sbin]# ./rabbitmqctl -n rabbit3@localhost join_cluster rabbit1@localhost
    Clustering node rabbit3@localhost with rabbit1@localhost
    [root@node1 sbin]# ./rabbitmqctl -n rabbit3@localhost start_app
    Starting node rabbit3@localhost
    [root@node1 sbin]# cd /usr/local/rabbitmq/sbin
    [root@node1 sbin]# ./rabbitmqctl -n rabbit1@localhost cluster_status
    Cluster status of node rabbit1@localhost
    [{nodes,[{disc,[rabbit1@localhost,rabbit2@localhost,rabbit3@localhost]}]},
    {running_nodes,[rabbit3@localhost,rabbit2@localhost,rabbit1@localhost]},
    {cluster_name,<<"rabbit1@localhost">>},
    {partitions,[]},
    {alarms,[{rabbit3@localhost,[]},
    {rabbit2@localhost,[]},
    {rabbit1@localhost,[]}]}]
    [root@node1 sbin]# cd /usr/local/rabbitmq2/sbin
    [root@node1 sbin]# ./rabbitmqctl -n rabbit2@localhost cluster_status
    Cluster status of node rabbit2@localhost
    [{nodes,[{disc,[rabbit1@localhost,rabbit2@localhost,rabbit3@localhost]}]},
    {running_nodes,[rabbit3@localhost,rabbit1@localhost,rabbit2@localhost]},
    {cluster_name,<<"rabbit1@localhost">>},
    {partitions,[]},
    {alarms,[{rabbit3@localhost,[]},
    {rabbit1@localhost,[]},
    {rabbit2@localhost,[]}]}]
    [root@node1 sbin]# ./rabbitmqctl -n rabbit3@localhost cluster_status
    Cluster status of node rabbit3@localhost
    [{nodes,[{disc,[rabbit1@localhost,rabbit2@localhost,rabbit3@localhost]}]},
    {running_nodes,[rabbit1@localhost,rabbit2@localhost,rabbit3@localhost]},
    {cluster_name,<<"rabbit1@localhost">>},
    {partitions,[]},
    {alarms,[{rabbit1@localhost,[]},
    {rabbit2@localhost,[]},
    {rabbit3@localhost,[]}]}]
    [root@node1 sbin]# ps aux|grep rabbit
    root 62732 0.7 1.7 3885124 67080 ? Sl 09:31 0:05 /usr/local/lib/erlang/erts-8.3/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -root /usr/local/lib/erlang -progname erl -- -home /root -- -pa /usr/local/rabbitmq/ebin -noshell -noinput -s rabbit boot -sname rabbit1 -boot start_sasl -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"auto",5672}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,"/usr/local/rabbitmq/var/log/rabbitmq/rabbit1.log"} -rabbit sasl_error_logger {file,"/usr/local/rabbitmq/var/log/rabbitmq/rabbit1-sasl.log"} -rabbit enabled_plugins_file "/usr/local/rabbitmq/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/rabbitmq/plugins" -rabbit plugins_expand_dir "/usr/local/rabbitmq/var/lib/rabbitmq/mnesia/rabbit1-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/rabbitmq/var/lib/rabbitmq/mnesia/rabbit1" -rabbitmq_management listener [{port,15672}] -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672 -noshell -noinput
    root 62982 1.0 1.7 3889912 67172 ? Sl 09:32 0:06 /usr/local/lib/erlang/erts-8.3/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -root /usr/local/lib/erlang -progname erl -- -home /root -- -pa /usr/local/rabbitmq2/ebin -noshell -noinput -s rabbit boot -sname rabbit2 -boot start_sasl -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"auto",5673}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,"/usr/local/rabbitmq2/var/log/rabbitmq/rabbit2.log"} -rabbit sasl_error_logger {file,"/usr/local/rabbitmq2/var/log/rabbitmq/rabbit2-sasl.log"} -rabbit enabled_plugins_file "/usr/local/rabbitmq2/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/rabbitmq2/plugins" -rabbit plugins_expand_dir "/usr/local/rabbitmq2/var/lib/rabbitmq/mnesia/rabbit2-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/rabbitmq2/var/lib/rabbitmq/mnesia/rabbit2" -rabbitmq_management listener [{port,15673}] -kernel inet_dist_listen_min 25673 -kernel inet_dist_listen_max 25673 -noshell -noinput
    root 63229 1.1 1.6 3887096 64512 ? Sl 09:33 0:06 /usr/local/lib/erlang/erts-8.3/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -root /usr/local/lib/erlang -progname erl -- -home /root -- -pa /usr/local/rabbitmq3/ebin -noshell -noinput -s rabbit boot -sname rabbit3 -boot start_sasl -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"auto",5674}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,"/usr/local/rabbitmq3/var/log/rabbitmq/rabbit3.log"} -rabbit sasl_error_logger {file,"/usr/local/rabbitmq3/var/log/rabbitmq/rabbit3-sasl.log"} -rabbit enabled_plugins_file "/usr/local/rabbitmq3/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/rabbitmq3/plugins" -rabbit plugins_expand_dir "/usr/local/rabbitmq3/var/lib/rabbitmq/mnesia/rabbit3-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/rabbitmq3/var/lib/rabbitmq/mnesia/rabbit3" -rabbitmq_management listener [{port,15674}] -kernel inet_dist_listen_min 25674 -kernel inet_dist_listen_max 25674 -noshell -noinput
    root 65322 0.0 0.0 112648 980 pts/0 S+ 09:42 0:00 grep --color=auto rabbit
    [root@node1 sbin]# pwd
    /usr/local/rabbitmq2/sbin
    [root@node1 sbin]# ./rabbitmq-plugins enable rabbitmq_management
    The following plugins have been enabled:
    amqp_client
    cowlib
    cowboy
    rabbitmq_web_dispatch
    rabbitmq_management_agent
    rabbitmq_management

    Applying plugin configuration to rabbit@node1... failed.
    * Could not contact node rabbit@node1.
    Changes will take effect at broker restart.
    * Options: --online - fail if broker cannot be contacted.
    --offline - do not try to contact broker.
    [root@node1 sbin]# ./rabbitmq-plugins -n rabbit1@localhost enable rabbitmq_management
    Plugin configuration unchanged.

    Applying plugin configuration to rabbit1@localhost... failed.
    Error: {enabled_plugins_mismatch,"/usr/local/rabbitmq2/etc/rabbitmq/enabled_plugins",
    "/usr/local/rabbitmq/etc/rabbitmq/enabled_plugins"}
    [root@node1 sbin]# ./rabbitmq-plugins -n rabbit2@localhost enable rabbitmq_management
    Plugin configuration unchanged.

    Applying plugin configuration to rabbit2@localhost... started 6 plugins.
    [root@node1 sbin]# pwd
    /usr/local/rabbitmq2/sbin
    [root@node1 sbin]# cd /usr/local/rabbitmq/sbin
    [root@node1 sbin]# ./rabbitmq-plugins -n rabbit1@localhost enable rabbitmq_management
    The following plugins have been enabled:
    amqp_client
    cowlib
    cowboy
    rabbitmq_web_dispatch
    rabbitmq_management_agent
    rabbitmq_management

    Applying plugin configuration to rabbit1@localhost... started 6 plugins.
    [root@node1 sbin]# cd /usr/local/rabbitmq3/sbin
    [root@node1 sbin]# ./rabbitmq-plugins -n rabbit3@localhost enable rabbitmq_management
    The following plugins have been enabled:
    amqp_client
    cowlib
    cowboy
    rabbitmq_web_dispatch
    rabbitmq_management_agent
    rabbitmq_management

    Applying plugin configuration to rabbit3@localhost... started 6 plugins.

    [root@node1 sbin]# pwd
    /usr/local/rabbitmq3/sbin
    [root@node1 sbin]# ./rabbitmqctl add_user admin admin
    Error: unable to connect to node rabbit@node1: nodedown

    DIAGNOSTICS
    ===========

    attempted to contact: [rabbit@node1]

    rabbit@node1:
    * connected to epmd (port 4369) on node1
    * epmd reports: node 'rabbit' not running at all
    other nodes on node1: [rabbit1,rabbit2,rabbit3,
    'rabbitmq-cli-82']
    * suggestion: start the node

    current node details:
    - node name: 'rabbitmq-cli-82@localhost'
    - home dir: /root
    - cookie hash: ct+K59z4oWF/n8u2DG4BFA==

    [root@node1 sbin]# ./rabbitmqctl -n rabbit1@localhost add_user admin admin
    Creating user "admin"
    [root@node1 sbin]# ./rabbitmqctl -n rabbit1@localhost set_user_tags admin administrator
    Setting tags for user "admin" to [administrator]

    设置镜像队列

    注意:1.需要指定集群节点进行设置: -n rabbit2@localhost

    2.发现同一个镜像策略,在任何节点设置一次或多次都同步到所有节点

    3.高可用同步方式选择manual,不让新加入slave自动同步已有镜像,避免影响性能(同步时队列阻塞,且RabbitMQ集群并不能热扩展,新加入slave基本也是停机加入)

    4.镜像队列模式选择了在集群所有节点进行镜像

    5.正则匹配镜像所有队列--实际生产环境需要根据性能和业务重要性酌情选择!!

    实际操作:

    [root@node1 sbin]# pwd
    /usr/local/rabbitmq/sbin
    [root@node1 sbin]# ./rabbitmqctl set_policy --priority 0 --apply-to queues mirror_queue "[sS]*" '{"ha-mode":"all","ha-sync-mode":"manual"}'
    Error: unable to connect to node rabbit@node1: nodedown

    DIAGNOSTICS
    ===========

    attempted to contact: [rabbit@node1]

    rabbit@node1:
    * connected to epmd (port 4369) on node1
    * epmd reports: node 'rabbit' not running at all
    other nodes on node1: [rabbit1,rabbit2,rabbit3,
    'rabbitmq-cli-71']
    * suggestion: start the node

    current node details:
    - node name: 'rabbitmq-cli-71@localhost'
    - home dir: /root
    - cookie hash: ct+K59z4oWF/n8u2DG4BFA==

    [root@node1 sbin]# ./rabbitmqctl -n rabbit2@localhost set_policy --priority 0 --apply-to queues mirror_queue "[sS]*" '{"ha-mode":"all","ha-sync-mode":"manual"}'
    Setting policy "mirror_queue" for pattern "[\s\S]*" to "{"ha-mode":"all","ha-sync-mode":"manual"}" with priority "0"
    [root@node1 sbin]# ./rabbitmqctl -n rabbit1@localhost set_policy --priority 0 --apply-to queues mirror_queue "[sS]*" '{"ha-mode":"all","ha-sync-mode":"manual"}'
    Setting policy "mirror_queue" for pattern "[\s\S]*" to "{"ha-mode":"all","ha-sync-mode":"manual"}" with priority "0"
    [root@node1 sbin]# ./rabbitmqctl -n rabbit1@localhost set_policy --priority 0 --apply-to queues mirror_queue "[sS]*" '{"ha-mode":"all","ha-sync-mode":"manual"}'
    Setting policy "mirror_queue" for pattern "[\s\S]*" to "{"ha-mode":"all","ha-sync-mode":"manual"}" with priority "0"
    [root@node1 sbin]# ./rabbitmqctl -n rabbit3@localhost set_policy --priority 0 --apply-to queues mirror_queue "[sS]*" '{"ha-mode":"all","ha-sync-mode":"manual"}'
    Setting policy "mirror_queue" for pattern "[\s\S]*" to "{"ha-mode":"all","ha-sync-mode":"manual"}" with priority "0"

    关于正则:

    https://www.cnblogs.com/exmyth/p/7868582.html

    https://blog.csdn.net/lynn_coder/article/details/79502322

    https://zhidao.baidu.com/question/1447232660045793060.html

    常用正则:

    http://www.cnblogs.com/zxin/archive/2013/01/26/2877765.html

    rpm安装rabbitmq的一些冲突

    1.yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel安装时出现

    PackageKit-0.8.9-11.el7.x86_64 has missing requires of PackageKit-backend及另外一个依赖冲突,参考:

    https://www.cnblogs.com/stxs/p/9155858.html

    使用yum命令来安装或更新rpm和yum的依赖包。

    $ yum install yum-utils

    $ yum install yum-rhn-plugin

    $ yum update rpm-build

    $ yum update rpm-libs

    $ yum update rpm-python

    然后

    谷歌搜索PackageKit-0.8.9-11.el7.x86_64,在http://buildlogs-seed.centos.org/c7.00.02/PackageKit/20140529191922/0.8.9-11.el7.x86_64/ 找到了相应的rpm包。

    将rpm包下载下来后,用rpm命令一一安装。我这时想起来当时用rpm -qa|grep yum命令时有一条是PackageKit-yum*****,而我现在使用rpm -qa|grep yum所得到的结果没有PackageKit-yum*****了,我就尝试从这个网站上下载PackageKit-yum-0.8.9-11.el7.x86_64.rpm 和PackageKit-yum-plugin-0.8.9-11.el7.x86_64.rpm,使用rpm命令安装,发现安装了PackageKit-yum-0.8.9-11.el7.x86_64.rpm之后系统就不提示信息了,至此问题得到完满解决

    2.上面的问题解决后,出现Processing Conflict: initscripts-9.49.46-1.el7.x86_64 conflicts redhat-release < 7.5-0.11,解决:

    删除冲突的包即可
    rpm -e redhat-release-server-7.0-1.el7.x86_64 --nodeps

    参考

    http://blog.51cto.com/2484643/2140696

    http://www.mamicode.com/info-detail-2369782.html

    常用yum和rpm命令参考:

    http://blog.chinaunix.net/uid-24677087-id-3935161.html

    https://blog.csdn.net/wzyzzu/article/details/41250905

  • 相关阅读:
    Ext checkbox
    Ext4.1 grid 多选(可无checkbox)
    System.Web.HttpContext.Current.Session获取值出错
    Ext4.1 tree grid的右键菜单
    javascript innerHTML、outerHTML、innerText、outerText的区别
    EXT ajax简单实例
    C# 各版本更新简介
    C#与.Net Framework的各种版本和联系
    Ext4 简单的treepanel
    Ext4.1 Grid 分页查询
  • 原文地址:https://www.cnblogs.com/free-wings/p/10273067.html
Copyright © 2011-2022 走看看