1. 首页 > ITPUX技术网 > 正文

kafka集群安装

[color=rgb(47, 47, 47)][font=-apple-system, &quot]1. 在根目录创建kafka文件夹(service1、service2、service3都创建)[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost /]# mkdir kafka[color=rgb(47, 47, 47)][font=-apple-system, &quot]2.通过Xshell上传文件到service1服务器:上传kafka_2.9.2-0.8.1.1.tgz到/software文件夹[color=rgb(47, 47, 47)][font=-apple-system, &quot]3.远程copy将service1下的/software/kafka_2.9.2-0.8.1.1.tgz到service2、service3[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost software]# scp -r /software/kafka_2.9.2-0.8.1.1.tgz [email]root@192.168.2.212[/email]:/software/[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost software]# scp -r /software/kafka_2.9.2-0.8.1.1.tgz [email]root@192.168.2.213[/email]:/software/[color=rgb(47, 47, 47)][font=-apple-system, &quot]3.copy /software/kafka_2.9.2-0.8.1.1.tgz到/kafka/目录(service1、service2、service3都执行)[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost software]# cp /software/kafka_2.9.2-0.8.1.1.tgz /kafka/[color=rgb(47, 47, 47)][font=-apple-system, &quot]4.安装解压kafka_2.9.2-0.8.1.1.tgz(service1、service2、service3都执行)[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost /]# cd /kafka/[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost kafka]# tar -zxvf kafka_2.9.2-0.8.1.1.tgz[color=rgb(47, 47, 47)][font=-apple-system, &quot]5.创建kafka消息目录(service1,service2,service3都要创建)[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost kafka]# mkdir kafkaLogs[color=rgb(47, 47, 47)][font=-apple-system, &quot]6. 修改kafka的配置文件(service1,service2,service3都要配置)[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost /]# cd /kafka/kafka_2.9.2-0.8.1.1/[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost kafka_2.9.2-0.8.1.1]# cd config/[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost config]# ls[color=rgb(47, 47, 47)][font=-apple-system, &quot]consumer.properties log4j.properties producer.properties server.properties test-log4j.properties tools-log4j.properties zookeeper.properties[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost config]# vi server.properties[color=rgb(47, 47, 47)][font=-apple-system, &quot]# Licensed to the Apache Software Foundation (ASF) under one or more[color=rgb(47, 47, 47)][font=-apple-system, &quot]# contributor license agreements. See the NOTICE file distributed with[color=rgb(47, 47, 47)][font=-apple-system, &quot]# this work for additional information regarding copyright ownership.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The ASF licenses this file to You under the Apache License, Version 2.0[color=rgb(47, 47, 47)][font=-apple-system, &quot]# (the “License”); you may not use this file except in compliance with[color=rgb(47, 47, 47)][font=-apple-system, &quot]# the License. You may obtain a copy of the License at[color=rgb(47, 47, 47)][font=-apple-system, &quot]#[color=rgb(47, 47, 47)][font=-apple-system, &quot]#[color=#3194d0]http://www.apache.org/licenses/LICENSE-2.0[color=rgb(47, 47, 47)][font=-apple-system, &quot]#[color=rgb(47, 47, 47)][font=-apple-system, &quot]# Unless required by applicable law or agreed to in writing, software[color=rgb(47, 47, 47)][font=-apple-system, &quot]# distributed under the License is distributed on an “AS IS” BASIS,[color=rgb(47, 47, 47)][font=-apple-system, &quot]# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# See the License for the specific language governing permissions and[color=rgb(47, 47, 47)][font=-apple-system, &quot]# limitations under the License.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# see kafka.server.KafkaConfig for additional details and defaults[color=rgb(47, 47, 47)][font=-apple-system, &quot]############################# Server Basics #############################[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The id of the broker. This must be set to a unique integer for each broker.[color=rgb(47, 47, 47)][font=-apple-system, &quot]broker.id=0 —唯一标识[color=rgb(47, 47, 47)][font=-apple-system, &quot]############################# Socket Server Settings #############################[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The port the socket server listens on[color=rgb(47, 47, 47)][font=-apple-system, &quot]port=19092 –当前broker对外提供的TCP端口,默认9092[color=rgb(47, 47, 47)][font=-apple-system, &quot]# Hostname the broker will bind to. If not set, the server will bind to all interfaces[color=rgb(47, 47, 47)][font=-apple-system, &quot]host.name=192.168.2.213 –一般是关闭状态,我们要将它打开,如果dns解析失败,会出现文件句柄泄露,不要小看dns解析失败率,如果dns解析失败率为万分之一,由于kafka的性能非常高,每个topic的每个分区,每秒可以处理十万多条的数据,即使万分之一的失败率,每秒也要泄露10个文件句柄,很快句柄数就会泄露完毕,就会超过[color=#3194d0]Linux打开文件的数,就会出现异常,所以我们配置ip,就不会进行dns解析[color=rgb(47, 47, 47)][font=-apple-system, &quot]# Hostname the broker will advertise to producers and consumers. If not set, it uses the[color=rgb(47, 47, 47)][font=-apple-system, &quot]# value for “host.name” if configured. Otherwise, it will use the value returned from[color=rgb(47, 47, 47)][font=-apple-system, &quot]#[color=#3194d0]Java[color=#3194d0].NET.InetAddress.getCanonicalHostName().[color=rgb(47, 47, 47)][font=-apple-system, &quot]#advertised.host.name=[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The port to publish to ZooKeeper for clients to use. If this is not set,[color=rgb(47, 47, 47)][font=-apple-system, &quot]# it will publish the same port that the broker binds to.[color=rgb(47, 47, 47)][font=-apple-system, &quot]#advertised.port=[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The number of threads handling network requests[color=rgb(47, 47, 47)][font=-apple-system, &quot]num.network.threads=2 –broker网络处理的线程数,一般不做处理[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The number of threads doing disk I/O[color=rgb(47, 47, 47)][font=-apple-system, &quot]num.io.threads=8 –broker io处理的线程数,这个数量一定要比log.dirs的目录数要大[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The send buffer (SO_SNDBUF) used by the socket server[color=rgb(47, 47, 47)][font=-apple-system, &quot]socket.send.buffer.bytes=1048576 –将发送的消息先放到缓冲区,当到达一定量的时候再一次性发出[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The receive buffer (SO_RCVBUF) used by the socket server[color=rgb(47, 47, 47)][font=-apple-system, &quot]socket.receive.buffer.bytes=1048576 –kafka接受消息的缓冲区,当接受的数量达到一定量的时候再写入磁盘[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The maximum size of a request that the socket server will accept (protection against OOM)[color=rgb(47, 47, 47)][font=-apple-system, &quot]socket.request.max.bytes=104857600 –像kafka发送或者请求消息的最大数,此设置不能超过java堆栈大小[color=rgb(47, 47, 47)][font=-apple-system, &quot]############################# Log Basics #############################[color=rgb(47, 47, 47)][font=-apple-system, &quot]# A comma seperated list of directories under which to store log files[color=rgb(47, 47, 47)][font=-apple-system, &quot]log.dirs=/kafka/kafkaLogs –多个目录可以用,隔开[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The default number of log partitions per topic. More partitions allow greater[color=rgb(47, 47, 47)][font=-apple-system, &quot]# parallelism for consumption, but this will also result in more files across[color=rgb(47, 47, 47)][font=-apple-system, &quot]# the brokers.[color=rgb(47, 47, 47)][font=-apple-system, &quot]num.partitions=2 –一个topic默认分区数[color=rgb(47, 47, 47)][font=-apple-system, &quot]############################# Log Flush Policy #############################[color=rgb(47, 47, 47)][font=-apple-system, &quot]# Messages are immediately written to the filesystem but by default we only fsync() to sync[color=rgb(47, 47, 47)][font=-apple-system, &quot]# the OS cache lazily. The following configurations control the flush of data to disk.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# There are a few important trade-offs here:[color=rgb(47, 47, 47)][font=-apple-system, &quot]# 1. Durability: Unflushed data may be lost if you are not using replication.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# 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.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# 3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The settings below allow one to configure the flush policy to flush data after a period of time or[color=rgb(47, 47, 47)][font=-apple-system, &quot]# every N messages (or both). This can be done globally and overridden on a per-topic basis.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The number of messages to accept before forcing a flush of data to disk[color=rgb(47, 47, 47)][font=-apple-system, &quot]#log.flush.interval.messages=10000[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The maximum amount of time a message can sit in a log before we force a flush[color=rgb(47, 47, 47)][font=-apple-system, &quot]#log.flush.interval.ms=1000[color=rgb(47, 47, 47)][font=-apple-system, &quot]############################# Log Retention Policy #############################[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The following configurations control the disposal of log segments. The policy can[color=rgb(47, 47, 47)][font=-apple-system, &quot]# be set to delete segments after a period of time, or after a given size has accumulated.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens[color=rgb(47, 47, 47)][font=-apple-system, &quot]# from the end of the log.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The minimum age of a log file to be eligible for deletion[color=rgb(47, 47, 47)][font=-apple-system, &quot]log.retention.hours=168[color=rgb(47, 47, 47)][font=-apple-system, &quot]message.max.byte=5048576 –kafka每条消息容纳的最大大小[color=rgb(47, 47, 47)][font=-apple-system, &quot]default.replication.factor=2 –默认的复制因子,默认消息只有一个副本,不太安全,所以设置为2,如果某个分区的消息失败了,我们可以使用另一个分区的消息服务[color=rgb(47, 47, 47)][font=-apple-system, &quot]replica.fetch.max.byte=5048576 –kafka每条消息容纳的最大大小[color=rgb(47, 47, 47)][font=-apple-system, &quot]# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining[color=rgb(47, 47, 47)][font=-apple-system, &quot]# segments don’t drop below log.retention.bytes.[color=rgb(47, 47, 47)][font=-apple-system, &quot]#log.retention.bytes=1073741824[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The maximum size of a log segment file. When this size is reached a new log segment will be created.[color=rgb(47, 47, 47)][font=-apple-system, &quot]log.segment.bytes=536870912 –消息持久化的最大大小[color=rgb(47, 47, 47)][font=-apple-system, &quot]# The interval at which log segments are checked to see if they can be deleted according[color=rgb(47, 47, 47)][font=-apple-system, &quot]# to the retention policies[color=rgb(47, 47, 47)][font=-apple-system, &quot]log.retention.check.interval.ms=60000[color=rgb(47, 47, 47)][font=-apple-system, &quot]# By default the log cleaner is disabled and the log retention policy will default to just delete segments after their retention expires.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# If log.cleaner.enable=true is set the cleaner will be enabled and individual logs can then be marked for log compaction.[color=rgb(47, 47, 47)][font=-apple-system, &quot]log.cleaner.enable=false –不使用log压缩[color=rgb(47, 47, 47)][font=-apple-system, &quot]############################# Zookeeper #############################[color=rgb(47, 47, 47)][font=-apple-system, &quot]# Zookeeper connection string (see zookeeper docs for details).[color=rgb(47, 47, 47)][font=-apple-system, &quot]# This is a comma separated host:port pairs, each corresponding to a zk[color=rgb(47, 47, 47)][font=-apple-system, &quot]# server. e.g. “127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002”.[color=rgb(47, 47, 47)][font=-apple-system, &quot]# You can also append an optional chroot string to the urls to specify the[color=rgb(47, 47, 47)][font=-apple-system, &quot]# root directory for all kafka znodes.[color=rgb(47, 47, 47)][font=-apple-system, &quot]zookeeper.connect=192.168.2.211:2181,192.168.2.212:2181,192.168.2.213:2181 –zk地址[color=rgb(47, 47, 47)][font=-apple-system, &quot]# Timeout in ms for connecting to zookeeper[color=rgb(47, 47, 47)][font=-apple-system, &quot]zookeeper.connection.timeout.ms=1000000[color=rgb(47, 47, 47)][font=-apple-system, &quot]7.启动kafka服务[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost bin]# ./kafka-server-start.sh -daemon ../config/server.properties[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost bin]# jps[color=rgb(47, 47, 47)][font=-apple-system, &quot]27413 Kafka[color=rgb(47, 47, 47)][font=-apple-system, &quot]27450 Jps[color=rgb(47, 47, 47)][font=-apple-system, &quot]17884 QuorumPeerMain[color=rgb(47, 47, 47)][font=-apple-system, &quot]8.验证kafka集群[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost bin]# ./kafka-topics.sh –create –zookeeper localhost:2181 –replication-factor 2 –partitions 1 –topic test[color=rgb(47, 47, 47)][font=-apple-system, &quot]Created topic “test”.[color=rgb(47, 47, 47)][font=-apple-system, &quot]9.在service1上开启producer程序[color=rgb(47, 47, 47)][font=-apple-system, &quot]./kafka-console-producer.sh –broker-list 192.168.2.211:9092 –topic test[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost bin]# ./kafka-console-producer.sh –broker-list 192.168.2.211:9092 –topic test[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: Defaulting to no-operation (NOP) logger implementation[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: See[color=#3194d0]http://www.slf4j.org/codes.html#StaticLoggerBinderfor further details.[color=rgb(47, 47, 47)][font=-apple-system, &quot]10. 在service2上开启consumer程序[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost bin]# ./kafka-console-consumer.sh –zookeeper localhost:2181 –topic test –from-beginning[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: Defaulting to no-operation (NOP) logger implementation[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: See[color=#3194d0]http://www.slf4j.org/codes.html#StaticLoggerBinderfor further details.[color=rgb(47, 47, 47)][font=-apple-system, &quot]11.在producer中发送消息:hello jeesz[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost bin]# ./kafka-console-consumer.sh –zookeeper localhost:2181 –topic test –from-beginning[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: Defaulting to no-operation (NOP) logger implementation[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: See[color=#3194d0]http://www.slf4j.org/codes.html#StaticLoggerBinderfor further details.[color=rgb(47, 47, 47)][font=-apple-system, &quot]hello jeesz[color=rgb(47, 47, 47)][font=-apple-system, &quot]12. 在consumer中接受到消息[color=rgb(47, 47, 47)][font=-apple-system, &quot][root@localhost bin]# ./kafka-console-consumer.sh –zookeeper localhost:2181 –topic test –from-beginning[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: Defaulting to no-operation (NOP) logger implementation[color=rgb(47, 47, 47)][font=-apple-system, &quot]SLF4J: See[color=#3194d0]http://www.slf4j.org/codes.html#StaticLoggerBinderfor further details.[color=rgb(47, 47, 47)][font=-apple-system, &quot]hello jeesz[color=rgb(47, 47, 47)][font=-apple-system, &quot]愿意了解框架技术或者源码的朋友直接加求:2042849237[color=rgb(47, 47, 47)][font=-apple-system, &quot]更多详细源码参考来源

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息