kafka學習——Introduction&QuickStart

** 今天看了一下kafka官網(wǎng)瘟则,嘗試著在自己電腦上安裝和配置黎炉,然后學一下官方document。**

Introduction

官網(wǎng)有個示意圖如下:


kafka_diagram

kafka特點:

  • 它是一個處理流式數(shù)據(jù)的”發(fā)布-訂閱“消息系統(tǒng)醋拧。
  • 實時高效處理流式數(shù)據(jù)慷嗜。
  • 將數(shù)據(jù)安全存儲在分布式集群淀弹。
  • 它是運行在集群上的。
  • 它將流式記錄存儲在topics中庆械。
  • 每個record由key,value和timestamp組成薇溃。

kafka幾個概念

  • broker:kafka集群包含一個或者多個服務(wù)器,服務(wù)器就稱作broker
  • topic:發(fā)布到kafka集群的消息類別干奢。
  • partition:每個topic劃分為多個partition痊焊。
  • producer:負責發(fā)布消息到broker
  • consumer:消費者,從broker獲取消息
  • consumer group

kafka的核心API

  • Producer
  • Consumer
  • Streams
  • Connector


    kafka API 示意圖

    Topic 結(jié)構(gòu)示意圖

    kafka 架構(gòu)示意圖

QuickStart

  1. 安裝
    brew install kafka
    注意:安裝kafka時忿峻,會同時安裝zookeeper,mac下默認安裝路徑為 /usr/local/Homebrew/Cellar/kafka/
    配置文件路徑在:/usr/local/Homebrew/etc/kafka/
    2 首先啟動zookeeper
    注意此時如果不啟動zookeeper而直接啟動kafka會報錯辕羽。
