kafka的安装及基本使用

Posted MMMirana

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kafka的安装及基本使用相关的知识,希望对你有一定的参考价值。

1、安装zookeeper

# 解压缩
[[email protected] zookeeper]# tar -zxvf zookeeper-3.4.12.tar.gz
[[email protected] zookeeper]# mv zookeeper-3.4.12 zk_simple
# 复制zoo_simple.cfg到zoo.cfg [[email protected] zookeeper]# cd zk_simple
/ [[email protected] zk_simple]# cp conf/zoo_sample.cfg conf/zoo.cfg -R
# 启动 [[email protected] zk_simple]# bin
/zkServer.sh start ZooKeeper JMX enabled by default Using config: /mirana/software/zookeeper/zk_simple/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
# 查看zookeeper启动状态 [[email protected] zk_simple]# bin
/zkServer.sh status ZooKeeper JMX enabled by default Using config: /mirana/software/zookeeper/zk_simple/bin/../conf/zoo.cfg Mode: standalone

2、安装kafka

  2.1下载并上传kafka_2.12-1.1.0.tgz

  2.2解压

[[email protected] software]# tar -zxvf kafka_2.12-1.1.0.tgz
[[email protected] software]# mv kafka_2.12-1.1.0 kafka2.12/
[[email protected] software]# cd kafka2.12/
[[email protected] kafka2.12]# ll
总用量 52
drwxr-xr-x. 3 root root  4096 3月  24 06:55 bin
drwxr-xr-x. 2 root root  4096 3月  24 06:55 config
drwxr-xr-x. 2 root root  4096 5月  26 14:29 libs
-rw-r--r--. 1 root root 28824 3月  24 06:51 LICENSE
drwxr-xr-x. 2 root root  4096 5月  26 15:06 logs
-rw-r--r--. 1 root root   336 3月  24 06:51 NOTICE
drwxr-xr-x. 2 root root    44 3月  24 06:55 site-docs 

  2.3 单节点模式启动kafka服务端,新开窗口用于持续打印kafka服务端的日志【窗口1】

