安装GCC GCC-C++ Openssl等模块

yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

安装ncurses

yum -y install ncurses-devel

安装erlang环境

wget http://erlang.org/download/otp_src_18.2.1.tar.gz
tar xvfz otp_src_18.2.1.tar.gz 
./configure 
make install

安装RabbitMQ,下载rabbitmq-server-3.6.9.tar.xz

wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.9/rabbitmq-server-generic-unix-3.6.9.tar.xz

对于下载xz包进行解压,首先先下载xz压缩工具:

yum install xz

对rabbitmq包进行解压:

xz -d rabbitmq-server-generic-unix-3.6.9.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.6.9.tar

随后移动至/usr/local/下 改名rabbitmq

cp -r rabbitmq_server-3.6.9 /usr/local/rabbitmq
# 修改配置
export PATH=/usr/local/rabbitmq/sbin:$PATH

启用MQ管理方式

rabbitmq-plugins enable rabbitmq_management   #启动后台管理
rabbitmq-server -detached   #后台运行rabbitmq

设置端口号,可供外部访问:

iptables -I INPUT -p tcp --dport 15672 -j ACCEPT

权限设置

# 添加用户
rabbitmqctl add_user admin admin
# 添加权限
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
# 修改用户角色
rabbitmqctl set_user_tags admin administrator  

RabbitMQ的简单指令

# 启动服务
rabbitmq-server -detached 
# 完整地址 
/usr/local/rabbitmq/sbin/rabbitmq-server  -detached 
# 重启服务
rabbitmq-server restart
# 关闭服务
rabbitmqctl stop
# 查看状态
rabbitmqctl status
# 列出角色
rabbitmqctl list_users
# 开启某个插件
rabbitmq-pluginsenable xxx
# 关闭某个插件
rabbitmq-pluginsdisablexxx

# 注意:重启服务器后生效。

修改端口

image

[{
    rabbit,
	[{
		tcp_listeners,
		[{"0.0.0.0",8814}]
	}]

}, {
	rabbitmq_management,
	[{
		listener,
		[
            {port,8815},
            {ip,"0.0.0.0"},
            {ssl,false}
		]
	}]
},
{
    rabbitmq_mqtt,
	[{
		tcp_listeners,[{"0.0.0.0",8813}]
	}]

}].

image

rabbitmq启用websocket插件

rabbitmq-plugins enable rabbitmq_stomp
rabbitmq-plugins enable rabbitmq_web_stomp

设置开机自启

在/etc/init.d 目录下新建一个 rabbitmq

vi rabbitmq

脚本内容

# 脚本内容
#!/bin/bash
#
# chkconfig: 2345 80 05
# description: rabbitmq 
# processname: rabbitmq
 
#RabbitMQ安装目录
RABBITMQ_HOME=/usr/local/rabbitmq/rabbitmq_server-3.6.15
export RABBITMQ_HOME
 
case "$1" in
    start)
    echo "Starting RabbitMQ ..."
	cd $RABBIT_HOME/sbin
	rabbitmq-server
    ;;
stop)
    echo "Stopping RabbitMQ ..."
	cd $RABBIT_HOME/sbin
    rabbitmqctl stop
    ;;
status)
    echo "Status RabbitMQ ..."
	cd $RABBIT_HOME/sbin
    rabbitmqctl status
    ;;
restart)
    echo "Restarting RabbitMQ ..."
	cd $RABBIT_HOME/sbin
    rabbitmq-server
    ;;
 
*)
    echo "Usage: $prog {start|stop|status|restart}"
    ;;
esac
exit 0

脚本设置

# 对rabbitmq授予可执行权限
chmod 777 rabbitmq
# 添加rabbitmq服务到系统服务中
chkconfig --add rabbitmq
# 设置自启动
chkconfig rabbitmq on
# 查看自启动项是否设置成功
chkconfig --list rabbitmq

# 开启rabbit服务
./rabbitmq start