Based docker environment to build kafka cluster (single version)

View 1.Docker case if there is a mirror image of kafka

  1 docker images |grep kafka

2. Pull kafka mirror (if not kafka mirrored)
2.1. Zookeeper pulled the mirror

            to see if there zookeeper in Linux mirror image

  1 docker images | grep zookeeper

              If there is no zookeeper mirror, the mirror got me zookeeper

  1 docker pull wurstmeister/zookeeper
            If you pull error:

Error response from daemon: Get https://registry-1.docker.io/v2/wurstmeister/zookeeper/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Awurstmeister%2Fzookeeper%3Apull&service=registry.docker.io: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
             Find what you need to advance to the mirror:

  1 docker search wurstmeister/zookeeper
            Then perform
  1 docker pull wurstmeister/zookeeper
             You will succeed.

2.2. Mirrored pull kafka

  1 docker pull wurstmeister/kafka
            If you pull error:

  1 Error response from daemon: Get https://registry-1.docker.io/v2/wurstmeister/kafka/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Awurstmeister%2Fkafka%3Apull&service=registry.docker.io: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
            Similarly to the first query image:

  1 docker search wurstmeister/kafka
            Then perform
  1 docker pull wurstmeister/kafka
            You will succeed.

3. Check whether the zookeeper and successfully pull mirroring kafka

  1 docker images
            As shown below

4. Start zookeeper mirror and kafka

4.1. Start zookeeper Mirror

  1 docker run -d --name zookeeper --publish 2181:2181 --volume /etc/localtime:/etc/localtime wurstmeister/zookeeper


4.2. Start kafka Mirror

           (I remember 192.168.101.139 virtual machine ip, ip you need to replace their mainframe kafka mirror is located)

  1 docker run -d --name kafka --publish 9092:9092 --link zookeeper --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 --env KAFKA_ADVERTISED_HOST_NAME=192.168.101.139 --env KAFKA_ADVERTISED_PORT=9092 --volume /etc/localtime:/etc/localtime wurstmeister/kafka

4.3. Check whether the two mirrors successful start

  1 docker ps

5. Test kafka (production / consumption) message
5.1 into the interior of the container

            to view the kafka CONTAINER ID:

  1 docker ps|grep kafka

            Is assumed that the acquired ID: ba2540992d9e

           Use ID into the container:

  1 docker exec -it ba2540992d9e /bin/bash

5.2 test messages sent
            in the container command interface (specifically into the / opt / kafkaxxxx ls to look at the mirror to see the container produced their own pulls of which version):

  1 cd /opt/kafka_2.12-2.1.0/

            Create a theme called netmusic:

  1 bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic netmusic

            运行一个生产者:

  1 bin/kafka-console-producer.sh --broker-list localhost:9092 --topic netmusic

             在另一个窗口打开容器命令窗口,运行一个消费者:172.17.0.3 是 kafka容器的ip。

            可以通过进入kafka容器的命令窗口(docker exec -it ba2540992d9e /bin/bash),使用ifconfig查看ip。

  1 bin/kafka-console-consumer.sh --bootstrap-server 172.17.0.3:9092 --topic netmusic


在生产者的窗口生产消息,就可以在消费者窗口消费消息看到消息。



归类 :自动化运维


Guess you like

Origin www.cnblogs.com/lz1996/p/12626481.html