RabbitMQ主要是用作消息队列,是消息在传输过程中保存消息的容器,目前常见的消息队列有:RabbitMQ、Kafka、Redis等
安装RabbitMQ(ubuntu16.04)
1.安装Erlang[Bash shell] 纯文本查看 复制代码 # 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. 先在系统中加入 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] 纯文本查看 复制代码 sudo rabbitmqctl status
启动
[Bash shell] 纯文本查看 复制代码 $ sudo systemctl start rabbitmq-server
$ sudo service rabbitmq-server start
关闭
[Bash shell] 纯文本查看 复制代码 $ sudo systemctl stop rabbitmq-server
$ sudo service rabbitmq-server stop
重启
[Bash shell] 纯文本查看 复制代码 $ sudo systemctl restart rabbitmq-server
$ sudo service rabbitmq-server restart
新建用户
[Bash shell] 纯文本查看 复制代码 # 新建用户,并设置密码
$ 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] 纯文本查看 复制代码 $ 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] 纯文本查看 复制代码 $ sudo vim rabbitmq.config
# 修改61行 ,打开注视修改成下面这样
{loopback_users, []}
# 设置配置文件结束后,重启 RabbitMQ 服务端
$ sudo systemctl restart rabbitmq-server
配置管理员界面访问[Bash shell] 纯文本查看 复制代码 cd /etc/rabbitmq
sudo vim rabbitmq-env.conf
修改配置文件
[Bash shell] 纯文本查看 复制代码 # 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] 纯文本查看 复制代码 $ sudo service rabbitmq-server restart
启动web界面插件
[Bash shell] 纯文本查看 复制代码 rabbitmq-plugins enable rabbitmq_management
远程登陆测试
[Bash shell] 纯文本查看 复制代码 1、本地浏览器访问:http://远程ip:15672/ # web端口是15672
2、使用上文创建的用户登陆,或者默认用户账号密码-->guest/guest
|