kafka 镜像:wurstmeister/kafka

docker run -d —name kafka -p 9092:9092 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=139.196.103.162:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://139.196.103.162:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -v /etc/localtime:/etc/localtime wurstmeister/kafka

//启动kafka
docker run -d —name kafka —publish 9092:9092 \ —link zookeeper \ —env KAFKA_ZOOKEEPER_CONNECT=139.196.103.162:2181 \ —env KAFKA_ADVERTISED_HOST_NAME=139.196.103.162 \ —env KAFKA_ADVERTISED_PORT=9092 \ —volume /etc/localtime:/etc/localtime \ wurstmeister/kafka

此命令成功安装并启动

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

docker run -d —name kafka -p 9092:9092 -e KAFKA_BROKER_ID=1 -e KAFKA_auto_create_topics_enable=true -e KAFKA_HEAP_OPTS=”-Xmx256M -Xms128M” -e KAFKA_ZOOKEEPER_CONNECT=139.196.103.162:2181 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://139.196.103.162:9092 \
-e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \
-e KAFKA_LOG_DIRS=/opt/kafka-logs \
-t wurstmeister/kafka

listeners=
advertised.listeners=INTERNAL://192.168.133.11:9092,EXTERNAL://<公网ip>:<端口>

命令详解

-e KAFKA_BROKER_ID=0 在kafka集群中,每个kafka都有一个BROKER_ID来区分自己
-e KAFKA_ZOOKEEPER_CONNECT=192.168.155.56:2181/kafka 配置zookeeper管理kafka的路径192.168.155.56:2181/kafka
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.155.56:9092 把kafka的地址端口注册给zookeeper
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 配置kafka的监听端口
-v /etc/localtime:/etc/localtime 容器时间同步虚拟机的时间

未使用命令

  1. docker run -d
  2. --name kafka
  3. -p 9092:9092
  4. -e KAFKA_BROKER_ID=1
  5. -e KAFKA_auto_create_topics_enable=true
  6. -e KAFKA_HEAP_OPTS="-Xmx256M -Xms128M"
  7. -e KAFKA_ZOOKEEPER_CONNECT=139.196.103.162:2181
  8. -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://139.196.103.162:9092
  9. -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
  10. -t wurstmeister/kafka
  11. ### 命令解析
  12. //配置分组id
  13.   KAFKA_BROKER_ID=1
  14.   //开启自动创建主题(不然代码整合服务后启动报错,必须自己手动到服务上创建)
  15.   KAFKA_auto_create_topics_enable=true
  16.   //连接zookeeper
  17.   KAFKA_ZOOKEEPER_CONNECT=公网ip:2181
  18.   //默认内存1G自己服务器太小,调小一点不然启动报错内存溢出(此处也比较坑)
  19.   KAFKA_HEAP_OPTS="-Xmx256M -Xms128M"
  20.   //配置外网ip访问kafka
  21.   KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://公网ip:9092