文档章节

Kafka 应用

x
 xixi74
发布于 2014/06/09 15:48
字数 2583
阅读 70
收藏 0


Replication 功能

Kafka 的replication功能默认在配置文件并没有开启


开启方法:

在 config/server.properties 文件中 添加 default.replication.factor=3(不要超过kafka服务的个数)


通过开启kafka的replication可以实现leader选举,这样在当前leader故障的时候会有新的server被选举为leader继续提供服务。 



Zookeeper 中查看当前的Brokers

// 我共创建了三各Borkers实例

[zk: localhost:2181(CONNECTED) 4] ls /brokers/ids   
[3, 2, 1]

// 创建时间,主机名,版本,端口
[zk: localhost:2181(CONNECTED) 5] get /brokers/ids/3
{"jmx_port":-1,"timestamp":"1402294984991","host":"hadoop216","version":1,"port":9092}
cZxid = 0x2000c1e6c
ctime = Mon Jun 09 14:23:11 CST 2014
mZxid = 0x2000c1e6c
mtime = Mon Jun 09 14:23:11 CST 2014
pZxid = 0x2000c1e6c
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x664627afbd95001e
dataLength = 86
numChildren = 0
[zk: localhost:2181(CONNECTED) 6] get /brokers/ids/2
{"jmx_port":-1,"timestamp":"1402295050069","host":"hadoop215","version":1,"port":9092}
cZxid = 0x2000c1ee2
ctime = Mon Jun 09 14:24:10 CST 2014
mZxid = 0x2000c1ee2
mtime = Mon Jun 09 14:24:10 CST 2014
pZxid = 0x2000c1ee2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x674627afe1a90015
dataLength = 86
numChildren = 0
[zk: localhost:2181(CONNECTED) 7] get /brokers/ids/1
{"jmx_port":-1,"timestamp":"1402298717099","host":"hadoop214","version":1,"port":9092}
cZxid = 0x2000c2c8b
ctime = Mon Jun 09 15:25:17 CST 2014
mZxid = 0x2000c2c8b
mtime = Mon Jun 09 15:25:17 CST 2014
pZxid = 0x2000c2c8b
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x674627afe1a90019
dataLength = 86
numChildren = 0

查看已创建的topics 

[zk: localhost:2181(CONNECTED) 9] ls /brokers
[topics, ids]

[zk: localhost:2181(CONNECTED) 10] ls /brokers/topics
[testtopic, mytopic, topic1, totem, test]

[zk: localhost:2181(CONNECTED) 11] ls /brokers/topics/topic1
[partitions]
[zk: localhost:2181(CONNECTED) 12] ls /brokers/topics/topic1/partitions
[1, 0]

查看“topic1” 分区的partition的leader,foller情况

[zk: localhost:2181(CONNECTED) 15] get  /brokers/topics/topic1/partitions/1/state
{"controller_epoch":9,"leader":2,"version":1,"leader_epoch":1,"isr":[2,3,1]}
cZxid = 0x2000c2a1e
ctime = Mon Jun 09 15:13:34 CST 2014
mZxid = 0x2000c2c92
mtime = Mon Jun 09 15:25:18 CST 2014
pZxid = 0x2000c2a1e
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 76
numChildren = 0

[zk: localhost:2181(CONNECTED) 16] get  /brokers/topics/topic1/partitions/0/state
{"controller_epoch":9,"leader":2,"version":1,"leader_epoch":1,"isr":[2,3,1]}
cZxid = 0x2000c2a21
ctime = Mon Jun 09 15:13:34 CST 2014
mZxid = 0x2000c2c91
mtime = Mon Jun 09 15:25:17 CST 2014
pZxid = 0x2000c2a21
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 76
numChildren = 0


kakfa brokers 的参数配置


Property Default Description
broker.id Each broker is uniquely identified by a non-negative integer id. This id serves as the broker's "name" and allows the broker to be moved to a different host/port without confusing consumers. You can choose any number you like so long as it is unique.
log.dirs /tmp/kafka-logs A comma-separated list of one or more directories in which Kafka data is stored. Each new partition that is created will be placed in the directory which currently has the fewest partitions.
port 6667 The port on which the server accepts client connections.
zookeeper.connect null Specifies the ZooKeeper connection string in the formhostname:port, where hostname and port are the host and port for a node in your ZooKeeper cluster. To allow connecting through other ZooKeeper nodes when that host is down you can also specify multiple hosts in the formhostname1:port1,hostname2:port2,hostname3:port3.

