Kafka: Linux环境-单机部署和伪集群集群部署

Posted 鮀城小帅

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kafka: Linux环境-单机部署和伪集群集群部署相关的知识,希望对你有一定的参考价值。

1. Kafka单机部署

1.1 下载zookeeper压缩包

到官网下载zookeeper压缩包,如下:

1.2 安装zookeeper

(1)上传zookeepe压缩包,并解压:

tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz

拷贝安装包到/usr/local/目录下:

cp -r apache-zookeeper-3.7.1-bin /usr/local/zookeeper

进入到 conf 目录,看到 zoo_sample.cfg 文件,cp 复制生成 zoo.cfg 文件,如下:

 cp conf/zoo_sample.cfg conf/zoo.cfg

(2)启动并查看状态

启动zookeeper
./bin/zkServer.sh start
查看zookeeper状态
./bin/zkServer.sh status

 standalone代表单机启动。

1.3 下载kafka压缩包

到官网下载kafka压缩包,如下

1.4安装kafka

(1)上传kafka安装包到服务器 /opt 目录下,解压kafka安装包:

tar -zxvf kafka_2.13-3.1.0.tgz

cp -r kafka_2.13-3.1.0 /usr/local/kafka

cd /usr/local/kafka

(2)修改配置,此配置用于消息发布与订阅的ip。进入到 conf 目录,在config/server.properties 文件,并做如下修改:

 vim config/server.properties
# 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
listeners=PLAINTEXT://127.0.0.1:9092

将listeners的ip修改为当前部署kafka的服务器ip。单机部署,可以修改为127.0.0.1或localhost;集群则需要修改为服务器的 ip 地址。

(3)启动kafka

./bin/kafka-server-start.sh config/server.properties &

(4)新建topic并查看状态

新建topic:

[root@9e02276c1212 kafka]# ./bin/kafka-topics.sh --create --topic test1 --bootstrap-server 127.0.0.1:9092

Created topic test1.

">"后后面的内容就是新建的topic。

查看状态:

[root@9e02276c1212 kafka]# ./bin/kafka-topics.sh --describe --topic test1 --bootstrap-server 127.0.0.1:9092
2
Topic: test1    TopicId: XCJCzuz5T_ac-cpbUdsBcg PartitionCount: 1       ReplicationFactor: 1    Configs: segment.bytes=1073741824
        Topic: test1    Partition: 0    Leader: 0       Replicas: 0     Isr: 0

然后zoo.cfg指定的目录就有了topic了,默认配置是 /tmp/kafka-logs 目录下:

(5)生产消息和消费消息

# 生产消息
./bin/kafka-console-producer.sh --bootstrap-server 127.0.0.1:9092 --topic test2
# 消费消息
./bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --topic test2 --from-beginning

消息消费过程:

(6)停止kafka

./kafka-server-stop.sh

2. Kafka伪集群

在同一台服务器上,以不同端口(2181,2182,2183)运行三个zookeeper,形成一个伪集群。

2.1 zookeeper 集群安装

(1)下载安装包,并上传解压到/opt目录下

(2)复制集群节点

cp -r /opt/apache-zookeeper-3.7.1-bin /usr/local/zookeeper-2181

(3)创建目录

mkdir /usr/local/zookeeper-2181/data
mkdir /usr/local/zookeeper-2181/logs

(4)修改配置文件

cd /usr/local/zookeeper-2181/conf/
cp zoo_sample.cfg zoo.cfg

修改dataDir,clientPort两个配置项

dataDir=/usr/local/zookeeper-2181/data
clientPort=2181

并添加以下配置项

dataLogDir=/usr/local/zookeeper-2181/logs
server.1=192.168.126.135:2287:3387
server.2=192.168.126.135:2288:3388
server.3=192.168.126.135:2289:3389

data目录下创建myid文件

cd /usr/local/zookeeper/zookeeper-2181/data
vim myid

myid中指定节点id在一个集群中不能重复。例如:将2181节点的id设置为12182节点设置为22183节点设置为3.

[root@linkhot local]# cat /usr/local/zookeeper-2181/data/myid
1

(5)复制多个zookeeper

cd /usr/local/
cp -r zookeeper-2181 zookeeper-2182
cp -r zookeeper-2181 zookeeper-2183

修改conf/zoo.cfg配置文件中的配置,参考第4小节

(6)修改内存大小

在各个节点的配置目录下,新增配置配置文件

