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消息