ZooKeeper also allows you to add a "chroot" path which will make all kafka data for this cluster appear under a particular path. This is a way to setup multiple Kafka clusters or other applications on the same ZooKeeper cluster. To do this give a connection string in the formhostname1:port1,hostname2:port2,hostname3:port3/chroot/pathwhich would put all this cluster's data under the path/chroot/path. Note that you must create this path yourself prior to starting the broker and consumers must use the same connection string.

message.max.bytes 1000000 The maximum size of a message that the server can receive. It is important that this property be in sync with the maximum fetch size your consumers use or else an unruly producer will be able to publish messages too large for consumers to consume.
num.network.threads 3 The number of network threads that the server uses for handling network requests. You probably don't need to change this.
num.io.threads 8 The number of I/O threads that the server uses for executing requests. You should have at least as many threads as you have disks.
background.threads 4 The number of threads to use for various background processing tasks such as file deletion. You should not need to change this.
queued.max.requests 500 The number of requests that can be queued up for processing by the I/O threads before the network threads stop reading in new requests.
host.name null

Hostname of broker. If this is set, it will only bind to this address. If this is not set, it will bind to all interfaces, and publish one to ZK.

advertised.host.name null

If this is set this is the hostname that will be given out to producers, consumers, and other brokers to connect to.

advertised.port null

The port to give out to producers, consumers, and other brokers to use in establishing connections. This only needs to be set if this port is different from the port the server should bind to.

