centos7.8环境安装rabbitmq3.8.5最新版并设置集群

centos7.8环境安装rabbitmq3.8.5最新版并设置集群

 

一、编译安装,单机设置
#1.增加用户
groupadd rabbitmq
useradd rabbitmq -g rabbitmq -s /sbin/nologin

#2.安装必须编译基础包
yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

#3.安装socat
yum install socat -y
yum install wxWidgets* -y
yum install gtk+.x86_64 -y

#4.环境变量,否则编译erlang可能会有问题
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/libexec/wxGTK3

#5.下载ERLANG源码包
wget http://erlang.org/download/otp_src_19.0.tar.gz(可不下载)
wget https://erlang.org/download/otp_src_22.1.tar.gz
wget https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.3/wxWidgets-3.1.3.tar.bz2(可不下载)

#6.解压并安装(低版本)
mkdir -p /usr/local/erlang
tar xvf otp_src_19.0.tar.gz
cd otp_src_19.0
./configure --prefix=/usr/local/erlang --with-ssl --enable-threads --enable-smmp-support -enable-kernel-poll --enable-hipe --without-javac
make && make install

#6.解压并安装(高版本)
mkdir -p /usr/local/erlang
tar xvf otp_src_22.1.tar.gz
cd otp_src_22.1
./configure --prefix=/usr/local/erlang --with-ssl=/usr/local/lab/openssl --enable-threads --enable-smmp-support -enable-kernel-poll --enable-hipe --without-javac
make && make install

#7.解压并安装(由于是通过yum安装,无需执行,如果是编译安装可以按照下面方法)
bzip2 -d wxWidgets-3.1.3.tar.bz2
tar xvf wxWidgets-3.1.3.tar
cd wxWidgets-3.1.3
./configure --with-opengl --enable-debug --enable-unicode

#8.修改环境变量
vi /etc/profile
ERLANG_HOME=/usr/local/erlang
PATH=$ERLANG_HOME/bin:$PATH
export ERLANG_HOME
export PATH

#9.生效环境变量
source /etc/profile

#10.测试是否支持ERLANG语言,输入erl后会弹出提示 按CTRL+C 退出
erl

#11. 安装simpleJson
wget https://github.com/simplejson/simplejson/releases/download/v3.16.1/simplejson-3.16.1.tar.gz
tar zxvf simplejson-3.16.1.tar.gz
cd simplejson-3.16.1
python setup.py install

#12.下载rabbitmq二进制免编译包(最新版本)
cd /usr/local/src
wget wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.5/rabbitmq-server-generic-unix-3.8.5.tar.xz


#12.下载rabbitmq二进制免编译包
cd /usr/local/src
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-generic-unix-3.6.10.tar.xz

#13.解压并安装
xz -d rabbitmq-server-generic-unix-3.8.5.tar.xz
tar xvf rabbitmq-server-generic-unix-3.8.5.tar
mv rabbitmq_server-3.8.5 /usr/local
cd /usr/local/
ln -s rrabbitmq_server-3.8.5 rabbitmq
cd ./rabbitmq/sbin/

#14.修改/etc/profile文件,添加下面的环境变量:
export PATH=$PATH:/usr/local/rabbitmq/sbin
执行source /etc/profile让文件生效。


#15.设置开启自启脚本
chown -R rabbitmq.rabbitmq rabbitmq_server-3.8.5

添加 source /etc/profile 否则可能提示erl无法找到
vi /usr/local/rabbitmq/sbin/rabbitmq-env
source /etc/profile


/usr/local/rabbitmq/var/log/rabbitmq/[email protected]


# cat ~/.erlang.cookie
QBISJBZGKYVFNASJQWDQ

注意 .erlang.cookie 文件在/home/rabbitmq 下,因通过rabbitmq账户去启动,并且/root/下的 .erlang.cookie值要和/home/rabbitmq 下的文件值保持一致,否则集群无法启动

# 启动管理程序

cat /usr/lib/systemd/system/rabbitmq-server.service

[Unit]
Description=RabbitMQ broker
After=syslog.target network.target

[Service]
Type=notify
User=rabbitmq
Group=rabbitmq
UMask=0027
NotifyAccess=all
TimeoutStartSec=3600

# To override LimitNOFILE, create the following file:
#
# /etc/systemd/system/rabbitmq-server.service.d/limits.conf
#
# with the following content:
#
# [Service]
# LimitNOFILE=65536

