分布式发布订阅消息系统kafka入门-1.介绍+安装

很文博客hinven.com 2018年4月20日10:12:11技术教程评论28918172字阅读模式

分布式发布订阅消息系统kafka入门-1.介绍+安装

 

Apache Kafka是一种高吞吐量的分布式发布订阅消息系统,它可以处理消费者规模的网站中的所有动作流数据。 这种动作(网页浏览,搜索和其他用户的行动)是在现代网络上的许多社会功能的一个关键因素。 这些数据通常是由于吞吐量的要求而通过处理日志和日志聚合来解决。 对于像Hadoop的一样的日志数据和离线分析系统,但又要求实时处理的限制,这是一个可行的解决方案。Kafka的目的是通过Hadoop的并行加载机制来统一线上和离线的消息处理,也是为了通过集群来提供实时的消费。

1.Kafka资料

  • github(https://github.com/apache/kafka)
  • .org官方文档(http://kafka.apache.org/)
  • 最新release 0.11.0.0(https://github.com/apache/kafka/releases)

分布式发布订阅消息系统kafka入门-1.介绍+安装

 

2.安装

Step 1: 下载

下载(https://www.apache.org/dyn/closer.cgi?path=/kafka/0.11.0.0/kafka_2.11-0.11.0.0.tgz) 0.11.0.0 release版本到自己喜欢的目录并且解压.下载慢的可以试试百度云(http://pan.baidu.com/s/1nvuosdj)。

  1. > tar -xzf kafka_2.11-0.11.0.0.tgz
  2. > cd kafka_2.11-0.11.0.0

STEP 2:启动服务

1.先启动一个ZooKeeper服务器

Kafka需要和ZooKeeper配套使用,所以需要先启动一个ZooKeeper服务器,如果还没有安装。 可以使用和kafka一起打包的便捷脚本来获取一个快速而又脏的单节点ZooKeeper实例:

  1. > bin/zookeeper-server-start.sh config/zookeeper.properties
  2. ZooKeeper JMX enabled by default
  3. Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
  4. Starting zookeeper ... STARTED

或者启动自己安装zookeeper

2. 启动kafka

在包目录下使用下面的命令启动kafka:

  1. > bin/kafka-server-start.sh config/server.properties
  2. [2017-08-08 14:49:00,838] INFO KafkaConfig values:
  3. advertised.host.name = null
  4. advertised.listeners = null
  5. advertised.port = null
  6. alter.config.policy.class.name = null
  7. authorizer.class.name =
  8. auto.create.topics.enable = true
  9. auto.leader.rebalance.enable = true
  10. background.threads = 10
  11. broker.id = 0
  12. broker.id.generation.enable = true
  13. broker.rack = null
  14. compression.type = producer
  15. connections.max.idle.ms = 600000
  16. controlled.shutdown.enable = true
  17. controlled.shutdown.max.retries = 3
  18. controlled.shutdown.retry.backoff.ms = 5000
  19. controller.socket.timeout.ms = 30000
  20. create.topic.policy.class.name = null
  21. default.replication.factor = 1
  22. delete.records.purgatory.purge.interval.requests = 1
  23. delete.topic.enable = false
  24. fetch.purgatory.purge.interval.requests = 1000
  25. group.initial.rebalance.delay.ms = 0
  26. group.max.session.timeout.ms = 300000
  27. group.min.session.timeout.ms = 6000
  28. host.name =
  29. inter.broker.listener.name = null
  30. inter.broker.protocol.version = 0.11.0-IV2
  31. leader.imbalance.check.interval.seconds = 300
  32. leader.imbalance.per.broker.percentage = 10
  33. listener.security.protocol.map = SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,TRACE:TRACE,SASL_SSL:SASL_SSL,PLAINTEXT:PLAINTEXT
  34. listeners = null
  35. log.cleaner.backoff.ms = 15000
  36. log.cleaner.dedupe.buffer.size = 134217728
  37. log.cleaner.delete.retention.ms = 86400000
  38. log.cleaner.enable = true
  39. log.cleaner.io.buffer.load.factor = 0.9
  40. log.cleaner.io.buffer.size = 524288
  41. log.cleaner.io.max.bytes.per.second = 1.7976931348623157E308
  42. log.cleaner.min.cleanable.ratio = 0.5
  43. log.cleaner.min.compaction.lag.ms = 0
  44. log.cleaner.threads = 1
  45. log.cleanup.policy = [delete]
  46. log.dir = /tmp/kafka-logs
  47. log.dirs = /tmp/kafka-logs
  48. log.flush.interval.messages = 9223372036854775807
  49. log.flush.interval.ms = null
  50. log.flush.offset.checkpoint.interval.ms = 60000
  51. log.flush.scheduler.interval.ms = 9223372036854775807
  52. log.flush.start.offset.checkpoint.interval.ms = 60000
  53. log.index.interval.bytes = 4096
  54. log.index.size.max.bytes = 10485760
  55. log.message.format.version = 0.11.0-IV2
  56. log.message.timestamp.difference.max.ms = 9223372036854775807
  57. log.message.timestamp.type = CreateTime
  58. log.preallocate = false
  59. log.retention.bytes = -1
  60. log.retention.check.interval.ms = 300000
  61. log.retention.hours = 168
  62. log.retention.minutes = null
  63. log.retention.ms = null
  64. log.roll.hours = 168
  65. log.roll.jitter.hours = 0
  66. log.roll.jitter.ms = null
  67. log.roll.ms = null
  68. log.segment.bytes = 1073741824
  69. log.segment.delete.delay.ms = 60000
  70. max.connections.per.ip = 2147483647
  71. max.connections.per.ip.overrides =
  72. message.max.bytes = 1000012
  73. metric.reporters = []
  74. metrics.num.samples = 2
  75. metrics.recording.level = INFO
  76. metrics.sample.window.ms = 30000
  77. min.insync.replicas = 1
  78. num.io.threads = 8
  79. num.network.threads = 3
  80. num.partitions = 1
  81. num.recovery.threads.per.data.dir = 1
  82. num.replica.fetchers = 1
  83. offset.metadata.max.bytes = 4096
  84. offsets.commit.required.acks = -1
  85. offsets.commit.timeout.ms = 5000
  86. offsets.load.buffer.size = 5242880
  87. offsets.retention.check.interval.ms = 600000
  88. offsets.retention.minutes = 1440
  89. offsets.topic.compression.codec = 0
  90. offsets.topic.num.partitions = 50
  91. offsets.topic.replication.factor = 1
  92. offsets.topic.segment.bytes = 104857600
  93. port = 9092
  94. principal.builder.class = class org.apache.kafka.common.security.auth.DefaultPrincipalBuilder
  95. producer.purgatory.purge.interval.requests = 1000
  96. queued.max.requests = 500
  97. quota.consumer.default = 9223372036854775807
  98. quota.producer.default = 9223372036854775807
  99. quota.window.num = 11
  100. quota.window.size.seconds = 1
  101. replica.fetch.backoff.ms = 1000
  102. replica.fetch.max.bytes = 1048576
  103. replica.fetch.min.bytes = 1
  104. replica.fetch.response.max.bytes = 10485760
  105. replica.fetch.wait.max.ms = 500
  106. replica.high.watermark.checkpoint.interval.ms = 5000
  107. replica.lag.time.max.ms = 10000
  108. replica.socket.receive.buffer.bytes = 65536
  109. replica.socket.timeout.ms = 30000
  110. replication.quota.window.num = 11
  111. replication.quota.window.size.seconds = 1
  112. request.timeout.ms = 30000
  113. reserved.broker.max.id = 1000
  114. sasl.enabled.mechanisms = [GSSAPI]
  115. sasl.kerberos.kinit.cmd = /usr/bin/kinit
  116. sasl.kerberos.min.time.before.relogin = 60000
  117. sasl.kerberos.principal.to.local.rules = [DEFAULT]
  118. sasl.kerberos.service.name = null
  119. sasl.kerberos.ticket.renew.jitter = 0.05
  120. sasl.kerberos.ticket.renew.window.factor = 0.8
  121. sasl.mechanism.inter.broker.protocol = GSSAPI
  122. security.inter.broker.protocol = PLAINTEXT
  123. socket.receive.buffer.bytes = 102400
  124. socket.request.max.bytes = 104857600
  125. socket.send.buffer.bytes = 102400
  126. ssl.cipher.suites = null
  127. ssl.client.auth = none
  128. ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
  129. ssl.endpoint.identification.algorithm = null
  130. ssl.key.password = null
  131. ssl.keymanager.algorithm = SunX509
  132. ssl.keystore.location = null
  133. ssl.keystore.password = null
  134. ssl.keystore.type = JKS
  135. ssl.protocol = TLS
  136. ssl.provider = null
  137. ssl.secure.random.implementation = null
  138. ssl.trustmanager.algorithm = PKIX
  139. ssl.truststore.location = null
  140. ssl.truststore.password = null
  141. ssl.truststore.type = JKS
  142. transaction.abort.timed.out.transaction.cleanup.interval.ms = 60000
  143. transaction.max.timeout.ms = 900000
  144. transaction.remove.expired.transaction.cleanup.interval.ms = 3600000
  145. transaction.state.log.load.buffer.size = 5242880
  146. transaction.state.log.min.isr = 1
  147. transaction.state.log.num.partitions = 50
  148. transaction.state.log.replication.factor = 1
  149. transaction.state.log.segment.bytes = 104857600
  150. transactional.id.expiration.ms = 604800000
  151. unclean.leader.election.enable = false
  152. zookeeper.connect = localhost:2181
  153. zookeeper.connection.timeout.ms = 6000
  154. zookeeper.session.timeout.ms = 6000
  155. zookeeper.set.acl = false
  156. zookeeper.sync.time.ms = 2000
  157. (kafka.server.KafkaConfig)
  158. [2017-08-08 14:49:00,936] INFO starting (kafka.server.KafkaServer)
  159. [2017-08-08 14:49:00,940] INFO Connecting to zookeeper on localhost:2181 (kafka.server.KafkaServer)
  160. [2017-08-08 14:49:00,962] INFO Starting ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
  161. [2017-08-08 14:49:00,980] INFO Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT (org.apache.zookeeper.ZooKeeper)
  162. [2017-08-08 14:49:00,980] INFO Client environment:host.name=watercubedembp.lan (org.apache.zookeeper.ZooKeeper)
  163. [2017-08-08 14:49:00,980] INFO Client environment:java.version=1.8.0_60 (org.apache.zookeeper.ZooKeeper)
  164. [2017-08-08 14:49:00,980] INFO Client environment:java.vendor=Oracle Corporation (org.apache.zookeeper.ZooKeeper)
  165. [2017-08-08 14:49:00,980] INFO Client environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre (org.apache.zookeeper.ZooKeeper)
  166. [2017-08-08 14:49:00,980] INFO Client environment:java.class.path=:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/aopalliance-repackaged-2.5.0-b05.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/argparse4j-0.7.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/commons-lang3-3.5.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/connect-api-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/connect-file-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/connect-json-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/connect-runtime-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/connect-transforms-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/guava-20.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/hk2-api-2.5.0-b05.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/hk2-locator-2.5.0-b05.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/hk2-utils-2.5.0-b05.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jackson-annotations-2.8.5.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jackson-core-2.8.5.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jackson-databind-2.8.5.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jackson-jaxrs-base-2.8.5.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jackson-jaxrs-json-provider-2.8.5.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jackson-module-jaxb-annotations-2.8.5.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/javassist-3.21.0-GA.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/javax.annotation-api-1.2.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/javax.inject-1.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/javax.inject-2.5.0-b05.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/javax.servlet-api-3.1.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/javax.ws.rs-api-2.0.1.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jersey-client-2.24.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jersey-common-2.24.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jersey-container-servlet-2.24.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jersey-container-servlet-core-2.24.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jersey-guava-2.24.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jersey-media-jaxb-2.24.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jersey-server-2.24.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jetty-continuation-9.2.15.v20160210.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jetty-http-9.2.15.v20160210.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jetty-io-9.2.15.v20160210.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jetty-security-9.2.15.v20160210.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jetty-server-9.2.15.v20160210.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jetty-servlet-9.2.15.v20160210.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jetty-servlets-9.2.15.v20160210.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jetty-util-9.2.15.v20160210.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/jopt-simple-5.0.3.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/kafka-clients-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/kafka-log4j-appender-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/kafka-streams-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/kafka-streams-examples-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/kafka-tools-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/kafka_2.11-0.11.0.0-sources.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/kafka_2.11-0.11.0.0-test-sources.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/kafka_2.11-0.11.0.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/log4j-1.2.17.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/lz4-1.3.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/maven-artifact-3.5.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/metrics-core-2.2.0.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/osgi-resource-locator-1.0.1.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/plexus-utils-3.0.24.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/reflections-0.9.11.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/rocksdbjni-5.0.1.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/scala-library-2.11.11.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/scala-parser-combinators_2.11-1.0.4.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/slf4j-api-1.7.25.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/slf4j-log4j12-1.7.25.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/snappy-java-1.1.2.6.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/validation-api-1.1.0.Final.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/zkclient-0.10.jar:/usr/local/kafka_2.11-0.11.0.0/bin/../libs/zookeeper-3.4.10.jar (org.apache.zookeeper.ZooKeeper)
  167. [2017-08-08 14:49:00,981] INFO Client environment:java.library.path=/Users/watercube/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. (org.apache.zookeeper.ZooKeeper)
  168. [2017-08-08 14:49:00,981] INFO Client environment:java.io.tmpdir=/var/folders/41/x0c6_wcs6813gw9qt_jhqmf40000gn/T/ (org.apache.zookeeper.ZooKeeper)
  169. [2017-08-08 14:49:00,981] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
  170. [2017-08-08 14:49:00,982] INFO Client environment:os.name=Mac OS X (org.apache.zookeeper.ZooKeeper)
  171. [2017-08-08 14:49:00,982] INFO Client environment:os.arch=x86_64 (org.apache.zookeeper.ZooKeeper)
  172. [2017-08-08 14:49:00,982] INFO Client environment:os.version=10.12.5 (org.apache.zookeeper.ZooKeeper)
  173. [2017-08-08 14:49:00,982] INFO Client environment:user.name=watercube (org.apache.zookeeper.ZooKeeper)
  174. [2017-08-08 14:49:00,982] INFO Client environment:user.home=/Users/watercube (org.apache.zookeeper.ZooKeeper)
  175. [2017-08-08 14:49:00,982] INFO Client environment:user.dir=/usr/local/kafka_2.11-0.11.0.0 (org.apache.zookeeper.ZooKeeper)
  176. [2017-08-08 14:49:00,983] INFO Initiating client connection, connectString=localhost:2181 sessionTimeout=6000 watcher=org.I0Itec.zkclient.ZkClient@3911c2a7 (org.apache.zookeeper.ZooKeeper)
  177. [2017-08-08 14:49:01,009] INFO Waiting for keeper state SyncConnected (org.I0Itec.zkclient.ZkClient)
  178. [2017-08-08 14:49:01,013] 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)
  179. [2017-08-08 14:49:01,129] INFO Socket connection established to localhost/127.0.0.1:2181, initiating session (org.apache.zookeeper.ClientCnxn)
  180. [2017-08-08 14:49:01,212] INFO Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x15dc097dc680000, negotiated timeout = 6000 (org.apache.zookeeper.ClientCnxn)
  181. [2017-08-08 14:49:01,215] INFO zookeeper state changed (SyncConnected) (org.I0Itec.zkclient.ZkClient)
  182. [2017-08-08 14:49:01,349] INFO Cluster ID = qV4RDpIbREegszqq6RAFcw (kafka.server.KafkaServer)
  183. [2017-08-08 14:49:01,354] WARN No meta.properties file under dir /tmp/kafka-logs/meta.properties (kafka.server.BrokerMetadataCheckpoint)
  184. [2017-08-08 14:49:01,394] INFO [ThrottledRequestReaper-Fetch]: Starting (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
  185. [2017-08-08 14:49:01,394] INFO [ThrottledRequestReaper-Produce]: Starting (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
  186. [2017-08-08 14:49:01,451] INFO [ThrottledRequestReaper-Request]: Starting (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
  187. [2017-08-08 14:49:01,511] INFO Log directory '/tmp/kafka-logs' not found, creating it. (kafka.log.LogManager)
  188. [2017-08-08 14:49:01,534] INFO Loading logs. (kafka.log.LogManager)
  189. [2017-08-08 14:49:01,549] INFO Logs loading complete in 15 ms. (kafka.log.LogManager)
  190. [2017-08-08 14:49:01,726] INFO Starting log cleanup with a period of 300000 ms. (kafka.log.LogManager)
  191. [2017-08-08 14:49:01,728] INFO Starting log flusher with a default period of 9223372036854775807 ms. (kafka.log.LogManager)
  192. [2017-08-08 14:49:01,793] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.Acceptor)
  193. [2017-08-08 14:49:01,798] INFO [Socket Server on Broker 0], Started 1 acceptor threads (kafka.network.SocketServer)
  194. [2017-08-08 14:49:01,819] INFO [ExpirationReaper-0-Produce]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
  195. [2017-08-08 14:49:01,820] INFO [ExpirationReaper-0-Fetch]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
  196. [2017-08-08 14:49:01,821] INFO [ExpirationReaper-0-DeleteRecords]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
  197. [2017-08-08 14:49:01,895] INFO [ExpirationReaper-0-topic]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
  198. [2017-08-08 14:49:01,902] INFO [ExpirationReaper-0-Heartbeat]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
  199. [2017-08-08 14:49:01,905] INFO [ExpirationReaper-0-Rebalance]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
  200. [2017-08-08 14:49:01,905] INFO Creating /controller (is it secure? false) (kafka.utils.ZKCheckedEphemeral)
  201. [2017-08-08 14:49:01,916] INFO Result of znode creation is: OK (kafka.utils.ZKCheckedEphemeral)
  202. [2017-08-08 14:49:01,929] INFO [GroupCoordinator 0]: Starting up. (kafka.coordinator.group.GroupCoordinator)
  203. [2017-08-08 14:49:01,930] INFO [GroupCoordinator 0]: Startup complete. (kafka.coordinator.group.GroupCoordinator)
  204. [2017-08-08 14:49:01,941] INFO [Group Metadata Manager on Broker 0]: Removed 0 expired offsets in 10 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
  205. [2017-08-08 14:49:01,988] INFO [ProducerId Manager 0]: Acquired new producerId block (brokerId:0,blockStartProducerId:0,blockEndProducerId:999) by writing to Zk with path version 1 (kafka.coordinator.transaction.ProducerIdManager)
  206. [2017-08-08 14:49:02,043] INFO [Transaction Coordinator 0]: Starting up. (kafka.coordinator.transaction.TransactionCoordinator)
  207. [2017-08-08 14:49:02,050] INFO [Transaction Coordinator 0]: Startup complete. (kafka.coordinator.transaction.TransactionCoordinator)
  208. [2017-08-08 14:49:02,052] INFO [Transaction Marker Channel Manager 0]: Starting (kafka.coordinator.transaction.TransactionMarkerChannelManager)
  209. [2017-08-08 14:49:02,147] INFO Will not load MX4J, mx4j-tools.jar is not in the classpath (kafka.utils.Mx4jLoader$)
  210. [2017-08-08 14:49:02,232] INFO Creating /brokers/ids/0 (is it secure? false) (kafka.utils.ZKCheckedEphemeral)
  211. [2017-08-08 14:49:02,237] INFO Result of znode creation is: OK (kafka.utils.ZKCheckedEphemeral)
  212. [2017-08-08 14:49:02,239] INFO Registered broker 0 at path /brokers/ids/0 with addresses: EndPoint(watercubedembp.lan,9092,ListenerName(PLAINTEXT),PLAINTEXT) (kafka.utils.ZkUtils)
  213. [2017-08-08 14:49:02,240] WARN No meta.properties file under dir /tmp/kafka-logs/meta.properties (kafka.server.BrokerMetadataCheckpoint)
  214. [2017-08-08 14:49:02,277] INFO Kafka version : 0.11.0.0 (org.apache.kafka.common.utils.AppInfoParser)
  215. [2017-08-08 14:49:02,277] INFO Kafka commitId : cb8625948210849f (org.apache.kafka.common.utils.AppInfoParser)
  216. [2017-08-08 14:49:02,279] INFO [Kafka Server 0], started (kafka.server.KafkaServer)

STEP 3:创建一个TOPIC

在一个分区下创建一个topic—“test”

  1. > bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
  2. Created topic "test".

我们可以使用list命令来查看这个topic:

  1. > bin/kafka-topics.sh --list --zookeeper localhost:2181
  2. test

除了手动创建topic,也可以将broker配置为当发布的主题不存在时自动创建主题。

STEP 4: 发送消息

Kafka附带一个命令行客户端,它将从文件或标准输入中输入,并将其作为消息发送到Kafka群集。 默认情况下,每行将作为单独的消息发送。
运行生产者,然后在控制台中输入一些消息以发送到服务器。

  1. > bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
  2. This is a message
  3. This is another message

STEP 5: 启动消费者

Kafka还有一个命令行消费者,将接收到的消息转储到标准输出。

  1. > bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
  2. This is a message
  3. This is another message

分布式发布订阅消息系统kafka入门-1.介绍+安装

收发信息

注,正常情况下,服务器,生产者,消费者分别占用一个terminal,简单的安装和测试到这里。

weinxin
扫一扫更精彩
大家的支持是我更新的动力!!!
Ctrl+C+V,快速安装ss和brook 技术教程

Ctrl+C+V,快速安装ss和brook

大部分人买VPS也不过就是当作学习服务器用,大部分就是自用,盈利开机场的,可以不看此文了。 如果是自用,几个人用,稳定应该才是第一位的,至于什么BBR,加速之类的,我自己的压根就没装,实在是没有必要。...
介绍几款 Docker 镜像 技术教程

介绍几款 Docker 镜像

Docker(https://www.docker.com/) 是一个开放源代码软件项目,让应用程序布署在软件容器下的工作可以自动化进行,借此在 Linux 操作系统上,提供一个额外的软件抽象层,以及...
广告也精彩
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定