socket.send.buffer.bytes 100 * 1024 The SO_SNDBUFF buffer the server prefers for socket connections.
socket.receive.buffer.bytes 100 * 1024 The SO_RCVBUFF buffer the server prefers for socket connections.
socket.request.max.bytes 100 * 1024 * 1024 The maximum request size the server will allow. This prevents the server from running out of memory and should be smaller than the Java heap size.
num.partitions 1 The default number of partitions per topic if a partition count isn't given at topic creation time.
log.segment.bytes 1024 * 1024 * 1024 The log for a topic partition is stored as a directory of segment files. This setting controls the size to which a segment file will grow before a new segment is rolled over in the log. This setting can be overridden on a per-topic basis (see the per-topic configuration section).
log.roll.hours 24 * 7 This setting will force Kafka to roll a new log segment even if the log.segment.bytes size has not been reached. This setting can be overridden on a per-topic basis (see the per-topic configuration section).
log.cleanup.policy delete This can take either the value delete or compact. If delete is set, log segments will be deleted when they reach the size or time limits set. If compact is set log compaction will be used to clean out obsolete records. This setting can be overridden on a per-topic basis (see the per-topic configuration section).
log.retention.minutes 7 days The number of minutes to keep a log segment before it is deleted, i.e. the default data retention window for all topics. Note that if both log.retention.minutes and log.retention.bytes are both set we delete a segment when either limit is exceeded. This setting can be overridden on a per-topic basis (see the per-topic configuration section).
log.retention.bytes -1 The amount of data to retain in the log for each topic-partitions. Note that this is the limit per-partition so multiply by the number of partitions to get the total data retained for the topic. Also note that if both log.retention.hours and log.retention.bytes are both set we delete a segment when either limit is exceeded. This setting can be overridden on a per-topic basis (see the per-topic configuration section).
log.retention.check.interval.ms 5 minutes The period with which we check whether any log segment is eligible for deletion to meet the retention policies.
log.cleaner.enable false This configuration must be set to true for log compaction to run.
log.cleaner.threads 1 The number of threads to use for cleaning logs in log compaction.
log.cleaner.io.max.bytes.per.second None The maximum amount of I/O the log cleaner can do while performing log compaction. This setting allows setting a limit for the cleaner to avoid impacting live request serving.
log.cleaner.dedupe.buffer.size 500*1024*1024 The size of the buffer the log cleaner uses for indexing and deduplicating logs during cleaning. Larger is better provided you have sufficient memory.
log.cleaner.io.buffer.size 512*1024 The size of the I/O chunk used during log cleaning. You probably don't need to change this.
log.cleaner.io.buffer.load.factor 0.9 The load factor of the hash table used in log cleaning. You probably don't need to change this.
log.cleaner.backoff.ms 15000 The interval between checks to see if any logs need cleaning.
log.cleaner.min.cleanable.ratio 0.5 This configuration controls how frequently the log compactor will attempt to clean the log (assuming log compaction is enabled). By default we will avoid cleaning a log where more than 50% of the log has been compacted. This ratio bounds the maximum space wasted in the log by duplicates (at 50% at most 50% of the log could be duplicates). A higher ratio will mean fewer, more efficient cleanings but will mean more wasted space in the log. This setting can be overridden on a per-topic basis (see the per-topic configuration section).
log.cleaner.delete.retention.ms 1 day The amount of time to retain delete tombstone markers for log compacted topics. This setting also gives a bound on the time in which a consumer must complete a read if they begin from offset 0 to ensure that they get a valid snapshot of the final stage (otherwise delete tombstones may be collected before they complete their scan). This setting can be overridden on a per-topic basis (see the per-topic configuration section).
log.index.size.max.bytes 10 * 1024 * 1024 The maximum size in bytes we allow for the offset index for each log segment. Note that we will always pre-allocate a sparse file with this much space and shrink it down when the log rolls. If the index fills up we will roll a new log segment even if we haven't reached the log.segment.bytes limit. This setting can be overridden on a per-topic basis (see the per-topic configuration section).
log.index.interval.bytes 4096 The byte interval at which we add an entry to the offset index. When executing a fetch request the server must do a linear scan for up to this many bytes to find the correct position in the log to begin and end the fetch. So setting this value to be larger will mean larger index files (and a bit more memory usage) but less scanning. However the server will never add more than one index entry per log append (even if more than log.index.interval worth of messages are appended). In general you probably don't need to mess with this value.
log.flush.interval.messages None The number of messages written to a log partition before we force an fsync on the log. Setting this lower will sync data to disk more often but will have a major impact on performance. We generally recommend that people make use of replication for durability rather than depending on single-server fsync, however this setting can be used to be extra certain.
log.flush.scheduler.interval.ms 3000 The frequency in ms that the log flusher checks whether any log is eligible to be flushed to disk.
log.flush.interval.ms None The maximum time between fsync calls on the log. If used in conjuction with log.flush.interval.messages the log will be flushed when either criteria is met.
log.delete.delay.ms 60000 The period of time we hold log files around after they are removed from the index. This period of time allows any in-progress reads to complete uninterrupted without locking. You generally don't need to change this.
log.flush.offset.checkpoint.interval.ms 60000 The frequency with which we checkpoint the last flush point for logs for recovery. You should not need to change this.
auto.create.topics.enable true Enable auto creation of topic on the server. If this is set to true then attempts to produce, consume, or fetch metadata for a non-existent topic will automatically create it with the default replication factor and number of partitions.
controller.socket.timeout.ms 30000 The socket timeout for commands from the partition management controller to the replicas.
controller.message.queue.size 10 The buffer size for controller-to-broker-channels
default.replication.factor 1 The default replication factor for automatically created topics.
replica.lag.time.max.ms 10000 If a follower hasn't sent any fetch requests for this window of time, the leader will remove the follower from ISR (in-sync replicas) and treat it as dead.
replica.lag.max.messages 4000 If a replica falls more than this many messages behind the leader, the leader will remove the follower from ISR and treat it as dead.
replica.socket.timeout.ms 30 * 1000 The socket timeout for network requests to the leader for replicating data.
replica.socket.receive.buffer.bytes 64 * 1024 The socket receive buffer for network requests to the leader for replicating data.
replica.fetch.max.bytes 1024 * 1024 The number of byes of messages to attempt to fetch for each partition in the fetch requests the replicas send to the leader.
replica.fetch.wait.max.ms 500 The maximum amount of time to wait time for data to arrive on the leader in the fetch requests sent by the replicas to the leader.
replica.fetch.min.bytes 1 Minimum bytes expected for each fetch response for the fetch requests from the replica to the leader. If not enough bytes, wait up to replica.fetch.wait.max.ms for this many bytes to arrive.
num.replica.fetchers 1

Number of threads used to replicate messages from leaders. Increasing this value can increase the degree of I/O parallelism in the follower broker.

replica.high.watermark.checkpoint.interval.ms 5000 The frequency with which each replica saves its high watermark to disk to handle recovery.
fetch.purgatory.purge.interval.requests 10000 The purge interval (in number of requests) of the fetch request purgatory.
producer.purgatory.purge.interval.requests 10000 The purge interval (in number of requests) of the producer request purgatory.
zookeeper.session.timeout.ms 6000 ZooKeeper session timeout. If the server fails to heartbeat to ZooKeeper within this period of time it is considered dead. If you set this too low the server may be falsely considered dead; if you set it too high it may take too long to recognize a truly dead server.
zookeeper.connection.timeout.ms 6000 The maximum amount of time that the client waits to establish a connection to zookeeper.
zookeeper.sync.time.ms 2000 How far a ZK follower can be behind a ZK leader.
controlled.shutdown.enable false Enable controlled shutdown of the broker. If enabled, the broker will move all leaders on it to some other brokers before shutting itself down. This reduces the unavailability window during shutdown.
controlled.shutdown.max.retries 3 Number of retries to complete the controlled shutdown successfully before executing an unclean shutdown.
controlled.shutdown.retry.backoff.ms 5000 Backoff time between shutdown retries.
auto.leader.rebalance.enable false If this is enabled the controller will automatically try to balance leadership for partitions among the brokers by periodically returning leadership to the "preferred" replica for each partition if it is available.
leader.imbalance.per.broker.percentage 10 The percentage of leader imbalance allowed per broker. The controller will rebalance leadership if this ratio goes above the configured value per broker.
leader.imbalance.check.interval.seconds 300 The frequency with which to check for leader imbalance.
offset.metadata.max.bytes 1024 The maximum amount of metadata to allow clients to save with their offsets.


