linux下单节点Kafka安装配置流程

时间:2021-03-23 21:34:13
  1. 假设节点的IP为127.0.0.1

  2. 去官网下载最新Kafka安装包

  3. 将安装包解压

  4. 进入解压后的文件夹,修改conf/server.properties文件

    broker.id=0#默认为0,在多节点下,每个节点的broker.id要不同 >
    listeners = PLAINTEXT://127.0.0.1:9092
    log.dirs=/tmp/kafka-logs#日志文件夹
    zookeeper.connect=localhost:2181#在多节点下,要指定其他节点的zookooper.connect,以逗号分隔

  5. 启动Kafka

    bin目录下执行./zookeeper-server-start.sh -daemon ../config/zookeeper.properties&启动zookeeper服务
    bin目录下执行./kafka-server-start.sh -daemon ../config/server.properties &启动kafka服务

  6. 测试

    创建一个topic ./kafka-topics.sh –create –zookeeper localhost:2181 –replication=factor 1 –partition 1 –topic testTopic
    查看在当前环境下所有topic ./kafka-topics.sh –list –zookeeper localhost:2181
    运行一个producer ./kafka-console-producer.sh –broker-list localhost:9092 –topic testTopic
    运行一个consumer ./kafka-console-consumer.sh –zookeeper localhost:2181 –topic testTopic–from-beginning
    producer 与 consumer要启在两个控制台,在producer控制台下输入,consumer控制台就会输出