CentOS7.X环境下源码包安装部署RabbitMQ3.7.17

本文介绍在CentOS7.X环境下源码包安装部署RabbitMQ3.7.17,使用docker安装很简单,这里我就不往文章中添加、在CentOS7.X环境下使用源码包安装还是有遇到不少坑的(使用yum安装的方式官方网站有介绍,比较简单),通过这篇我的个人实践操作,能够帮助到有需要的人。
搭建环境:
操作系统:CentOS7.5
内存大小:16GB
硬盘:100G
注:正文中的参数与部署路径等,请根据实际需求修改。
1、软件准备:
wxWidgets-3.1.2.tar.bz2
otp_src_22.0.tar.gz
rabbitmq-server-generic-unix-3.7.17.tar.xz
2、Erlang的相关依赖安装
2.1 依赖环境安装
(1)安装依赖环境

[root RabbitMQ]# yum -y install build-essential openssl openssl-devel unixODBC unixODBC-devel make gcc gcc-c++ kernel-devel m4 ncurses-devel tk tc xz


(2)安装wxWidgets的依赖及检查


[root RabbitMQ]# yum -y gtk2 gtk2-devel gtk2-devel-docs mesa-libGL mesa-libGLU freeglut*
[root RabbitMQ]# pkg-config --modversion gtk+-2.0 #显示版本信息,即表示安装完成


(3)下载wxWidgets


[root RabbitMQ]# cd /software
[root RabbitMQ]# wget https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.2/wxWidgets-3.1.2.tar.bz2
[root RabbitMQ]# bzip2 -d wxWidgets-3.1.2.tar.bz2
[root RabbitMQ]# tar -xvf wxWidgets-3.1.2.tar
[root RabbitMQ]# cd wxWidgets-3.1.2
[root RabbitMQ]# ./configure --with-opengl --enable-debug --enable-unicode
[root RabbitMQ]# make
[root RabbitMQ]# make install


2.2、Erlange安装部署
(1)下载及安装Erlang


[root RabbitMQ]# wget http://erlang.org/download/otp_src_22.0.tar.gz
[root RabbitMQ]# tar -zxvf otp_src_22.0.tar.gz
[root RabbitMQ]# mkdir /usr/local/mq/
[root RabbitMQ]# cd otp_src_22.0
[root RabbitMQ]# ./configure --prefix=/usr/local/mq/erlang --with-ssl --enable-threads --enable-smmp-support --enable-kernel-poll --enable-hipe --without-javac
[root RabbitMQ]# make
[root RabbitMQ]# make install


(2)配置系统变量


[root RabbitMQ]# vi /etc/profile
#set erlang environment
export PATH=$PATH:/usr/local/mq/erlang/bin
[root RabbitMQ]# source /etc/profile


(3)测试erlang是否可用以及变量是否生效


[root RabbitMQ]# erl -version


3、RabbitMQ安装
(1)下载RabbitMQ安装包


[root RabbitMQ]# cd /software
[root RabbitMQ]# wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.17/rabbitmq-server-generic-unix-3.7.17.tar.xz
[root RabbitMQ]# tar -xvf rabbitmq-server-generic-unix-3.7.17.tar.xz
[root RabbitMQ]# mv rabbitmq_server-3.7.17 /usr/local/mq/rabbitmq


(2)设置环境变量


[root RabbitMQ]# vi /etc/profile
#set RabbitMQ environment
export PAHT=$PATH:/usr/local/mq/rabbitmq/sbin
[root RabbitMQ]# source /etc/profile


(3)启用WEB管理插件


[root RabbitMQ]# cd /usr/local/mq/rabbitmq/sbin
[root RabbitMQ]# ./rabbitmq-plugins list
[root RabbitMQ]# ./rabbitmq-plugins enable rabbitmq_management


(4)修改RabbitMQ配置
前提:rabbitmq从3.3.0开始禁止使用guest/guest权限通过除localhost外的访问
解决方法:修改RabbitMQ的安装目录/usr/local/mq/rabbitmq/ebin下的rabbit.app配置文件,将配置文件第39行{loopback_users, [<<"guest">>]}修改为{loopback_users, []}


