赞
踩
kafka版本2.2+的版本,已经不需要依赖zookeeper来查看、创建topic,新版本使用--bootstrap-server替换老版本的--zookeeper-server。
listeners=PLAINTEXT://172.16.61.125:9092
配置完内网可以正常得去消费或者添加kfka数据
如果配置了advertised.listeners就无法正常访问消费
- advertised.listeners=PLAINTEXT://11.11.11.11:9092
-
- WARN [Consumer clientId=consumer-console-consumer-94880-1, groupId=console-consumer-94880] Error while fetching metadata with correlation id 2 : {ooxx=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
因为我的外网通讯虽然注册得zookeeper里面了,但是外网网络无法在kafka 集群机器上来回通讯导致问题,所以这个时候需要切换成内外网分流访问
- listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
- listeners=INTERNAL://172.16.61.125:9092,EXTERNAL://172.16.61.125:19092
- advertised.listeners=INTERNAL://172.16.61.125:9092,EXTERNAL://11.11.11.11:19092
- inter.broker.listener.name=INTERNAL
- listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
- listeners=INTERNAL://172.16.61.125:9092,EXTERNAL://11.11.11.11:19092
- advertised.listeners=INTERNAL://172.16.61.125:9092,EXTERNAL://11.11.11.11:19092
- inter.broker.listener.name=INTERNAL
注意这两的区别是listeners的EXTERNAL使用的ip不一样,一个使用内网ip,一个使用外网ip。
在这里配置得 kafka内部访问端口与外部访问端口不能是一致得。
- # 进入kafka目录
- [root@icoolkj kafka_2.13-3.4.0]#
- # 创建 data 目录
- [root@icoolkj kafka_2.13-3.4.0]# mkdir data
- [root@icoolkj kafka_2.13-3.4.0]# cd data
- # 创建 logs 目录
- [root@icoolkj data]# mkdir logs dataDir dataLogDir
- # 进入kafka的config配置目录
- [root@icoolkj data]# cd /home/kafka/kafka_2.13-3.4.0/config/
- # 配置kafka的server.properties配置文件
- [root@icoolkj config]# vi server.properties
-
- broker.id=0
- # 端口号
- port=9092
- # 主机地址,如果是单机可以直接使用127.0.0.1
- host.name=127.0.0.1
- # 日志存放路径
- log.dirs=/home/kafka/kafka_2.13-3.4.0/data/logs
- # 关联的zookeeper的地址和端口,如果是单机可以直接使用127.0.0.1
- zookeeper.connect=127.0.0.1:2181
- 1、完整的配置文件
- #grep -Ev '^#|^$' /soft/kafka/config/server.properties
- broker.id=0
- listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
- listeners=INTERNAL://172.16.61.125:9092,EXTERNAL://172.16.61.125:19092
- advertised.listeners=INTERNAL://172.16.61.125:9092,EXTERNAL://11.11.11.11:19092
- inter.broker.listener.name=INTERNAL
- num.network.threads=3
- num.io.threads=8
- socket.send.buffer.bytes=102400
- socket.receive.buffer.bytes=102400
- socket.request.max.bytes=104857600
- log.dirs=/soft/kafka/data/logs
- num.partitions=1
- num.recovery.threads.per.data.dir=1
- offsets.topic.replication.factor=1
- transaction.state.log.replication.factor=1
- transaction.state.log.min.isr=1
- log.retention.hours=168
- log.retention.check.interval.ms=300000
- zookeeper.connect=localhost:2181
- zookeeper.connection.timeout.ms=18000
- group.initial.rebalance.delay.ms=0
-
- 2、启动脚本
- #cat /etc/systemd/system/kafka.service
- [Unit]
- Description=kafka Service
- After=ssh.service
- [Service]
- User=root
- Restart=always
- Environment=JAVA_HOME=/data/jdk
- Type=forking
- ExecStart=/soft/kafka/bin/kafka-server-start.sh -daemon /soft/kafka/config/server.properties
- ExecReload=/bin/kill -s HUP $MAINPID
- ExecStop=/soft/kafka/bin/kafka-server-stop.sh
- [Install]
- WantedBy=multi-user.target
- 1、配置文件
- #grep -Ev '^#|^$' /soft/kafka/config/zookeeper.properties
- dataDir=/soft/kafka/data/dataDir
- dataLogDir=/soft/kafka/data/logs
- clientPort=2181
- maxClientCnxns=100
- tickTime=2000
- initLimit=10
- admin.enableServer=false
-
- 2、启动脚本
- #cat /etc/systemd/system/zk.service
- [Unit]
- Description=Zoopker Service
- After=ssh.service
- [Service]
- User=root
- Restart=always
- Environment=JAVA_HOME=/data/jdk
- Type=forking
- ExecStart=/soft/kafka/bin/zookeeper-server-start.sh -daemon /soft/kafka/config/zookeeper.properties
- ExecReload=/bin/kill -s HUP $MAINPID
- ExecStop=/soft/kafka/bin/zookeeper-server-stop.sh
- [Install]
- WantedBy=multi-user.target
- 1、创建
- #cd /soft/kafka/bin
- #sh kafka-topics.sh --create --topic kafka_test --bootstrap-server 11.11.11.11:19092
- WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
- Created topic kafka_test.
-
- 2、查看
- #sh kafka-topics.sh --list --bootstrap-server 11.11.11.11:19092
- __consumer_offsets
- kafka_test
-
- 3、删除测试数据
- #sh kafka-topics.sh --delete --topic kafka_test --bootstrap-server 11.11.11.11:19092
- #sh kafka-topics.sh --list --bootstrap-server 11.11.11.11:19092
- __consumer_offsets
- #systemctl daemon-reload
- #systemctl start zk; systemctl start kafka
- #systemctl enable zk; systemctl enable kafka
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。