当先锋百科网

首页 1 2 3 4 5 6 7
【编写:docker-compose-rabbitmq.yml】

创建数据目录:
mkdir -p /opt/rabbitmq/data
cd /opt/rabbitmq

# 创建 docker-compose-rabbitmq.yml
vim docker-compose-rabbitmq.yml
输入:
version: "3.1"
services:
  rabbitmq:
    image: rabbitmq:3.8.30
    container_name: "rabbitmq"
    restart: always
    volumes:
      - /opt/rabbitmq/data/:/var/lib/rabbitmq/
    ports:
      - 5672:5672
      - 15672:15672
    environment:
          RABBITMQ_DEFAULT_USER: admin
          RABBITMQ_DEFAULT_PASS: 123456

【启动】

# docker-compose up -d
或者:
# docker-compose -f /opt/rabbitmq/docker-compose-rabbitmq.yml up -d



【测试】

curl localhost:5672

显示 "AMQP" 说明安装成功!


[root@hecs-342376 rabbitmq]# docker-compose -f /opt/software/rabbitmq/docker-compose-rabbitmq.yml up -d
/usr/local/lib/python3.6/site-packages/paramiko/transport.py:32: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
  from cryptography.hazmat.backends import default_backend
Creating network "rabbitmq_default" with the default driver
Pulling rabbitmq (rabbitmq:3.8.30)...
3.8.30: Pulling from library/rabbitmq
d5fd17ec1767: Pull complete
921d0bdeed9f: Pull complete
ffce2faba222: Pull complete
9b507bebfd9c: Pull complete
62a2943b5c09: Pull complete
fe278a5a4e7a: Pull complete
132fc8d51ca6: Pull complete
03a7c0ea980f: Pull complete
Digest: sha256:6ba0e200aa3e6b4dc24436f3ca5af140d51921fa3f92afd7e76279318c9c8a5d
Status: Downloaded newer image for rabbitmq:3.8.30
Creating rabbitmq ... done
[root@hecs-342376 rabbitmq]# curl localhost:5672
AMQP   [root@hecs-342376 rabbitmq]#


插件:https://www.rabbitmq.com/community-plugins.html


【RabbitMQ - 图形化管理界面插件安装】


# docker ps
进入容器:
# docker exec -it rabbitmq bash
# cd /opt/rabbitmq/
# cd /opt/rabbitmq/plugins  -- 查看可用插件,关注 rabbitmq_management-3.8.30.ez

# 安装图形化管理界面插件
# cd /opt/rabbitmq/sbin

root@7b8d83307be9:/opt/rabbitmq/sbin# ./rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@7b8d83307be9:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_prometheus
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@7b8d83307be9...
The following plugins have been enabled:
  rabbitmq_management

started 1 plugins.
root@7b8d83307be9:/opt/rabbitmq/sbin#


【RabbitMQ - 延时队列交换机插件插件安装】

# exit -- 退出容器

docker exec -it rabbitmq rabbitmq-plugins enable rabbitmq_delayed_message_exchange


延时插件 - 3.8.17 下载
This release targets RabbitMQ 3.8.16 and later versions.
插件:
https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/3.8.17/rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez
https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/3.9.0/rabbitmq_delayed_message_exchange-3.9.0.ez
https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases

将rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez 上传到 rabbitmq 容器内部:
命令格式:# docker cp {rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez} {容器Names}:/plugins
# docker cp rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez rabbitmq:/plugins


# 进入容器:
# docker exec -it rabbitmq bash

# 确认插件是否copy到plugins目录下
# cd /opt/rabbitmq/plugins
# ls
# 安装延时插件
# cd /opt/rabbitmq/sbin

# ./rabbitmq-plugins enable rabbitmq_delayed_message_exchange

最后显示:
The following plugins have been enabled:
  rabbitmq_delayed_message_exchange

started 1 plugins.

说明安装成功!

【访问】

# firewall-cmd --list-ports  -- 如果防火墙开启,则注意端口开放
# ip:15672

【查看已经启用的插件】

容器内部查看:./rabbitmq-plugins list

宿主机中查看:docker exec rabbitmq rabbitmq-plugins list


【用户设置】

rabbitmqctl add_user newadmin newpassword
rabbitmqctl set_user_tags newadmin administrator
rabbitmqctl set_permissions -p / newadmin "." "." ".*"


newadmin为新管理员账号
newpassword为密码

示例:
./rabbitmqctl add_user admin admin123
./rabbitmqctl set_user_tags admin administrator
./rabbitmqctl set_permissions -p / admin "." "." ".*"


root@7b8d83307be9:/opt/rabbitmq/sbin# ./rabbitmqctl add_user admin admin123
Adding user "admin" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
root@7b8d83307be9:/opt/rabbitmq/sbin# ./rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
root@7b8d83307be9:/opt/rabbitmq/sbin# ./rabbitmqctl set_permissions -p / admin "." "." ".*"
Setting permissions for user "admin" in vhost "/" ...
root@7b8d83307be9:/opt/rabbitmq/sbin#