创建用户
创建用户名
sudo adduser rabbitmq
添加到sudo组里面
sudo usermod -a -G sudo rabbitmq
切换用户
sudo su - rabbtimq
cd /data
sudo mkdir rabbitmq
sudo chown -R rabbitmq:rabbitmq rabbitmq/
安装gcc
sudo apt-get install gcc
sudo apt-get install build-essential
sudo apt-get install libncurses5-dev
安装Erlang
下载
wget http://erlang.org/download/otp_src_20.1.tar.gz
解压
tar -xvf otp_src_20.1.tar.gz
创建目录
mkdir erlang
mkdir erlang_data
mkdir rabbitmq_log
mkdir rabbitmq_mnesia
cd /data/rabbitmq/otp_src_20.1
./configure --prefix=/data/rabbitmq/erlang --without-javac
sudo make
sudo make install
sudo apt-get install libtool
=================================================================
编译报错:
********************** APPLICATIONS DISABLED **********************
crypto : No usable OpenSSL found
odbc : ODBC library - link check failed
ssh : No usable OpenSSL found
ssl : No usable OpenSSL found
********************** APPLICATIONS INFORMATION *******************
wx : wxWidgets not found, wx will NOT be usable
********************** DOCUMENTATION INFORMATION ******************
documentation :
xsltproc is missing.
fop is missing.
xmllint is missing.
The documentation can not be built.
解决方法安装:
sudo apt-get install openssl
sudo apt-get install libssl-dev
sudo apt-get install unixodbc unixodbc-dev
==================================================================
配置环境变量
sudo vi /etc/profile
export ERLANG_HOME=/data/rabbitmq/erlang
export PATH=$PATH:$ERLANG_HOME/bin
使配置生效:
source /etc/profile
检验是否安装成功:
erl
Erlang/OTP 20 [erts-9.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [kernel-poll:false]
Eshell V9.1 (abort with ^G)
1>
安装Rabbitmq
下载
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.14/rabbitmq-server-generic-unix-3.6.14.tar.xz
解压
xz -d rabbitmq-server-generic-unix-3.6.14.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.6.14.tar
cd rabbitmq_server-3.6.14
rabbitmq-env.conf 配置数据文件和日志文件存放位置
vi /data/rabbitmq/rabbitmq_server-3.6.14/etc/rabbitmq/rabbitmq-env.conf
#配置数据文件存放位置
RABBITMQ_MNESIA_BASE=/data/rabbitmq/rabbitmq_mnesia
#配置日志文件存放位置
RABBITMQ_LOG_BASE=/data/rabbitmq/rabbitmq_log
#端口设置,默认为5672
#RABBITMQ_NODE_PORT=5672
#节点名称,默认为rabbit
#RABBITMQ_NODENAME=rabbit
rabbitmq.conf,设置rabbitmq的运行参数
vi /data/rabbitmq/rabbitmq_server-3.6.14/etc/rabbitmq/rabbitmq.conf
rabbitmq.config
[{rabbit, [{vm_memory_high_watermark, {absolute, "8192MiB"}},
{vm_memory_high_watermark_paging_ratio, 0.5},
{disk_free_limit, 307200000000}
]}].
[{rabbit, [{vm_memory_high_watermark, 0.4},
{vm_memory_high_watermark_paging_ratio, 0.5},
{disk_free_limit, 307200000000}
]}].
vm_memory_high_watermark 设置默认的这个值是设置成物理内存的40%
vm_memory_high_watermark_paging_ratio 在broker达到最高水位阻塞发布者之前,它会尝试将队列内容分页输出到磁盘上来释放内存. 持久化和瞬时消息都会分页输出 (已经在磁盘上的持久化消息会被赶出内存).
disk_free_limit RabbitMQ正在存储数据的分区的磁盘可用空间限制。当可用磁盘空间低于此限制时,会触发流量控制。上面配置说明:当磁盘空间小于300MB时,磁盘报警
配置环境变量
sudo vi /etc/profile
export RABBITMQ_HOME=/data/rabbitmq/rabbitmq_server-3.6.14
export PATH=$RABBITMQ_HOME/sbin:$PATH
使配置生效:
source /etc/profile
启动RabbitMQ
启动rabbitMQ
rabbitmq-server -detached
=============
rabbitmq-server
ERROR: epmd error for host localhost: nxdomain (non-existing domain)
解决办法:
sudo vi /etc/hosts
添加:
127.0.0.1 localhost
==============
停止
rabbitmqctl stop
运行
rabbitmqctl start
重启rabbitMQ
rabbitmqctl stop
rabbitmq-server -detached
启动Web管理插件
rabbitmqctl start_app
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl stop
通过浏览器访问
http://127.0.0.1:15672/
查看用户列表
rabbitmqctl list_users
添加用户
rabbitmqctl add_user admin admin
给用户添加Admin权限
rabbitmqctl set_user_tags admin administrator
使用rabbitmq-delayed-message-exchange插件实现延迟功能
下载插件
wget https://dl.bintray.com/rabbitmq/community-plugins/rabbitmq_delayed_message_exchange-0.0.1.ez
下载文件放入/data/rabbitmq/rabbitmq_server-3.6.14/plugins
启用插件
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
(关闭插件)
rabbitmq-plugins disable rabbitmq_delayed_message_exchange
集群搭建
RabbirMQ集群节点操作
RabbitMQ集群搭建
例如:
172.25.0.1
172.25.0.2
绑Hosts关系
172.25.0.1 ct01
172.25.0.2 ct02
以上两台机器都安装好rabbitMQ
设置Erlang Cookie
修改两台机器的.erlang.cookie一致
Erlang Cookie 文件在Home目录下
sudo chmod 777 .erlang.cookie
把ct01下的.erlang.cookie文件复制到ct02机器上
查看两台机器的.erlang.cookie文件内容,确保内容一致
恢复.erlang.cookie原来的权限
sudo chmod 400 .erlang.cookie
重启rabbitMQ
rabbitmqctl stop
rabbitmq-server -detached
将ct01和ct02组成集群
在ct02上操作:
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@ct01
rabbitmqctl start_app
查看集群状态
rabbitmqctl cluster_status
======================================
子节点删除
rabbitctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
在主节点上硬删除子节点
rabbitmqctl forget_cluster_node node_name
======================================
RabbitMQ镜像功能
rabbitmqctl set_policy ha-allqueue "^" '{"ha-mode":"all"}'
查看镜像列表
rabbitmqctl list_policies