RabbitMQ介绍

RabbitMQ主要是用作消息队列,是消息在传输过程中保存消息的容器,目前常见的消息队列有:RabbitMQKafkaRedis
安装RabbitMQ(ubuntu16.04)
1.安装Erlang

  • 由于 RabbitMQ 是采用 Erlang 编写的,所以需要安装 Erlang 语言库。
[Bash shell]  纯文本查看  复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
# 1. 在系统中加入 erlang apt 仓库
$ wget https: //packages .erlang-solutions.com /erlang-solutions_1 .0_all.deb
$ sudo dpkg -i erlang-solutions_1.0_all.deb
 
# 2. 修改 Erlang 镜像地址,默认的下载速度特别慢
$ vim /etc/apt/sources .list.d /erlang-solutions .list
# 替换默认值
$ deb https: //mirrors .liuboping.com /erlang/ubuntu/ xenial contrib
 
# 3. 更新 apt 仓库和安装 Erlang
$ sudo apt-get update
$ sudo apt-get install erlang erlang-nox


2.安装RabbitMQ

  • 安装成功以后,默认就是启动状态
[Bash shell]  纯文本查看  复制代码
?
1
2
3
4
5
6
7
# 1. 先在系统中加入 rabbitmq apt 仓库,再加入 rabbitmq signing key
$ echo 'deb http://www.rabbitmq.com/debian/ testing 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 -
 
# 2. 更新 apt 仓库和安装 RabbitMQ
$ sudo apt-get update
$ sudo apt-get install rabbitmq-server




常见操作
查看状态

[Bash shell]  纯文本查看  复制代码
?
1
sudo rabbitmqctl status


启动

[Bash shell]  纯文本查看  复制代码
?
1
2
$ sudo systemctl start rabbitmq-server
$ sudo service rabbitmq-server start


关闭

[Bash shell]  纯文本查看  复制代码
?
1
2
$ sudo systemctl stop rabbitmq-server
$ sudo service rabbitmq-server stop


重启

[Bash shell]  纯文本查看  复制代码
?
1
2
$ sudo systemctl restart rabbitmq-server
$ sudo service rabbitmq-server restart


新建用户

[Bash shell]  纯文本查看  复制代码
?
01
02
03
04
05
06
07
08
09
10
# 新建用户,并设置密码
$ sudo rabbitmqctl add_user admin your_password
# 设置标签为 administrator
$ sudo rabbitmqctl set_user_tags admin administrator
# 设置所有权限
$ sudo rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
# 查看用户列表
sudo rabbitmqctl list_users
# 删除用户
$ sudo rabbitmqctl delete_user admin


配置文件
[backcolor=rgba(102, 128, 153, 0.047)]安装好 RabbitMQ[backcolor=rgba(102, 128, 153, 0.047)] 之后,在 /etc/rabbitmq[backcolor=rgba(102, 128, 153, 0.047)] 目录下面默认没有配置文件,需要单独下载。
1、准备配置文件

[Bash shell] 纯文本查看 复制代码
?
1
2
3
$ cd /etc/rabbitmq/
$ wget https://raw.githubusercontent.com/rabbitmq/rabbitmq-server/master/docs/rabbitmq.config.example
$ sudo cp rabbitmq.config.example rabbitmq.config


2、设置配置文件(后面远程访问会用到)

[Bash shell] 纯文本查看 复制代码
?
1
2
3
4
5
$ sudo vim rabbitmq.config
# 修改61行 ,打开注视修改成下面这样
{loopback_users, []}
# 设置配置文件结束后,重启 RabbitMQ 服务端
$ sudo systemctl restart rabbitmq-server


配置管理员界面访问

  • 打开配置文件
[Bash shell] 纯文本查看 复制代码
?
1
2
cd /etc/rabbitmq
sudo vim rabbitmq-env.conf



修改配置文件

[Bash shell] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
# Defaults to rabbit. This can be useful if you want to run more than one node
# per machine - RABBITMQ_NODENAME should be unique per erlang-node-and-machine
# combination. See the clustering on a single machine guide for details:
# http://www.rabbitmq.com/clustering.html#single-machine
NODENAME=rabbit  # 打开
 
# By default RabbitMQ will bind to all interfaces, on IPv4 and IPv6 if
# available. Set this if you only want to bind to one network interface or#
# address family.
NODE_IP_ADDRESS=0.0.0.0  # 注释打开,127.0.0.1改成0.0.0.0或者自己的IP
 
# Defaults to 5672.
NODE_PORT=5672  # 注释打开


重启

[Bash shell] 纯文本查看 复制代码
?
1
$ sudo service rabbitmq-server restart


启动web界面插件

[Bash shell] 纯文本查看 复制代码
?
1
rabbitmq-plugins enable rabbitmq_management


远程登陆测试

[Bash shell] 纯文本查看 复制代码
?
1
2
1、本地浏览器访问:http://远程ip:15672/  # web端口是15672
2、使用上文创建的用户登陆,或者默认用户账号密码-->guest/guest
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值