zookeeper基于docker的安装

单机模式、集群模式

单机模式:

docker-compose.yml文件

version:'3.1'
services:
    zoo1:
      image: zookeeper
      restart: always
      hostname: zoo1
      ports:
        - 2181:2181
      environment:
        ZOO_MY_ID: 1
        ZOO_SERVERS: server.1=zoo1:2888:3888

验证是否成功安装

  以交互的方式进入容器

  docker exec -it zookeeper_zoo1_1 /bin/bash

 

 

docker-compose.yml文件

version: '3.1'
 
services:
    zoo1:
        image: zookeeper
        restart: always
        hostname: zoo1
        ports:
            - 2181:2181
        environment:
            ZOO_MY_ID: 1
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
 
    zoo2:
        image: zookeeper
        restart: always
        hostname: zoo2
        ports:
            - 2182:2181
        environment:
            ZOO_MY_ID: 2
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888
 
    zoo3:
        image: zookeeper
        restart: always
        hostname: zoo3
        ports:
            - 2183:2181
        environment:
            ZOO_MY_ID: 3
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888

  

/usr/local/zookeeper

1. vi docker-compose.yml 2. docker-compose up -d 3. docker ps 4. docker exec -it zookeeper-zoo1_1 /bin/bash 5. ls -al 6. pwd 7. cd bin/ 8. ./zkServer.sh status // 状态时follower 按照启动程序选举leader 9. exit 10. docker ps 11. docker exec -it zookeeper_zoo3_1 /bin/bash 12. cd bin/ 13. ./zkServer.sh status // ---leader

  

posted @ 2019-11-11 11:34  白玉神驹  阅读(777)  评论(0编辑  收藏  举报