微系列:6、在Centos系统中,搭建RabbitMQ集群

2023-01-09 18:54:16 浏览数 (1)

一、安装erlang

编辑/etc/yum.repos.d/rabbitmq_erlang.repo文件,配置yum源,如下

代码语言:javascript复制
[rabbitmq_erlang]
name=rabbitmq-rabbitmq-erlang
baseurl=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/rpm/el/7/$basearch
repo_gpgcheck=1
enabled=1
gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key
       https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
gpgcheck=1
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
pkg_gpgcheck=1
autorefresh=1
type=rpm-md

[rabbitmq_erlang-noarch]
name=rabbitmq-rabbitmq-erlang-noarch
baseurl=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/rpm/el/7/noarch
repo_gpgcheck=1
enabled=1
gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key
       https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
gpgcheck=1
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
pkg_gpgcheck=1
autorefresh=1
type=rpm-md

[rabbitmq_erlang-source]
name=rabbitmq-rabbitmq-erlang-source
baseurl=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/rpm/el/7/SRPMS
repo_gpgcheck=1
enabled=1
gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key
       https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
gpgcheck=1
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
pkg_gpgcheck=1
autorefresh=1
type=rpm-md

执行命令进行安装erlang

代码语言:javascript复制
yum update -y
yum install -y erlang-23.3.4

二、安装RabbitMQ

下载RabbitMQ包

代码语言:javascript复制
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.8/rabbitmq-server-3.8.8-1.el7.noarch.rpm
rpm –import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc

安装相关依赖

代码语言:javascript复制
yum install socat -y

安装RabbitMQ

代码语言:javascript复制
rpm -Uvh rabbitmq-server-3.8.8-1.el7.noarch.rpm

防火墙设置

代码语言:javascript复制
firewall-cmd --add-port=4369/tcp --permanent
firewall-cmd --add-port=5672/tcp --permanent
firewall-cmd --add-port=25672/tcp --permanent
firewall-cmd --add-port=5671-5672/tcp --permanent
firewall-cmd --add-port=15672/tcp --permanent
firewall-cmd --add-port=61613-61614/tcp --permanent
firewall-cmd --add-port=1883/tcp --permanent
firewall-cmd --add-port=8883/tcp --permanent

firewall-cmd --reload

三、配置RabbitMQ参数

配置host,执行vim /etc/hosts,写入以下内容,各个节点上一致

代码语言:javascript复制
192.168.0.1 node01
192.168.0.2 node02
192.168.0.3 node03

配置hostname(注意,每个节点不一样),执行vim /etc/hostname,写入以下内容

代码语言:javascript复制
node01

编辑网络配置文件,执行

代码语言:javascript复制
vim /etc/sysconfig/network
代码语言:javascript复制
NETWORKING=yes
HOSTNAME=node01

重启network

代码语言:javascript复制
systemctl restart network

配置erlang cookie,RabbitMQ 集群是基于erlang进行同步,cookie中各个节点内容一致

cookie所在文件/var/lib/rabbitmq/.erlang.cookie

四、启动节点

启动rabbitmq-server

代码语言:javascript复制
systemctl start rabbitmq-server

将其他节点加入集群 假设有01,02,03三个节点,在02,03节点上执行以下命令

代码语言:javascript复制
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@node01
rabbitmqctl start_app

查看集群状态

代码语言:javascript复制
rabbitmqctl cluster_status

五、设置RabbitMQ

添加vhost

代码语言:javascript复制
rabbitmqctl add_vhost cxt_local

创建用户

代码语言:javascript复制
rabbitmqctl add_user cxt_local password

设置用户角色

代码语言:javascript复制
rabbitmqctl set_user_tags cxt_local administrator

设置用户权限

代码语言:javascript复制
rabbitmqctl set_permissions -p cxt_local cxt_local ".*" ".*" ".*"

启用web界面

代码语言:javascript复制
rabbitmq-plugins enable rabbitmq_management

设置高可用模式 使用admin用户登录页面,设置User policies,将队列设置为HA模式,如下图

0 人点赞