[[email protected] kafka2.12]# bin/kafka-server-start.sh config/server.properties 
[2018-05-26 15:12:57,658] INFO Registered kafka:type=kafka.Log4jController MBean (kafka.utils.Log4jControllerRegistration$)
[2018-05-26 15:12:59,297] INFO starting (kafka.server.KafkaServer)
[2018-05-26 15:12:59,299] INFO Connecting to zookeeper on localhost:2181 (kafka.server.KafkaServer)
[2018-05-26 15:12:59,364] INFO [ZooKeeperClient] Initializing a new session to localhost:2181. (kafka.zookeeper.ZooKeeperClient)
[2018-05-26 15:12:59,375] INFO Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,375] INFO Client environment:host.name=localhost (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,375] INFO Client environment:java.version=1.8.0_172 (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,375] INFO Client environment:java.vendor=Oracle Corporation (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,375] INFO Client environment:java.home=/mirana/software/jdk1.8/jre (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,376] INFO Client environment:java.class.path=/mirana/software/jdk1.8/jre/lib/rt.jar:/mirana/software/jdk1.8/jre/lib/ext:/mirana/software/kafka2.12/bin/../libs/aopalliance-repackaged-2.5.0-b32.jar:/mirana/software/kafka2.12/bin/../libs/argparse4j-0.7.0.jar:/mirana/software/kafka2.12/bin/../libs/commons-lang3-3.5.jar:/mirana/software/kafka2.12/bin/../libs/connect-api-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/connect-file-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/connect-json-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/connect-runtime-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/connect-transforms-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/guava-20.0.jar:/mirana/software/kafka2.12/bin/../libs/hk2-api-2.5.0-b32.jar:/mirana/software/kafka2.12/bin/../libs/hk2-locator-2.5.0-b32.jar:/mirana/software/kafka2.12/bin/../libs/hk2-utils-2.5.0-b32.jar:/mirana/software/kafka2.12/bin/../libs/jackson-annotations-2.9.4.jar:/mirana/software/kafka2.12/bin/../libs/jackson-core-2.9.4.jar:/mirana/software/kafka2.12/bin/../libs/jackson-databind-2.9.4.jar:/mirana/software/kafka2.12/bin/../libs/jackson-jaxrs-base-2.9.4.jar:/mirana/software/kafka2.12/bin/../libs/jackson-jaxrs-json-provider-2.9.4.jar:/mirana/software/kafka2.12/bin/../libs/jackson-module-jaxb-annotations-2.9.4.jar:/mirana/software/kafka2.12/bin/../libs/javassist-3.20.0-GA.jar:/mirana/software/kafka2.12/bin/../libs/javassist-3.21.0-GA.jar:/mirana/software/kafka2.12/bin/../libs/javax.annotation-api-1.2.jar:/mirana/software/kafka2.12/bin/../libs/javax.inject-1.jar:/mirana/software/kafka2.12/bin/../libs/javax.inject-2.5.0-b32.jar:/mirana/software/kafka2.12/bin/../libs/javax.servlet-api-3.1.0.jar:/mirana/software/kafka2.12/bin/../libs/javax.ws.rs-api-2.0.1.jar:/mirana/software/kafka2.12/bin/../libs/jersey-client-2.25.1.jar:/mirana/software/kafka2.12/bin/../libs/jersey-common-2.25.1.jar:/mirana/software/kafka2.12/bin/../libs/jersey-container-servlet-2.25.1.jar:/mirana/software/kafka2.12/bin/../libs/jersey-container-servlet-core-2.25.1.jar:/mirana/software/kafka2.12/bin/../libs/jersey-guava-2.25.1.jar:/mirana/software/kafka2.12/bin/../libs/jersey-media-jaxb-2.25.1.jar:/mirana/software/kafka2.12/bin/../libs/jersey-server-2.25.1.jar:/mirana/software/kafka2.12/bin/../libs/jetty-client-9.2.24.v20180105.jar:/mirana/software/kafka2.12/bin/../libs/jetty-continuation-9.2.24.v20180105.jar:/mirana/software/kafka2.12/bin/../libs/jetty-http-9.2.24.v20180105.jar:/mirana/software/kafka2.12/bin/../libs/jetty-io-9.2.24.v20180105.jar:/mirana/software/kafka2.12/bin/../libs/jetty-security-9.2.24.v20180105.jar:/mirana/software/kafka2.12/bin/../libs/jetty-server-9.2.24.v20180105.jar:/mirana/software/kafka2.12/bin/../libs/jetty-servlet-9.2.24.v20180105.jar:/mirana/software/kafka2.12/bin/../libs/jetty-servlets-9.2.24.v20180105.jar:/mirana/software/kafka2.12/bin/../libs/jetty-util-9.2.24.v20180105.jar:/mirana/software/kafka2.12/bin/../libs/jopt-simple-5.0.4.jar:/mirana/software/kafka2.12/bin/../libs/kafka_2.12-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/kafka_2.12-1.1.0-sources.jar:/mirana/software/kafka2.12/bin/../libs/kafka_2.12-1.1.0-test-sources.jar:/mirana/software/kafka2.12/bin/../libs/kafka-clients-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/kafka-log4j-appender-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/kafka-streams-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/kafka-streams-examples-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/kafka-streams-test-utils-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/kafka-tools-1.1.0.jar:/mirana/software/kafka2.12/bin/../libs/log4j-1.2.17.jar:/mirana/software/kafka2.12/bin/../libs/lz4-java-1.4.jar:/mirana/software/kafka2.12/bin/../libs/maven-artifact-3.5.2.jar:/mirana/software/kafka2.12/bin/../libs/metrics-core-2.2.0.jar:/mirana/software/kafka2.12/bin/../libs/osgi-resource-locator-1.0.1.jar:/mirana/software/kafka2.12/bin/../libs/plexus-utils-3.1.0.jar:/mirana/software/kafka2.12/bin/../libs/reflections-0.9.11.jar:/mirana/software/kafka2.12/bin/../libs/rocksdbjni-5.7.3.jar:/mirana/software/kafka2.12/bin/../libs/scala-library-2.12.4.jar:/mirana/software/kafka2.12/bin/../libs/scala-logging_2.12-3.7.2.jar:/mirana/software/kafka2.12/bin/../libs/scala-reflect-2.12.4.jar:/mirana/software/kafka2.12/bin/../libs/slf4j-api-1.7.25.jar:/mirana/software/kafka2.12/bin/../libs/slf4j-log4j12-1.7.25.jar:/mirana/software/kafka2.12/bin/../libs/snappy-java-1.1.7.1.jar:/mirana/software/kafka2.12/bin/../libs/validation-api-1.1.0.Final.jar:/mirana/software/kafka2.12/bin/../libs/zkclient-0.10.jar:/mirana/software/kafka2.12/bin/../libs/zookeeper-3.4.10.jar (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,378] INFO Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,379] INFO Client environment:java.io.tmpdir=/tmp (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,379] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,379] INFO Client environment:os.name=Linux (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,379] INFO Client environment:os.arch=amd64 (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,379] INFO Client environment:os.version=3.10.0-514.el7.x86_64 (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,379] INFO Client environment:user.name=root (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,379] INFO Client environment:user.home=/root (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,379] INFO Client environment:user.dir=/mirana/software/kafka2.12 (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,383] INFO Initiating client connection, connectString=localhost:2181 sessionTimeout=6000 watcher=[email protected] (org.apache.zookeeper.ZooKeeper)
[2018-05-26 15:12:59,414] 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)
[2018-05-26 15:12:59,427] INFO [ZooKeeperClient] Waiting until connected. (kafka.zookeeper.ZooKeeperClient)
[2018-05-26 15:12:59,462] INFO Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2018-05-26 15:12:59,493] INFO Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x100002832db0001, negotiated timeout = 6000 (org.apache.zookeeper.ClientCnxn)
[2018-05-26 15:12:59,510] INFO [ZooKeeperClient] Connected. (kafka.zookeeper.ZooKeeperClient)
[2018-05-26 15:13:00,058] INFO Cluster ID = MHj0qP-5T-OFVNpn87zSXg (kafka.server.KafkaServer)
[2018-05-26 15:13:00,355] INFO KafkaConfig values: 
    advertised.host.name = null
    advertised.listeners = null
    advertised.port = null
    alter.config.policy.class.name = null
    alter.log.dirs.replication.quota.window.num = 11
    alter.log.dirs.replication.quota.window.size.seconds = 1
    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
    delegation.token.expiry.check.interval.ms = 3600000
    delegation.token.expiry.time.ms = 86400000
    delegation.token.master.key = null
    delegation.token.max.lifetime.ms = 604800000
    delete.records.purgatory.purge.interval.requests = 1
    delete.topic.enable = true
    fetch.purgatory.purge.interval.requests = 1000
    group.initial.rebalance.delay.ms = 0
    group.max.session.timeout.ms = 300000
    group.min.session.timeout.ms = 6000
    host.name = 
    inter.broker.listener.name = null
    inter.broker.protocol.version = 1.1-IV0
    leader.imbalance.check.interval.seconds = 300
    leader.imbalance.per.broker.percentage = 10
    listener.security.protocol.map = PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
    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 = /tmp/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.flush.start.offset.checkpoint.interval.ms = 60000
    log.index.interval.bytes = 4096
    log.index.size.max.bytes = 10485760
    log.message.format.version = 1.1-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 = 
    max.incremental.fetch.session.cache.slots = 1000
    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.alter.log.dirs.threads = null
    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 = 1
    offsets.topic.segment.bytes = 104857600
    password.encoder.cipher.algorithm = AES/CBC/PKCS5Padding
    password.encoder.iterations = 4096
    password.encoder.key.length = 128
    password.encoder.keyfactory.algorithm = null
    password.encoder.old.secret = null
    password.encoder.secret = null
    port = 9092
    principal.builder.class = null
    producer.purgatory.purge.interval.requests = 1000
    queued.max.request.bytes = -1
    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.jaas.config = null
    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 = []
    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
    transaction.abort.timed.out.transaction.cleanup.interval.ms = 60000
    transaction.max.timeout.ms = 900000
    transaction.remove.expired.transaction.cleanup.interval.ms = 3600000
    transaction.state.log.load.buffer.size = 5242880
    transaction.state.log.min.isr = 1
    transaction.state.log.num.partitions = 50
    transaction.state.log.replication.factor = 1
    transaction.state.log.segment.bytes = 104857600
    transactional.id.expiration.ms = 604800000
    unclean.leader.election.enable = false
    zookeeper.connect = localhost:2181
    zookeeper.connection.timeout.ms = 6000
    zookeeper.max.in.flight.requests = 10
    zookeeper.session.timeout.ms = 6000
    zookeeper.set.acl = false
    zookeeper.sync.time.ms = 2000
 (kafka.server.KafkaConfig)
