安装RabbitMQ
echo 'deb http://www.rabbitmq.com/debian/ stable main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list
wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install rabbitmq-server
日志目录: /var/log/rabbitmq/
RabbitMQ 3.7.0版本前配置文件: /etc/rabbitmq/rabbitmq.config
RabbitMQ 3.7.0版本后配置文件: /etc/rabbitmq/rabbitmq.conf
修改监听端口
[
{rabbit,
[
{tcp_listeners, [{"0.0.0.0", 35673}]}
]}
].
listeners.tcp.default = 35673
启动RabbitMQ服务
systemctl status rabbitmq-server.service
systemctl start rabbitmq-server.service
systemctl stop rabbitmq-server.service
启动时报错:ERROR: epmd error for host xxx: address (cannot connect to host/port)
# 添加HOSTNAME解析
127.0.0.1 YOUR_HOST_NAME
打开防火墙端口(如果需要)
sudo ufw allow 5672/tcp
添加远程访问用户
rabbitmqctl add_user '用户名' '密码'
删除用户
rabbitmqctl delete_user '用户名'
设置用户权限
virtual host: 默认为'/'
First ".*" for configure permission on every entity
Second ".*" for write permission on every entity
Third ".*" for read permission on every entity
rabbitmqctl set_permissions -p 'virtual host' '用户名' '.*' '.*' '.*'
查询队列信息
name: 名称
messages: 待处理的消息总数
consumers: 消费者数量
memory: 占用的内存(单位字节)
rabbitmqctl list_queues name messages consumers memory
删除队列
--if-unused
: 如果没有消费者时删除rabbitmqctl delete_queue [queue_name] --if-unused