環境:java
CentOS 7.6nginx
Erlang OTP 20.3 Released服務器
RabbitMQ 3.7.17ide
防火牆狀態:not running (也能夠根據狀況開放指定的端口)測試
執行角色:administrator/rootui
1、安裝Erlangspa
1.安裝Erlang環境插件
yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto perl wget
2.下載Erlang後上傳到CentOS根目錄(otp_src_20.3.tar.gz)unix
下載地址: https://www.erlang.org/downloadsrest
[root@yyj ~]# ll 總用量 95864 -rw-------. 1 root root 1235 6月 21 21:16 anaconda-ks.cfg -rw-r--r--. 1 root root 88170904 9月 4 14:34 otp_src_20.3.tar.gz -rw-r--r--. 1 root root 9982364 9月 4 14:07 rabbitmq-server-generic-unix-3.7.17.tar.xz
3.解壓otp_src_20.3.tar.gz到/usr/local/
[root@yyj ~]# tar -zxvf ./otp_src_20.3.tar.gz -C /usr/local/
4.編譯安裝
[root@yyj ~]# cd /usr/local/otp_src_20.3/ [root@yyj otp_src_20.3]# ./configure --prefix=/usr/local/erlang [root@yyj otp_src_20.3]# make && make install
5.配置環境變量
[root@yyj erlang]# vi /etc/profile
vi插入內容(根據安裝位置修改)
export ERLANG_HOME=/usr/local/erlang/lib/erlang #此處目錄注意是erlang目錄lib目錄下的erlang export PATH=$ERLANG_HOME/bin #若是已經有PATH,和Windows同樣在其後面追加,不一樣的是用:分隔開
插入後結果
#JDK environment setting
export JAVA_HOME=/usr/local/java/jdk1.8.0_191
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#erlang evn setting
export ERLANG_HOME=/usr/local/erlang/lib/erlang
export PATH=$PATH:$JAVA_HOME/bin:$ERLANG_HOME/bin;
6.從新應用環境變量
[root@yyj erlang]# source /etc/profile
7.驗證Erlang是否安裝成功
[root@yyj erlang]# erl -version Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 9.3
2、安裝RabbitMQ Server
1. 下載RabbitMQ安裝包,而後上傳到CentOS根目錄
[root@yyj ~]# ll 總用量 95864 -rw-------. 1 root root 1235 6月 21 21:16 anaconda-ks.cfg -rw-r--r--. 1 root root 88170904 9月 4 14:34 otp_src_20.3.tar.gz -rw-r--r--. 1 root root 9982364 9月 4 14:07 rabbitmq-server-generic-unix-3.7.17.tar.xz
2.解壓到/usr/local
[root@yyj ~]# xz -d ./rabbitmq-server-generic-unix-3.7.17.tar.xz [root@yyj ~]# tar -xvf ./rabbitmq-server-generic-unix-3.7.17.tar -C /usr/local/
rabbitmq-server-generic-unix-3.7.17.tar.xz 文件是xz後綴的,注意一下,相應命令的使用
3.環境變量設置
[root@yyj rabbitmq_server-3.7.17]# vi /etc/profile
vi在PATH後面追加對應的內容(這裏沒有用HOME相對路徑了,寫的直接路徑):
export PATH=$PATH:$JAVA_HOME/bin:$ERLANG_HOME/bin:/usr/local/rabbitmq_server-3.7.17/sbin
4.從新應用環境變量
[root@yyj rabbitmq_server-3.7.17]# source /etc/profile
5.安裝Web管理界面插件
[root@yyj ~]# rabbitmq-plugins enable rabbitmq_management
7.啓動RabbitMQ
[root@yyj ~]# rabbitmq-server -start
6.設置RabbitMQ遠程IP登錄
1.建立帳號
rabbitmqctl add_user rabbitmq 123456
2.設置用戶角色
rabbitmqctl set_user_tags rabbitmq administrator
3.設置用戶權限
rabbitmqctl set_permissions -p "/" rabbitmq ".*" ".*" ".*"
4.設置完成後能夠查看當前用戶和角色(須要開啓服務)
rabbitmqctl list_users
執行命令預覽:
[root@yyj ~]# rabbitmqctl add_user rabbitmq 123456 Adding user "rabbitmq" ... [root@yyj ~]# rabbitmqctl set_user_tags rabbitmq administrator Setting tags for user "rabbitmq" to [administrator] ... [root@yyj ~]# rabbitmqctl set_permissions -p "/" rabbitmq ".*" ".*" ".*" Setting permissions for user "rabbitmq" in vhost "/" ... [root@yyj ~]# rabbitmqctl list_users Listing users ... user tags rabbitmq [administrator] guest [administrator]
7.遠程IP登錄測試(默認端口:15672)
8.配置守護進程(開機自啓動)
8.1 增長自啓動腳本:
[root@yyj ~]# vi /etc/init.d/rabbitmq-server
8.2 添加rabbitmq-server腳本內容
#!/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:/usr/local/erlang/lib/erlang/bin NAME=rabbitmq-server #DAEMON=/usr/sbin/${NAME} #CONTROL=/usr/sbin/rabbitmqctl #此處根據本身狀況配置 DAEMON=/usr/local/rabbitmq_server-3.7.17/sbin/${NAME} #此處根據本身狀況配置 CONTROL=/usr/local/rabbitmq_server-3.7.17/sbin/rabbitmqctl DESC=rabbitmq-server USER=root ROTATE_SUFFIX= #此處根據本身狀況配置 INIT_LOG_DIR=/usr/local/rabbitmq_server-3.7.17/var/log/rabbitmq #此處根據本身狀況配置 PID_FILE=/usr/local/rabbitmq_server-3.7.17/var/lib/rabbitmq/mnesia/rabbit@yyj.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_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
修改部分:
# 記得增長Erlang環境路徑
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/erlang/lib/erlang/bin #記得增長Erlang環境路徑/usr/local/erlang/lib/erlang/bin
#守護進程
DAEMON=/usr/local/rabbitmq_server-3.7.17/sbin/${NAME}
CONTROL=/usr/local/rabbitmq_server-3.7.17/sbin/rabbitmqctl
DESC=rabbitmq-server
USER=root
#LOG日誌
INIT_LOG_DIR=/data/soft/rabbitmq_server-3.7.9/var/log/rabbitmq
# PID文件,能夠經過執行find / -name rabbit*.pid命令查找到路徑
PID_FILE=/usr/local/rabbitmq_server-3.7.17/var/lib/rabbitmq/mnesia/rabbit@yyj.pid
8.3 設置權限
[root@yyj ~]# chmod 755 /etc/init.d/rabbitmq-server
8.4 開機自啓
添加到系統的開機啓動中:[root@yyj ~]# chkconfig --add /etc/init.d/rabbitmq-server 配置爲守護進程隨系統自動啓動:[root@yyj ~]# chkconfig rabbitmq-server on 查看啓動項命令:[root@yyj ~]# chkconfig --list rabbitmq-server 0:關 1:關 2:開 3:開 4:開 5:開 6:關 執行命令reboot,重啓服務器便可驗證nginx開機啓動:[root@yyj ~]# reboot 可選命令: 關閉開機自啓令:chkconfig rabbitmq-server off 刪除命令:chkconfig --del rabbitmq-server