1.下载安装包并解压java
kafka_2.11-2.1.0.tgz 详解: https://blog.csdn.net/lingbo229/article/details/80761778
2. 配置kafka集群
node
cd /usr/local/kafka_2.11-2.1.0/config ############################# Server Basics ############################# # The id of the broker. This must be set to a unique integer for each broker. broker.id=0 # 这个标识是kafka这台服务器 ############################# Socket Server Settings ############################# # 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 # kafka 监听地址端口 ############################# Log Basics ############################# # A comma separated list of directories under which to store log files log.dirs=/tmp/kafka-logs # 日志存储目录 & 保存kafka数据(维护消息持久化) # The default number of log partitions per topic. More partitions allow greater # parallelism for consumption, but this will also result in more files across # the brokers. num.partitions=1 #存储kafka每条消息的分区数量 ############################# Zookeeper ############################# # 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=10.10.23.39:2181,10.10.23.40:2181,10.10.23.41:2181 # Timeout in ms for connecting to zookeeper zookeeper.connection.timeout.ms=6000 auto.create.topics.enable=true #自动建立topics,防止信息没法存储 delete.topic.enable=true #完全删除topics
3. kafka 启动bootstrap
./kafka-server-start.sh ../config/server.properties 或 nohup ./kafka-server-start.sh ../config/server.properties
4. kafka经常使用操做bash
提供查看、建立、修改、删除topic信息。 ./kafka-topics.sh --zookeeper 10.10.23.39:2181,10.10.23.40:2181,10.10.23.41:2181 --list#查询topics ./kafka-topics.sh --create --zookeeper 10.10.23.39:2181,10.10.23.40:2181,10.10.23.41:2181 \ --replication-factor 1 --partitions 3 --topic mytopic #建立一个topics,副本 1 分片 3 ./kafka-topics.sh --describe --zookeeper 10.10.23.39:2181,10.10.23.40:2181,10.10.23.41:2181 \ --topic mytopic #查看topic 属性 ./kafka-console-producer.sh --broker-list 10.10.23.39:9092,10.10.23.40:9092,10.10.23.41:9092\ --topic mytopic #指定topic 生产消息 ./kafka-console-consumer.sh --bootstrap-server 10.10.23.39:9092,10.10.23.40:9092,10.10.23.41:9092\ --from-beginning --topic test01 #消费指定topic消息 ./kafka-topics.sh --delete --zookeeper 10.10.23.39:2181,10.10.23.40:2181,10.10.23.41:2181 \ --topic osmessage #删除一个topic消息