[2018-05-26 15:13:00,412] INFO KafkaConfig values: 
    advertised.host.name = null
    advertised.listeners = null
    advertised.port = null
    alter.config.policy.class.name = null
    alter.log.dirs.replication.quota.window.num = 11
    alter.log.dirs.replication.quota.window.size.seconds = 1
    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
    delegation.token.expiry.check.interval.ms = 3600000
    delegation.token.expiry.time.ms = 86400000
    delegation.token.master.key = null
    delegation.token.max.lifetime.ms = 604800000
    delete.records.purgatory.purge.interval.requests = 1
    delete.topic.enable = true
    fetch.purgatory.purge.interval.requests = 1000
    group.initial.rebalance.delay.ms = 0
    group.max.session.timeout.ms = 300000
    group.min.session.timeout.ms = 6000
    host.name = 
    inter.broker.listener.name = null
    inter.broker.protocol.version = 1.1-IV0
    leader.imbalance.check.interval.seconds = 300
    leader.imbalance.per.broker.percentage = 10
    listener.security.protocol.map = PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
    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 = /tmp/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.flush.start.offset.checkpoint.interval.ms = 60000
    log.index.interval.bytes = 4096
    log.index.size.max.bytes = 10485760
    log.message.format.version = 1.1-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 = 
    max.incremental.fetch.session.cache.slots = 1000
    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.alter.log.dirs.threads = null
    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 = 1
    offsets.topic.segment.bytes = 104857600
    password.encoder.cipher.algorithm = AES/CBC/PKCS5Padding
    password.encoder.iterations = 4096
    password.encoder.key.length = 128
    password.encoder.keyfactory.algorithm = null
    password.encoder.old.secret = null
    password.encoder.secret = null
    port = 9092
    principal.builder.class = null
    producer.purgatory.purge.interval.requests = 1000
    queued.max.request.bytes = -1
    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.jaas.config = null
    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 = []
    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
    transaction.abort.timed.out.transaction.cleanup.interval.ms = 60000
    transaction.max.timeout.ms = 900000
    transaction.remove.expired.transaction.cleanup.interval.ms = 3600000
    transaction.state.log.load.buffer.size = 5242880
    transaction.state.log.min.isr = 1
    transaction.state.log.num.partitions = 50
    transaction.state.log.replication.factor = 1
    transaction.state.log.segment.bytes = 104857600
    transactional.id.expiration.ms = 604800000
    unclean.leader.election.enable = false
    zookeeper.connect = localhost:2181
    zookeeper.connection.timeout.ms = 6000
    zookeeper.max.in.flight.requests = 10
    zookeeper.session.timeout.ms = 6000
    zookeeper.set.acl = false
    zookeeper.sync.time.ms = 2000
 (kafka.server.KafkaConfig)