RaindeMacBook-Pro:bin rain$ ./kafka-server-start /usr/local/Homebrew/etc/kafka/server.properties
[2017-04-20 21:00:38,027] INFO KafkaConfig values:
    advertised.host.name = null
    advertised.listeners = null
    advertised.port = null
    authorizer.class.name =
    auto.create.topics.enable = true
    auto.leader.rebalance.enable = true
    background.threads = 10
    broker.id = 0
    broker.id.generation.enable = true
    broker.rack = null
    compression.type = producer
    connections.max.idle.ms = 600000
    controlled.shutdown.enable = true
    controlled.shutdown.max.retries = 3
    controlled.shutdown.retry.backoff.ms = 5000
    controller.socket.timeout.ms = 30000
    create.topic.policy.class.name = null
    default.replication.factor = 1
    delete.topic.enable = false
    fetch.purgatory.purge.interval.requests = 1000
    group.max.session.timeout.ms = 300000
    group.min.session.timeout.ms = 6000
    host.name =
    inter.broker.listener.name = null
    inter.broker.protocol.version = 0.10.2-IV0
    leader.imbalance.check.interval.seconds = 300
    leader.imbalance.per.broker.percentage = 10
    listener.security.protocol.map = SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,TRACE:TRACE,SASL_SSL:SASL_SSL,PLAINTEXT:PLAINTEXT
    listeners = null
    log.cleaner.backoff.ms = 15000
    log.cleaner.dedupe.buffer.size = 134217728
    log.cleaner.delete.retention.ms = 86400000
    log.cleaner.enable = true
    log.cleaner.io.buffer.load.factor = 0.9
    log.cleaner.io.buffer.size = 524288
    log.cleaner.io.max.bytes.per.second = 1.7976931348623157E308
    log.cleaner.min.cleanable.ratio = 0.5
    log.cleaner.min.compaction.lag.ms = 0
    log.cleaner.threads = 1
    log.cleanup.policy = [delete]
    log.dir = /tmp/kafka-logs
    log.dirs = /usr/local/Homebrew/var/lib/kafka-logs
    log.flush.interval.messages = 9223372036854775807
    log.flush.interval.ms = null
    log.flush.offset.checkpoint.interval.ms = 60000
    log.flush.scheduler.interval.ms = 9223372036854775807
    log.index.interval.bytes = 4096
    log.index.size.max.bytes = 10485760
    log.message.format.version = 0.10.2-IV0
    log.message.timestamp.difference.max.ms = 9223372036854775807
    log.message.timestamp.type = CreateTime
    log.preallocate = false
    log.retention.bytes = -1
    log.retention.check.interval.ms = 300000
    log.retention.hours = 168
    log.retention.minutes = null
    log.retention.ms = null
    log.roll.hours = 168
    log.roll.jitter.hours = 0
    log.roll.jitter.ms = null
    log.roll.ms = null
    log.segment.bytes = 1073741824
    log.segment.delete.delay.ms = 60000
    max.connections.per.ip = 2147483647
    max.connections.per.ip.overrides =
    message.max.bytes = 1000012
    metric.reporters = []
    metrics.num.samples = 2
    metrics.recording.level = INFO
    metrics.sample.window.ms = 30000
    min.insync.replicas = 1
    num.io.threads = 8
    num.network.threads = 3
    num.partitions = 1
    num.recovery.threads.per.data.dir = 1
    num.replica.fetchers = 1
    offset.metadata.max.bytes = 4096
    offsets.commit.required.acks = -1
    offsets.commit.timeout.ms = 5000
    offsets.load.buffer.size = 5242880
    offsets.retention.check.interval.ms = 600000
    offsets.retention.minutes = 1440
    offsets.topic.compression.codec = 0
    offsets.topic.num.partitions = 50
    offsets.topic.replication.factor = 3
    offsets.topic.segment.bytes = 104857600
    port = 9092
    principal.builder.class = class org.apache.kafka.common.security.auth.DefaultPrincipalBuilder
    producer.purgatory.purge.interval.requests = 1000
    queued.max.requests = 500
    quota.consumer.default = 9223372036854775807
    quota.producer.default = 9223372036854775807
    quota.window.num = 11
    quota.window.size.seconds = 1
    replica.fetch.backoff.ms = 1000
    replica.fetch.max.bytes = 1048576
    replica.fetch.min.bytes = 1
    replica.fetch.response.max.bytes = 10485760
    replica.fetch.wait.max.ms = 500
    replica.high.watermark.checkpoint.interval.ms = 5000
    replica.lag.time.max.ms = 10000
    replica.socket.receive.buffer.bytes = 65536
    replica.socket.timeout.ms = 30000
    replication.quota.window.num = 11
    replication.quota.window.size.seconds = 1
    request.timeout.ms = 30000
    reserved.broker.max.id = 1000
    sasl.enabled.mechanisms = [GSSAPI]
    sasl.kerberos.kinit.cmd = /usr/bin/kinit
    sasl.kerberos.min.time.before.relogin = 60000
    sasl.kerberos.principal.to.local.rules = [DEFAULT]
    sasl.kerberos.service.name = null
    sasl.kerberos.ticket.renew.jitter = 0.05
    sasl.kerberos.ticket.renew.window.factor = 0.8
    sasl.mechanism.inter.broker.protocol = GSSAPI
    security.inter.broker.protocol = PLAINTEXT
    socket.receive.buffer.bytes = 102400
    socket.request.max.bytes = 104857600
    socket.send.buffer.bytes = 102400
    ssl.cipher.suites = null
    ssl.client.auth = none
    ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
    ssl.endpoint.identification.algorithm = null
    ssl.key.password = null
    ssl.keymanager.algorithm = SunX509
    ssl.keystore.location = null
    ssl.keystore.password = null
    ssl.keystore.type = JKS
    ssl.protocol = TLS
    ssl.provider = null
    ssl.secure.random.implementation = null
    ssl.trustmanager.algorithm = PKIX
    ssl.truststore.location = null
    ssl.truststore.password = null
    ssl.truststore.type = JKS
    unclean.leader.election.enable = true
    zookeeper.connect = localhost:2181
    zookeeper.connection.timeout.ms = 6000
    zookeeper.session.timeout.ms = 6000
    zookeeper.set.acl = false
    zookeeper.sync.time.ms = 2000
 (kafka.server.KafkaConfig)
