外包精通--RabbitMQ源码包集群部署(最新版本)

2023-07-31 19:33:33 浏览数 (2)

部署环境

服务器信息

服务器分别命名master, node01, node02

Server

ip

OS

master

192.168.2.130

CentOS Linux release 7.9.2009 (Core)

node01

192.168.2.208

CentOS Linux release 7.9.2009 (Core)

node02

192.168.2.126

CentOS Linux release 7.9.2009 (Core)

rabbitmq最新版本

Package

Version

openssl

openssl-1.1.1s.tar.gz

erlang

otp_src_25.1.2.tar.gz

rabbitmq

rabbitmq-server-generic-unix-3.11.4.tar.xz

rabbitmq官网下载Generic Binary Build ("Generic UNIX Build") — RabbitMQ

erlang官网下载Downloads - Erlang/OTP

rabbitmq-github地址

erlang-github地址

RabbitMQ是采用 Erlang语言开发的,所以系统环境必须提供 Erlang环境,需要是安装 Erlangerlang版本校验

设置Hostname

下面很多地方会用到hostname来标识节点名称,所以在每台服务器上配置一下hosts

Tip

操作机器:rabbitmq所有节点

代码语言:txt复制
hostnamectl set-hostname node02
rabbitmq1=192.168.2.159
node01=192.168.2.208
node02=192.168.2.126

cat << EOF >> /etc/hosts
$master    master
$node01    node01
$node02    node02
EOF

cat /etc/hosts

编译erlang

安装编译依赖

Tip

操作机器:rabbitmq所有节点

代码语言:txt复制
yum install -y gcc gcc-c   unixODBC-devel  openssl-devel ncurses-devel socat logrotate perl-perl5i

编译openssl

tip

操作机器:rabbitmq所有节点

代码语言:txt复制
mkdir -pv /opt/openssl
mkdir -pv /opt/erlang
代码语言:txt复制
[root@master opt]# mkdir openssl
[root@kmaster opt]# cd openssl-1.1.1s/
[root@kmaster openssl-1.1.1s]# ./config --prefix=/opt/openssl
Operating system: x86_64-whatever-linux2
Configuring OpenSSL version 1.1.1s (0x1010113fL) for linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************
[root@kmaster openssl-1.1.1s]# make && make install 

编译erlang

Tip:

rabbitmq插件启用失败

代码语言:txt复制
./configure --prefix=/opt/erlang --with-ssl=/opt/openssl --enable-threads --enable-smp-support --enable-kernel-poll --enable-hipe --without-javac
代码语言:txt复制
[root@master otp_src_25.1.2]# cd /opt/otp_src_25.1.2/
[root@master otp_src_25.1.2]# 
[root@master otp_src_25.1.2]# ./configure --prefix=/opt/erlang --with-ssl=/opt/openssl  --without-javac
[root@master otp_src_25.1.2]#
[root@master otp_src_25.1.2]# make && make install

安装rabbitmq

解压rabbitmq

操作机器:rabbitmq所有节点

代码语言:txt复制
[root@kmaster ~]# cd mq/
[root@kmaster mq]# tar xf rabbitmq-server-generic-unix-3.11.4.tar.xz -C /opt/
[root@kmaster mq]# 

配置环境变量

操作机器:rabbitmq所有节点

代码语言:txt复制
export MQROOT=/var/lib/rabbitmq
export OPENSSL=/opt/openssl
export ERLANG=/opt/erlang
export PATH=$PATH:$ERLANG/bin:$MQROOT/sbin:$OPENSSL

Tip:

确认环境变量生效及配置过程

代码语言:txt复制
[root@kmaster lib]# cd /var/lib
[root@kmaster lib]# ln -sv rabbitmq_server-3.11.4/ rabbitmq               
'rabbitmq' -> 'rabbitmq_server-3.11.4/'
[root@kmaster opt]#
[root@kmaster mq]# echo 'export PATH=/opt/rabbitmq/sbin:$PATH'>> /etc/profile
[root@kmaster mq]# source /etc/profile
[root@kmaster opt]# which rabbitmqctl
/opt/rabbitmq/sbin/rabbitmqctl
[root@kmaster opt]#

rabbitmq-plugins

