CentOS7安装及搭建RabbitMQ集群
rabbitmq3.3.5
官网下载地址 https://www.rabbitmq.com/download.html
centos提供的下载地址 https://cbs.centos.org/kojifiles/packages/rabbitmq-server/3.3.5/6.el7/noarch/rabbitmq-server-3.3.5-6.el7.noarch.rpm
(引用 https://cbs.centos.org/koji/buildinfo?buildID=4739)
github提供的下载地址 https://github.com/rabbitmq/rabbitmq-server/releases/tag
注意:RabbitMQ需要erlang环境,Erlang和RabbitMQ对应版本(https://www.rabbitmq.com/which-erlang.html),注意有最大和最小版本要求。
建议erlang通过系统安装,用yum install erlang查看其版本,如我本机R14B-04.3.el6 (erlang.x86_64 0:R16B-03.18.el7)适合的MQ版本为3.5.x
# 添加镜像源(非必须) wget -O /etc/yum.repos.d/epel-erlang.repo http://repos.fedorapeople.org/repos/peter/erlang/epel-erlang.repo yum -y update # epel-release.noarch 0:7-13 yum -y install epel-release sudo yum -y install lrzsz pcre pcre-devel openssl openssl-devel zlib zlib-devel axel telnet # erlang.x86_64 0:R16B-03.18.el7 的安装 yum install erlang -y # 测试erlang是否安装成功 执行 erl wget https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v3_6_14/rabbitmq-server-3.6.14-1.el7.noarch.rpm yum install socat -y rpm -ivh rabbitmq-server-3.6.14-1.el7.noarch.rpm
单机模式
-- 查看是否启动
ps -ef|grep rabbitmq
/sbin/service rabbitmq-server status #状态
/sbin/service rabbitmq-server start #启动
/sbin/service rabbitmq-server stop #关闭
/sbin/service rabbitmq-server restart #重启
-- 执行添加用户命令
rabbitmqctl add_user root 1qaz@WSX
-- 执行设置权限命令
rabbitmqctl set_permissions -p / root ".*" ".*" ".*"
-- 执行设置角色命令
rabbitmqctl set_user_tags root administrator
-- 执行查看用户命令
rabbitmqctl list_users
-- rabbitmq开启web管理后台(rabbitmq自带管理后台,安装后需要配置开启,进入rabbitmq安装目录中的sbin目录执行)
rabbitmq-plugins enable rabbitmq_management
测试是否开启成功: curl -i -k 127.0.0.1:15672 如果返回一个html页面数据,表示配置ok
链接 http://IP:15672/
出现错误:Error: unable to connect to node rabbit@iZj6cgwpv82s1jrkhgmwcaZ: nodedown /sbin/service rabbitmq-server stop /sbin/service rabbitmq-server start rabbitmqctl status
下面的命令好像有问题
状态 rabbitmqctl status
停止 rabbitmqctl stop_app
启动 rabbitmqctl start_app
-- 最简配置 vi /etc/rabbitmq/rabbitmq.config [ {rabbit, [ {default_user, <<"guest">>}, {default_pass, <<"guest">>}, {loopback_users, []}, {cluster_partition_handling, autoheal}, {rabbit, [{tcp_listeners, [5672]}, {loopback_users, ["lyh"]}]} ]}, {kernel, [ net_ticktime,40} ]} ].
集群模式
-- 假设三台节点IP为
172.16.0.10
172.16.0.11
172.16.0.12
-- 配置本地 /etc/hosts(三个节点同步执行)
echo "
47.56.14.178 rabbitmq-node1
47.75.105.113 rabbitmq-node2
47.75.126.92 rabbitmq-node3" >> /etc/hosts
-- 加入配置文件(三个节点同步执行)
vim /etc/rabbitmq/rabbitmq.config
%% -*- mode: erlang -*- [ { rabbit,[ {tcp_listeners, [5672]}, {num_tcp_acceptors, 10}, {handshake_timeout, 10000}, {log_levels, [{connection, info}, {channel, info}]}, {loopback_users, []}, {default_vhost, <<"/">>}, {default_user, <<"root">>}, {default_pass, <<"1qaz@WSX">>}, {default_permissions, [<<".*">>, <<".*">>, <<".*">>]}, {default_user_tags, [administrator]}, {heartbeat, 60}, {cluster_partition_handling, autoheal} ] }, { kernel,[] }, { rabbitmq_management,[ {listener, [{port, 15672}]} ] }, { rabbitmq_management_agent,[] }, { rabbitmq_shovel,[ {shovels,[]} ] }, { rabbitmq_stomp,[] }, { rabbitmq_mqtt,[] }, { rabbitmq_amqp1_0,[] }, { rabbitmq_auth_backend_ldap,[] } ].
web访问页面 http://xx.xx.xx.xx:15672/