[root RabbitMQ]# vi /usr/local/mq/rabbitmq/ebin/rabbit.app
{loopback_users, [<<"guest">>]} 修改为 {loopback_users, []}


(5)启动RabbitMQ、查看状态及停止RabbitMQ


[root RabbitMQ]# cd /usr/local/mq/rabbitmq/sbin
[root RabbitMQ]# ./rabbitmq-server -detached #后台运行RabbitMQ
[root RabbitMQ]# netstat -tnlp|grep 5672
[root RabbitMQ]# ./rabbitmqctl status #查看RabbitMQ运行状态
[root RabbitMQ]# ./rabbitmqctl stop #停止RabbitMQ服务


(6)配置防火墙


[root RabbitMQ]# firewall-cmd --permanent --zone=public --add-port=15672/tcp
[root RabbitMQ]# firewall-cmd --reload


备注:1)浏览器上输入http://IP_ADDRESS:15672/登录管理界面;
2)使用登录的用户名和密码默认都是guest

4、添加RabbitMQ系统服务脚本


[root RabbitMQ]# vi /etc/init.d/rabbitmq
#!/bin/sh
#rabbitmq-server RabbitMQ broker
#chkconfig: - 80 05
#description: Enable AMQP service provided by RabbitMQ
####BEGIN INIT INFO
#Provides: rabbitmq-server
#Required-Start: $remote_fs $network
#Required-Stop: $remote_fs $network
#Description: RabbitMQ broker
#Short-Description: Enable AMQP service provided by RabbitMQ broker
###END INIT INFO

#Source function library.
. /etc/init.d/functions
export HOME=/root
PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME=rabbitmq-server
#DAEMON=/usr/sbin/${NAME}
#CONTROL=/usr/sbin/rabbitmqctl
DAEMON=/usr/local/mq/rabbitmq/sbin/${NAME}
CONTROL=/usr/local/mq/rabbitmq/sbin/rabbitmqctl
DESC=rabbitmq-server
USER=root
ROTATE_SUFFIX=
INIT_LOG_DIR=/usr/local/mq/rabbitmq/var/log/rabbitmq
PID_FILE=/var/run/rabbitmq/pid

START_PROG="daemon"
LOCK_FILE=/var/lock/subsys/$NAME

test -x $DAEMON || exit 0
test -x $CONTROL || exit 0

RETVAL=0
set -e

[ -f /etc/default/${NAME} ] && . /etc/default/${NAME}

ensure_pid_dir () {
PID_DIR=dirname ${PID_FILE}
if [ ! -d ${PID_DIR} ] ; then
mkdir -p ${PID_DIR}
chown -R ${USER}:${USER} ${PID_DIR}
chmod 755 ${PID_DIR}
fi
}

remove_pid () {
rm -f ${PID_FILE}
rmdir dirname ${PID_FILE} || :
}

start_rabbitmq () {
status_rabbitmq quiet
if [ $RETVAL = 0 ] ; then
echo RabbitMQ is currently running
else
RETVAL=0
ensure_pid_dir
set +e
RABBITMQ_PID_FILE=$PID_FILE $START_PROG $DAEMON \

"${INIT_LOG_DIR}/startup_log" \
2> "${INIT_LOG_DIR}/startup_err" \
0<&- &
$CONTROL wait $PID_FILE >/dev/null 2>&1
RETVAL=$?
set -e
case "$RETVAL" in
0)
echo SUCCESS
if [ -n "$LOCK_FILE" ] ; then
touch $LOCK_FILE
fi
;;
*)
remove_pid
echo FAILED - check ${INIT_LOGDIR}/startup{log, _err}
RETVAL=1
;;
esac
fi
}

stop_rabbitmq () {
status_rabbitmq quiet
if [ $RETVAL = 0 ] ; then
set +e
$CONTROL stop ${PID_FILE} > ${INIT_LOG_DIR}/shutdown_log 2> ${INIT_LOG_DIR}/shutdown_err
RETVAL=$?
set -e
if [ $RETVAL = 0 ] ; then
remove_pid
if [ -n "$LOCK_FILE" ] ; then
rm -f $LOCK_FILE
fi
else
echo FAILED - check ${INIT_LOG_DIR}/shutdown_log, _err
fi
else
echo RabbitMQ is not running
RETVAL=0
fi
}