[2017-04-20 21:00:38,075] INFO starting (kafka.server.KafkaServer)
[2017-04-20 21:00:38,080] INFO Connecting to zookeeper on localhost:2181 (kafka.server.KafkaServer)
[2017-04-20 21:00:38,094] INFO Starting ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
[2017-04-20 21:00:38,107] INFO Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,107] INFO Client environment:host.name=172.23.233.166 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,107] INFO Client environment:java.version=1.8.0_111 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,107] INFO Client environment:java.vendor=Oracle Corporation (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,107] INFO Client environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:java.class.path=:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/aopalliance-repackaged-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/argparse4j-0.7.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-api-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-file-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-json-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-runtime-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-transforms-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/guava-18.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/hk2-api-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/hk2-locator-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/hk2-utils-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-annotations-2.8.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-annotations-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-core-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-databind-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-jaxrs-base-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-jaxrs-json-provider-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-module-jaxb-annotations-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javassist-3.20.0-GA.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.annotation-api-1.2.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.inject-1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.inject-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.servlet-api-3.1.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.ws.rs-api-2.0.1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-client-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-common-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-container-servlet-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-container-servlet-core-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-guava-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-media-jaxb-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-server-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-continuation-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-http-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-io-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-security-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-server-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-servlet-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-servlets-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-util-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jopt-simple-5.0.3.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-clients-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-log4j-appender-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-streams-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-streams-examples-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-tools-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka_2.11-0.10.2.0-sources.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka_2.11-0.10.2.0-test-sources.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka_2.11-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/log4j-1.2.17.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/lz4-1.3.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/metrics-core-2.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/osgi-resource-locator-1.0.1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/reflections-0.9.10.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/rocksdbjni-5.0.1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/scala-library-2.11.8.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/scala-parser-combinators_2.11-1.0.4.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/slf4j-api-1.7.21.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/slf4j-log4j12-1.7.21.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/snappy-java-1.1.2.6.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/validation-api-1.1.0.Final.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/zkclient-0.10.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/zookeeper-3.4.9.jar (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:java.library.path=/Users/rain/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:java.io.tmpdir=/var/folders/lt/cqdkmb2x74nb7pj4ftp0ym0h0000gn/T/ (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:os.name=Mac OS X (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:os.arch=x86_64 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:os.version=10.12.3 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:user.name=rain (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:user.home=/Users/rain (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,108] INFO Client environment:user.dir=/usr/local/Homebrew/Cellar/kafka/0.10.2.0/bin (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,109] INFO Initiating client connection, connectString=localhost:2181 sessionTimeout=6000 watcher=org.I0Itec.zkclient.ZkClient@63355449 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:00:38,130] INFO Waiting for keeper state SyncConnected (org.I0Itec.zkclient.ZkClient)
[2017-04-20 21:00:38,133] INFO Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2017-04-20 21:00:38,236] WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
[2017-04-20 21:00:38,347] INFO Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2017-04-20 21:00:38,349] WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
[2017-04-20 21:00:39,460] INFO Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2017-04-20 21:00:39,461] WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
[2017-04-20 21:00:39,567] INFO Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2017-04-20 21:00:39,568] WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
[2017-04-20 21:00:40,669] INFO Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2017-04-20 21:00:40,669] WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
[2017-04-20 21:00:40,775] INFO Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2017-04-20 21:00:40,776] WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
^C[2017-04-20 21:00:41,658] INFO shutting down (kafka.server.KafkaServer)
[2017-04-20 21:00:41,659] FATAL Fatal error during KafkaServer shutdown. (kafka.server.KafkaServer)
java.lang.IllegalStateException: Kafka server is still starting up, cannot shut down!
    at kafka.server.KafkaServer.shutdown(KafkaServer.scala:575)
    at kafka.server.KafkaServerStartable.shutdown(KafkaServerStartable.scala:51)
    at kafka.Kafka$$anon$1.run(Kafka.scala:63)
[2017-04-20 21:00:41,660] FATAL Fatal error during KafkaServerStable shutdown. Prepare to halt (kafka.server.KafkaServerStartable)
java.lang.IllegalStateException: Kafka server is still starting up, cannot shut down!
    at kafka.server.KafkaServer.shutdown(KafkaServer.scala:575)
    at kafka.server.KafkaServerStartable.shutdown(KafkaServerStartable.scala:51)
    at kafka.Kafka$$anon$1.run(Kafka.scala:63)

所以首先要啟動zookeeper:

RaindeMacBook-Pro:bin rain$ ./zookeeper-server-start /usr/local/Homebrew/etc/kafka/
connect-console-sink.properties    connect-file-sink.properties       connect-standalone.properties      producer.properties                zookeeper.properties
connect-console-source.properties  connect-file-source.properties     consumer.properties                server.properties
connect-distributed.properties     connect-log4j.properties           log4j.properties                   tools-log4j.properties
RaindeMacBook-Pro:bin rain$ ./zookeeper-server-start /usr/local/Homebrew/etc/kafka/
connect-console-sink.properties    connect-file-sink.properties       connect-standalone.properties      producer.properties                zookeeper.properties
connect-console-source.properties  connect-file-source.properties     consumer.properties                server.properties
connect-distributed.properties     connect-log4j.properties           log4j.properties                   tools-log4j.properties
RaindeMacBook-Pro:bin rain$ ./zookeeper-server-start /usr/local/Homebrew/etc/kafka/zookeeper.properties
[2017-04-20 21:01:39,285] INFO Reading configuration from: /usr/local/Homebrew/etc/kafka/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
[2017-04-20 21:01:39,288] INFO autopurge.snapRetainCount set to 3 (org.apache.zookeeper.server.DatadirCleanupManager)
[2017-04-20 21:01:39,288] INFO autopurge.purgeInterval set to 0 (org.apache.zookeeper.server.DatadirCleanupManager)
[2017-04-20 21:01:39,288] INFO Purge task is not scheduled. (org.apache.zookeeper.server.DatadirCleanupManager)
[2017-04-20 21:01:39,288] WARN Either no config or no quorum defined in config, running  in standalone mode (org.apache.zookeeper.server.quorum.QuorumPeerMain)
[2017-04-20 21:01:39,307] INFO Reading configuration from: /usr/local/Homebrew/etc/kafka/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
[2017-04-20 21:01:39,307] INFO Starting server (org.apache.zookeeper.server.ZooKeeperServerMain)
[2017-04-20 21:01:39,325] INFO Server environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,325] INFO Server environment:host.name=172.23.233.166 (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,325] INFO Server environment:java.version=1.8.0_111 (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,325] INFO Server environment:java.vendor=Oracle Corporation (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,325] INFO Server environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,325] INFO Server environment:java.class.path=:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/aopalliance-repackaged-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/argparse4j-0.7.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-api-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-file-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-json-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-runtime-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-transforms-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/guava-18.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/hk2-api-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/hk2-locator-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/hk2-utils-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-annotations-2.8.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-annotations-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-core-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-databind-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-jaxrs-base-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-jaxrs-json-provider-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-module-jaxb-annotations-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javassist-3.20.0-GA.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.annotation-api-1.2.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.inject-1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.inject-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.servlet-api-3.1.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.ws.rs-api-2.0.1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-client-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-common-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-container-servlet-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-container-servlet-core-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-guava-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-media-jaxb-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-server-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-continuation-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-http-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-io-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-security-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-server-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-servlet-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-servlets-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-util-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jopt-simple-5.0.3.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-clients-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-log4j-appender-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-streams-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-streams-examples-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-tools-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka_2.11-0.10.2.0-sources.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka_2.11-0.10.2.0-test-sources.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka_2.11-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/log4j-1.2.17.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/lz4-1.3.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/metrics-core-2.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/osgi-resource-locator-1.0.1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/reflections-0.9.10.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/rocksdbjni-5.0.1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/scala-library-2.11.8.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/scala-parser-combinators_2.11-1.0.4.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/slf4j-api-1.7.21.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/slf4j-log4j12-1.7.21.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/snappy-java-1.1.2.6.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/validation-api-1.1.0.Final.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/zkclient-0.10.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/zookeeper-3.4.9.jar (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,332] INFO Server environment:java.library.path=/Users/rain/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,332] INFO Server environment:java.io.tmpdir=/var/folders/lt/cqdkmb2x74nb7pj4ftp0ym0h0000gn/T/ (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,332] INFO Server environment:java.compiler=<NA> (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,332] INFO Server environment:os.name=Mac OS X (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,332] INFO Server environment:os.arch=x86_64 (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,332] INFO Server environment:os.version=10.12.3 (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,332] INFO Server environment:user.name=rain (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,332] INFO Server environment:user.home=/Users/rain (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,332] INFO Server environment:user.dir=/usr/local/Homebrew/Cellar/kafka/0.10.2.0/bin (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,346] INFO tickTime set to 3000 (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,346] INFO minSessionTimeout set to -1 (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,346] INFO maxSessionTimeout set to -1 (org.apache.zookeeper.server.ZooKeeperServer)
[2017-04-20 21:01:39,366] INFO binding to port 0.0.0.0/0.0.0.0:2181 (org.apache.zookeeper.server.NIOServerCnxnFactory)

啟動完后zookeeper會處于監(jiān)聽狀態(tài)逛尚。

  1. 然后啟動kafka:
RaindeMacBook-Pro:bin rain$ ./kafka-server-start /usr/local/Homebrew/etc/kafka/server.properties
[2017-04-20 21:03:19,425] INFO KafkaConfig values:
    advertised.host.name = null
    advertised.listeners = null
    advertised.port = null
    authorizer.class.name =
    auto.create.topics.enable = true
    auto.leader.rebalance.enable = true
    background.threads = 10
    broker.id = 0
    broker.id.generation.enable = true
    broker.rack = null
    compression.type = producer
    connections.max.idle.ms = 600000
    controlled.shutdown.enable = true
    controlled.shutdown.max.retries = 3
    controlled.shutdown.retry.backoff.ms = 5000
    controller.socket.timeout.ms = 30000
    create.topic.policy.class.name = null
    default.replication.factor = 1
    delete.topic.enable = false
    fetch.purgatory.purge.interval.requests = 1000
    group.max.session.timeout.ms = 300000
    group.min.session.timeout.ms = 6000
    host.name =
    inter.broker.listener.name = null
    inter.broker.protocol.version = 0.10.2-IV0
    leader.imbalance.check.interval.seconds = 300
    leader.imbalance.per.broker.percentage = 10
    listener.security.protocol.map = SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,TRACE:TRACE,SASL_SSL:SASL_SSL,PLAINTEXT:PLAINTEXT
    listeners = null
    log.cleaner.backoff.ms = 15000
    log.cleaner.dedupe.buffer.size = 134217728
    log.cleaner.delete.retention.ms = 86400000
    log.cleaner.enable = true
    log.cleaner.io.buffer.load.factor = 0.9
    log.cleaner.io.buffer.size = 524288
    log.cleaner.io.max.bytes.per.second = 1.7976931348623157E308
    log.cleaner.min.cleanable.ratio = 0.5
    log.cleaner.min.compaction.lag.ms = 0
    log.cleaner.threads = 1
    log.cleanup.policy = [delete]
    log.dir = /tmp/kafka-logs
    log.dirs = /usr/local/Homebrew/var/lib/kafka-logs
    log.flush.interval.messages = 9223372036854775807
    log.flush.interval.ms = null
    log.flush.offset.checkpoint.interval.ms = 60000
    log.flush.scheduler.interval.ms = 9223372036854775807
    log.index.interval.bytes = 4096
    log.index.size.max.bytes = 10485760
    log.message.format.version = 0.10.2-IV0
    log.message.timestamp.difference.max.ms = 9223372036854775807
    log.message.timestamp.type = CreateTime
    log.preallocate = false
    log.retention.bytes = -1
    log.retention.check.interval.ms = 300000
    log.retention.hours = 168
    log.retention.minutes = null
    log.retention.ms = null
    log.roll.hours = 168
    log.roll.jitter.hours = 0
    log.roll.jitter.ms = null
    log.roll.ms = null
    log.segment.bytes = 1073741824
    log.segment.delete.delay.ms = 60000
    max.connections.per.ip = 2147483647
    max.connections.per.ip.overrides =
    message.max.bytes = 1000012
    metric.reporters = []
    metrics.num.samples = 2
    metrics.recording.level = INFO
    metrics.sample.window.ms = 30000
    min.insync.replicas = 1
    num.io.threads = 8
    num.network.threads = 3
    num.partitions = 1
    num.recovery.threads.per.data.dir = 1
    num.replica.fetchers = 1
    offset.metadata.max.bytes = 4096
    offsets.commit.required.acks = -1
    offsets.commit.timeout.ms = 5000
    offsets.load.buffer.size = 5242880
    offsets.retention.check.interval.ms = 600000
    offsets.retention.minutes = 1440
    offsets.topic.compression.codec = 0
    offsets.topic.num.partitions = 50
    offsets.topic.replication.factor = 3
    offsets.topic.segment.bytes = 104857600
    port = 9092
    principal.builder.class = class org.apache.kafka.common.security.auth.DefaultPrincipalBuilder
    producer.purgatory.purge.interval.requests = 1000
    queued.max.requests = 500
    quota.consumer.default = 9223372036854775807
    quota.producer.default = 9223372036854775807
    quota.window.num = 11
    quota.window.size.seconds = 1
    replica.fetch.backoff.ms = 1000
    replica.fetch.max.bytes = 1048576
    replica.fetch.min.bytes = 1
    replica.fetch.response.max.bytes = 10485760
    replica.fetch.wait.max.ms = 500
    replica.high.watermark.checkpoint.interval.ms = 5000
    replica.lag.time.max.ms = 10000
    replica.socket.receive.buffer.bytes = 65536
    replica.socket.timeout.ms = 30000
    replication.quota.window.num = 11
    replication.quota.window.size.seconds = 1
    request.timeout.ms = 30000
    reserved.broker.max.id = 1000
    sasl.enabled.mechanisms = [GSSAPI]
    sasl.kerberos.kinit.cmd = /usr/bin/kinit
    sasl.kerberos.min.time.before.relogin = 60000
    sasl.kerberos.principal.to.local.rules = [DEFAULT]
    sasl.kerberos.service.name = null
    sasl.kerberos.ticket.renew.jitter = 0.05
    sasl.kerberos.ticket.renew.window.factor = 0.8
    sasl.mechanism.inter.broker.protocol = GSSAPI
    security.inter.broker.protocol = PLAINTEXT
    socket.receive.buffer.bytes = 102400
    socket.request.max.bytes = 104857600
    socket.send.buffer.bytes = 102400
    ssl.cipher.suites = null
    ssl.client.auth = none
    ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
    ssl.endpoint.identification.algorithm = null
    ssl.key.password = null
    ssl.keymanager.algorithm = SunX509
    ssl.keystore.location = null
    ssl.keystore.password = null
    ssl.keystore.type = JKS
    ssl.protocol = TLS
    ssl.provider = null
    ssl.secure.random.implementation = null
    ssl.trustmanager.algorithm = PKIX
    ssl.truststore.location = null
    ssl.truststore.password = null
    ssl.truststore.type = JKS
    unclean.leader.election.enable = true
    zookeeper.connect = localhost:2181
    zookeeper.connection.timeout.ms = 6000
    zookeeper.session.timeout.ms = 6000
    zookeeper.set.acl = false
    zookeeper.sync.time.ms = 2000
 (kafka.server.KafkaConfig)