cd /usr/local/zookeeper-2181/conf
vim zkEnv.sh

添加以下内容

#!/bin/sh
export JVMFLAGS="-Xms100m -Xmx100m $JVMFLAGS"

(7)启动zookeeper

进入到每个zookeeper中,启动zookeeper

cd /usr/local/zookeeper-2181
./bin/zkServer.sh start conf/zoo.cfg

(8)查看zookeeper运行状态

for i in 1,2,3; do sh /usr/local/zookeeper-218$i/bin/zkServer.sh status; done

 查看某个节点的状态

/usr/local/zookeeper-2181/bin/zkServer.sh status

2.2 kafka 伪集群安装

(1)下载安装包并解压到/opt目录下

(2)复制解压的安装包文件到/usr/local目录下:

 cp -r /opt/kafka_2.13-3.1.0 /usr/local/kafka-9091/

(3)新建日志目录:

mkdir -p /usr/local/kafka-9091/logs

(4)修改配置文件

cd /usr/local/kafka-9091/conf

修改配置文件server.properties

broker.id=1
listeners=PLAINTEXT://192.168.126.135:9091
log.dirs=/usr/local/kafka-9091/logs
zookeeper.connect=192.168.126.135:2181,192.168.126.135:2182,192.168.126.135:2183
  • broker.id:节点id,在同一个集群中,不能重复
  • listeners:节点监听的端口,在同一台机器上,也不能相同
  • log.dris:存储数据的位置
  • zookeeper.connectzookeeper集群的连接地址

(5)复制多个kafka

cd /usr/local/
cp -r kafka-9091 kafka-9092
cp -r kafka-9091 kafka-9093

复制完成后,根据第四小节,修改配置项

(6)修改内存大小

在各个节点下,修改脚本文件

cd /usr/local/kafka-9091/bin
vim kafka-server-start.sh

修改配置项KAFKA_HEAP_OPTS

export KAFKA_HEAP_OPTS="-Xmx200M -Xms200M"

(7)启动kafka

进入kafka的各个节点安装目录

cd /usr/local/kafka-9091

启动kafka

./bin/kafka-server-start.sh -daemon config/server.properties 

关闭kafka

./bin/kafka-server-stop.sh 

(8)验证kafka集群是否可以

创建主题为 "kafka1" 的topic:

[root@linkhot local]#  ./kafka-9091/bin/kafka-topics.sh --create --topic kafk                                           a1 --bootstrap-server 192.168.126.135:9091
Created topic kafka1.

查询kafkatopic信息

[root@linkhot local]# ./kafka-9091/bin/kafka-topics.sh --describe --topic kafka1 --bootstrap-server 192.168.126.135:9091
kafka1

如下图:

kafka集群多个节点对topic的创建和查询都正常执行,说明集群搭建成功。

3.kafka集群

在三台服务器分别搭建 zookeeper+kafka的主从集群。

3.1 zookeeper集群搭建

由于Kafka依赖于Zk,因此搭建Kafka环境需先搭建Zk集群环境。

主机ip
主机一192.168.126.135
主机二192.168.126.136
主机三192.168.126.137

 (1)上传zookeepe压缩包,并解压:

tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz

拷贝安装包到/usr/local/目录下:

cp -r apache-zookeeper-3.7.1-bin /usr/local/zookeeper

进入到 conf 目录,看到 zoo_sample.cfg 文件,cp 复制生成 zoo.cfg 文件,如下:

 cp conf/zoo_sample.cfg conf/zoo.cfg

(3)创建data目录,并新建myid用于集群服务,里面内容填写当前主机id,我是三台服务器的集群,id分别为1,2,3

mkdir /usr/local/zookeeper/data
vim data/myid

(4)将zookeeper/conf下的zoo_sample.cfg重命名为zoo.cfg

修改内容:

dataDir=/usr/local/zookeeper/data 
#这个地方的路径就是上面创建data文件夹的地址。根据自己的实际地址填写。

并在文本最后添加节点信息:

server.1=192.168.126.135:2888:3888
server.2=192.168.126.136:2888:3888
server.3=192.168.126.137:2888:3888

节点信息里的 “server.”后面的数字就是约定该服务器的主机id。必须一致,不然集群启动会失败。

(5)启动zookeeper

/usr/local/zookeeper^Cin/zkServer.sh start

(6)查看zookeeper状态

/usr/local/zookeeper^Cin/zkServer.sh status

