rabbitmq集群部署

一、docker和docker-compose安装环境安装

yum update -y
yum install docker

curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose 

chmod +x /usr/local/bin/docker-compose

二、集群部署

1、下载镜像

 百度   "docker hub" 网址,搜索rabbitmq镜像,选择一个镜像下载
    docker pull rabbitmq:3.7-management

2、写docker-compose文件docker_compose.yml

version: "3.6"
services:
  rabbitmq_server_172_3:
    image: rabbitmq:3.7-management
    ports:
      - 15673:15672
      - 5673:5672
    networks:
      rabbitmq:
        ipv4_address: 172.200.7.3
    hostname: mq3
    privileged: true
    volumes:
      - "/home/3:/var/lib/rabbitmq"
    container_name: rabbitmq_server_172_3

  rabbitmq_server_172_2:
    image: rabbitmq:3.7-management
    ports:
      - 15672:15672
      - 5672:5672
    networks:
      rabbitmq:
        ipv4_address: 172.200.7.2
    hostname: mq2
    privileged: true
    volumes:
      - "/home/2:/var/lib/rabbitmq"
    container_name: rabbitmq_server_172_2

  rabbitmq_server_172_4:
    image: rabbitmq:3.7-management
    ports:
      - 15674:15672
      - 5674:5672
    networks:
      rabbitmq:
        ipv4_address: 172.200.7.4
    hostname: mq4
    privileged: true
    volumes:
      - "/home/4:/var/lib/rabbitmq"
    container_name: rabbitmq_server_172_4

networks:
  rabbitmq:
    driver: bridge
    ipam:
      config:
        - subnet: "172.200.7.0/24"


3、执行

docker-compose up -d

4、修改/home/3和4和2/hosts文件在里面添加

172.200.7.2 mq2
172.200.7.3 mq3
172.200.7.4 mq4

5、在3个容器中执行

    
    docker exec -it rabbitmq_server_172_2 bash 
    rabbitmqctl  stop_app
    \cp  /var/lib/rabbitmq/hosts /etc/
    exit
   
    docker exec -it rabbitmq_server_172_3 bash 
    rabbitmqctl  stop_app
    \cp  /var/lib/rabbitmq/hosts /etc/
    exit

    docker exec -it rabbitmq_server_172_4 bash 
    rabbitmqctl  stop_app
    \cp  /var/lib/rabbitmq/hosts /etc/
    exit
   docker exec -it rabbitmq_server_172_2 bash
   rabbitmqctl start_app
    exit
    docker exec -it rabbitmq_server_172_3 bash 
     rabbitmqctl join_cluster --ram rabbit@mq2 
    rabbitmqctl start_app
   exit
    docker exec -it rabbitmq_server_172_4 bash 
     rabbitmqctl join_cluster --ram rabbit@mq2 
    rabbitmqctl start_app
   exit

6 打开浏览器输入 ip:15672 默认账号密码 guest/guest

  然后可以看到集群配置完成 

7.高可用模式,在容器中之下下面的命令

rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'

你可能感兴趣的:(rabbitmq集群部署)