Docker安装kafka集群

  • 获取镜像
​$ docker pull zookeeper:3.4
 
$ docker pull wurstmeister/kafka:1.1.0
  • 创建网络
$ docker network create --attachable --driver overlay --subnet 192.168.1.0/24 svc_net
  • zookpeer集群
$ export ZK_ID=1
$ docker service create --name zk$ZK_ID --mode global --hostname zk$ZK_ID \
  --network svc_net --endpoint-mode dnsrr \
  --mount type=bind,src=/data/zk/data,target=/data \
  --constraint node.labels.zk==$ZK_ID \
  --publish published=2080,target=8080,mode=host \
  -e ZOO_MY_ID=$ZK_ID \
  -e ZOO_SERVERS="server.1=tasks.zk1:2888:3888 server.2=tasks.zk2:2888:3888 server.3=tasks.zk3:2888:3888" \
  -e JVMFLAGS="-Xmx256m" zookeeper:3.4
 
$ export ZK_ID=2
$ docker service create --name zk$ZK_ID --mode global --hostname zk$ZK_ID \
  --network svc_net --endpoint-mode dnsrr \
  --mount type=bind,src=/data/zk/data,target=/data \
  --constraint node.labels.zk==$ZK_ID \
  -e ZOO_ADMINSERVER_ENABLED=false \
  -e ZOO_MY_ID=$ZK_ID \
  -e ZOO_SERVERS="server.1=tasks.zk1:2888:3888 server.2=tasks.zk2:2888:3888 server.3=tasks.zk3:2888:3888" \
  -e JVMFLAGS="-Xmx256m" zookeeper:3.4
 
$ export ZK_ID=3
$ docker service create --name zk$ZK_ID --mode global --hostname zk$ZK_ID \
  --network svc_net --endpoint-mode dnsrr \
  --mount type=bind,src=/data/zk/data,target=/data \
  --constraint node.labels.zk==$ZK_ID \
  -e ZOO_ADMINSERVER_ENABLED=false \
  -e ZOO_MY_ID=$ZK_ID \
  -e ZOO_SERVERS="server.1=tasks.zk1:2888:3888 server.2=tasks.zk2:2888:3888 server.3=tasks.zk3:2888:3888" \
  -e JVMFLAGS="-Xmx256m" zookeeper:3.4
  • kafka集群
$ export ZK_ID=1
$ docker service create --name kf$ZK_ID --mode global --hostname kf$ZK_ID \
  --constraint node.labels.zk==$ZK_ID \
  --network svc_net --endpoint-mode dnsrr \
  --publish published=9092,target=9092,mode=host \
  --mount type=bind,src=/data/kf/data,target=/kafka \
  -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
  -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://tasks.kf$ZK_ID:9092 \
  -e KAFKA_BROKER_ID=$ZK_ID \
  -e KAFKA_ZOOKEEPER_CONNECT="tasks.zk1:2181,tasks.zk2:2181,tasks.zk3:2181/kafka" \
   wurstmeister/kafka:1.1.0
 
$ export ZK_ID=2
$ docker service create --name kf$ZK_ID --mode global --hostname kf$ZK_ID \
  --constraint node.labels.zk==$ZK_ID \
  --network svc_net --endpoint-mode dnsrr \
  --publish published=9092,target=9092,mode=host \
  --mount type=bind,src=/data/kf/data,target=/kafka \
  -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
  -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://tasks.kf$ZK_ID:9092 \
  -e KAFKA_BROKER_ID=$ZK_ID \
  -e KAFKA_ZOOKEEPER_CONNECT="tasks.zk1:2181,tasks.zk2:2181,tasks.zk3:2181/kafka" \
   wurstmeister/kafka:1.1.0
 
$ export ZK_ID=3
$ docker service create --name kf$ZK_ID --mode global --hostname kf$ZK_ID \
  --constraint node.labels.zk==$ZK_ID \
  --network svc_net --endpoint-mode dnsrr \
  --publish published=9092,target=9092,mode=host \
  --mount type=bind,src=/data/kf/data,target=/kafka \
  -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
  -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://tasks.kf$ZK_ID:9092 \
  -e KAFKA_BROKER_ID=$ZK_ID \
  -e KAFKA_ZOOKEEPER_CONNECT="tasks.zk1:2181,tasks.zk2:2181,tasks.zk3:2181/kafka" \
   wurstmeister/kafka:1.1.0

 

你可能感兴趣的:(Docker安装kafka集群)