操作机器:rabbitmq所有节点

代码语言:txt复制
[root@localhost otp_src_25.1.2]# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@master:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@master...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

set 3 plugins.
Offline change; changes will take effect at broker restart.
[root@localhost otp_src_25.1.2]# rabbitmq-server -detached
[root@localhost otp_src_25.1.2]# 

启动rabbitmq

操作机器:rabbitmq所有节点

代码语言:txt复制
2022-12-08 18:17:57.728479 08:00 [notice] <0.44.0> Application syslog exited with reason: stopped
2022-12-08 18:17:57.754674 08:00 [notice] <0.229.0> Logging: switching to configured handler(s); following messages may not be visible in this log output
2022-12-08 18:17:57.790109 08:00 [notice] <0.229.0> Logging: configured log handlers are now ACTIVE
2022-12-08 18:18:06.543424 08:00 [info] <0.229.0> ra: starting system quorum_queues
2022-12-08 18:18:06.543548 08:00 [info] <0.229.0> starting Ra system: quorum_queues in directory: /var/lib/rabbitmq/var/lib/rabbitmq/mnesia/rabbit@master/quorum/rabbit@master
2022-12-08 18:18:06.546629 08:00 [info] <0.294.0> ra system 'quorum_queues' running pre init for 0 registered servers
2022-12-08 18:18:06.549109 08:00 [info] <0.297.0> ra: meta data store initialised for system quorum_queues. 0 record(s) recovered
2022-12-08 18:18:06.549450 08:00 [notice] <0.308.0> WAL: ra_log_wal init, open tbls: ra_log_open_mem_tables, closed tbls: ra_log_closed_mem_tables
2022-12-08 18:18:06.554153 08:00 [info] <0.229.0> ra: starting system coordination
2022-12-08 18:18:06.554235 08:00 [info] <0.229.0> starting Ra system: coordination in directory: /var/lib/rabbitmq/var/lib/rabbitmq/mnesia/rabbit@master/coordination/rabbit@master
2022-12-08 18:18:06.556419 08:00 [info] <0.326.0> ra system 'coordination' running pre init for 0 registered servers
2022-12-08 18:18:06.558560 08:00 [info] <0.330.0> ra: meta data store initialised for system coordination. 0 record(s) recovered
2022-12-08 18:18:06.558877 08:00 [notice] <0.342.0> WAL: ra_coordination_log_wal init, open tbls: ra_coordination_log_open_mem_tables, closed tbls: ra_coordination_log_closed_mem_tables
2022-12-08 18:18:06.565926 08:00 [info] <0.229.0>
2022-12-08 18:18:06.565926 08:00 [info] <0.229.0>  Starting RabbitMQ 3.11.4 on Erlang 25.1.2 [emu]
2022-12-08 18:18:06.565926 08:00 [info] <0.229.0>  Copyright (c) 2007-2022 VMware, Inc. or its affiliates.
2022-12-08 18:18:06.565926 08:00 [info] <0.229.0>  Licensed under the MPL 2.0. Website: https://rabbitmq.com

  ##  ##      RabbitMQ 3.11.4
  ##  ##
  ##########  Copyright (c) 2007-2022 VMware, Inc. or its affiliates.
  ######  ##
  ##########  Licensed under the MPL 2.0. Website: https://rabbitmq.com

  Erlang:      25.1.2 [emu]
  TLS Library: OpenSSL - OpenSSL 1.1.1s  1 Nov 2022
  Release series support status: supported

  Doc guides:  https://rabbitmq.com/documentation.html
  Support:     https://rabbitmq.com/contact.html
  Tutorials:   https://rabbitmq.com/getstarted.html
  Monitoring:  https://rabbitmq.com/monitoring.html

  Logs: /var/lib/rabbitmq/var/log/rabbitmq/rabbit@master_upgrade.log
        <stdout>

  Config file(s): /var/lib/rabbitmq/etc/rabbitmq/rabbitmq.conf

  Starting broker...2022-12-08 18:18:06.570890 08:00 [info] <0.229.0>
