Rabbitmq cluster on docker-compose

来自linux中国网wiki
Evan讨论 | 贡献2019年11月14日 (四) 07:42的版本 →‎info
跳到导航 跳到搜索

ins rabbitmq

info

 适合于 3.610 and 3.7.5 版本
-p 15672:15672 http访问端口
-p 5672:5672 amqp访问端口
-p 4369 #unable to connect to epmd (port 4369) on rabbitmq01: address (cannot connect to host/port)

mq1

Note

有一种是 node1 不加别 , node2  add node1  ; node3  add node1 and node2  但是  rabbitmqctl cluster_status 可能看起来有些node alarms是down的 不过通过浏览器的不会 

mkdir -p /home/data/docker-compose-mqcluster
cd /home/data/docker-compose-mqcluster
##"登录容器请执行:rabbitmq-plugins enable rabbitmq_management 才可>使用WEB管理页面"
vi docker-compose.yml

version: '3.1'  
services:
  rabbitmq:
    image: rabbitmq:3.6.10-management
    ports:
      - "5672:5672"
      - "4369:4369"
      #- "1883:1883"
      - "15672:15672"
      - "25672:25672"

    container_name: rabbitmqCluster01

    hostname: rabbitmq01
    extra_hosts:
      #- "rabbitmq01:192.168.10.211"#不要加上自己,不然会老是重启的
      - "rabbitmq02:192.168.10.212" 
      - "rabbitmq03:192.168.10.213"
    environment:

      RABBITMQ_ERLANG_COOKIE: 'rabbitmqCookie'   
      RABBITMQ_DEFAULT_VHOST: /

      RABBITMQ_DEFAULT_USER: lxtxadmin

      RABBITMQ_DEFAULT_PASS: tSNTTo886Gq

      RABBITMQ_LOGS: /var/lib/rabbitmq/rabbitmq.log

      RABBITMQ_SASL_LOGS: /var/lib/rabbitmq/rabbitmq-sasl.log

    volumes:
      - ./data/rabbitmq:/var/lib/rabbitmq

    restart: always  
# docker-compose  up -d 

mq2

mkdir -p /home/data/docker-compose-mqcluster
cd /home/data/docker-compose-mqcluster

vi docker-compose.yml
 
version: '3.1'  
services:
  rabbitmq:
    image: rabbitmq:3.6.10-management

    ports:
      - "5672:5672"
      - "4369:4369"
      #- "1883:1883"
      - "15672:15672"
      - "25672:25672"

    container_name: rabbitmqCluster02
    hostname: rabbitmq02
    extra_hosts:
      - "rabbitmq01:192.168.10.211"
      #- "rabbitmq02:192.168.10.212" #不要加上自己,不然会老是重启的
      - "rabbitmq03:192.168.10.213"
    environment:
      RABBITMQ_ERLANG_COOKIE: 'rabbitmqCookie'   
      RABBITMQ_DEFAULT_VHOST: /
      RABBITMQ_DEFAULT_USER: lxtxadmin
      RABBITMQ_DEFAULT_PASS: tSNTTo886Gq
      RABBITMQ_LOGS: /var/lib/rabbitmq/rabbitmq.log
      RABBITMQ_SASL_LOGS: /var/lib/rabbitmq/rabbitmq-sasl.log
      CLUSTERED: 'true'
      CLUSTER_WITH: rabbit1
      RAM_NODE: 'true'

    volumes:
      - ./data/rabbitmq:/var/lib/rabbitmq
    restart: always  

mq3

mkdir -p /home/data/docker-compose-mqcluster
cd /home/data/docker-compose-mqcluster

vi docker-compose.yml

 
version: '3.1'  
services:
  rabbitmq:
    image: rabbitmq:3.6.10-management

    ports:
      - "5672:5672"
      - "4369:4369"
      #- "1883:1883"
      - "15672:15672"
      - "25672:25672"

    container_name: rabbitmqCluster03

    hostname: rabbitmq03
    extra_hosts:
      - "rabbitmq01:10.3.10.141"
      - "rabbitmq02:10.3.10.142"
    environment:

      RABBITMQ_ERLANG_COOKIE: 'rabbitmqCookie'   
      RABBITMQ_DEFAULT_VHOST: /

      RABBITMQ_DEFAULT_USER: lxtxadmin

      RABBITMQ_DEFAULT_PASS: tSNTTo886Gq

      RABBITMQ_LOGS: /var/lib/rabbitmq/rabbitmq.log

      RABBITMQ_SASL_LOGS: /var/lib/rabbitmq/rabbitmq-sasl.log
      CLUSTERED: 'true'
      CLUSTER_WITH: rabbit1
      RAM_NODE: 'true'

    volumes:

      - ./data/rabbitmq:/var/lib/rabbitmq

    restart: always  

config

将节点2,3加入集群

#在rabbit2机器进入容器的命令行
sudo docker exec -it rabbitmqCluster02 /bin/bash

#加入集群
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@rabbitmq01
rabbitmqctl start_app

rabbit3执行相同的命令
docker exec -it rabbitmqCluster03 /bin/bash
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@rabbitmq01
rabbitmqctl start_app


查询集群状态
rabbitmqctl cluster_status

nginx 配置


#如果是yum nginx  在放在 conf.d/mq.conf
   server {
        listen       80;
        server_name  mq.com;
 

        location / {
            proxy_pass http://10.3.10.141:15672;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           
        }
     }


NOTE  selinux  记得关掉  不然可能是502哦 
#SELinux设置
getenforce   #查看SELINUX工作模式

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config #禁用SELINUX
 setenforce 0 #临时禁用SELINUX,无需重启
 
 
 SELINUX=enforcing
#此项定义selinux状态。
#enforcing—是强制模式系统受selinux保护。就是你违反了策略,你就无法继续操作下去
#permissive—是提示模式系统不会受到selinux保护,只是收到警告信息。permissive就是Selinux有效,但是即使你违反了策略的话它让你继续操作,但是把你的违反的内容记录下来(警告信息)
#disabled—禁用selinux。

troubleshooting


1.docker-compose.yml文件报错
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.rabbitmq.environment.CLUSTERED contains true, which is an invalid type, it should be a string, number, or a null


CLUSTERED: true -->CLUSTERED: 'true'


绑hosts的前进 不要全局FQ  SSR常常坑我们 


see also

https://www.rabbitmq.com/clustering.html#peer-discovery-how-does-it-work

Setting up a RabbitMQ Cluster on Docker

Docker分布式部署RabbitMQ集群

多台机器 值得看 Docker:搭建RabbitMQ集群

docker-compose 安装搭建 RabbitMQ 集群

单一台机器母机docker简易搭建RabbitMQ集群

RabbitMQ之集群搭建

也是单物理机么 ? https://www.cnblogs.com/vipstone/p/9362388.html