首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Kafka集群部署

KAFKA集群部署

1 软硬件环境

Linux环境:centos6.7-64x

Kafka版本:kafka_2.12-0.10.2.0

Kafka节点:kafka01,kafka02,kafka03

Zookeeper节点:zookeeper01,zookeeper02,zookeeper03

2 安装

(1)Zookeeper安装

Zookeeper安装并启动(此处忽略安装步骤)。

(2)Kakfa安装

分别上传Kafka安装包kafka_2.12-0.10.2.0.tgz至kafka01,kafka02,kafka03三台机器的/opt目录下,解压并重命名。

注:在三台机器上做同样操作

[root@kafka01opt]# tar -zxvfkafka_2.12-0.10.2.0.tgz

··· ···

[root@kafka01opt]# mvkafka_2.12-0.10.2.0kafka

[root@kafka01opt]# rmkafka_2.12-0.10.2.0.tgz

3 配置环境变量

注:在三台机器上做同样操作

[root@kafka01opt]# vim /etc/profile

export JAVA_HOME=/opt/jdk

export JRE_HOME=/opt/jdk/jre

export HADOOP_HOME=/opt/hadoop

export ZOOKEEPER_HOME=/opt/zookeeper

export KAFKA_HOME=/opt/kafka

exportPATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin:$KAFKA_HOME/bin

export

CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$HADOOP_HOME/lib:$ZOOKEEPER_HOME/lib:$KAFKA_HOME/lib

4 参数配置

注:修改kafka Server配置文档,在kafka01,kafka02,kafka03上做同样操作

[root@kafka01~]# cd /opt/kafka/config

[root@kafka01 config]# vi server.properties

# Licensed to the Apache Software Foundation (ASF) under one or more

# contributor license agreements. See the NOTICE file distributed with

# this work for additional information regarding copyright ownership.

# The ASF licenses this file to You under the Apache License, Version 2.0

# (the "License"); you may not use this file except in compliance with

# the License. You may obtain a copy of the License at

#

# http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.

# see kafka.server.KafkaConfig for additional details and defaults

############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.

#broker在kafka集群中的唯一标识,必须为唯一的整数:kafka01标识设置为0,kafka02标识设置为1,kafka03标识设置为2

broker.id=0

# Switch to enable topic deletion or not, default value is false

#是否启用删除Topic的操作,默认为false

########################### Socket Server Settings ############################

# The address the socket server listens on. It will get the value returned from

# java.net.InetAddress.getCanonicalHostName() if not configured.

# FORMAT:

# listeners = listener_name://host_name:port

# EXAMPLE:

# listeners = PLAINTEXT://your.host.name:9092

#broker的监听IP/主机名:端口

#listeners=PLAINTEXT://:9092

# Hostname and port the broker will advertise to producers and consumers. If not set,

# it uses the value for "listeners" if configured. Otherwise, it will use the value

# returned from java.net.InetAddress.getCanonicalHostName().

#advertised.listeners=PLAINTEXT://your.host.name:9092

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details

# The number of threads handling network requests

# The number of threads doing disk I/O

#处理磁盘I/O的线程数,高峰期可能有些io等待,因此配置需要大些;配置线程数量为cpu核数2倍,最大不超过3倍。

# The send buffer (SO_SNDBUF) used by the socket server

# socket的发送缓冲区,socket的调优参数SO_SNDBUFF

# The receive buffer (SO_RCVBUF) used by the socket server

# Socket的接收缓冲区 ,socket的调优参数SO_RCVBUFF

# The maximum size of a request that the socket server will accept (protection against OOM)

############################# Log Basics #############################

# A comma seperated list of directories under which to store log files

#用于存储日志文件,多个用逗号分隔

log.dirs=/tmp/kafka-logs

# The default number of log partitions per topic. More partitions allow greater

# parallelism for consumption, but this will also result in more files across

# the brokers.

#kafka分区默认数量

num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.

# This value is recommended to be increased for installations with data dirs located in RAID array.

