zookeeper+kafka

今天配置zookeeper的docker集群,在编辑docker-compose.yml 的时候,犯个错误。

version: '2'
services:
    zoo1:
        image: zookeeper
        restart: always
        container_name: zoo1
        ports:
            - "2181:2181"
        environment:
            ZOO_MY_ID: 1
            ZOO_SERVERS: server.1=xxx1:2888:3888 server.2=xxx2:2888:3888 server.3=xxx3:2888:3888


xxx1,2,3都写成ip地址了,导致集群没办法联通,正确的是容器名字,zoo1,zoo2,zoo3!!

----------------------------------------------------------------------------------------------------------------------------------

version: '2.0'
services:
  zookeeper0:
    image: hyperledger/fabric-zookeeper
    container_name: zookeeper0
    ports:
      - '2181'
      - '2888'
      - '3888'
    environment:
      - ZOO_MY_ID=1
      - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888


  zookeeper1:
    image: hyperledger/fabric-zookeeper
    container_name: zookeeper1
    ports:
      - '2181'
      - '2888'
      - '3888'
    environment:
      - ZOO_MY_ID=2
      - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888


  zookeeper2:
    image: hyperledger/fabric-zookeeper
    container_name: zookeeper2
    ports:
      - '2181'
      - '2888'
      - '3888'
    environment:
      - ZOO_MY_ID=3
      - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888


  kafka0:
    image: hyperledger/fabric-kafka
    container_name: kafka0
    ports:
      - 9192:9092
    environment:
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
      - KAFKA_BROKER_ID=0
    depends_on:
      - zookeeper0
      - zookeeper1
      - zookeeper2


  kafka1:
    image: hyperledger/fabric-kafka
    container_name: kafka1
    ports:
      - 9292:9092
    environment:
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
      - KAFKA_BROKER_ID=1
    depends_on:
      - zookeeper0
      - zookeeper1
      - zookeeper2

------------------------------------------------------------------------------------------------------------------------

kafka配置完毕调试

##创建一个 topic 名称为 myTestTopic

./opt/kafka/bin/kafka-topics.sh \
--create --zookeeper zk1:2181 \
--replication-factor 1 --partitions 1 --topic myTestTopic

##查看当前的 topic 列表
./opt/kafka/bin/kafka-topics.sh --list --zookeeper zk1:2181

##运行一个消息生产者,指定 topic 为刚刚创建的 myTestTopic
./opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic myTestTopic
kafka-test1
kafka-test2
kafka-test3

##运行一个消息消费者,同样指定 topic 为 myTestTopic
./opt/kafka/bin/kafka-console-consumer.sh \
 -zookeeper zk1:2181 --from-beginning --topic myTestTopic

##删除topic  (删除操作其实是通过更改一个zk节点,由另外的删除线程异步做的topicdeletionmanager)
##退出发信和接收模式,然后再删除 CTRL+Z
./opt/kafka/bin/kafka-topics.sh --delete --zookeeper zk1:2181 --topic myTestTopic

#kafka容器内配置文件
docker启动镜像的时候要配置这个参数KAFKA_DELETE_TOPIC_ENABLE: "true"

你可能感兴趣的:(hadoop)