Kafka cluster installation and configuration

Source: Internet
Author: User

First, cluster installation

1. Kafka Download:

Can be found on the official website of Kafka (http://kafka.apache.org), and then wget
wget http://mirrors.cnnic.cn/apache/kafka/0.8.2.2/kafka_2.10-0.8.2.2.tgz

Unzip the file:

Tar zxvf kafka_2.10-0.8.2.2.tgz

Note that Kafka relies on zookeeper and Scala, and 2.10 of the above tgz file names is the version number of Scala

The installation of ZK and Scala will not be mentioned here

2. Start the ZK cluster

Suppose the ZK cluster is bluejoe1:2181,bluejoe2:2181,bluejoe3:2181

3. Configure Config/server.properties

Server.properties the meanings of the parameters are as follows:

    • ID of the Broker.id Agent node, unique ID in the cluster
    • Log.dirs set to hard drive path
    • Num.network.threads
    • Num.partitions Default number of partitions
    • Num.io.threads recommended value is the number of cores of the machine;
    • Zookeeper.connect is set to zookeeper Servers list, each node separated by commas;
server.properties中所有配置参数说明(解释)如下列表:参数说明(解释)broker.id =0每一个broker在集群中的唯一表示,要求是正数。当该服务器的IP地址发生改变时,broker.id没有变化,则不会影响consumers的消息情况log.dirs=/data/kafka-logskafka数据的存放地址,多个地址的话用逗号分割 /data/kafka-logs-1,/data/kafka-logs-2port =9092broker server服务端口message.max.bytes =6525000表示消息体的最大大小,单位是字节num.network.threads =4broker处理消息的最大线程数,一般情况下不需要去修改num.io.threads =8broker处理磁盘IO的线程数,数值应该大于你的硬盘数background.threads =4一些后台任务处理的线程数,例如过期消息文件的删除等,一般情况下不需要去做修改queued.max.requests =500等待IO线程处理的请求队列最大数,若是等待IO的请求超过这个数值,那么会停止接受外部消息,应该是一种自我保护机制。host.namebroker的主机地址,若是设置了,那么会绑定到这个地址上,若是没有,会绑定到所有的接口上,并将其中之一发送到ZK,一般不设置socket.send.buffer.bytes=100*1024socket的发送缓冲区,socket的调优参数SO_SNDBUFFsocket.receive.buffer.bytes =100*1024socket的接受缓冲区,socket的调优参数SO_RCVBUFFsocket.request.max.bytes =100*1024*1024socket请求的最大数值,防止serverOOM,message.max.bytes必然要小于socket.request.max.bytes,会被topic创建时的指定参数覆盖log.segment.bytes =1024*1024*1024topic的分区是以一堆segment文件存储的,这个控制每个segment的大小,会被topic创建时的指定参数覆盖log.roll.hours =24*7这个参数会在日志segment没有达到log.segment.bytes设置的大小,也会强制新建一个segment会被 topic创建时的指定参数覆盖log.cleanup.policy = delete日志清理策略选择有:delete和compact主要针对过期数据的处理,或是日志文件达到限制的额度,会被 topic创建时的指定参数覆盖log.retention.minutes=3days数据存储的最大时间超过这个时间会根据log.cleanup.policy设置的策略处理数据,也就是消费端能够多久去消费数据log.retention.bytes和log.retention.minutes任意一个达到要求,都会执行删除,会被topic创建时的指定参数覆盖log.retention.bytes=-1topic每个分区的最大文件大小,一个topic的大小限制 = 分区数*log.retention.bytes。-1没有大小限log.retention.bytes和log.retention.minutes任意一个达到要求,都会执行删除,会被topic创建时的指定参数覆盖log.retention.check.interval.ms=5minutes文件大小检查的周期时间,是否处罚 log.cleanup.policy中设置的策略log.cleaner.enable=false是否开启日志压缩log.cleaner.threads = 2日志压缩运行的线程数log.cleaner.io.max.bytes.per.second=None日志压缩时候处理的最大大小log.cleaner.dedupe.buffer.size=500*1024*1024日志压缩去重时候的缓存空间,在空间允许的情况下,越大越好log.cleaner.io.buffer.size=512*1024日志清理时候用到的IO块大小一般不需要修改log.cleaner.io.buffer.load.factor =0.9日志清理中hash表的扩大因子一般不需要修改log.cleaner.backoff.ms =15000检查是否处罚日志清理的间隔log.cleaner.min.cleanable.ratio=0.5日志清理的频率控制,越大意味着更高效的清理,同时会存在一些空间上的浪费,会被topic创建时的指定参数覆盖log.cleaner.delete.retention.ms =1day对于压缩的日志保留的最长时间,也是客户端消费消息的最长时间,同log.retention.minutes的区别在于一个控制未压缩数据,一个控制压缩后的数据。会被topic创建时的指定参数覆盖log.index.size.max.bytes =10*1024*1024对于segment日志的索引文件大小限制,会被topic创建时的指定参数覆盖log.index.interval.bytes =4096当执行一个fetch操作后,需要一定的空间来扫描最近的offset大小,设置越大,代表扫描速度越快,但是也更好内存,一般情况下不需要搭理这个参数log.flush.interval.messages=Nonelog文件”sync”到磁盘之前累积的消息条数,因为磁盘IO操作是一个慢操作,但又是一个”数据可靠性"的必要手段,所以此参数的设置,需要在"数据可靠性"与"性能"之间做必要的权衡.如果此值过大,将会导致每次"fsync"的时间较长(IO阻塞),如果此值过小,将会导致"fsync"的次数较多,这也意味着整体的client请求有一定的延迟.物理server故障,将会导致没有fsync的消息丢失.log.flush.scheduler.interval.ms =3000检查是否需要固化到硬盘的时间间隔log.flush.interval.ms = None仅仅通过interval来控制消息的磁盘写入时机,是不足的.此参数用于控制"fsync"的时间间隔,如果消息量始终没有达到阀值,但是离上一次磁盘同步的时间间隔达到阀值,也将触发.log.delete.delay.ms =60000文件在索引中清除后保留的时间一般不需要去修改log.flush.offset.checkpoint.interval.ms =60000控制上次固化硬盘的时间点,以便于数据恢复一般不需要去修改auto.create.topics.enable =true是否允许自动创建topic,若是false,就需要通过命令创建topicdefault.replication.factor =1是否允许自动创建topic,若是false,就需要通过命令创建topicnum.partitions =1每个topic的分区个数,若是在topic创建时候没有指定的话会被topic创建时的指定参数覆盖以下是kafka中Leader,replicas配置参数controller.socket.timeout.ms =30000partition leader与replicas之间通讯时,socket的超时时间controller.message.queue.size=10partition leader与replicas数据同步时,消息的队列尺寸replica.lag.time.max.ms =10000replicas响应partition leader的最长等待时间,若是超过这个时间,就将replicas列入ISR(in-sync replicas),并认为它是死的,不会再加入管理中replica.lag.max.messages =4000如果follower落后与leader太多,将会认为此follower[或者说partition relicas]已经失效##通常,在follower与leader通讯时,因为网络延迟或者链接断开,总会导致replicas中消息同步滞后##如果消息之后太多,leader将认为此follower网络延迟较大或者消息吞吐能力有限,将会把此replicas迁移##到其他follower中.##在broker数量较少,或者网络不足的环境中,建议提高此值.replica.socket.timeout.ms=30*1000follower与leader之间的socket超时时间replica.socket.receive.buffer.bytes=64*1024leader复制时候的socket缓存大小replica.fetch.max.bytes =1024*1024replicas每次获取数据的最大大小replica.fetch.wait.max.ms =500replicas同leader之间通信的最大等待时间,失败了会重试replica.fetch.min.bytes =1fetch的最小数据尺寸,如果leader中尚未同步的数据不足此值,将会阻塞,直到满足条件num.replica.fetchers=1leader进行复制的线程数,增大这个数值会增加follower的IOreplica.high.watermark.checkpoint.interval.ms =5000每个replica检查是否将最高水位进行固化的频率controlled.shutdown.enable =false是否允许控制器关闭broker ,若是设置为true,会关闭所有在这个broker上的leader,并转移到其他brokercontrolled.shutdown.max.retries =3控制器关闭的尝试次数controlled.shutdown.retry.backoff.ms =5000每次关闭尝试的时间间隔leader.imbalance.per.broker.percentage =10leader的不平衡比例,若是超过这个数值,会对分区进行重新的平衡leader.imbalance.check.interval.seconds =300检查leader是否不平衡的时间间隔offset.metadata.max.bytes客户端保留offset信息的最大空间大小kafka中zookeeper参数配置 zookeeper.connect = localhost:2181zookeeper集群的地址,可以是多个,多个之间用逗号分割 hostname1:port1,hostname2:port2,hostname3:port3zookeeper.session.timeout.ms=6000ZooKeeper的最大超时时间,就是心跳的间隔,若是没有反映,那么认为已经死了,不易过大zookeeper.connection.timeout.ms =6000ZooKeeper的连接超时时间zookeeper.sync.time.ms =2000ZooKeeper集群中leader和follower之间的同步时间

Here the main changes under Zookeeper.connect for the ZK Cluster service address, such as:

zookeeper.connect=bluejoe1:2181,bluejoe2:2181,bluejoe3:2181

4. SCP to other nodes, such as: Bluejoe2,bluejoe3

5. Under the Kafka deployment directory, start with the following command on each node:
$ bin/kafka-server-start.sh Config/server.properties

6. At this point, you can start the ZK client and view the list of broker

Second, the test message to send and receive

Create topic

bin/kafka-topics.sh--zookeeper bluejoe1:2181,bluejoe2:2181,bluejoe3:2181--topic mytopic--replication-factor 1-- Partitions 1--create

View topic List

bin/kafka-topics.sh--zookeeper bluejoe1:2181,bluejoe2:2181,bluejoe3:2181--list

You can also view the list of topic from ZK

Producer Testing

bin/kafka-console-producer.sh--broker-list bluejoe1:9092,bluejoe2:9092,bluejoe3:9092--topic mytopic

Consumer Testing

bin/kafka-console-consumer.sh--zookeeper bluejoe1:2181,bluejoe2:2181,bluejoe3:2181--topic mytopic

The following shows the producer interface:

The following shows the consumer interface:

Kafka cluster installation and configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.