Kafka 删除主题的方法:

  • 删除kafka存储目录(server.properties文件log.dirs配置,默认为"/tmp/kafka-logs")相关topic目录
  • 删除zookeeper "/brokers/topics/"目录下相关topic节点

© 著作权归作者所有

x
粉丝 0
博文 4
码字总数 3100
作品 0
东城
程序员
私信 提问
干货满满,腾讯云+社区技术沙龙 Kafka Meetup 深圳站圆满结束

云+导语:4月22日,由腾讯云和 Kafka 社区主办、开源中国协办的腾讯云+社区技术沙龙 Kafka Meetup 深圳站在腾讯大厦举行,本次活动全程干货满满,不仅有 Kafka 的前世今生及展望,也有对 Ka...

小鱼丁
2018/04/25
240
0
干货满满,腾讯云+社区技术沙龙 Kafka Meetup 深圳站圆满结束

云加社区技术沙龙 发表于腾讯云技术沙龙订阅 56 干货满满,腾讯云+社区技术沙龙 Kafka Meetup 深圳站圆满结束 云+导语:4月22日,由腾讯云和 Kafka 社区主办、开源中国协办的腾讯云+社区技术...

腾讯云开发者社区
2018/04/25
65
0
如何使用Docker内的kafka服务

版权声明:欢迎转载,请注明出处,谢谢。 https://blog.csdn.net/boling_cavalry/article/details/85528519 基于Docker可以很轻松的搭建一个kafka集群,其他机器上的应用如何使用这个kafka集...

博陵精骑
2019/01/01
0
0
日志打入kafka改造历程-我们到底能走多远系列49

方案 日志收集的方案有很多,包括各种日志过滤清洗,分析,统计,而且看起来都很高大上。本文只描述一个打入kafka的功能。 流程:app->kafka->logstash->es->kibana 业务应用直接将日志打入k...

每当变幻时
2018/08/21
0
0
云+社区技术沙龙 Kafka meetup 深圳站

如果说 2018 年是技术大爆炸年,那么 Apache Kafka 绝对是其中闪亮的新星。 自Kafka 从首发之日起,已经走过了快八个年头。Kafka 已经从最开始的大规模消息系统,发展成为功能完善的分布式流...

吉衣OSC
2018/04/02
535
0

没有更多内容

加载失败,请刷新页面

加载更多

spring-boot-maven-plugin not found的解决方案。

通过IDE创建一个springboot项目, <plugin> <groupId>org.springframework.boot</groupId>//这行红色 <artifactId>spring-boot-maven-plugin</artifactId>//这行红色</plugin> 提示sprin......

一片云里的天空
今天
52
0
OSChina 周三乱弹 —— 我可能是个憨憨

Osc乱弹歌单(2020)请戳(这里) 【今日歌曲】 @宇辰OSC :分享Hare Je的单曲《Alan Walker-Faded(Hare Je remix)》: #今日歌曲推荐# 可以放松大脑的一首纯音乐 《Alan Walker-Faded(Har...

小小编辑
今天
99
0
搞定SpringBoot多数据源(3):参数化变更源

春节将至,今天放假了,在此祝小伙伴们新春大吉,身体健康,思路清晰,永远无BUG! 一句话概括:参数化变更源意思是根据参数动态添加数据源以及切换数据源,解决不确定数据源的问题。 1. 引言...

mason技术记录
昨天
99
0
sql 基础知识

sql 基础知识 不要极至最求一条sql语句搞定一切,可合理拆分为多条语句 1. sql 变量定义与赋值 Sql 语句中,直接在SELECT使用@定义一个变量,如:[@a](https://my.oschina.net/a8856225a)。 ...

DrChenXX
昨天
57
0
MacOSX 安装 TensorFlow

TensorFlow是一个端到端开源机器学习平台。它拥有一个包含各种工具、库和社区资源的全面灵活生态系统,可以让研究人员推动机器学习领域的先进技术的。 准备 安装 Anaconda TensorFlow 安装的...

叉叉敌
昨天
79
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部