#每个数据目录的线程数,用于启动时的日志恢复和关闭时的刷新。

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync

# the OS cache lazily. The following configurations control the flush of data to disk.

# There are a few important trade-offs here:

# 1. Durability: Unflushed data may be lost if you are not using replication.

# 2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.

# 3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks.

# The settings below allow one to configure the flush policy to flush data after a period of time or

# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk

#在强制将数据刷新到磁盘之前要接受的消息数,如下:每当producer写入10000条消息时,刷新数据到磁盘。

# The maximum amount of time a message can sit in a log before we force a flush

#消息在强制刷新到磁盘之前可以在日志中存留的最长时间。如下:每隔1秒,刷新数据到磁盘

########################### Log Retention Policy ###########################

# The following configurations control the disposal of log segments. The policy can

# be set to delete segments after a period of time, or after a given size has accumulated.

# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens

# from the end of the log.

# The minimum age of a log file to be eligible for deletion due to age

# 当kafka server的被写入海量消息后,会生成很多数据文件,且占用大量磁盘空间,如果不及时清理,可能磁盘空间不够用,kafka默认是保留7天。建议保留三天,也可以根据磁盘是否充裕设置。

# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining

# 控制日志数据存储的最大字节数,如果超过这个界限,会根据pplicy处理数据

# The maximum size of a log segment file. When this size is reached a new log segment will be created.

#控制日志segment文件的大小,超出该大小则追加到一个新的日志segment文件中(-1表示没有限制)。段文件配置1GB,有利于快速回收磁盘空间,重启kafka加载也会加快;如果文件过小,则文件数量比较多,kafka启动时是单线程扫描目录(log.dir)下所有数据文件

# The interval at which log segments are checked to see if they can be deleted according

# to the retention policies

############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).

# This is a comma separated host:port pairs, each corresponding to a zk

# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".

# You can also append an optional chroot string to the urls to specify the

# root directory for all kafka znodes.

#指定zookeeper集群,必须和broker使用同样的zookeeper配置

zookeeper.connect=zookeeper01:2181,zookeeper02:2181zookeeper03:2181

# Timeout in ms for connecting to zookeeper

#客户端等待和zookeeper建立连接的最大时间,默认为6000ms,如果设置太小,容易超时,设置过大,影响效率。

5 测试

注:Kafka 的运行依赖 Zookeeper,启动 Kafka 前要保证 Zookeeper 服务已经启动

(1)启动kafka

注:在kafka01,kafka02,kafka03上做同样操作

[root@kafka01~]# cd /opt/kafka/bin

[root@kafka01 bin]#./kafka-server-start.sh../config/server.properties &

(2)创建Topic

[root@kafka01~]# cd /opt/kafka/bin

[root@kafka01 bin]#./kafka-topics.sh --zookeeperzookeeper01:2181,zookeeper02:2181,zookeeper03:2181 --create --topic test --partitions 3 --replication-factor 1

(3)查询所有Topic

[root@kafka01~]# cd /opt/kafka/bin

[root@kafka01 bin]#./kafka-topics.sh --zookeeperzookeeper01:2181,zookeeper02:2181,zookeeper03:2181 --list

(4)查询Topic详情

[root@kafka01~]# cd /opt/kafka/bin

[root@kafka01 bin]#./kafka-topics.sh --zookeeperzookeeper01:2181,zookeeper02:2181,zookeeper03:2181 --describe--topic test

(5)测试发布

[root@kafka01~]# cd /opt/kafka/bin

[root@kafka01 bin]#./kafka-console-producer.sh --broker-listkafka01:9092,kafka02:9092,kafka03:9092--topic test

测试发布

(6)测试消费

[root@kafka02~]# cd /opt/kafka/bin

[root@kafka02 bin]#./kafka-console-consumer.sh --zookeeperzookeeper01:2181,zookeeper02:2181,zookeeper03:2181--topic test

测试发布

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180425G105KZ00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券