(7)192.168.126.135配置:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.1=192.168.126.135:2888:3888
server.2=192.168.126.136:2888:3888
server.3=192.168.126.137:2888:3888

(8)192.168.126.136配置:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.1=192.168.126.135:2888:3888
server.2=192.168.126.136:2888:3888
server.3=192.168.126.137:2888:3888

(9)192.168.126.137配置:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.1=192.168.126.135:2888:3888
server.2=192.168.126.136:2888:3888
server.3=192.168.126.137:2888:3888

3.2 kafka集群

(1)下载安装包并解压到/opt目录下

(2)复制解压的安装包文件到/usr/local目录下:

 cp -r /opt/kafka_2.13-3.1.0 /usr/local/kafka/

(3)修改kafka/config/server.properties文件

修改broker.id,分别为1,2,3

#对应上面配置zk的每台节点的id
broker.id=1

修改listeners

#本机主机的ip
listeners=PLAINTEXT://192.168.126.135:9092

修改zookeeper.connect

#每个节点的信息
zookeeper.connect=192.168.126.135:2181,192.168.126.136:2181,192.168.126.137:2181

修改日志目录:

log.dirs=/usr/local/kafka/logs

(4)进入kafka_2.12-2.6.0/bin下启动kafka

./kafka-server-start.sh -daemon ../config/server.properties

(5)创建topic并查询topic状态

创建topic:

[root@linkhot bin]# ./kafka-topics.sh --create --topic kafka --bootstrap-server 192.168.126.135:9092
Created topic kafka.

查询topic状态:

[root@linkhot bin]# ./kafka-topics.sh --describe --topic kafka --bootstrap-server 192.168.126.136:9092
Topic: kafka    TopicId: _fjdIKr5S2CyA6Fpu9EZaA PartitionCount: 1       ReplicationFactor: 1 Configs: segment.bytes=1073741824
        Topic: kafka    Partition: 0    Leader: 3       Replicas: 3     Isr: 3

 (6)主机1  192.168.126.135配置 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.id=1

############################# 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
listeners=PLAINTEXT://192.168.126.135: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
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3

# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


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

# A comma separated list of directories under which to store log files
log.dirs=/usr/local/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.
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.
num.recovery.threads.per.data.dir=1

############################# Internal Topic Settings  #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1

############################# 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 excessive 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
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# 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
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

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

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

############################# 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.connect=192.168.126.135:2181,192.168.126.136:2181,192.168.126.137:2181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000


############################# Group Coordinator Settings #############################

# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.
# The default value for this is 3 seconds.
# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.
# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup.
group.initial.rebalance.delay.ms=0

(7)主机2  192.168.126.136配置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.id=2

############################# 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
listeners=PLAINTEXT://192.168.126.136: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
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3

# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


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

# A comma separated list of directories under which to store log files
log.dirs=/usr/local/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.
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.
num.recovery.threads.per.data.dir=1

############################# Internal Topic Settings  #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1

############################# 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 excessive 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
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# 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
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

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

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

############################# 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.connect=192.168.126.135:2181,192.168.126.136:2181,192.168.126.137:2
181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000


############################# Group Coordinator Settings #############################

# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.
# The default value for this is 3 seconds.
# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.
# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup.
group.initial.rebalance.delay.ms=0

(8)主机3  192.168.126.137配置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.id=3

############################# 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
listeners=PLAINTEXT://192.168.126.137: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
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3

# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


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

# A comma separated list of directories under which to store log files
log.dirs=/usr/local/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.
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.
num.recovery.threads.per.data.dir=1

############################# Internal Topic Settings  #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1

############################# 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 excessive 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
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# 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
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

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

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

############################# 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.connect=192.168.126.135:2181,192.168.126.136:2181,192.168.126.137:2
181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000


############################# Group Coordinator Settings #############################

# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.
# The default value for this is 3 seconds.
# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.
# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup.
group.initial.rebalance.delay.ms=0

以上是关于Kafka: Linux环境-单机部署和伪集群集群部署的主要内容,如果未能解决你的问题,请参考以下文章

Kafka 单机和伪分布式集群搭建

kafka集群环境部署fabric1.4.6

kafka服务部署从单机到集群

解开Kafka神秘的面纱:kafka单机部署和集群部署

解开Kafka神秘的面纱:kafka单机部署和集群部署

RocketMq: Linux环境-单机部署和主从集群部署