kafka的安装及基本使用
1、安装zookeeper
# 解压缩 [root@localhost zookeeper]# tar -zxvf zookeeper-3.4.12.tar.gz [root@localhost zookeeper]# mv zookeeper-3.4.12 zk_simple # 复制zoo_simple.cfg到zoo.cfg [root@localhost zookeeper]# cd zk_simple/ [root@localhost zk_simple]# cp conf/zoo_sample.cfg conf/zoo.cfg -R # 启动 [root@localhost 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启动状态 [root@localhost 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解压
[root@localhost software]# tar -zxvf kafka_2.12-1.1.0.tgz [root@localhost software]# mv kafka_2.12-1.1.0 kafka2.12/ [root@localhost software]# cd kafka2.12/ [root@localhost 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】
后台启动,将所有的日志推送到linux黑洞
[root@localhost kafka2.12]# bin/kafka-server-start.sh config/server.properties >>/dev/null 2>&1 &
正常启动后当前窗口作为服务端的日志输出窗口
[root@localhost 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=kafka.zookeeper.ZooKeeperClient$ZooKeeperClientWatcher$@3e92efc3 (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 = nulladvertised.listeners = nulladvertised.port = nullalter.config.policy.class.name = nullalter.log.dirs.replication.quota.window.num = 11alter.log.dirs.replication.quota.window.size.seconds = 1authorizer.class.name = auto.create.topics.enable = trueauto.leader.rebalance.enable = truebackground.threads = 10broker.id = 0broker.id.generation.enable = truebroker.rack = nullcompression.type = producerconnections.max.idle.ms = 600000controlled.shutdown.enable = truecontrolled.shutdown.max.retries = 3controlled.shutdown.retry.backoff.ms = 5000controller.socket.timeout.ms = 30000create.topic.policy.class.name = nulldefault.replication.factor = 1delegation.token.expiry.check.interval.ms = 3600000delegation.token.expiry.time.ms = 86400000delegation.token.master.key = nulldelegation.token.max.lifetime.ms = 604800000delete.records.purgatory.purge.interval.requests = 1delete.topic.enable = truefetch.purgatory.purge.interval.requests = 1000group.initial.rebalance.delay.ms = 0group.max.session.timeout.ms = 300000group.min.session.timeout.ms = 6000host.name = inter.broker.listener.name = nullinter.broker.protocol.version = 1.1-IV0leader.imbalance.check.interval.seconds = 300leader.imbalance.per.broker.percentage = 10listener.security.protocol.map = PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSLlisteners = nulllog.cleaner.backoff.ms = 15000log.cleaner.dedupe.buffer.size = 134217728log.cleaner.delete.retention.ms = 86400000log.cleaner.enable = truelog.cleaner.io.buffer.load.factor = 0.9log.cleaner.io.buffer.size = 524288log.cleaner.io.max.bytes.per.second = 1.7976931348623157E308log.cleaner.min.cleanable.ratio = 0.5log.cleaner.min.compaction.lag.ms = 0log.cleaner.threads = 1log.cleanup.policy = [delete]log.dir = /tmp/kafka-logslog.dirs = /tmp/kafka-logslog.flush.interval.messages = 9223372036854775807log.flush.interval.ms = nulllog.flush.offset.checkpoint.interval.ms = 60000log.flush.scheduler.interval.ms = 9223372036854775807log.flush.start.offset.checkpoint.interval.ms = 60000log.index.interval.bytes = 4096log.index.size.max.bytes = 10485760log.message.format.version = 1.1-IV0log.message.timestamp.difference.max.ms = 9223372036854775807log.message.timestamp.type = CreateTimelog.preallocate = falselog.retention.bytes = -1log.retention.check.interval.ms = 300000log.retention.hours = 168log.retention.minutes = nulllog.retention.ms = nulllog.roll.hours = 168log.roll.jitter.hours = 0log.roll.jitter.ms = nulllog.roll.ms = nulllog.segment.bytes = 1073741824log.segment.delete.delay.ms = 60000max.connections.per.ip = 2147483647max.connections.per.ip.overrides = max.incremental.fetch.session.cache.slots = 1000message.max.bytes = 1000012metric.reporters = []metrics.num.samples = 2metrics.recording.level = INFOmetrics.sample.window.ms = 30000min.insync.replicas = 1num.io.threads = 8num.network.threads = 3num.partitions = 1num.recovery.threads.per.data.dir = 1num.replica.alter.log.dirs.threads = nullnum.replica.fetchers = 1offset.metadata.max.bytes = 4096offsets.commit.required.acks = -1offsets.commit.timeout.ms = 5000offsets.load.buffer.size = 5242880offsets.retention.check.interval.ms = 600000offsets.retention.minutes = 1440offsets.topic.compression.codec = 0offsets.topic.num.partitions = 50offsets.topic.replication.factor = 1offsets.topic.segment.bytes = 104857600password.encoder.cipher.algorithm = AES/CBC/PKCS5Paddingpassword.encoder.iterations = 4096password.encoder.key.length = 128password.encoder.keyfactory.algorithm = nullpassword.encoder.old.secret = nullpassword.encoder.secret = nullport = 9092principal.builder.class = nullproducer.purgatory.purge.interval.requests = 1000queued.max.request.bytes = -1queued.max.requests = 500quota.consumer.default = 9223372036854775807quota.producer.default = 9223372036854775807quota.window.num = 11quota.window.size.seconds = 1replica.fetch.backoff.ms = 1000replica.fetch.max.bytes = 1048576replica.fetch.min.bytes = 1replica.fetch.response.max.bytes = 10485760replica.fetch.wait.max.ms = 500replica.high.watermark.checkpoint.interval.ms = 5000replica.lag.time.max.ms = 10000replica.socket.receive.buffer.bytes = 65536replica.socket.timeout.ms = 30000replication.quota.window.num = 11replication.quota.window.size.seconds = 1request.timeout.ms = 30000reserved.broker.max.id = 1000sasl.enabled.mechanisms = [GSSAPI]sasl.jaas.config = nullsasl.kerberos.kinit.cmd = /usr/bin/kinitsasl.kerberos.min.time.before.relogin = 60000sasl.kerberos.principal.to.local.rules = [DEFAULT]sasl.kerberos.service.name = nullsasl.kerberos.ticket.renew.jitter = 0.05sasl.kerberos.ticket.renew.window.factor = 0.8sasl.mechanism.inter.broker.protocol = GSSAPIsecurity.inter.broker.protocol = PLAINTEXTsocket.receive.buffer.bytes = 102400socket.request.max.bytes = 104857600socket.send.buffer.bytes = 102400ssl.cipher.suites = []ssl.client.auth = nonessl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]ssl.endpoint.identification.algorithm = nullssl.key.password = nullssl.keymanager.algorithm = SunX509ssl.keystore.location = nullssl.keystore.password = nullssl.keystore.type = JKSssl.protocol = TLSssl.provider = nullssl.secure.random.implementation = nullssl.trustmanager.algorithm = PKIXssl.truststore.location = nullssl.truststore.password = nullssl.truststore.type = JKStransaction.abort.timed.out.transaction.cleanup.interval.ms = 60000transaction.max.timeout.ms = 900000transaction.remove.expired.transaction.cleanup.interval.ms = 3600000transaction.state.log.load.buffer.size = 5242880transaction.state.log.min.isr = 1transaction.state.log.num.partitions = 50transaction.state.log.replication.factor = 1transaction.state.log.segment.bytes = 104857600transactional.id.expiration.ms = 604800000unclean.leader.election.enable = falsezookeeper.connect = localhost:2181zookeeper.connection.timeout.ms = 6000zookeeper.max.in.flight.requests = 10zookeeper.session.timeout.ms = 6000zookeeper.set.acl = falsezookeeper.sync.time.ms = 2000(kafka.server.KafkaConfig) [2018-05-26 15:13:00,412] INFO KafkaConfig values: advertised.host.name = nulladvertised.listeners = nulladvertised.port = nullalter.config.policy.class.name = nullalter.log.dirs.replication.quota.window.num = 11alter.log.dirs.replication.quota.window.size.seconds = 1authorizer.class.name = auto.create.topics.enable = trueauto.leader.rebalance.enable = truebackground.threads = 10broker.id = 0broker.id.generation.enable = truebroker.rack = nullcompression.type = producerconnections.max.idle.ms = 600000controlled.shutdown.enable = truecontrolled.shutdown.max.retries = 3controlled.shutdown.retry.backoff.ms = 5000controller.socket.timeout.ms = 30000create.topic.policy.class.name = nulldefault.replication.factor = 1delegation.token.expiry.check.interval.ms = 3600000delegation.token.expiry.time.ms = 86400000delegation.token.master.key = nulldelegation.token.max.lifetime.ms = 604800000delete.records.purgatory.purge.interval.requests = 1delete.topic.enable = truefetch.purgatory.purge.interval.requests = 1000group.initial.rebalance.delay.ms = 0group.max.session.timeout.ms = 300000group.min.session.timeout.ms = 6000host.name = inter.broker.listener.name = nullinter.broker.protocol.version = 1.1-IV0leader.imbalance.check.interval.seconds = 300leader.imbalance.per.broker.percentage = 10listener.security.protocol.map = PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSLlisteners = nulllog.cleaner.backoff.ms = 15000log.cleaner.dedupe.buffer.size = 134217728log.cleaner.delete.retention.ms = 86400000log.cleaner.enable = truelog.cleaner.io.buffer.load.factor = 0.9log.cleaner.io.buffer.size = 524288log.cleaner.io.max.bytes.per.second = 1.7976931348623157E308log.cleaner.min.cleanable.ratio = 0.5log.cleaner.min.compaction.lag.ms = 0log.cleaner.threads = 1log.cleanup.policy = [delete]log.dir = /tmp/kafka-logslog.dirs = /tmp/kafka-logslog.flush.interval.messages = 9223372036854775807log.flush.interval.ms = nulllog.flush.offset.checkpoint.interval.ms = 60000log.flush.scheduler.interval.ms = 9223372036854775807log.flush.start.offset.checkpoint.interval.ms = 60000log.index.interval.bytes = 4096log.index.size.max.bytes = 10485760log.message.format.version = 1.1-IV0log.message.timestamp.difference.max.ms = 9223372036854775807log.message.timestamp.type = CreateTimelog.preallocate = falselog.retention.bytes = -1log.retention.check.interval.ms = 300000log.retention.hours = 168log.retention.minutes = nulllog.retention.ms = nulllog.roll.hours = 168log.roll.jitter.hours = 0log.roll.jitter.ms = nulllog.roll.ms = nulllog.segment.bytes = 1073741824log.segment.delete.delay.ms = 60000max.connections.per.ip = 2147483647max.connections.per.ip.overrides = max.incremental.fetch.session.cache.slots = 1000message.max.bytes = 1000012metric.reporters = []metrics.num.samples = 2metrics.recording.level = INFOmetrics.sample.window.ms = 30000min.insync.replicas = 1num.io.threads = 8num.network.threads = 3num.partitions = 1num.recovery.threads.per.data.dir = 1num.replica.alter.log.dirs.threads = nullnum.replica.fetchers = 1offset.metadata.max.bytes = 4096offsets.commit.required.acks = -1offsets.commit.timeout.ms = 5000offsets.load.buffer.size = 5242880offsets.retention.check.interval.ms = 600000offsets.retention.minutes = 1440offsets.topic.compression.codec = 0offsets.topic.num.partitions = 50offsets.topic.replication.factor = 1offsets.topic.segment.bytes = 104857600password.encoder.cipher.algorithm = AES/CBC/PKCS5Paddingpassword.encoder.iterations = 4096password.encoder.key.length = 128password.encoder.keyfactory.algorithm = nullpassword.encoder.old.secret = nullpassword.encoder.secret = nullport = 9092principal.builder.class = nullproducer.purgatory.purge.interval.requests = 1000queued.max.request.bytes = -1queued.max.requests = 500quota.consumer.default = 9223372036854775807quota.producer.default = 9223372036854775807quota.window.num = 11quota.window.size.seconds = 1replica.fetch.backoff.ms = 1000replica.fetch.max.bytes = 1048576replica.fetch.min.bytes = 1replica.fetch.response.max.bytes = 10485760replica.fetch.wait.max.ms = 500replica.high.watermark.checkpoint.interval.ms = 5000replica.lag.time.max.ms = 10000replica.socket.receive.buffer.bytes = 65536replica.socket.timeout.ms = 30000replication.quota.window.num = 11replication.quota.window.size.seconds = 1request.timeout.ms = 30000reserved.broker.max.id = 1000sasl.enabled.mechanisms = [GSSAPI]sasl.jaas.config = nullsasl.kerberos.kinit.cmd = /usr/bin/kinitsasl.kerberos.min.time.before.relogin = 60000sasl.kerberos.principal.to.local.rules = [DEFAULT]sasl.kerberos.service.name = nullsasl.kerberos.ticket.renew.jitter = 0.05sasl.kerberos.ticket.renew.window.factor = 0.8sasl.mechanism.inter.broker.protocol = GSSAPIsecurity.inter.broker.protocol = PLAINTEXTsocket.receive.buffer.bytes = 102400socket.request.max.bytes = 104857600socket.send.buffer.bytes = 102400ssl.cipher.suites = []ssl.client.auth = nonessl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]ssl.endpoint.identification.algorithm = nullssl.key.password = nullssl.keymanager.algorithm = SunX509ssl.keystore.location = nullssl.keystore.password = nullssl.keystore.type = JKSssl.protocol = TLSssl.provider = nullssl.secure.random.implementation = nullssl.trustmanager.algorithm = PKIXssl.truststore.location = nullssl.truststore.password = nullssl.truststore.type = JKStransaction.abort.timed.out.transaction.cleanup.interval.ms = 60000transaction.max.timeout.ms = 900000transaction.remove.expired.transaction.cleanup.interval.ms = 3600000transaction.state.log.load.buffer.size = 5242880transaction.state.log.min.isr = 1transaction.state.log.num.partitions = 50transaction.state.log.replication.factor = 1transaction.state.log.segment.bytes = 104857600transactional.id.expiration.ms = 604800000unclean.leader.election.enable = falsezookeeper.connect = localhost:2181zookeeper.connection.timeout.ms = 6000zookeeper.max.in.flight.requests = 10zookeeper.session.timeout.ms = 6000zookeeper.set.acl = falsezookeeper.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的服务
[root@localhost kafka2.12]# jps 6230 Kafka 6183 QuorumPeerMain 6542 Jps
2.4 创建和查看主题topic
创建并查看主题topic
[root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic mytopic01 Created topic "mytopic01". [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --list mytopic01 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic mytopic02 Created topic "mytopic02". [root@localhost 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】
[root@localhost 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].
在先前的窗口模拟生产者生产消息,这里生产三条消息
[root@localhost kafka2.12]# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mytopic01 >my first msg>my second msg>my third msg >
订阅者窗口【窗口2】打印日志如下:
[root@localhost 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
3、单节点多代理模式
3.1 创建多个kafka brokers
复制server.properties到server1.properties,server2.properties,server3.properties,修改配置如下
# server1.properties broker.id=1 port=9091 log.dirs=/tmp/kafka1-logs# server2.properties broker.id=2 port=9092 log.dirs=/tmp/kafka2-logs # server3.properties broker.id=3 port=9093 log.dirs=/tmp/kafka3-logs
3.2 启动三个kafka代理(不启动server.properties,启动sever1.properties,server2.properties,server3.properties)
[root@localhost kafka2.12]# bin/kafka-server-start.sh config/server1.properties [root@localhost kafka2.12]# bin/kafka-server-start.sh config/server2.properties [root@localhost kafka2.12]# bin/kafka-server-start.sh config/server3.properties
查看zookeeper和kafka的进程,其中QuorumPeerMain是zookeeper的守护进程,三个kafka分别对应kafka的代理进程
[root@localhost kafka2.12]# jps 3923 Kafka 2808 QuorumPeerMain 4505 Kafka 4202 Kafka 8426 Jps
创建主题,查看当某节点宕机后主题的状态
# 创建三个副本因子为3,分区数量为1的topic[root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 3 --partitions 1 --topic Multibrokerapplication01 Created topic "Multibrokerapplication01". [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 3 --partitions 1 --topic Multibrokerapplication02 Created topic "Multibrokerapplication02". [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 3 --partitions 1 --topic Multibrokerapplication03 Created topic "Multibrokerapplication03". # 创建三个副本因子为2,分区数量为1的topic [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 2 --partitions 1 --topic Multibrokerapplication04 Created topic "Multibrokerapplication04". [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 2 --partitions 1 --topic Multibrokerapplication05 Created topic "Multibrokerapplication05". [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 2 --partitions 1 --topic Multibrokerapplication06 Created topic "Multibrokerapplication06".
# 创建三个副本因子为1,分区数量为1的topic
[root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic Multibrokerapplication07 Created topic "Multibrokerapplication07". [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic Multibrokerapplication08 Created topic "Multibrokerapplication08". [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic Multibrokerapplication09 Created topic "Multibrokerapplication09". # 查看每个topic的状态 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication01 Topic:Multibrokerapplication01 PartitionCount:1 ReplicationFactor:3 Configs:Topic: Multibrokerapplication01 Partition: 0 Leader: 2 Replicas: 2,1,3 Isr: 2,1,3 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication02 Topic:Multibrokerapplication02 PartitionCount:1 ReplicationFactor:3 Configs:Topic: Multibrokerapplication02 Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2,3 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication03 Topic:Multibrokerapplication03 PartitionCount:1 ReplicationFactor:3 Configs:Topic: Multibrokerapplication03 Partition: 0 Leader: 3 Replicas: 3,1,2 Isr: 3,1,2 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication04 Topic:Multibrokerapplication04 PartitionCount:1 ReplicationFactor:2 Configs:Topic: Multibrokerapplication04 Partition: 0 Leader: 2 Replicas: 2,1 Isr: 2,1 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication05 Topic:Multibrokerapplication05 PartitionCount:1 ReplicationFactor:2 Configs:Topic: Multibrokerapplication05 Partition: 0 Leader: 2 Replicas: 2,3 Isr: 2,3 ^[[A[root@localhost kafka2.1bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication06 Topic:Multibrokerapplication06 PartitionCount:1 ReplicationFactor:2 Configs:Topic: Multibrokerapplication06 Partition: 0 Leader: 3 Replicas: 3,2 Isr: 3,2 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication07 Topic:Multibrokerapplication07 PartitionCount:1 ReplicationFactor:1 Configs:Topic: Multibrokerapplication07 Partition: 0 Leader: 1 Replicas: 1 Isr: 1 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication08 Topic:Multibrokerapplication08 PartitionCount:1 ReplicationFactor:1 Configs:Topic: Multibrokerapplication08 Partition: 0 Leader: 3 Replicas: 3 Isr: 3 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication09 Topic:Multibrokerapplication09 PartitionCount:1 ReplicationFactor:1 Configs:Topic: Multibrokerapplication09 Partition: 0 Leader: 3 Replicas: 3 Isr: 3 # 杀掉brokerid为3的kafka代理节点 [root@localhost kafka2.12]# [root@localhost kafka2.12]# [root@localhost kafka2.12]# kill -9 4505
# 查看每个topic的状态
[root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication01 Topic:Multibrokerapplication01 PartitionCount:1 ReplicationFactor:3 Configs:Topic: Multibrokerapplication01 Partition: 0 Leader: 2 Replicas: 2,1,3 Isr: 2,1 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication02 Topic:Multibrokerapplication02 PartitionCount:1 ReplicationFactor:3 Configs:Topic: Multibrokerapplication02 Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication03 Topic:Multibrokerapplication03 PartitionCount:1 ReplicationFactor:3 Configs:Topic: Multibrokerapplication03 Partition: 0 Leader: 1 Replicas: 3,1,2 Isr: 1,2 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication04 Topic:Multibrokerapplication04 PartitionCount:1 ReplicationFactor:2 Configs:Topic: Multibrokerapplication04 Partition: 0 Leader: 2 Replicas: 2,1 Isr: 2,1 ^[[A[root@localhost kafka2.1bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication05 Topic:Multibrokerapplication05 PartitionCount:1 ReplicationFactor:2 Configs:Topic: Multibrokerapplication05 Partition: 0 Leader: 2 Replicas: 2,3 Isr: 2 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication06 Topic:Multibrokerapplication06 PartitionCount:1 ReplicationFactor:2 Configs:Topic: Multibrokerapplication06 Partition: 0 Leader: 2 Replicas: 3,2 Isr: 2 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication07 Topic:Multibrokerapplication07 PartitionCount:1 ReplicationFactor:1 Configs:Topic: Multibrokerapplication07 Partition: 0 Leader: 1 Replicas: 1 Isr: 1 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication08 Topic:Multibrokerapplication08 PartitionCount:1 ReplicationFactor:1 Configs:Topic: Multibrokerapplication08 Partition: 0 Leader: 3 Replicas: 3 Isr: 3 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication09 Topic:Multibrokerapplication09 PartitionCount:1 ReplicationFactor:1 Configs:Topic: Multibrokerapplication09 Partition: 0 Leader: 3 Replicas: 3 Isr: 3 [root@localhost kafka2.12]#
3.3 启动生产者发送消息
【Multibrokerapplication01】brokerid为1的代理,生产消息
[root@localhost kafka2.12]# bin/kafka-console-producer.sh --broker-list localhost:9091 --topic Multibrokerapplication01 >hello >this is first msg >this is 9091 >
【Multibrokerapplication01】订阅的消息如下
[root@localhost kafka2.12]# bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic Multibrokerapplication01 --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]. hello this is first msg this is 9091
【Multibrokerapplication01】brokerid为2的代理,生产消息
[root@localhost kafka2.12]# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic Multibrokerapplication01 >hello >this is second msg >this is 9092 >
【Multibrokerapplication01】订阅的消息如下
[root@localhost kafka2.12]# bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic Multibrokerapplication01 --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].
hello this is first msg this is 9091
hello this is second msg this is 9092
【Multibrokerapplication01】brokerid为3的代理,生产消息(之前杀掉了brokerid=3的kafka代理)
[root@localhost kafka2.12]# bin/kafka-console-producer.sh --broker-list localhost:9093 --topic Multibrokerapplication01 >hello [2018-05-27 11:05:49,045] WARN [Producer clientId=console-producer] Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient) [2018-05-27 11:05:52,490] WARN [Producer clientId=console-producer] Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient) [2018-05-27 11:05:53,627] WARN [Producer clientId=console-producer] Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient) [2018-05-27 11:05:54,649] WARN [Producer clientId=console-producer] Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
【Multibrokerapplication01】订阅的消息没有日志输出
3.4 修改主题
# 修改名称为'Multibrokerapplication02'的主题,分区数量为2,由于副本因子比实际的brokers代理要多,发生异常 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic Multibrokerapplication02 --partitions 2 WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected Error while executing topic command : Replication factor: 3 larger than available brokers: 2. [2018-05-27 11:14:45,297] ERROR org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 3 larger than available brokers: 2.(kafka.admin.TopicCommand$)# 重启brokerid=3的kafka代理 [root@localhost kafka2.12]# bin/kafka-server-start.sh config/server3.properties >>/dev/null 2>&1 & [1] 19183# 修改名称为'Multibrokerapplication02'的主题,分区数量为2 [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic Multibrokerapplication02 --partitions 2 WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected Adding partitions succeeded! # 查看主题'Multibrokerapplication02'详情
[root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic Multibrokerapplication02 Topic:Multibrokerapplication02 PartitionCount:2 ReplicationFactor:3 Configs: Topic: Multibrokerapplication02 Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2,3 Topic: Multibrokerapplication02 Partition: 1 Leader: 2 Replicas: 2,3,1 Isr: 2,3,1
3.5 删除主题
[root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic Multibrokerapplication02 Topic Multibrokerapplication02 is marked for deletion. Note: This will have no impact if delete.topic.enable is not set to true. [root@localhost kafka2.12]# bin/kafka-topics.sh --zookeeper localhost:2181 --list Multibrokerapplication01 Multibrokerapplication03 Multibrokerapplication04 Multibrokerapplication05 Multibrokerapplication06 Multibrokerapplication07 Multibrokerapplication08 Multibrokerapplication09
转载于:https://www.cnblogs.com/wrcold520/p/9093094.html
kafka的安装及基本使用相关推荐
- kafka的安装与启动运行
kafka简介 kafka是一种高吞吐量的分布式发布订阅消息系统. 环境搭建 1.首先安装JDK 下载地址https://www.oracle.com/technetwork/java/javase/ ...
- kafka mysql安装与配置_Mac环境canal+mysql+kafka的安装及使用
为了实现 实时同步数据,在mac环境搭建了canal,mysql,kafka的一套流程 使用canal加mysql加kafka的方式传递数据 mysql 数据源头 canal模仿slave冲mysql ...
- Docker Kafka 单机版安装
一.安装 下载library/zookeeper并运行 docker run --name zookeeper -d -p 2181:2181 -v /etc/localtime:/etc/local ...
- kafka 的安装部署
Kafka 的简介: Kafka 是一款分布式消息发布和订阅系统,具有高性能.高吞吐量的特点而被广泛应用与大数据传输场景.它是由 LinkedIn 公司开发,使用 Scala 语言编写,之后成为 Ap ...
- Kafka单机安装Version1.0.1(自带Zookeeper)
1.说明 Kafka单机安装,基于版本1.0.1, 使用kafka_2.12-1.0.1.tgz安装包, 其中2.12是编译工具Scala的版本. 而且不需要另外安装Zookeeper服务, 使用Ka ...
- kafka php 安装配置,kafka安装及Kafka-PHP扩展的使用,kafkakafka-php扩展_PHP教程
kafka安装及Kafka-PHP扩展的使用,kafkakafka-php扩展 话说用了就要有点产出,要不然过段时间又忘了,所以在这里就记录一下试用Kafka的安装过程和php扩展的试用. 实话说,如 ...
- 【kafka】Kafka 可视化工具Kafka Eagle安装和使用
一.背景 Kafka产线环境需要管理的Topic和Consumser越来越多,使用命令行工具进行管理会非常繁杂.因此,大数据平台上需要一套Kafka的管理监控系统,Kafka-Eagle. Kafka ...
- Kafka的安装与配置
一 jar包方式安装Kafka jar包下载地址:https://kafka.apache.org/downloads下载 1.配置java环境 1.1.上传jdk-8u341-linux-x6 ...
- kafka的安装使用
一:注册中心 首先,kafka的注册中心是zk,后期版本已经自带,可以不用单独下载zk,直接使用kafka里的就好,如果自己下载部署也行, zk的下载安装: 下载安装包,解压,复制zoo_sample ...
- 【Kafka】Kafka的安装
Kafka的安装 准备工作 正式安装 Kafka命令行操作 本篇只讲述Kafka的安装与基本命令,不做框架和运行原理的描述,想了解Kafka的框架和运行原理可以点击链接: Kafka的框架与运行原理 ...
最新文章
- Stimulsoft Reports.Net基础教程(十):创建图表报表②
- 进程和线程的区别?什么时候用进程?什么时候用线程?
- 【Android 事件分发】ItemTouchHelper 源码分析 ( OnItemTouchListener 事件监听器源码分析 )
- 谷歌guava_Google Guava –期货
- 关联规则挖掘算法综述
- C#基础知识(收藏)
- (简单)华为Nova青春 WAS-AL00的USB调试模式在哪里开启的流程
- ASCII码常用范围
- 插件学习笔记:搜索引擎ElasticSearch
- 线性代数学习笔记——线性方程组解的判定与解法
- Unity摄像机平滑处理跟随
- 异常检测论文(一):CutPaste
- 领英问题问答--有关领英各类问题整理,置顶推荐
- python编程midi键盘按键错乱_电脑键盘按键错乱怎么回事?几步轻松搞定
- 华为防火墙查看日志命令_华为防火墙命令
- 7-2 海盗分赃 (25 分)(PTA)
- 本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止.
- JavaScript零基础入门 13:DOM规范中的MutationObserver接口
- 《大话设计模式》--牛市股票还会亏钱?--外观模式Facade(12)
- 网络管理软件都有哪些,目前好用的网络管理软件
热门文章
- PHP水果店管理系统,水果店管理系统设计是?水果店管理系统优势是?
- Android调用miui给权限,Android 11+MIUI12,APP任意获取用户隐私的路子被封死
- 美团点评CodeM编程大赛-题二
- 电脑装机硬盘分区格式
- java 发送邮件添加附件,Java实现带附件的邮件发送功能
- 2022-04-24_数组的定义和初始化
- Qt编写4K/8K大分辨率播放器(8K占用1%CPU)
- can收发器 rx_MCU如何扩展CAN/CAN FD接口?
- python bytes与str之间的转换 hex的字符转换
- 在postfix使用qq企业邮箱的smtp