centos7.7部署rabbitmq镜像模式集群

centos7.7部署rabbitmq镜像模式集群

部署前强烈建议先了解RabbitMQ的集群模式,以方便更好的部署,可参考如下地址:
https://blog.csdn.net/qq_35663625/article/details/106406351

基础环境:
IP地址主机名用途
10.0.1.209rabbitmq01磁盘节点
10.0.1.211rabbitmq02内存节点
操作部署:

1、修改hosts表(两台机器均执行)
添加两行,保证两台机器能互相ping通主机名

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.1.209  rabbitmq01
10.0.1.211  rabbitmq02

2、安装jdk(两台机器均执行)
可自行百度安装,版本可以是1.7或者1.8均可,略。。。

3、配置erlang环境(两台机器均执行)

# yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto perl wget libwxgtk* fop.noarch unixODBC.x86_64 unixODBC-devel.x86_64 gtk3-devel.x86_64
# cd /data/service
# tar xf otp_src_18.3.tar.gz         ##软件包可自行下载
# cd otp_src_18.3
# ./configure --prefix=/data/service/erlang

./configure 编译结尾位置会出现如下报错,可忽略,其他disable错误,需要解决

********************** APPLICATIONS INFORMATION *******************
wx : wxWidgets not found, wx will NOT be usable
********************** DOCUMENTATION INFORMATION ******************
documentation :
fop is missing.
Using fakefop to generate placeholder PDF files.

# make && make install
# vim /etc/profile                       ##添加系统环境变量
添加如下几行
 	#set erlang environment
	ERL_HOME=/data/service/erlang
	PATH=$ERL_HOME/bin:$PATH
	export PATH
# source /etc/profile    
# erl                                    ###验证是否安装成功
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V7.3  (abort with ^G)
1>

4、安装rabbitmq(两台机器均执行

# cd /data/service/
# tar xf rabbitmq-server-generic-unix-3.6.1.tar
# mv rabbitmq_server-3.6.1/ rabbitmq
# cd rabbitmq/sbin
# ./rabbitmq-server -detached                     ##启动rabbitmq
Warning: PID file not written; -detached was passed.
# ps -ef | grep rabbitmq
# ./rabbitmq-plugins enable rabbitmq_management       ##启动rabbitmq页面管理
The following plugins have been enabled:
  mochiweb
  webmachine
  rabbitmq_web_dispatch
  amqp_client
  rabbitmq_management_agent
  rabbitmq_management

Applying plugin configuration to rabbit@rabbitmq01... started 6 plugins.

5、同步rabbitmq01机器的.erlang.cookie文件到rabbitmq02,保证两台机器互相通信,.erlang.cookie文件一般位于$HOME下

# scp /root/.erlang.cookie root@10.0.1.211:/root/

当然,这里也可以根据自己的情况,将文件内容复制粘贴到rabbitmq02

6、rabbitmq02加入集群rabbitmq01(在rabbitmq02机器执行)

# cd /data/service/rabbitmq/sbin
# ./rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq02 ...
[{nodes,[{disc,[rabbit@rabbitmq02]}]},
 {running_nodes,[rabbit@rabbitmq02]},
 {cluster_name,<<"rabbit@rabbitmq02">>},
 {partitions,[]},
 {alarms,[{rabbit@rabbitmq02,[]}]}]
# ./rabbitmqctl stop_app
Stopping node rabbit@rabbitmq02 ...
# ./rabbitmqctl reset
Resetting node rabbit@rabbitmq02 ...
# ./rabbitmqctl join_cluster rabbit@rabbitmq01 --ram     ##加--ram表示为内存节点,不加默认为磁盘节点          
Clustering node rabbit@rabbitmq02 with rabbit@rabbitmq01 ...
# ./rabbitmqctl start_app
Starting node rabbit@rabbitmq02 ...

查看集群状态: ./rabbitmqctl cluster_status
停止rabbitmq上的应用:./rabbitmqctl stop_app
重置rabbitmq:./rabbitmqctl reset
加入集群:./rabbitmqctl join_cluster rabbit@rabbitmq01 --ram
启动rabbitmq上的应用:./rabbitmqctl start_app

附加:
自定义集群名: ./rabbitmqctl set_cluster_name rabbit@cluster_name

7、验证是否加入集群(在rabbitmq01机器执行)

# cd /data/service/rabbitmq/sbin
# ./rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq01 ...
[{nodes,[{disc,[rabbit@rabbitmq01]},{ram,[rabbit@rabbitmq02]}]},
 {running_nodes,[rabbit@rabbitmq01]},
 {cluster_name,<<"rabbit@rabbitmq01">>},
 {partitions,[]},
 {alarms,[{rabbit@rabbitmq01,[]}]}]

8、新建用户、用户授权、虚拟主机等配置(在rabbitmq01机器执行)

# ./rabbitmqctl add_user test test
Creating user "test" ...
# ./rabbitmqctl add_vhost /test
Creating vhost "/test" ...
# ./rabbitmqctl set_permissions -p /test test  ".*" ".*" ".*"
Setting permissions for user "test" in vhost "/test" ...
# ./rabbitmqctl set_user_tags test administrator
Setting tags for user "test" to [administrator] ...
# ./rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq01 ...
[{nodes,[{disc,[rabbit@rabbitmq01]}]},
 {running_nodes,[rabbit@rabbitmq01]},
 {cluster_name,<<"rabbit@rabbitmq01">>},
 {partitions,[]},
 {alarms,[{rabbit@rabbitmq01,[]}]}]
# ./rabbitmqctl list_users
Listing users ...
test	[administrator]
guest	[administrator]
# ./rabbitmqctl list_vhosts
Listing vhosts ...
/test
/

可以在rabbitmq02机器验证信息是否同步
创建用户:./rabbitmqctl add_user test test
创建虚拟空间:./rabbitmqctl add_vhost /test
用户空间授权:./rabbitmqctl set_permissions -p /test test “." ".” “.*”
.*表示授予所有权限
设置用户tag为administrator最高权限: ./rabbitmqctl set_user_tags test administrator
查看所有用户:./rabbitmqctl list_users
查看所有虚拟空间:./rabbitmqctl list_vhosts

9、部署镜像模式(在rabbitmq01机器执行),只有设置policy策略才能算得上是镜像模式,1-8步配置的是普通模式

# ./rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'
Setting policy "ha-all" for pattern "^" to "{\"ha-mode\":\"all\"}" with priority "0" ...
# ./rabbitmqctl set_policy -p /test ha-allqueue "^rqmessage" '{"ha-mode":"all"}'
Setting policy "ha-allqueue" for pattern "^rqmessage" to "{\"ha-mode\":\"all\"}" with priority "0" ...

rabbitmqctl set_policy ha-all “^” ‘{“ha-mode”:“all”}’ 表示同步所以的队列消息
rabbitmqctl set_policy -p /test ha-allqueue “^rqmessage” ‘{“ha-mode”:“all”}’ 表示同步以rqmessage开头的消息

10、打开浏览器,输入 IP:15672
账号密码 test/test
在这里插入图片描述

好了,这就是rabbitmq集群的部署方法了,如有问题可与博主一起交流讨论!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值