2022-12-08 18:18:06.570890 08:00 [info] <0.229.0>  node           : rabbit@master
2022-12-08 18:18:06.570890 08:00 [info] <0.229.0>  home dir       : /root
2022-12-08 18:18:06.570890 08:00 [info] <0.229.0>  config file(s) : /var/lib/rabbitmq/etc/rabbitmq/rabbitmq.conf
2022-12-08 18:18:06.570890 08:00 [info] <0.229.0>  cookie hash    : x2o a5 vTFdpx3wYvFlUnQ==
2022-12-08 18:18:06.570890 08:00 [info] <0.229.0>  log(s)         : /var/lib/rabbitmq/var/log/rabbitmq/rabbit@master_upgrade.log
2022-12-08 18:18:06.570890 08:00 [info] <0.229.0>                 : <stdout>
2022-12-08 18:18:06.570890 08:00 [info] <0.229.0>  database dir   : /var/lib/rabbitmq/var/lib/rabbitmq/mnesia/rabbit@master
2022-12-08 18:18:07.331229 08:00 [info] <0.229.0> Running boot step pre_boot defined by app rabbit
2022-12-08 18:18:07.331489 08:00 [info] <0.229.0> Running boot step rabbit_global_counters defined by app rabbit
2022-12-08 18:18:07.331750 08:00 [info] <0.229.0> Running boot step rabbit_osiris_metrics defined by app rabbit
2022-12-08 18:18:07.331866 08:00 [info] <0.229.0> Running boot step rabbit_core_metrics defined by app rabbit
2022-12-08 18:18:07.335610 08:00 [info] <0.229.0> Running boot step rabbit_alarm defined by app rabbit

相关错误参考链接

Rabbitmq常用命令

操作机器:rabbitmq所有节点

代码语言:txt复制
[root@localhost otp_src_25.1.2]# rabbitmqctl add_user 27ops KJH9238hasdkhIWh
Adding user "27ops" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
[root@localhost otp_src_25.1.2]# rabbitmqctl set_user_tags 27ops
Setting tags for user "27ops" to [] ...
[root@localhost otp_src_25.1.2]#
[root@localhost otp_src_25.1.2]#
[root@localhost otp_src_25.1.2]# rabbitmqctl set_permissions -p / 27ops ".*" ".*" ".*"
Setting permissions for user "27ops" in vhost "/" ...
[root@localhost otp_src_25.1.2]#
[root@localhost otp_src_25.1.2]# rabbitmqctl list_users
Listing users ...
user    tags
27ops   []
guest   [administrator]
[root@localhost otp_src_25.1.2]# rabbitmqctl set_user_tags 27ops administrator
Setting tags for user "27ops" to [administrator] ...
[root@localhost otp_src_25.1.2]#

部署集群相关操作

代码语言:txt复制
rabbitmq-plugins enable rabbitmq_management
rabbitmq-server -detached 
rabbitmqctl add_user 27ops KJH9238hasdkhIWh     
rabbitmqctl set_user_tags 27ops administrator
rabbitmqctl set_permissions -p / 27ops ".*" ".*" ".*"
more .erlang.cookie
rabbitmqctl stop_app 
rabbitmqctl reset 
rabbitmqctl join_cluster rabbit@master
rabbitmqctl start_app

rabbitmq-server restart

Synchronised mirros:rabbit@
Synchronised mirros:rabbit@需要以下步骤:
    新增一个ha-all Policy
    Policy: ha-all
    Overview
    Pattern    ^
    Apply to    all
    Definition    
    ha-mode:    all
    Priority    0

rabbitmqctl官网学习

RabbitMQ集群部署

代码语言:txt复制
chown rabbitmq:rabbitmq .erlang.cookie
chmod 400 .erlang.cookie
mv -f .erlang.cookie /var/lib/rabbitmq/

加入集群命令

操作机器:rabbitmq剩余两台机器

代码语言:txt复制
[root@node01 ~]# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@node01 ...
[root@node01 ~]# rabbitmqctl reset
Resetting node rabbit@node01 ...
[root@node01 ~]# rabbitmqctl join_cluster rabbit@master
Clustering node rabbit@node01 with rabbit@master
[root@node01 ~]# rabbitmqctl start_app
Starting node rabbit@node01 ...
[root@node01 ~]# 

RabbitMQ rpm包集群部署

rpm官网地址

0 人点赞