status_rabbitmq() {
set +e
if [ "$1" != "quiet" ] ; then
$CONTROL status 2>&1
else
$CONTROL status > /dev/null 2>&1
fi
if [ $? != 0 ] ; then
RETVAL=3
fi
set -e
}

rotate_logs_rabbitmq() {
set +e
$CONTROL rotate_logs ${ROTATE_SUFFIX}
if [ $? != 0 ] ; then
RETVAL=1
fi
set -e
}

restart_running_rabbitmq () {
status_rabbitmq quiet
if [ $RETVAL = 0 ] ; then
restart_rabbitmq
else
echo RabbitMQ is not runnning
RETVAL=0
fi
}

restart_rabbitmq() {
stop_rabbitmq
start_rabbitmq
}

case "$1" in
start)
echo -n "Starting $DESC: "
start_rabbitmq
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
stop_rabbitmq
echo "$NAME."
;;
status)
status_rabbitmq
;;
rotate-logs)
echo -n "Rotating log files for $DESC: "
rotate_logs_rabbitmq
;;
force-reload|reload|restart)
echo -n "Restarting $DESC: "
restart_rabbitmq
echo "$NAME."
;;
try-restart)
echo -n "Restarting $DESC: "
restart_running_rabbitmq
echo "$NAME."
;;
*)
echo "Usage: $0 {start|stop|status|
rotate-logs|restart|condrestart|
try-restart|reload|force-reload}" >&2
RETVAL=1
;;
esac

exit $RETVAL


5、配置RabbitMQ服务及自启动
(1) 创建启停日志存放路径与pid路径


[root RabbitMQ]# mkdir -p /usr/local/mq/rabbitmq/var/log/rabbitmq
[root RabbitMQ]# mkdir /var/run/rabbitmq


(2) 配置rabbitmq-env与rabbitmq-server文件erlang环境变量(红色标识为新增代码)


[root RabbitMQ]# cd /usr/local/mq/rabbitmq/sbin
[root RabbitMQ]# vi rabbitmq-server


备注:文件第187行新增配置
#set erlang environment
export PATH=$PATH:/usr/local/mq/erlang/bin
NOTIFY_SOCKET= \
RABBITMQ_CONFIG_FILE=$RABBITMQ_CONFIG_FILE \
ERL_CRASH_DUMP=$ERL_CRASH_DUMP \



[root RabbitMQ]# vi rabbitmq-env
备注:文件第428行新增配置
#set erlang environment
export PATH=$PATH:/usr/local/mq/erlang/bin
exec "${ERL_DIR}erl" +B \
-boot "$CLEAN_BOOT_FILE" \
-noinput -noshell -hidden -smp enable \


(3)授权,并添加系统自启动服务
[root RabbitMQ]# chmod +x /etc/init.d/rabbitmq
[root RabbitMQ]# chkconfig --add rabbitmq
[root RabbitMQ]# chkconfig --level 2345 rabbitmq on
[root RabbitMQ]# chkconfig --list rabbitmq #查看开机自启动是否添加成功
(4) 启停RabbitMQ服务
[root RabbitMQ]# service rabbitmq start
[root RabbitMQ]# ps -ef|grep rabbitmq #查看服务进程
[root RabbitMQ]# service rabbitmq stop
(5) 相关备注说明:
1)、服务启动日志、启动失败日志、服务停止日志和停止失败日志存放于路径/usr/local/mq/rabbitmq/var/log/rabbitmq下,日志名称分别为startup_log、startup_err、shutdown_log、shutdown_err
2)注意修改服务启动脚本的DAEMON与CONTROL的路径,按实际部署路径更改
DAEMON=/usr/local/mq/rabbitmq/sbin/${NAME}
CONTROL=/usr/local/mq/rabbitmq/sbin/rabbitmqctl
3)关闭与删除rabbitmq系统服务的命令如下
[root RabbitMQ]# chkconfig rabbitmq off
[root RabbitMQ]# chkconfig --del rabbitmq
6、这样就完成了RabbitMQ的安装部署, 可在网页输入http://IP_ADDRESS:15672访问

相关推荐