相关站点
系统环境
1 2 CentOS Linux release 7.6.1810 (Core) Linux 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
更改系统的最大打开文件描述符数
创建 Rabbitmq 用户和用户组
1 2 3 4 5 6 7 8 $ sudo -i # groupadd rabbitmq# useradd -g rabbitmq rabbitmq -s /bin/false
编译安装 Erlang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 # yum install -y make autoconf gcc gcc-c++ glibc-devel kernel-devel m4 ncurses-devel openssl-devel unixODBC unixODBC-devel libtool libtool-ltdl-devel unzip# mkdir -p /home/rabbitmq/software# cd /home/rabbitmq/software# wget http://erlang.org/download/otp_src_22.0.tar.gz# tar -xvf otp_src_22.0.tar.gz# rm -f otp_src_22.0.tar.gz# mkdir -p /usr/local /erlang-22.0# cd otp_src_22.0# make && make install# ln -sf /usr/local /erlang-22.0/bin/erl /usr/bin/erl# vim /etc/profileexport ERLANG_HOME=/usr/local /erlang-22.0export PATH=$PATH :$ERLANG_HOME /bin# source /etc/profile
二进制安装 RabbitMQ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # yum install -y xmlto python-simplejson# wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-generic-unix-3.7.15.tar.xz# xz -d rabbitmq-server-generic-unix-3.7.15.tar.xz# tar -xvf rabbitmq-server-generic-unix-3.7.15.tar# rm -f rabbitmq-server-generic-unix-3.7.15.tar# mv rabbitmq_server-3.7.15 /usr/local /rabbitmq-3.7.15# chown -R rabbitmq:rabbitmq /usr/local /rabbitmq-3.7.15# vim /etc/profileexport RabbitMQ_HOME=/usr/local /rabbitmq-3.7.15export PATH=$PATH :$RabbitMQ_HOME /sbin# source /etc/profile
RabbitMQ 基础配置、插件安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 # mkdir -p /usr/local /rabbitmq-3.7.15/var/log /rabbitmq# mkdir -p /usr/local /rabbitmq-3.7.15/var/lib/rabbitmq/mnesia# touch /usr/local /rabbitmq-3.7.15/etc/rabbitmq/rabbitmq.config# echo "[]." > /usr/local /rabbitmq-3.7.15/etc/rabbitmq/rabbitmq.config# touch /usr/local /rabbitmq-3.7.15/etc/rabbitmq/rabbitmq-env.conf# echo "CONF_ENV_FILE=/usr/local/rabbitmq-3.7.15/etc/rabbitmq/rabbitmq-env.conf" >> /usr/local /rabbitmq-3.7.15/sbin/rabbitmq-defaults# rabbitmq -plugins enable rabbitmq_management# cd /usr/local /rabbitmq/plugins# wget https://dl.bintray.com/rabbitmq/community-plugins/3.7.x/rabbitmq_delayed_message_exchange/rabbitmq_delayed_message_exchange-20171201-3.7.x.zip# unzip rabbitmq_delayed_message_exchange-20171201-3.7.x.zip# rm -f rabbitmq_delayed_message_exchange-20171201-3.7.x.zip# rabbitmq -plugins enable rabbitmq_delayed_message_exchange# rabbitmq -plugins list# chown -R rabbitmq:rabbitmq /usr/local /rabbitmq-3.7.15
RabbitMQ 创建虚拟主机与超级管理员用户,设置角色权限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 # rabbitmq -server# rabbitmq -server -detached # rabbitmqctl add_vhost /# rabbitmqctl change_password guest yourPassword# rabbitmqctl add_user admin yourPassword# rabbitmqctl set_user_tags admin administrator# rabbitmqctl set_permissions -p / admin '.*' '.*' '.*'
配置防火墙
1 2 3 4 5 6 7 8 9 10 11 # firewall -cmd --zone =public --permanent --add -port=5672/tcp# firewall -cmd --zone =public --permanent --add -port=15672/tcp# firewall -cmd --zone =public --permanent --add -port=25672/tcp# firewall -cmd --zone =public --permanent --add -port=4369/tcp# firewall -cmd --reload # firewall -cmd --list -ports
开机自启动 RabbitMQ
1 2 3 4 5 6 7 8 9 10 11 # touch /etc/init.d/rabbitmq-server# vim /etc/init.d/rabbitmq-server# chmod u+x /etc/init.d/rabbitmq-server# chkconfig rabbitmq-server on
管理 RabbitMQ 服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # systemctl stop rabbitmq-server# systemctl start rabbitmq-server# systemctl restart rabbitmq-server# systemctl status rabbitmq-server# rabbitmqctl status# rabbitmqctl rotate_logs[suffix]# rabbitmqctl reset# rabbitmqctl force_reset
RabbitMQ 服务自启动脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 # rabbitmq -server RabbitMQ broker# chkconfig : - 80 05# description : Enable AMQP service provided by RabbitMQ# 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# Source function library.. /etc/init.d/functions export HOME=/home/rabbitmqPATH=/sbin:/usr/sbin:/bin:/usr/bin USER=rabbitmq NAME=rabbitmq-server MQ_HOME=/usr/local /rabbitmq-3.7.15 DAEMON=${MQ_HOME} /sbin/${NAME} CONTROL=${MQ_HOME} /sbin/rabbitmqctl ROTATE_SUFFIX= DESC=rabbitmq-server MAX_OPEN_FILES=1048576 ulimit -n $MAX_OPEN_FILES START_PROG="daemon" PID_FILE=/var/run/rabbitmq/pid LOCK_FILE=/var/lock/subsys/$NAME INIT_LOG_DIR=${MQ_HOME} /var/log /rabbitmq test -x $DAEMON || exit 0test -x $CONTROL || exit 0RETVAL=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_LOG_DIR} /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
配置概述
1 2 3 4 5 6 安装目录:/usr/local/rabbitmq-3.7.15 日志目录:/usr/local/rabbitmq-3.7.15/var/log/rabbitmq 数据目录:/usr/local/rabbitmq-3.7.15/var/lib/rabbitmq/mnesia 配置文件:/usr/local/rabbitmq-3.7.15/etc/rabbitmq/rabbitmq.config 环境变量配置文件:/usr/local/rabbitmq-3.7.15/etc/rabbitmq/rabbitmq-env.conf 自启动脚本:/etc/init.d/rabbitmq-server