docker安装过程:Apache Kafka® Quick Start - Docker
注意:如果想要跨机器访问,对应的yaml配置如下:
--- version: '2' services: zookeeper: image: confluentinc/cp-zookeeper:7.0.1 restart: always container_name: zookeeper environment: ZOOKEEPER_CLIENT_PORT: 2181 ZOOKEEPER_TICK_TIME: 2000 broker: image: confluentinc/cp-kafka:7.0.1 restart: always container_name: broker ports: # To learn about configuring Kafka for access across networks see # https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/ - "9092:9092" depends_on: - zookeeper environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://IP:9092,PLAINTEXT_INTERNAL://broker:29092 KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 kafka-manager: image: kafka-manager restart: always container_name: kafka-manager hostname: kafka-manager ports: - 9010:9000 links: - broker external_links: - zookeeper environment: ZK_HOSTS: zookeeper:2181
启动顺序,
第一步安装java1.8,https://blog.csdn.net/sslfk/article/details/122806226
java环境变量配置:Linux普通用户对java环境变量进行配置 - 温馨世界 - 博客园
第二步:安装kafka3.0.0,内置zookeeper,Apache Kafka,直接解压即可
第三步启动zookeeper
线程守护启动,可以防止进程异常死亡:
守护进程模式启动安全可靠,进程不会异常死亡:
./zookeeper-server-start.sh -daemon ../config/zookeeper.properties 1>/dev/null 2>&1 &
守护进程模式启动安全可靠,进程可能异常死亡:
./zookeeper-server-start.sh ../config/zookeeper.properties 1>/dev/null 2>&1 &
第四步:配置kafka
config/server1.properties:
broker.id=0
listeners=PLAINTEXT://IP:9092
log.dirs=kafka-logs
zookeeper.connect=localhost:2181
第五步:启动kfakfa
守护进程启动,防止异常死亡:
./kafka-server-start.sh -daemon ../config/server.properties 1>/dev/null 2>&1 &
非守护进程启动,容易异常死亡:
./kafka-server-start.sh ../config/server.properties 1>/dev/null 2>&1 &
其他相关命令:
停止kafka
./kafka-server-stop.sh
停止zookeeper
./zookeeper-server-stop.sh
启动zookeeper
守护进程模式启动安全可靠,进程不会异常死亡:
./zookeeper-server-start.sh -daemon ../config/zookeeper.properties 1>/dev/null 2>&1 &
守护进程模式启动安全可靠,进程可能异常死亡:
./zookeeper-server-start.sh ../config/zookeeper.properties 1>/dev/null 2>&1 &
启动kafka
守护进程启动,防止异常死亡:
./kafka-server-start.sh -daemon ../config/server.properties 1>/dev/null 2>&1 &
非守护进程启动,容易异常死亡:
./kafka-server-start.sh ../config/server.properties 1>/dev/null 2>&1 &
topic创建:
./kafka-topics.sh --create --bootstrap-server IP:9092 --replication-factor 1 --partitions 1 --topic test1
当前topic列表查看:
./kafka-topics.sh --list --bootstrap-server IP:9092
修改topic的partition数:
kafka-topics.sh --bootstrap-server IP:9092 --alter --topic mytest --partitions 5
topic对应的消息查看:
./kafka-topics.sh --describe --bootstrap-server IP:9092
topic删除:
./kafka-topics.sh --delete --bootstrap-server IP:9092 --topic test1
查看消费者组列表:
./kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --list
查看消费者组的消费情况:
./kafka-consumer-groups.sh --describe --bootstrap-server 127.0.0.1:9092 --group invoiceUpload
kafka默认保存数据的周期是7天,如果磁盘空间有限,可以减少保存周期
配置方式为:
log.retention.hours=1 # 超过1个小时就清理数据
log.segment.bytes=5000 # 数据量超过5000byte就清理数据
log.cleanup.interval.mins=100 # 指定日志每隔多久检查看是否可以被删除,默认1分钟
log.retention.check.interval.ms=300 # 文件大小检查的周期时间,是否触发 log.cleanup.policy中设置的策略
参考:
Kafka常用命令(zookeeper与bootstrap-server)_沐已成风的博客-CSDN博客
Kafka broker-list,bootstrap-server以及zookeeper的区别 - 夏天换上冬装 - 博客园
Kafka Shell基本命令(包括topic的增删改查) - XIAO的博客 - 博客园
修改kafka topic的offset几种方法_奔向新世界-CSDN博客_kafka修改偏移量offset
kafka监控命令kafka-run-class.sh查看消费了多少条数据_小强签名设计 的博客-CSDN博客_kafka-run-class.sh
基于Python的Spark Streaming+Kafka编程实践_不积跬步,无以至千里;不积小流,无以成江海!-CSDN博客_python spark streaming