1 Kafka简介

kafka官网下载

1.1 基本概念

2 Kafka安装和测试

2.1 下载

kafka_2.12-2.8.0下载

2.2 配置

2.2.1 zookeeper.properties

# the directory where the snapshot is stored.
dataDir=/home/huangyc/kafka_2.12-2.8.0/zk_logs
# the port at which the clients will connect
clientPort=2183

2.2.2 server.properties

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9092

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2183

# A comma separated list of directories under which to store log files
log.dirs=/home/huangyc/kafka_2.12-2.8.0/kafka_logs

2.3 启动

启动zookeeper

./bin/zookeeper-server-start.sh ./config/zookeeper.properties

启动kafka

./bin/kafka-server-start.sh ./config/server.properties

查看Kafka进程

[root@Hmaster kafka_2.12-2.8.0]# jps | grep Kafka
23425 Kafka

2.4 测试

查看主题列表

bin/kafka-topics.sh --zookeeper localhost:2183 --list

消息生产者

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

消息消费者

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
0.9以前版本: 
kafka-console-consumer.bat --zookeeper localhost:2183 --topic test --from-beginning

2.5 另一套方案

server.properties

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9092

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
advertised.listeners=PLAINTEXT://192.168.123.21:9092

# A comma separated list of directories under which to store log files
log.dirs=/home/huangyc/kafka_2.12-2.8.0/kafka_logs

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2183

消息生产者

bin/kafka-console-producer.sh --broker-list localhost:9092 --topiest

消息消费者

bin/kafka-console-consumer.sh --bootstrap-server 192.168.123.21:9092

2.6 其他问题

win10访问

需要配置host

C:\Windows\System32\drivers\etc\hosts

192.168.123.21 Hmaster

# 查看 hostname
[root@Hmaster ~]# hostnamectl
   Static hostname: Hmaster
         Icon name: computer-desktop
           Chassis: desktop
        Machine ID: 87af5eaaaf7c48f6b1cd9f42bfb51c76
           Boot ID: 9fe58388f3274f0e838b7cd1b720eacd
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1160.el7.x86_64
      Architecture: x86-64

防火墙开启

systemctl start firewalld

端口开启

firewall-cmd --zone=public --add-port=9092/tcp --permanent

生效

firewall-cmd --reload

Copyright © narutohyc.com 2021 all right reserved,powered by Gitbook该文件修订时间: 2024-05-06 07:11:23

results matching ""

    No results matching ""