[2018-05-26 15:13:00,495] INFO [ThrottledRequestReaper-Fetch]: Starting (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
[2018-05-26 15:13:00,498] INFO [ThrottledRequestReaper-Produce]: Starting (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
[2018-05-26 15:13:00,503] INFO [ThrottledRequestReaper-Request]: Starting (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
[2018-05-26 15:13:00,649] INFO Loading logs. (kafka.log.LogManager)
[2018-05-26 15:13:00,965] INFO [Log partition=Hello-Kafka-0, dir=/tmp/kafka-logs] Loading producer state from offset 7 with message format version 2 (kafka.log.Log)
[2018-05-26 15:13:01,021] INFO [ProducerStateManager partition=Hello-Kafka-0] Loading producer state from snapshot file /tmp/kafka-logs/Hello-Kafka-0/00000000000000000007.snapshot (kafka.log.ProducerStateManager)
[2018-05-26 15:13:01,082] INFO [Log partition=Hello-Kafka-0, dir=/tmp/kafka-logs] Completed load of log with 1 segments, log start offset 0 and log end offset 7 in 275 ms (kafka.log.Log)
[2018-05-26 15:13:01,158] INFO [Log partition=kafka_topic02-0, dir=/tmp/kafka-logs] Loading producer state from offset 0 with message format version 2 (kafka.log.Log)
[2018-05-26 15:13:01,166] INFO [Log partition=kafka_topic02-0, dir=/tmp/kafka-logs] Completed load of log with 1 segments, log start offset 0 and log end offset 0 in 20 ms (kafka.log.Log)
[2018-05-26 15:13:01,214] INFO Logs loading complete in 565 ms. (kafka.log.LogManager)
[2018-05-26 15:13:01,240] INFO Starting log cleanup with a period of 300000 ms. (kafka.log.LogManager)
[2018-05-26 15:13:01,244] INFO Starting log flusher with a default period of 9223372036854775807 ms. (kafka.log.LogManager)
[2018-05-26 15:13:02,240] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.Acceptor)
[2018-05-26 15:13:02,390] INFO [SocketServer brokerId=0] Started 1 acceptor threads (kafka.network.SocketServer)
[2018-05-26 15:13:02,461] INFO [ExpirationReaper-0-Produce]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2018-05-26 15:13:02,461] INFO [ExpirationReaper-0-Fetch]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2018-05-26 15:13:02,481] INFO [ExpirationReaper-0-DeleteRecords]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2018-05-26 15:13:02,589] INFO [LogDirFailureHandler]: Starting (kafka.server.ReplicaManager$LogDirFailureHandler)
[2018-05-26 15:13:02,701] INFO Creating /brokers/ids/0 (is it secure? false) (kafka.zk.KafkaZkClient)
[2018-05-26 15:13:02,717] INFO Result of znode creation at /brokers/ids/0 is: OK (kafka.zk.KafkaZkClient)
[2018-05-26 15:13:02,720] INFO Registered broker 0 at path /brokers/ids/0 with addresses: ArrayBuffer(EndPoint(localhost,9092,ListenerName(PLAINTEXT),PLAINTEXT)) (kafka.zk.KafkaZkClient)
[2018-05-26 15:13:02,981] INFO [ExpirationReaper-0-topic]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2018-05-26 15:13:02,981] INFO [ExpirationReaper-0-Heartbeat]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2018-05-26 15:13:02,993] INFO [ExpirationReaper-0-Rebalance]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2018-05-26 15:13:03,020] INFO Creating /controller (is it secure? false) (kafka.zk.KafkaZkClient)
[2018-05-26 15:13:03,052] INFO Result of znode creation at /controller is: OK (kafka.zk.KafkaZkClient)
[2018-05-26 15:13:03,075] INFO [GroupCoordinator 0]: Starting up. (kafka.coordinator.group.GroupCoordinator)
[2018-05-26 15:13:03,081] INFO [GroupCoordinator 0]: Startup complete. (kafka.coordinator.group.GroupCoordinator)
[2018-05-26 15:13:03,137] INFO [GroupMetadataManager brokerId=0] Removed 0 expired offsets in 53 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
[2018-05-26 15:13:03,169] INFO [ProducerId Manager 0]: Acquired new producerId block (brokerId:0,blockStartProducerId:2000,blockEndProducerId:2999) by writing to Zk with path version 3 (kafka.coordinator.transaction.ProducerIdManager)
[2018-05-26 15:13:03,300] INFO [TransactionCoordinator id=0] Starting up. (kafka.coordinator.transaction.TransactionCoordinator)
[2018-05-26 15:13:03,394] INFO [TransactionCoordinator id=0] Startup complete. (kafka.coordinator.transaction.TransactionCoordinator)
[2018-05-26 15:13:03,411] INFO [Transaction Marker Channel Manager 0]: Starting (kafka.coordinator.transaction.TransactionMarkerChannelManager)
[2018-05-26 15:13:03,637] INFO [/config/changes-event-process-thread]: Starting (kafka.common.ZkNodeChangeNotificationListener$ChangeEventProcessThread)
[2018-05-26 15:13:03,779] INFO Kafka version : 1.1.0 (org.apache.kafka.common.utils.AppInfoParser)
[2018-05-26 15:13:03,779] INFO Kafka commitId : fdcf75ea326b8e07 (org.apache.kafka.common.utils.AppInfoParser)
[2018-05-26 15:13:03,782] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)
[2018-05-26 15:13:04,083] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions Hello-Kafka-0,kafka_topic02-0 (kafka.server.ReplicaFetcherManager)
[2018-05-26 15:13:04,134] INFO Replica loaded for partition Hello-Kafka-0 with initial high watermark 7 (kafka.cluster.Replica)
[2018-05-26 15:13:04,150] INFO [Partition Hello-Kafka-0 broker=0] Hello-Kafka-0 starts at Leader Epoch 0 from offset 7. Previous Leader Epoch was: -1 (kafka.cluster.Partition)
[2018-05-26 15:13:04,232] INFO Replica loaded for partition kafka_topic02-0 with initial high watermark 0 (kafka.cluster.Replica)
[2018-05-26 15:13:04,234] INFO [Partition kafka_topic02-0 broker=0] kafka_topic02-0 starts at Leader Epoch 0 from offset 0. Previous Leader Epoch was: -1 (kafka.cluster.Partition)
[2018-05-26 15:13:04,284] INFO [ReplicaAlterLogDirsManager on broker 0] Added fetcher for partitions List() (kafka.server.ReplicaAlterLogDirsManager)

  2.3 查看启动的zookeeper和kafka的服务

