RabbitMQ集群
1 IP规划
本示例中三台服务器信息如下:
主机名 | IP地址 |
---|---|
MQ01 | 192.168.11.20 |
MQ02 | 192.168.11.21 |
MQ03 | 192.168.11.22 |
2 软件包
rabbitmq.zip下载地址:
https://download.csdn.net/download/Zhuge_Dan/19875254
3 基础配置
操作设备:所有节点
3.1 关闭SELinux
[root@MQ01 ~]# setenforce 0
[root@MQ01 ~]# vi /etc/selinux/config
SELINUX=disabled #将SELINUX设置为disabled
[root@MQ01 ~]# getenforce
Permissive
3.2 关闭防火墙或开放需要的业务端口
[root@MQ01 ~]# systemctl stop firewalld #关闭防火墙
[root@MQ01 ~]# systemctl disable firewalld #禁止防火墙开机自启
3.3 调整max_open_files
[root@MQ01 ~]# echo '* soft nofile 65535' >> /etc/security/limits.conf
[root@MQ01 ~]# echo '* hard nofile 65535' >> /etc/security/limits.conf
[root@MQ01 ~]# cat /etc/security/limits.conf | tail -2
* soft nofile 65535
* hard nofile 65535
[root@MQ01 ~]# echo 'ulimit -SHn 65535' >> /etc/rc.d/rc.local
[root@MQ01 ~]# cat /etc/rc.d/rc.local | tail -1
ulimit -SHn 65535
[root@MQ01 ~]# chmod +x /etc/rc.d/rc.local #为rc.local增加可执行权限
3.4 重启检查SELinux、firewalld和open files
[root@MQ01 ~]# reboot
[root@MQ01 ~]# getenforce #查看SELinux是否关闭成功
Disabled #关闭成功
[root@MQ01 ~]# systemctl status firewalld #查看防火墙状态
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead) #防火墙已关闭
Docs: man:firewalld(1)
[root@MQ01 ~]# systemctl is-enabled firewalld #查看防火墙是否开机自启
disabled #防火墙已禁止开机自启
[root@MQ01 ~]# ulimit -a | grep open
open files (-n) 65535 #open files已调整为65535
3.5 安装配置OpenJDK1.8
参考文章:《CentOS 7安装配置OpenJDK1.8》
https://blog.csdn.net/Zhuge_Dan/article/details/117448760
4 集群搭建
4.1 hostname解析
操作设备:所有节点
RabbitMQ集群各节点通过hostname进行识别和加入集群,所以首先需要在3台服务器上配置hostname解析。
[root@MQ01 ~]# echo '192.168.11.20 MQ01' >> /etc/hosts
[root@MQ01 ~]# echo '192.168.11.21 MQ02' >> /etc/hosts
[root@MQ01 ~]# echo '192.168.11.22 MQ03' >> /etc/hosts
4.2 安装erlang环境
操作设备:所有节点
3台服务器分别进行RabbitMQ的初始化安装。
上传rabbitmq.zip目录到服务器,以上传到/usr/local/目录下为例。
首先安装erlang环境及其依赖包。
4.2.1 解压缩并编译安装erlang
[root@MQ01 ~]# rpm -ivh /usr/local/rabbitmq/erlang_dependents/*.rpm --force
警告:/usr/local/rabbitmq/erlang_dependents/erlang-asn1-R16B-03.18.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
准备中... ################################# [100%]
……
77:libselinux-python-2.5-14.1.el7 ################################# [ 99%]
78:libselinux-utils-2.5-14.1.el7 ################################# [100%]
[root@MQ01 ~]# cd /usr/local/rabbitmq/
[root@MQ01 rabbitmq]# tar -zxvf otp_src_21.1.tar.gz
otp_src_21.1/
otp_src_21.1/aclocal.m4
……
otp_src_21.1/xcomp/erl-xcomp-x86_64-saf-linux-gnu.conf
otp_src_21.1/xcomp/erl-xcomp.conf.template
[root@MQ01 rabbitmq]# cd otp_src_21.1
[root@MQ01 otp_src_21.1]# ./configure --prefix=/usr/local/erlang --with-ssl -enable-threads -enable-smmp-support -enable-kernel-poll --enable-hipe --without-javac
Ignoring the --cache-file argument since it can cause the system to be