当前位置:   article > 正文

kafka内外网配置_kafka external

kafka external

看此文档,需要首先会安装kafka集群,zookeeper集群;熟悉组件命令;

三台kafka集群(设置加密通道):

     

192.168.1.86:9092外网IP:19092
192.168.1.87:9092外网IP:19093
192.168.1.88:9092外网IP:19094

修改kafka server.properties  其中listeners 和 advertised.listeners 中 EXTERNAL的端口必须一致

1. 修改86 kafka 内外网配置

  1. listeners=INTERNAL://0.0.0.0:9092,EXTERNAL://0.0.0.0:19092
  2. advertised.listeners=INTERNAL://192.168.1.86:9092,EXTERNAL://外网IP:19092
  3. inter.broker.listener.name=INTERNAL
  4. listener.security.protocol.map = SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL,PLAINTEXT:PLAINTEXT,INTERNAL:SASL_PLAINTEXT,EXTERNAL:SASL_PLAINTEXT

2. 修改87 kafka 内外网配置

  1. listeners=INTERNAL://0.0.0.0:9092,EXTERNAL://0.0.0.0:19093
  2. advertised.listeners=INTERNAL://192.168.1.87:9092,EXTERNAL://外网IP:19093
  3. inter.broker.listener.name=INTERNAL
  4. listener.security.protocol.map = SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL,PLAINTEXT:PLAINTEXT,INTERNAL:SASL_PLAINTEXT,EXTERNAL:SASL_PLAINTEXT

3. 修改88 kafka 内外网配置

  1. listeners=INTERNAL://0.0.0.0:9092,EXTERNAL://0.0.0.0:19094
  2. advertised.listeners=INTERNAL://192.168.1.88:9092,EXTERNAL://外网IP:19094
  3. inter.broker.listener.name=INTERNAL
  4. listener.security.protocol.map = SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL,PLAINTEXT:PLAINTEXT,INTERNAL:SASL_PLAINTEXT,EXTERNAL:SASL_PLAINTEXT

4. 注释配置

  1. # security.inter.broker.protocol=SASL_PLAINTEXT
  2. # listeners=SASL_PLAINTEXT://0.0.0.0:9092
  3. # advertised.listeners=SASL_PLAINTEXT://192.168.1.86:9092

5. 最终配置demo

  1. broker.id=0
  2. authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
  3. # security.inter.broker.protocol=INTERNAL
  4. sasl.mechanism.inter.broker.protocol=PLAIN
  5. sasl.enabled.mechanisms=PLAIN
  6. super.users=User:admin
  7. # listeners=SASL_PLAINTEXT://0.0.0.0:9092
  8. # advertised.listeners=SASL_PLAINTEXT://192.168.1.86:9092
  9. num.network.threads=3
  10. num.io.threads=8
  11. socket.send.buffer.bytes=102400
  12. socket.receive.buffer.bytes=102400
  13. socket.request.max.bytes=104857600
  14. log.dirs=/opt/kafka-logs
  15. num.partitions=1
  16. num.recovery.threads.per.data.dir=1
  17. log.cleanup.policy=delete
  18. log.retention.hours=72
  19. log.segment.bytes=1073741824
  20. zookeeper.connect=192.168.1.86:2181,192.168.1.87:2181,192.168.1.88:2181
  21. delete.topic.enable=true
  22. zookeeper.connection.timeout.ms=60000
  23. listeners=INTERNAL://0.0.0.0:9092,EXTERNAL://0.0.0.0:19092
  24. advertised.listeners=INTERNAL://192.168.1.86:9092,EXTERNAL://外网IP:19092
  25. inter.broker.listener.name=INTERNAL
  26. # 这个协议底层使用了哪种安全协议 PLAINTEXT 不加密;SASL_PLAINTEXT 普通加密;SSL 高级加密
  27. listener.security.protocol.map = SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL,PLAINTEXT:PLAINTEXT,INTERNAL:SASL_PLAINTEXT,EXTERNAL:SASL_PLAINTEXT

操作kafka集群命令集合:

  1. # 如何进入docker:
  2. docker ps -a 查看所有进程
  3. docker exec -it 容器id bash / 使用管理员权限进入容器)
  4. docker exec -it -u root b667f9cfa164 bash
  5. docker exec -it test bash
  6. #杀掉zk和kafka
  7. ps -ef|grep -E "kafka|zookeeper"|grep -v grep |awk '{print $2}'|while read pid;do kill -9 $pid;done
  8. ps -ef|grep -E "kafka" |grep -v grep |awk '{print $2}'|while read pid;do kill -9 $pid;done
  9. ps -ef|grep -E "zookeeper"|grep -v grep |awk '{print $2}'|while read pid;do kill -9 $pid;done
  10. #启动zk (清除数据:需要删除 zoo.cfg 中 dataDir指向的文件夹下所有的非 myid的文件和文件夹)
  11. /usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo.cfg
  12. # 查看zk的状态 (启动状态不正确时,查看zoo.cfg 中 dataDir 下的 zookeeper.out日志)
  13. /usr/local/zookeeper/bin/zkServer.sh status /usr/local/zookeeper/conf/zoo.cfg
  14. # 临时启动kafka (查看是否有异常,根据日志调试;查看server.properties中log.dirs指向 删除干净)
  15. /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
  16. # 启动kafka
  17. nohup /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties >>/usr/local/kafka/logs/kafka.log 2>1 &
  18. # 查看topic列表
  19. /usr/local/kafka/bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list
  20. # 删除topic
  21. /usr/local/kafka/bin/kafka-topics.sh --delete --zookeeper 127.0.0.1:2181 --topic douzi-test
  22. # 创建topic
  23. /usr/local/kafka/bin/kafka-topics.sh --create --topic douzi-test --replication-factor 3 --partitions 3 --zookeeper localhost:2181
  24. # 接收消息:(普通模式)
  25. ./kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic douzi-test
  26. # 接收消息:(加密情况下的命令)
  27. /usr/local/kafka/bin/reader-kafka-console-consumer.sh --bootstrap-server 0.0.0.0:9092 --topic douzi-test --from-beginning --consumer.config /usr/local/kafka/producer.config
  28. # 发送消息:
  29. ./kafka-console-producer.sh --broker-list localhost:9092 --topic douzi-test
  30. # 发送消息:(加密情况下的命令)
  31. /usr/local/kafka/bin/writer-kafka-console-producer.sh --broker-list localhost:9092 --topic douzi-test --producer.config /usr/local/kafka/producer.config

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/822422
推荐阅读
相关标签
  

闽ICP备14008679号