[2017-04-20 21:03:19,481] INFO starting (kafka.server.KafkaServer)
[2017-04-20 21:03:19,484] INFO Connecting to zookeeper on localhost:2181 (kafka.server.KafkaServer)
[2017-04-20 21:03:19,496] INFO Starting ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
[2017-04-20 21:03:19,504] INFO Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,504] INFO Client environment:host.name=172.23.233.166 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,504] INFO Client environment:java.version=1.8.0_111 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,504] INFO Client environment:java.vendor=Oracle Corporation (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,504] INFO Client environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,505] INFO Client environment:java.class.path=:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/aopalliance-repackaged-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/argparse4j-0.7.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-api-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-file-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-json-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-runtime-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/connect-transforms-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/guava-18.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/hk2-api-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/hk2-locator-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/hk2-utils-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-annotations-2.8.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-annotations-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-core-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-databind-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-jaxrs-base-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-jaxrs-json-provider-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jackson-module-jaxb-annotations-2.8.5.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javassist-3.20.0-GA.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.annotation-api-1.2.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.inject-1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.inject-2.5.0-b05.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.servlet-api-3.1.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/javax.ws.rs-api-2.0.1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-client-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-common-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-container-servlet-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-container-servlet-core-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-guava-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-media-jaxb-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jersey-server-2.24.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-continuation-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-http-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-io-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-security-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-server-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-servlet-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-servlets-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jetty-util-9.2.15.v20160210.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/jopt-simple-5.0.3.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-clients-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-log4j-appender-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-streams-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-streams-examples-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka-tools-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka_2.11-0.10.2.0-sources.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka_2.11-0.10.2.0-test-sources.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/kafka_2.11-0.10.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/log4j-1.2.17.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/lz4-1.3.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/metrics-core-2.2.0.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/osgi-resource-locator-1.0.1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/reflections-0.9.10.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/rocksdbjni-5.0.1.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/scala-library-2.11.8.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/scala-parser-combinators_2.11-1.0.4.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/slf4j-api-1.7.21.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/slf4j-log4j12-1.7.21.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/snappy-java-1.1.2.6.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/validation-api-1.1.0.Final.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/zkclient-0.10.jar:/usr/local/Homebrew/Cellar/kafka/0.10.2.0/libexec/bin/../libs/zookeeper-3.4.9.jar (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,539] INFO Client environment:java.library.path=/Users/rain/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,539] INFO Client environment:java.io.tmpdir=/var/folders/lt/cqdkmb2x74nb7pj4ftp0ym0h0000gn/T/ (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,539] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,539] INFO Client environment:os.name=Mac OS X (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,539] INFO Client environment:os.arch=x86_64 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,539] INFO Client environment:os.version=10.12.3 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,539] INFO Client environment:user.name=rain (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,540] INFO Client environment:user.home=/Users/rain (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,540] INFO Client environment:user.dir=/usr/local/Homebrew/Cellar/kafka/0.10.2.0/bin (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,540] INFO Initiating client connection, connectString=localhost:2181 sessionTimeout=6000 watcher=org.I0Itec.zkclient.ZkClient@63355449 (org.apache.zookeeper.ZooKeeper)
[2017-04-20 21:03:19,562] INFO Waiting for keeper state SyncConnected (org.I0Itec.zkclient.ZkClient)
[2017-04-20 21:03:19,566] INFO Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2017-04-20 21:03:19,642] INFO Socket connection established to localhost/127.0.0.1:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2017-04-20 21:03:19,731] INFO Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x15b8b7430bb0000, negotiated timeout = 6000 (org.apache.zookeeper.ClientCnxn)
[2017-04-20 21:03:19,734] INFO zookeeper state changed (SyncConnected) (org.I0Itec.zkclient.ZkClient)
[2017-04-20 21:03:19,851] INFO Cluster ID = VRgsFMxtToes8yi60hoveQ (kafka.server.KafkaServer)
[2017-04-20 21:03:19,857] WARN No meta.properties file under dir /usr/local/Homebrew/var/lib/kafka-logs/meta.properties (kafka.server.BrokerMetadataCheckpoint)
[2017-04-20 21:03:19,895] INFO [ThrottledRequestReaper-Fetch], Starting  (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
[2017-04-20 21:03:19,897] INFO [ThrottledRequestReaper-Produce], Starting  (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
[2017-04-20 21:03:19,938] INFO Log directory '/usr/local/Homebrew/var/lib/kafka-logs' not found, creating it. (kafka.log.LogManager)
[2017-04-20 21:03:19,961] INFO Loading logs. (kafka.log.LogManager)
[2017-04-20 21:03:19,969] INFO Logs loading complete in 8 ms. (kafka.log.LogManager)
[2017-04-20 21:03:20,064] INFO Starting log cleanup with a period of 300000 ms. (kafka.log.LogManager)
[2017-04-20 21:03:20,066] INFO Starting log flusher with a default period of 9223372036854775807 ms. (kafka.log.LogManager)
[2017-04-20 21:03:20,107] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.Acceptor)
[2017-04-20 21:03:20,110] INFO [Socket Server on Broker 0], Started 1 acceptor threads (kafka.network.SocketServer)
[2017-04-20 21:03:20,128] INFO [ExpirationReaper-0], Starting  (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2017-04-20 21:03:20,130] INFO [ExpirationReaper-0], Starting  (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2017-04-20 21:03:20,162] INFO Creating /controller (is it secure? false) (kafka.utils.ZKCheckedEphemeral)
[2017-04-20 21:03:20,172] INFO Result of znode creation is: OK (kafka.utils.ZKCheckedEphemeral)
[2017-04-20 21:03:20,173] INFO 0 successfully elected as leader (kafka.server.ZookeeperLeaderElector)
[2017-04-20 21:03:20,279] INFO [ExpirationReaper-0], Starting  (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2017-04-20 21:03:20,283] INFO [ExpirationReaper-0], Starting  (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2017-04-20 21:03:20,285] INFO [ExpirationReaper-0], Starting  (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2017-04-20 21:03:20,301] INFO [GroupCoordinator 0]: Starting up. (kafka.coordinator.GroupCoordinator)
[2017-04-20 21:03:20,302] INFO [GroupCoordinator 0]: Startup complete. (kafka.coordinator.GroupCoordinator)
[2017-04-20 21:03:20,309] INFO [Group Metadata Manager on Broker 0]: Removed 0 expired offsets in 2 milliseconds. (kafka.coordinator.GroupMetadataManager)
[2017-04-20 21:03:20,327] INFO Will not load MX4J, mx4j-tools.jar is not in the classpath (kafka.utils.Mx4jLoader$)
[2017-04-20 21:03:20,365] INFO Creating /brokers/ids/0 (is it secure? false) (kafka.utils.ZKCheckedEphemeral)
[2017-04-20 21:03:20,375] INFO Result of znode creation is: OK (kafka.utils.ZKCheckedEphemeral)
[2017-04-20 21:03:20,376] INFO Registered broker 0 at path /brokers/ids/0 with addresses: EndPoint(172.23.233.166,9092,ListenerName(PLAINTEXT),PLAINTEXT) (kafka.utils.ZkUtils)
[2017-04-20 21:03:20,377] WARN No meta.properties file under dir /usr/local/Homebrew/var/lib/kafka-logs/meta.properties (kafka.server.BrokerMetadataCheckpoint)
[2017-04-20 21:03:20,403] INFO New leader is 0 (kafka.server.ZookeeperLeaderElector$LeaderChangeListener)
[2017-04-20 21:03:20,427] INFO Kafka version : 0.10.2.0 (org.apache.kafka.common.utils.AppInfoParser)
[2017-04-20 21:03:20,427] INFO Kafka commitId : 576d93a8dc0cf421 (org.apache.kafka.common.utils.AppInfoParser)
[2017-04-20 21:03:20,429] INFO [Kafka Server 0], started (kafka.server.KafkaServer)
[2017-04-20 21:13:20,328] INFO [Group Metadata Manager on Broker 0]: Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.GroupMetadataManager)
  1. 創(chuàng)建topic:
RaindeMacBook-Pro:bin rain$ ./kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic myfirstTopic
Created topic "myfirstTopic".
  1. 查看創(chuàng)建的topic
    為了測試,我創(chuàng)建了兩個topic
RaindeMacBook-Pro:bin rain$ ./kafka-topics --list --zookeeper localhost:2181
myfirstTopic
mysecondTopic
  1. 生產(chǎn)者發(fā)送消息
RaindeMacBook-Pro:bin rain$ ./kafka-console-producer --broker-list localhost:9092 --topic myfirstTopic
fjdkg
haha
what are you doing?
how are you doing?
  1. 消費者消費消息
    經(jīng)過測試刁愿,生產(chǎn)者每發(fā)送一條消息绰寞,消費者就能接收到消息。
RaindeMacBook-Pro:bin rain$ ./kafka-console-consumer --bootstrap-server localhost:9092 --topic myfirstTopic --from-beginning
fjdkg
haha
what are you doing?
how are you doing?
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末铣口,一起剝皮案震驚了整個濱河市滤钱,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌脑题,老刑警劉巖件缸,帶你破解...
    沈念sama閱讀 206,013評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異叔遂,居然都是意外死亡他炊,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,205評論 2 382
  • 文/潘曉璐 我一進店門已艰,熙熙樓的掌柜王于貴愁眉苦臉地迎上來痊末,“玉大人,你說我怎么就攤上這事哩掺≡涞” “怎么了?”我有些...
    開封第一講書人閱讀 152,370評論 0 342
  • 文/不壞的土叔 我叫張陵嚼吞,是天一觀的道長盒件。 經(jīng)常有香客問我,道長誊薄,這世上最難降的妖魔是什么履恩? 我笑而不...
    開封第一講書人閱讀 55,168評論 1 278
  • 正文 為了忘掉前任,我火速辦了婚禮呢蔫,結(jié)果婚禮上切心,老公的妹妹穿的比我還像新娘飒筑。我一直安慰自己,他們只是感情好绽昏,可當我...
    茶點故事閱讀 64,153評論 5 371
  • 文/花漫 我一把揭開白布协屡。 她就那樣靜靜地躺著,像睡著了一般全谤。 火紅的嫁衣襯著肌膚如雪肤晓。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 48,954評論 1 283
  • 那天认然,我揣著相機與錄音补憾,去河邊找鬼。 笑死卷员,一個胖子當著我的面吹牛盈匾,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播毕骡,決...
    沈念sama閱讀 38,271評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼削饵,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了未巫?” 一聲冷哼從身側(cè)響起窿撬,我...
    開封第一講書人閱讀 36,916評論 0 259
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎叙凡,沒想到半個月后劈伴,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,382評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡狭姨,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,877評論 2 323
  • 正文 我和宋清朗相戀三年宰啦,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片饼拍。...
    茶點故事閱讀 37,989評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡赡模,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出师抄,到底是詐尸還是另有隱情漓柑,我是刑警寧澤,帶...
    沈念sama閱讀 33,624評論 4 322
  • 正文 年R本政府宣布叨吮,位于F島的核電站辆布,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏茶鉴。R本人自食惡果不足惜锋玲,卻給世界環(huán)境...
    茶點故事閱讀 39,209評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望涵叮。 院中可真熱鬧惭蹂,春花似錦伞插、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,199評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至廷雅,卻和暖如春耗美,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背航缀。 一陣腳步聲響...
    開封第一講書人閱讀 31,418評論 1 260
  • 我被黑心中介騙來泰國打工商架, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人芥玉。 一個月前我還...
    沈念sama閱讀 45,401評論 2 352
  • 正文 我出身青樓甸私,卻偏偏與公主長得像,于是被迫代替她去往敵國和親飞傀。 傳聞我的和親對象是個殘疾皇子汉规,可洞房花燭夜當晚...
    茶點故事閱讀 42,700評論 2 345

推薦閱讀更多精彩內(nèi)容