[[email protected] kafka2.12]# jps
6230 Kafka
6183 QuorumPeerMain
6542 Jps

  2.4 创建和查看主题topic

创建并查看主题topic

[[email protected] kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic mytopic01
Created topic "mytopic01".
[[email protected] kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --list
mytopic01
[[email protected] kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic mytopic02
Created topic "mytopic02".
[[email protected] kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --list
mytopic01
mytopic02

kafka服务端【窗口1】输入日志如下:

[2018-05-26 15:22:40,831] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions mytopic01-0 (kafka.server.ReplicaFetcherManager)
[2018-05-26 15:22:40,850] INFO [Log partition=mytopic01-0, dir=/tmp/kafka-logs] Loading producer state from offset 0 with message format version 2 (kafka.log.Log)
[2018-05-26 15:22:40,857] INFO [Log partition=mytopic01-0, dir=/tmp/kafka-logs] Completed load of log with 1 segments, log start offset 0 and log end offset 0 in 17 ms (kafka.log.Log)
[2018-05-26 15:22:40,870] INFO Created log for partition mytopic01-0 in /tmp/kafka-logs with properties {compression.type -> producer, message.format.version -> 1.1-IV0, file.delete.delay.ms -> 60000, max.message.bytes -> 1000012, min.compaction.lag.ms -> 0, message.timestamp.type -> CreateTime, min.insync.replicas -> 1, segment.jitter.ms -> 0, preallocate -> false, min.cleanable.dirty.ratio -> 0.5, index.interval.bytes -> 4096, unclean.leader.election.enable -> false, retention.bytes -> -1, delete.retention.ms -> 86400000, cleanup.policy -> [delete], flush.ms -> 9223372036854775807, segment.ms -> 604800000, segment.bytes -> 1073741824, retention.ms -> 604800000, message.timestamp.difference.max.ms -> 9223372036854775807, segment.index.bytes -> 10485760, flush.messages -> 9223372036854775807}. (kafka.log.LogManager)
[2018-05-26 15:22:40,886] INFO [Partition mytopic01-0 broker=0] No checkpointed highwatermark is found for partition mytopic01-0 (kafka.cluster.Partition)
[2018-05-26 15:22:40,887] INFO Replica loaded for partition mytopic01-0 with initial high watermark 0 (kafka.cluster.Replica)
[2018-05-26 15:22:40,888] INFO [Partition mytopic01-0 broker=0] mytopic01-0 starts at Leader Epoch 0 from offset 0. Previous Leader Epoch was: -1 (kafka.cluster.Partition)
[2018-05-26 15:22:40,890] INFO [ReplicaAlterLogDirsManager on broker 0] Added fetcher for partitions List() (kafka.server.ReplicaAlterLogDirsManager)
[2018-05-26 15:23:00,860] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions mytopic02-0 (kafka.server.ReplicaFetcherManager)
[2018-05-26 15:23:00,888] INFO [Log partition=mytopic02-0, dir=/tmp/kafka-logs] Loading producer state from offset 0 with message format version 2 (kafka.log.Log)
[2018-05-26 15:23:00,898] INFO [Log partition=mytopic02-0, dir=/tmp/kafka-logs] Completed load of log with 1 segments, log start offset 0 and log end offset 0 in 12 ms (kafka.log.Log)
[2018-05-26 15:23:00,900] INFO Created log for partition mytopic02-0 in /tmp/kafka-logs with properties {compression.type -> producer, message.format.version -> 1.1-IV0, file.delete.delay.ms -> 60000, max.message.bytes -> 1000012, min.compaction.lag.ms -> 0, message.timestamp.type -> CreateTime, min.insync.replicas -> 1, segment.jitter.ms -> 0, preallocate -> false, min.cleanable.dirty.ratio -> 0.5, index.interval.bytes -> 4096, unclean.leader.election.enable -> false, retention.bytes -> -1, delete.retention.ms -> 86400000, cleanup.policy -> [delete], flush.ms -> 9223372036854775807, segment.ms -> 604800000, segment.bytes -> 1073741824, retention.ms -> 604800000, message.timestamp.difference.max.ms -> 9223372036854775807, segment.index.bytes -> 10485760, flush.messages -> 9223372036854775807}. (kafka.log.LogManager)
[2018-05-26 15:23:00,901] INFO [Partition mytopic02-0 broker=0] No checkpointed highwatermark is found for partition mytopic02-0 (kafka.cluster.Partition)
[2018-05-26 15:23:00,901] INFO Replica loaded for partition mytopic02-0 with initial high watermark 0 (kafka.cluster.Replica)
[2018-05-26 15:23:00,901] INFO [Partition mytopic02-0 broker=0] mytopic02-0 starts at Leader Epoch 0 from offset 0. Previous Leader Epoch was: -1 (kafka.cluster.Partition)
[2018-05-26 15:23:00,909] INFO [ReplicaAlterLogDirsManager on broker 0] Added fetcher for partitions List() (kafka.server.ReplicaAlterLogDirsManager)
[2018-05-26 15:23:03,078] INFO [GroupMetadataManager brokerId=0] Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)

  2.5 重新打开一个窗口,用于查看订阅者收到的消息【窗口2】

[[email protected] kafka2.12]# bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic mytopic01 --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].

  在先前的窗口模拟生产者生产消息,这里生产三条消息

[[email protected] kafka2.12]# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mytopic01
>my first msg>my second msg>my third msg
>

  订阅者窗口【窗口2】打印日志如下:

[[email protected] kafka2.12]# bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic mytopic01 --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
my first msg
my second msg
my third msg

 

以上是关于kafka的安装及基本使用的主要内容,如果未能解决你的问题,请参考以下文章

kafka的安装部署及应用

kafka的安装部署及应用

(转) Java中的负数及基本类型的转型详解

Kafka的入门及安装使用

kafka集群安装及简单使用

linux环境kafka安装及配置