LimitNOFILE=32768

# Note: systemd on CentOS 7 complains about in-line comments,
# so only append them here
#
# Restart:
# The following setting will automatically restart RabbitMQ
# in the event of a failure. systemd service restarts are not a
# replacement for service monitoring. Please see
# https://www.rabbitmq.com/monitoring.html
Restart=on-failure
RestartSec=10
WorkingDirectory=/usr/local/rabbitmq/var/lib/rabbitmq
ExecStart=/usr/local/rabbitmq/sbin/rabbitmq-server
ExecStop=/usr/local/rabbitmq/sbin/rabbitmqctl shutdown
# See rabbitmq/rabbitmq-server-release#51
SuccessExitStatus=69

[Install]
WantedBy=multi-user.target

# 无法启动的原因可能是日志使用rabbitmq用户没有权限

chown -R rabbitmq.rabbitmq /usr/local/rabbitmq_server-3.8.5


#15.启动rabbitMQ
systemctl start rabbitmq-server.service

#15.启动rabbitMQ(可选,但是最好不要这样启动)
rabbitmq-server

#15.后台运行服务(可选,但是最好不要这样启动)
rabbitmq-server -detached

#16.设置开机自启
systemctl enable rabbitmq-server.service

#17.关闭rabbitMQ
systemctl stop rabbitmq-server.service

#17.关闭rabbitMQ
rabbitmqctl stop

#18.安装web界面扩展
rabbitmq-plugins enable rabbitmq_management

#19.添加用户
rabbitmqctl add_user admin pass

#20.列出用户
rabbitmqctl  list_users

#21.将admin指定为管理员权限
rabbitmqctl set_user_tags admin administrator

#22.删除来宾用户
rabbitmqctl delete_user guest

#23.安装成功,访问如下地址
http://192.168.101.21:15672/

二.加入集群
#1.修改 /etc/hosts
# rabbitmq cluster
172.30.0.1 eus-video-compose01
172.30.0.2 eus-video-compose02

#2.设置 Erlang Cookie,路径为/home/rabbitmq/.erlang.cookie,这里将 eus-video-compose01 的该文件复制到 eus-video-compose02,由于这个文件权限是 400,所以需要先修改 eus-video-compose02,中的该文件权限为 777,然后将 node1 中的该文件拷贝到 node2,最后将权限和所属用户/组修改回来
chown rabbitmq /home/rabbitmq/.erlang.cookie
chgrp rabbitmq /home/rabbitmq/.erlang.cookie

也可以直接复制里面的内容,让两台机器的 .erlang.cookie 内容保持一致

#3.使用 -detached 参数运行各节点
systemctl stop rabbitmq-server.service  #推荐
rabbitmqctl stop                        #不推荐

systemctl start rabbitmq-server.service  #推荐
rabbitmq-server -detached               #不推荐

#4.组成集群,注意防火墙开启4637端口,在eus-video-compose01上执行
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@eus-video-compose02
[root@eus-video-compose01:~]# rabbitmqctl join_cluster rabbit@eus-video-compose02
Clustering node rabbit@eus-video-compose01 with rabbit@eus-video-compose02
rabbitmqctl start_app

#5.如果要使用内存节点,则可以使用下面的命令加入集群。
rabbitmqctl join_cluster *--ram* rabbit@rabbitmq_02

设置镜像集群模式:
#6.设置镜像队列策略,在任意一个节点上执行下面的命令,将所有队列设置为镜像队列,即队列会被复制到各个节点,各个节点状态保持一直
rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'


[root@eus-video-compose01:~]# rabbitmqctl list_policies
Listing policies for vhost "/" ...

[root@eus-video-compose01:~]# rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'
Setting policy "ha-all" for pattern "^" to "{"ha-mode":"all"}" with priority "0" for vhost "/" ...
[root@eus-video-compose01:~]# rabbitmqctl list_policies
Listing policies for vhost "/" ...
vhost    name    pattern    apply-to    definition    priority
/    ha-all    ^    all    {"ha-mode":"all"}    0


[root@eus-video-compose02:/usr/local]# rabbitmqctl list_policies
Listing policies for vhost "/" ...
vhost   name    pattern apply-to        definition      priority
/       ha-all  ^       all     {"ha-mode":"all"}       0



查看集群状态:
# rabbitmqctl cluster_status

 

你可能感兴趣的:(centos7.8环境安装rabbitmq3.8.5最新版并设置集群)