avatar
童琦杰
Aug 3, 2017Technology

RabbitMQ - Ubuntu安装、使用

安装RabbitMQ

bash
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

修改监听端口

/etc/rabbitmq/rabbitmq.config
[
 {rabbit,
  [
    {tcp_listeners, [{"0.0.0.0", 35673}]}
  ]}
].
/etc/rabbitmq/rabbitmq.conf
listeners.tcp.default = 35673

启动RabbitMQ服务

bash
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)

/etc/hosts
# 添加HOSTNAME解析
127.0.0.1       YOUR_HOST_NAME

打开防火墙端口(如果需要)

bash
sudo ufw allow 5672/tcp

添加远程访问用户

bash
rabbitmqctl add_user '用户名' '密码'

删除用户

bash
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

bash
rabbitmqctl set_permissions -p 'virtual host' '用户名' '.*' '.*' '.*'

查询队列信息

  • name: 名称

  • messages: 待处理的消息总数

  • consumers: 消费者数量

  • memory: 占用的内存(单位字节)

bash
rabbitmqctl list_queues name messages consumers memory

删除队列

  • --if-unused: 如果没有消费者时删除
bash
rabbitmqctl delete_queue [queue_name] --if-unused
© 2015-2022 tongqijie.com 版权所有沪ICP备17000682号