c8-1 10.1.1.100 centos8.1
c8-2 10.1.1.101 centos8.1
c8-3 10.1.1.102 centos8.1
zookeeper已经安装好了,版本apache-zookeeper-3.6.0-bin.tar.gz
jdk版本 —jdk1.8.0_241
安装包下载链接:kafka_2.13-2.5.0
下载完之后就准备rz上传安装包
#解压上传的kafka安装包
[root@c8-1 opt]# tar xf kafka_2.13-2.5.0.tgz
[root@c8-1 opt]# ll
total 0
drwxrwxr-x. 7 root root 245 Dec 11 05:39 jdk1.8.0_241
drwxr-xr-x. 6 root root 89 Apr 7 21:18 kafka_2.13-2.5.0
drwxr-xr-x. 9 root root 168 May 13 00:35 zookeeper
#配置JAVA环境并修改目录权限
[root@c8-1 opt]# vim /root/.bash_profile
[root@c8-1 opt]# cat /root/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:
export JAVA_HOME=/opt/jdk1.8.0_241
export PATH
[root@c8-1 opt]#
[root@c8-1 opt]# source /root/.bash_profile
[root@c8-1 opt]# jps
4963 Jps
4648 QuorumPeerMain
[root@c8-1 opt]# scp /root/.bash_profile root@c8-2:/root/
.bash_profile 100% 226 268.2KB/s 00:00
[root@c8-2 bin]# source /root/.bash_profile
[root@c8-2 bin]# jps
4288 Jps
4002 QuorumPeerMain
[root@c8-1 opt]# scp /root/.bash_profile root@c8-3:/root/
.bash_profile 100% 226 86.3KB/s 00:00
[root@c8-3 bin]# source /root/.bash_profile
[root@c8-3 bin]# jps
4196 QuorumPeerMain
4461 Jps
[root@c8-1 opt]# chmod -R 775 /opt/kafka_2.13-2.5.0/bin/ *
#修改配置文件并scp给其他主机
[root@c8-1 opt]# ls
jdk1.8.0_241 kafka_2.13-2.5.0 zookeeper
[root@c8-1 opt]# cd kafka_2.13-2.5.0/
[root@c8-1 kafka_2.13-2.5.0]# ll
total 56
drwxr-xr-x. 3 root root 4096 Apr 7 21:18 bin
drwxr-xr-x. 2 root root 4096 Apr 7 21:18 config
drwxr-xr-x. 2 root root 8192 May 13 00:39 libs
-rw-r--r--. 1 root root 32216 Apr 7 21:13 LICENSE
-rw-r--r--. 1 root root 337 Apr 7 21:13 NOTICE
drwxr-xr-x. 2 root root 44 Apr 7 21:18 site-docs
[root@c8-1 kafka_2.13-2.5.0]# cd config/
[root@c8-1 config]# ll
total 72
-rw-r--r--. 1 root root 906 Apr 7 21:13 connect-console-sink.properties
-rw-r--r--. 1 root root 909 Apr 7 21:13 connect-console-source.properties
-rw-r--r--. 1 root root 5321 Apr 7 21:13 connect-distributed.properties
-rw-r--r--. 1 root root 883 Apr 7 21:13 connect-file-sink.properties
-rw-r--r--. 1 root root 881 Apr 7 21:13 connect-file-source.properties
-rw-r--r--. 1 root root 2247 Apr 7 21:13 connect-log4j.properties
-rw-r--r--. 1 root root 2540 Apr 7 21:13 connect-mirror-maker.properties
-rw-r--r--. 1 root root 2262 Apr 7 21:13 connect-standalone.properties
-rw-r--r--. 1 root root 1221 Apr 7 21:13 consumer.properties
-rw-r--r--. 1 root root 4675 Apr 7 21:13 log4j.properties
-rw-r--r--. 1 root root 1925 Apr 7 21:13 producer.properties
-rw-r--r--. 1 root root 6849 Apr 7 21:13 server.properties
-rw-r--r--. 1 root root 1032 Apr 7 21:13 tools-log4j.properties
-rw-r--r--. 1 root root 1169 Apr 7 21:13 trogdor.conf
-rw-r--r--. 1 root root 1205 Apr 7 21:13 zookeeper.properties
[root@c8-1 config]# vim server.properties ---需要注意broker.id这个编号,按照主机顺序0、1、2.......依次填写。
[root@c8-1 config]# more 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=0
############################# 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://:9092
host.name=c8-1
port=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 docum
entation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_S
SL
# The number of threads that the server uses for receiving requests from the network and sending response
s to the network
num.network.threads=2
# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=2
# 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=/opt/kafka_2.13-2.5.0/log/kafka
# 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=4
# The number of threads per data directory to be used for log recovery at startup and flushing at shutdow
n.
# 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_s
tate"
# For anything other than development testing, a value greater than 1 is recommended to ensure availabili
ty 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 l
ead 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=72
# 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=c8-1:2181,c8-2:2181,c8-3: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 t
he initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members j
oin 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 testi
ng.
# However, in production environments the default value of 3 seconds is more suitable as this will help t
o avoid unnecessary, and potentially expensive, rebalances during application startup.
group.initial.rebalance.delay.ms=0
[root@c8-1 bin]#
[root@c8-1 bin]# more kafka-server-start.sh
#!/bin/bash
export KAFKA_HEAP_OPTS="-Xmx2G -Xms2G"
# 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.
if [ $# -lt 1 ];
then
echo "USAGE: $0 [-daemon] server.properties [--override property=value]*"
exit 1
fi
base_dir=$(dirname $0)
if [ "x$KAFKA_LOG4J_OPTS" = "x" ]; then
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.propertie
s"
fi
if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"
fi
EXTRA_ARGS=${EXTRA_ARGS-'-name kafkaServer -loggc'}
COMMAND=$1
case $COMMAND in
-daemon)
EXTRA_ARGS="-daemon "$EXTRA_ARGS
shift
;;
*)
;;
esac
exec $base_dir/kafka-run-class.sh $EXTRA_ARGS kafka.Kafka "$@"
[root@c8-2 bin]#
[root@c8-1 bin]#scp -r /opt/kafka_2.13-2.5.0 root@c8-2:/opt/ 将config文件中的broker.id=0修改为broker.id=1
[root@c8-1 bin]#scp -r /opt/kafka_2.13-2.5.0 root@c8-3:/opt/ 将config文件中的broker.id=0修改为broker.id=2
[root@c8-1 kafka_2.13-2.5.0]# cd bin/
[root@c8-1 bin]# ./kafka-server-start.sh -daemon /opt/kafka_2.13-2.5.0/config/server.properties
[root@c8-1 bin]# jps
7559 Jps
4648 QuorumPeerMain
7517 Kafka ---启动成功
[root@c8-1 bin]#
[root@c8-2 bin]# ./kafka-server-start.sh -daemon /opt/kafka_2.13-2.5.0/config/server.properties
[root@c8-2 bin]# jps
4002 QuorumPeerMain
6868 Kafka ---启动成功
6885 Jps
[root@c8-3 bin]# ./kafka-server-start.sh -daemon /opt/kafka_2.13-2.5.0/config/server.properties
[root@c8-3 bin]# jps
5824 Jps
5809 Kafka ---启动成功
4196 QuorumPeerMain
先停kafka,再停zookeeper,先启动zookeeper,再启动kafka。
查看日志可以tail -f server.log
##停止kafka
[root@c8-1 bin]# ./kafka-server-stop.sh
[root@c8-1 bin]# jps
7747 Jps
4648 QuorumPeerMain
[root@c8-1 bin]#
备注:安装过于简单,欢迎来交流指点。