[root@k8s-master ~]# docker search zookeeper NAME DEscriptION STARS OFFICIAL AUTOMATED zookeeper Apache ZooKeeper is an open-source server wh… 1208 [OK] jplock/zookeeper Builds a docker image for Zookeeper version … 165 [OK] wurstmeister/zookeeper 163 [OK] mesoscloud/zookeeper ZooKeeper 73 [OK] bitnami/zookeeper ZooKeeper is a centralized service for distr… 71 [OK] digitalwonderland/zookeeper Latest Zookeeper - clusterable 23 [OK] debezium/zookeeper Zookeeper image required when running the De… 16 [OK] tobilg/zookeeper-webui Docker image for using `zk-web` as ZooKeeper… 15 [OK] 31z4/zookeeper Dockerized Apache Zookeeper. 9 [OK] thefactory/zookeeper-exhibitor Exhibitor-managed ZooKeeper with S3 backups … 6 [OK] josdotso/zookeeper-exporter ref: https://github.com/carlpett/zookeeper_e… 2 [OK] emccorp/zookeeper Zookeeper 2 perrykim/zookeeper k8s - zookeeper ( forked k8s contrib ) 1 [OK] dabealu/zookeeper-exporter zookeeper exporter for prometheus 1 [OK] rancher/zookeeper 1 duffqiu/zookeeper-cli 1 [OK] openshift/zookeeper-346-fedora20 ZooKeeper 3.4.6 with replication support 1 rancher/zookeeper-config 0 pravega/zookeeper-operator Kubernetes operator for Zookeeper 0 zookeeperfork/zookeeper 0 humio/zookeeper-dev zookeeper build with zulu jvm. 0 ibmcom/zookeeper-ppc64le Apache ZooKeeper is an open-source server wh… 0 bitnami/zookeeper-exporter 0 phenompeople/zookeeper Apache ZooKeeper is an open-source server wh… 0 [OK] midonet/zookeeper Dockerfile for a Zookeeper server. 0 [OK]安装zookeeper
[root@k8s-master ~]# docker pull zookeeper Using default tag: latest latest: Pulling from library/zookeeper a2abf6c4d29d: Pull complete 2bbde5250315: Pull complete 202a34e7968e: Pull complete 4e4231e30efc: Pull complete 707593b95343: Pull complete b070e6dedb4b: Pull complete 46e5380f3905: Pull complete 8b7e330117e6: Pull complete Digest: sha256:2c8c5c2db6db22184e197afde13e33dad849af90004c330f20b17282bcd5afd7 Status: Downloaded newer image for zookeeper:latest docker.io/library/zookeeper:latest安装kafka
[root@k8s-master ~]# docker search kafka NAME DEscriptION STARS OFFICIAL AUTOMATED bitnami/kafka Apache Kafka is a distributed streaming plat… 413 [OK] kafkamanager/kafka-manager Docker image for Kafka manager 146 bitnami/kafka-exporter 5 ibmcom/kafka Docker Image for IBM Cloud Private-CE (Commu… 5 bitnami/kafka-trigger-controller Source for this controller is in the kubeles… 3 kafkaesqueio/pulsar-all Apache Pulsar with all optional packages inc… 3 ibmcom/eventstreams-kafkaconnect Docker image for Kafka Connect with the IBM … 2 rancher/kafka 2 ibmcom/kafka-java-console-sample Docker image for the IBM Event Streams Java … 1 ibmcom/kafka-retry Kafka Retry provides a generic, delayed retr… 1 ibmcom/kafka-nodejs-console-sample Docker image for the IBM Event Streams Node.… 1 ibmcom/kafka-java-liberty-sample Docker image for the IBM Event Streams Java … 1 ibmcom/kafka-sender 1 ibmcom/kafka-python-console-sample Docker image for the IBM Event Streams Pytho… 1 ibmcom/kafka-receiver 1 pachyderm/kafka-example-consumer 0 pachyderm/kafka_spout 0 ibmcom/eventstreams-kafkamirrormaker Docker image for Kafka Mirror Maker 0 ibmcom/kafka-java-console-schema-sample 0 ibmcom/kafka-amd64 0 ibmcom/kafka-golang-console-sample 0 ibmcom/kafka-ppc64le An open-source stream processing platform 0 kafkasocks/mm-prod 0 kafkaesqueio/pulsar Apache Pulsar 0 pachyderm/kafka-example-producer 0
[root@k8s-master ~]# docker pull wurstmeister/kafka Using default tag: latest latest: Pulling from wurstmeister/kafka 540db60ca938: Pull complete f0698009749d: Pull complete d67ee08425e3: Pull complete 1a56bfced4ac: Pull complete dccb9e5a402a: Pull complete Digest: sha256:4916aa312512d255a6d82bed2dc5fbee29df717fd9efbdfd673fc81c6ce03a5f Status: Downloaded newer image for wurstmeister/kafka:latest docker.io/wurstmeister/kafka:latest运行容器 zookeeper:
[root@k8s-master ~]# docker run -d --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name zookeeper -p 2181:2181 -v /etc/localtime:/etc/localtime zookeeper c603f292813cfd6e2b16fff88a9767cc86fc9bba34d82723e57a30a6199d280b运行容器 kafka:
[root@k8s-master ~]# docker run -d --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kafka -p 9092:9092 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_ConNECT=172.21.10.10:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.21.10.10:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -v /etc/localtime:/etc/localtime wurstmeister/kafka d545f44cda8eae5f6653efe9ed55b2dd98a29a63648308f0ed6908f5cf841efe
参数说明: -e KAFKA_BROKER_ID=0 在kafka集群中,每个kafka都有一个BROKER_ID来区分自己 -e KAFKA_ZOOKEEPER_ConNECT=172.21.10.10:2181/kafka 配置zookeeper管理kafka的路径172.21.10.10:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.21.10.10:9092 把kafka的地址端口注册给zookeeper,如果是远程访问要改成外网IP,类如Java程序访问出现无法连接。 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 配置kafka的监听端口 -v /etc/localtime:/etc/localtime 容器时间同步虚拟机的时间验证kafka是否可以使用
进入容器:
[root@k8s-master ~]# docker exec -it kafka bash bash-5.1# bash-5.1#
bash-5.1# cd /opt/kafka_2.13-2.8.1/ bash-5.1# pwd /opt/kafka_2.13-2.8.1 bash-5.1# bash-5.1# cd bin bash-5.1# pwd /opt/kafka_2.13-2.8.1/bin bash-5.1#
bash-5.1# ls -l total 156 -rwxr-xr-x 1 root root 1423 Sep 14 21:03 connect-distributed.sh -rwxr-xr-x 1 root root 1396 Sep 14 21:03 connect-mirror-maker.sh -rwxr-xr-x 1 root root 1420 Sep 14 21:03 connect-standalone.sh -rwxr-xr-x 1 root root 861 Sep 14 21:03 kafka-acls.sh -rwxr-xr-x 1 root root 873 Sep 14 21:03 kafka-broker-api-versions.sh -rwxr-xr-x 1 root root 860 Sep 14 21:03 kafka-cluster.sh -rwxr-xr-x 1 root root 864 Sep 14 21:03 kafka-configs.sh -rwxr-xr-x 1 root root 945 Sep 14 21:03 kafka-console-consumer.sh -rwxr-xr-x 1 root root 944 Sep 14 21:03 kafka-console-producer.sh -rwxr-xr-x 1 root root 871 Sep 14 21:03 kafka-consumer-groups.sh -rwxr-xr-x 1 root root 948 Sep 14 21:03 kafka-consumer-perf-test.sh -rwxr-xr-x 1 root root 871 Sep 14 21:03 kafka-delegation-tokens.sh -rwxr-xr-x 1 root root 869 Sep 14 21:03 kafka-delete-records.sh -rwxr-xr-x 1 root root 866 Sep 14 21:03 kafka-dump-log.sh -rwxr-xr-x 1 root root 863 Sep 14 21:03 kafka-features.sh -rwxr-xr-x 1 root root 870 Sep 14 21:03 kafka-leader-election.sh -rwxr-xr-x 1 root root 863 Sep 14 21:03 kafka-log-dirs.sh -rwxr-xr-x 1 root root 873 Sep 14 21:03 kafka-metadata-shell.sh -rwxr-xr-x 1 root root 862 Sep 14 21:03 kafka-mirror-maker.sh -rwxr-xr-x 1 root root 886 Sep 14 21:03 kafka-preferred-replica-election.sh -rwxr-xr-x 1 root root 959 Sep 14 21:03 kafka-producer-perf-test.sh -rwxr-xr-x 1 root root 874 Sep 14 21:03 kafka-reassign-partitions.sh -rwxr-xr-x 1 root root 874 Sep 14 21:03 kafka-replica-verification.sh -rwxr-xr-x 1 root root 10329 Sep 14 21:03 kafka-run-class.sh -rwxr-xr-x 1 root root 1376 Sep 14 21:03 kafka-server-start.sh -rwxr-xr-x 1 root root 1361 Sep 14 21:03 kafka-server-stop.sh -rwxr-xr-x 1 root root 860 Sep 14 21:03 kafka-storage.sh -rwxr-xr-x 1 root root 945 Sep 14 21:03 kafka-streams-application-reset.sh -rwxr-xr-x 1 root root 863 Sep 14 21:03 kafka-topics.sh -rwxr-xr-x 1 root root 958 Sep 14 21:03 kafka-verifiable-consumer.sh -rwxr-xr-x 1 root root 958 Sep 14 21:03 kafka-verifiable-producer.sh -rwxr-xr-x 1 root root 1714 Sep 14 21:03 trogdor.sh drwxr-xr-x 2 root root 4096 Dec 31 00:30 windows -rwxr-xr-x 1 root root 867 Sep 14 21:03 zookeeper-security-migration.sh -rwxr-xr-x 1 root root 1393 Sep 14 21:03 zookeeper-server-start.sh -rwxr-xr-x 1 root root 1366 Sep 14 21:03 zookeeper-server-stop.sh -rwxr-xr-x 1 root root 1019 Sep 14 21:03 zookeeper-shell.sh运行kafka生产者发送消息:
bash-5.1# ./kafka-console-producer.sh --broker-list localhost:9092 --topic test >helloworld >运行消费者:
bash-5.1# cd /opt/kafka_2.13-2.8.1/bin/ bash-5.1# ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning helloworld
至此完成



