RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件)。RabbitMQ服务器是用Erlang语言编写的,而集群和故障转移是构建在开放电信平台框架上的。所有主要的编程语言均有与代理接口通讯的客户端库。
实验环境
centos7_x64
rabbitmq_server mq1 192.168.10.17
rabbitmq_slave mq2 192.168.10.19
4369 erlang发现
5672 client端通信口
25672 server间内部通信口
15672 管理界面ui端口
实验软件
otp_src_22.1.tar.gz
rabbitmq-server-generic-unix-3.8.0.tar
软件安装
sed -i.bak 's/https/http/g' /etc/yum.repos.d/epel.repo
systemctl stop firewalld.service && systemctl disable firewalld.service
cp -pv /etc/hosts /etc/hosts.bak
cat /etc/hosts | grep mq1
192.168.10.17 mq1
192.168.10.19 mq2 mq1/mq2操作
hostnamectl set-hostname mq1/mq2 mq1/mq2操作
scp -p /etc/hosts [email protected]:/etc/
reboot/init6 重启系统生效 mq1/mq2操作
yum install -y gcc gcc-c++ glibc-devel make ncurses-devel redhat-lsb
yum install -y openssl-devel autoconf java-1.8.0-openjdk-devel git mq1/mq2操作
tar zxvf /root/otp_src_22.1.tar.gz
cd /root/otp_src_22.1
./configure && make -j6 && make install
openssl version -a
OpenSSL 1.0.2k-fips
erl --version
Eshell V10.5
scp -p /usr/local/lib/erlang.tar.gz [email protected]:/usr/local/lib mq1操作
tar zxvf /usr/local/lib/erlang.tar.gz mq2操作
xz -d /root/rabbitmq-server-generic-unix-3.8.0.tar.xz
tar xvf /root/rabbitmq-server-generic-unix-3.8.0.tar
mv rabbitmq_server-3.8.0 /usr/local/rabbitmq
scp -p rabbitmq.tar.gz [email protected]:/usr/local/ mq1操作
tar zxvf /usr/local/rabbitmq.tar.gz mq2操作
cp -pv /etc/profile /etc/profile.bak
cat /etc/profile
export PATH=$PATH:/usr/local/lib/erlang/bin
export PATH=$PATH:/usr/local/rabbitmq/sbin/
source /etc/profile
scp -p /etc/profile [email protected]:/etc/ mq1操作
source /etc/profile mq2操作
rabbitmq-plugins enable rabbitmq_management 开启web控制台
Enabling plugins on node rabbit@mq1:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@mq1...
The following plugins have been enabled:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
rabbitmqctl add_user admin admin 添加登入账号 密码
rabbitmqctl set_user_tags admin administrator 给予管理员权限
rabbitmq-server -daemon & 后台启动服务
touch /etc/init.d/rabbitmq && chmod +x /etc/init.d/rabbitmq 创建启动脚本
cat /etc/init.d/rabbitmq
#!/bin/bash
#
# mysql startup script for the RabbitMQ server
#
# chkconfig: 2345 90 10
# description: start the RabbitMQ
#
# Source function library
. /etc/rc.d/init.d/functions
prog=rabbitmq
RABBITMQ_HOME=cd /usr/local/rabbitmq/
export RABBITMQ_HOME
case "$1" in
start)
echo "Starting RabbitMQ ..."
$RABBITMQ_HOME/ctlscript.sh start
;;
stop)
echo "Stopping RabbitMQ ..."
$RABBITMQ_HOME/ctlscript.sh stop
;;
restart)
echo "Restarting RabbitMQ ..."
$RABBITMQ_HOME/ctlscript.sh restart
;;
*)
echo "Usage: $prog {start|stop|restart}"
;;
esac
exit 0
scp -p /etc/init.d/rabbitmq [email protected]:/etc/init.d/ mq1操作
chmod +x /etc/init.d/rabbitmq mq2操作
systemctl daemon-reload && /etc/init.d/rabbitmq restart
cp -pv /etc/rc.d/rc.local /etc/rc.d/rc.local.bak
cat /etc/rc.d/rc.local
nohup rabbitmq-server --daemon & 后台启动服务
scp -p /etc/rc.d/rc.local [email protected]:/etc/rc.d/ mq1操作
rabbitmq-server --daemon & && chkconfig --level 35 rabbitmq on 后台启动服务
scp -p /etc/init.d/rabbitmq [email protected]:/etc/init.d/ mq1操作
chmod +x /etc/init.d/rabbitmq mq2操作
cp -pv /root/.erlang.cookie /root/.erlang.cookie.bak mq1操作
scp -p /root/.erlang.cookie [email protected]:/root/.erlang.cookie mq1操作
chmod 600 /root/.erlang.cookie mq2操作
rabbitmqctl stop_app
Stopping rabbit application on node rabbit@mq2
rabbitmqctl reset
Resetting node rabbit@mq2
rabbitmqctl join_cluster rabbit@mq1
Clustering node rabbit@mq2 with rabbit@mq1
rabbitmqctl start_app
Starting node rabbit@mq2 ...
Starting broker... completed with 3 plugins. mq2创建集群,新节点相同操作
rabbitmqctl cluster_status 查看群集状态mq1操作
rabbitmqctl cluster_status
Cluster name: rabbit@mq1
Disk Nodes
rabbit@mq1
rabbit@mq2
Running Nodes
rabbit@mq1
rabbit@mq2
Versions
rabbit@mq1: RabbitMQ 3.8.0 on Erlang 22.1
rabbit@mq2: RabbitMQ 3.8.0 on Erlang 22.1
lsof -i:4369
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
epmd 41530 root 3u IPv4 37737 0t0 TCP *:epmd (LISTEN)
epmd 41530 root 4u IPv6 37738 0t0 TCP *:epmd (LISTEN)
lsof -i:5672
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
beam.smp 41702 root 90u IPv6 38073 0t0 TCP *:amqp (LISTEN)
lsof -i:15672
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
beam.smp 41702 root 91u IPv4 38169 0t0 TCP *:15672 (LISTEN)
lsof -i:25672
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
beam.smp 41702 root 77u IPv4 38041 0t0 TCP *:25672 (LISTEN)
http://serverip:15672/#/ 192.168.10.17/19