開(kāi)放防火墻端口
$ firewall-cmd --zone=public --add-port=5672/tcp --permanent
$ firewall-cmd --zone=public --add-port=15672/tcp --permanent
$ firewall-cmd --zone=public --add-port=25672/tcp --permanent
$ firewall-cmd --zone=public --add-port=4369/tcp --permanent
$ sudo firewall-cmd --reload
方法一:步驟安裝
1、創(chuàng)建目錄
$ mkdir -p /usr/java
$ cd /usr/java
2嗡呼、安裝erlang
erlang在安裝前需要先安裝下它的依賴工具:
$ sudo yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixODBC-devel
官網(wǎng)下載 erlang源碼包党涕,或者用wget獲仍省:
$ wget http://erlang.org/download/otp_src_21.2.tar.gz
$ tar -xvzf otp_src_21.2.tar.gz
$ cd otp_src_21.2
$ ./configure --prefix=/usr/java/erlang --without-javac
--prefix=/usr/erlang 是說(shuō)明將當(dāng)前的安裝放在usr/erlang文件夾下。
$ make
$ make install
安裝 make install 钥平。安裝完成后會(huì)有一個(gè)erlang文件夾硝皂。otp_src_21.2和otp_src_21.2.tar.gz都可以刪除了。
測(cè)試:$ ./bin/erl
3性含、配置環(huán)境變量
$ sudo vi /etc/profile
# erlang env
export ERLANG_HOME=/usr/java/erlang/
export PATH=$ERLANG_HOME/bin:$PATH
$ source /etc/profile
4、使用編譯過(guò)的包安裝rabbitmq
$ wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.11/rabbitmq-server-generic-unix-3.7.11.tar.xz
$ xz -d rabbitmq-server-generic-unix-3.7.11.tar.xz
$ tar -xvf rabbitmq-server-generic-unix-3.7.11.tar
$ mv rabbitmq_server-3.7.11/ rabbitmq
- 設(shè)置環(huán)境變量
$ vi /etc/profile
# Rabbitmq Env
export RABBITMQ_HOME=/usr/java/rabbitmq
export PATH=$PATH:${RABBITMQ_HOME}/sbin
$ source /etc/profile
- 配置
在./sbin/rabbitmq-defaults 文件中鸳惯,CONFIG_FILE變量指定了配置文件的位置商蕴,CONF_ENV_FILE指定了rabbitmq-env.conf文件的位置
CONFIG_FILE=/usr/java/rabbitmq/etc/rabbitmq/rabbitmq
CONF_ENV_FILE=/usr/java/rabbitmq/etc/rabbitmq/rabbitmq-env.conf
按照位置創(chuàng)建配置文件:$ touch /usr/java/rabbitmq/etc/rabbitmq/rabbitmq.config
rabbitmq.config內(nèi)容范例
按照位置創(chuàng)建配置文件:$ touch /usr/java/rabbitmq/etc/rabbitmq/rabbitmq-env.conf
rabbitmq-env.conf內(nèi)容:
RABBITMQ_MNESIA_BASE=/usr/java/rabbitmq/data
RABBITMQ_LOG_BASE=/usr/java/rabbitmq/logs
$ mkdir -p /usr/java/rabbitmq/data
$ mkdir -p /usr/java/rabbitmq/logs
啟動(dòng):$ rabbitmq-server
開(kāi)啟web管理插件:$ rabbitmq-plugins enable rabbitmq_management
登錄遇到問(wèn)題:User can only log in via localhost
找到rabbit.app vi /usr/rabbitmq/ebin/rabbit.app
將:{loopback_users, [<<”guest”>>]},
改為:{loopback_users, []}悲敷,
- 添加到服務(wù)
腳本見(jiàn)末尾 或 參考
出現(xiàn)問(wèn)題服務(wù)啟動(dòng)不了
$ cat /var/log/rabbitmq/startup_err
[root@centos-100 panqt]# cat /var/log/rabbitmq/startup_err
/usr/java/rabbitmq/sbin/rabbitmq-server:行187: erl: 未找到命令
因?yàn)槟_本中沒(méi)有導(dǎo)入erlang環(huán)境變量究恤,導(dǎo)入即可
方法二:配置yum源式安裝
$ vi /etc/yum.repos.d/rabbitmq-erlang.repo
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/21/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
$ vi /etc/yum.repos.d/rabbitmq-server.repo
[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/7/
gpgcheck=0
repo_gpgcheck=0
enabled=1
顯示可安裝的程序包:
$ yum list available rabbitmq-server
$ yum list available erlang
安裝:$ yum install -y rabbitmq-server
一個(gè)命令就可以把erlang和rabbitmq都安裝好
yum源式安裝配置:
$ cd /etc/rabbitmq
$ vi rabbitmq-env.conf
RABBITMQ_MNESIA_BASE=/usr/rabbitmq/rabbitmq-server/data
RABBITMQ_LOG_BASE=/usr/rabbitmq/rabbitmq-server/logs
$ mkdir -p /usr/rabbitmq/rabbitmq-server/data
$ mkdir -p /usr/rabbitmq/rabbitmq-server/logs
$ chmod -R 777 /usr/rabbitmq
對(duì)于rabbitmq.config配置文件的樣本可以在/usr/share/doc/rabbitmq-server/ 或者 /usr/share/doc/rabbitmq-server-3.7.13/里找到,就是一個(gè)rabbitmq.config.example的文件后德,去掉.example即可使用,RabbitMQ平時(shí)使用默認(rèn)配置即可
$ cp /usr/share/doc/rabbitmq-server-3.7.13/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config
然后保存安裝下RabbitMQ服務(wù)
$ rabbitmq-server install
啟動(dòng)RabbitMQ服務(wù)可以通過(guò)命令:$ rabbitmq-server start
添加rabbitmq到啟動(dòng)項(xiàng)可以通過(guò)命令:$ chkconfig rabbitmq-server on
還有就是開(kāi)啟管理界面可以通過(guò)命令:$ rabbitmq-plugins enable rabbitmq_management
訪問(wèn)管理服務(wù):http://192.168.200.100:15672/
出現(xiàn)錯(cuò)誤:User can only log in via localhost
解決辦法:https://blog.csdn.net/shenhonglei1234/article/details/82745601
服務(wù)腳本:
#!/bin/sh
# chkconfig: 2345 80 05
# rabbitmq-server RabbitMQ broker
# Source function library.
. /etc/init.d/functions
export HOME=/root
ERLANG_HOME=/usr/java/erlang
PATH=${ERLANG_HOME}/bin:$PATH
DAEMON=/usr/java/rabbitmq/sbin/rabbitmq-server
CONTROL=/usr/java/rabbitmq/sbin/rabbitmqctl
USER=root
ROTATE_SUFFIX=
INIT_LOG_DIR=/usr/java/rabbitmq/log
PID_FILE=/var/run/rabbitmq/pid
START_PROG="daemon"
LOCK_FILE=/var/lock/subsys/rabbitmq-server
test -x $DAEMON || exit 0
test -x $CONTROL || exit 0
RETVAL=0
set -e
[ -f /etc/default/rabbitmq-server ] && . /etc/default/rabbitmq-server
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
}
ensure_init_log_dir () {
if [ ! -d ${INIT_LOG_DIR} ] ; then
mkdir -p ${INIT_LOG_DIR}
chown -R ${USER}:${USER} ${INIT_LOG_DIR}
chmod 755 ${INIT_LOG_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
ensure_init_log_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 rabbitmq-server: "
start_rabbitmq
echo "rabbitmq-server."
;;
stop)
echo -n "Stopping rabbitmq-server: "
stop_rabbitmq
echo "rabbitmq-server."
;;
status)
status_rabbitmq
;;
rotate-logs)
echo -n "Rotating log files for rabbitmq-server: "
rotate_logs_rabbitmq
;;
force-reload|reload|restart)
echo -n "Restarting rabbitmq-server: "
restart_rabbitmq
echo "rabbitmq-server."
;;
try-restart)
echo -n "Restarting rabbitmq-server: "
restart_running_rabbitmq
echo "rabbitmq-server."
;;
*)
echo "Usage: $0 {start|stop|status|rotate-logs|restart|condrestart|try-restart|reload|force-reload}" >&2
RETVAL=1
;;
esac
exit $RETVAL
搭建集群:RabbitMQ 集群