`
springcloud关注者
  • 浏览: 309638 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
12d8ea3d-4199-3941-8a17-acd5024729b8
Spring_Cloud构...
浏览量:249713
文章分类
社区版块
存档分类
最新评论
阅读更多

最近在使用Spring Cloud进行分布式微服务搭建,顺便对集成KafKa的方案做了一些总结,今天详细介绍一下KafKa集群安装过程:

 

1. 在根目录创建kafka文件夹(service1、service2、service3都创建)

[root@localhost /]# mkdir kafka

 

2.通过Xshell上传文件到service1服务器:上传kafka_2.9.2-0.8.1.1.tgz到/software文件夹

3.远程copy将service1下的/software/kafka_2.9.2-0.8.1.1.tgz到service2、service3

[root@localhost software]# scp -r /software/kafka_2.9.2-0.8.1.1.tgz root@192.168.2.212:/software/

[root@localhost software]# scp -r /software/kafka_2.9.2-0.8.1.1.tgz root@192.168.2.213:/software/

 

3.copy /software/kafka_2.9.2-0.8.1.1.tgz到/kafka/目录(service1、service2、service3都执行)

[root@localhost software]# cp /software/kafka_2.9.2-0.8.1.1.tgz /kafka/

 

4.安装解压kafka_2.9.2-0.8.1.1.tgz(service1、service2、service3都执行)

[root@localhost /]# cd /kafka/

[root@localhost kafka]# tar -zxvf kafka_2.9.2-0.8.1.1.tgz

 

 

5.创建kafka消息目录(service1,service2,service3都要创建)

[root@localhost kafka]# mkdir kafkaLogs

 

6. 修改kafka的配置文件(service1,service2,service3都要配置)

[root@localhost /]# cd /kafka/kafka_2.9.2-0.8.1.1/

[root@localhost kafka_2.9.2-0.8.1.1]# cd config/

[root@localhost config]# ls

consumer.properties  log4j.properties  producer.properties  server.properties  test-log4j.properties  tools-log4j.properties  zookeeper.properties

[root@localhost 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.id=0  ---唯一标识

 

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

 

# The port the socket server listens on

port=19092  --当前broker对外提供的TCP端口,默认9092

 

# Hostname the broker will bind to. If not set, the server will bind to all interfaces

host.name=192.168.2.213  --一般是关闭状态,我们要将它打开,如果dns解析失败,会出现文件句柄泄露,不要小看dns解析失败率,如果dns解析失败率为万分之一,由于kafka的性能非常高,每个topic的每个分区,每秒可以处理十万多条的数据,即使万分之一的失败率,每秒也要泄露10个文件句柄,很快句柄数就会泄露完毕,就会超过linux打开文件的数,就会出现异常,所以我们配置ip,就不会进行dns解析

 

 

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

# value for "host.name" if configured.  Otherwise, it will use the value returned from

# java.net.InetAddress.getCanonicalHostName().

#advertised.host.name=<hostname routable by clients>

 

# The port to publish to ZooKeeper for clients to use. If this is not set,

# it will publish the same port that the broker binds to.

#advertised.port=<port accessible by clients>

 

# The number of threads handling network requests

num.network.threads=2   --broker网络处理的线程数,一般不做处理

 

# The number of threads doing disk I/O

num.io.threads=8  --broker io处理的线程数,这个数量一定要比log.dirs的目录数要大

 

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

socket.send.buffer.bytes=1048576  --将发送的消息先放到缓冲区,当到达一定量的时候再一次性发出

 

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

socket.receive.buffer.bytes=1048576  --kafka接受消息的缓冲区,当接受的数量达到一定量的时候再写入磁盘

 

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

socket.request.max.bytes=104857600   --像kafka发送或者请求消息的最大数,此设置不能超过java堆栈大小

 

 

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

 

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

log.dirs=/kafka/kafkaLogs  --多个目录可以用,隔开

 

# 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=2  --一个topic默认分区数

 

############################# 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

#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

log.retention.hours=168

 

message.max.byte=5048576   --kafka每条消息容纳的最大大小

default.replication.factor=2  --默认的复制因子,默认消息只有一个副本,不太安全,所以设置为2,如果某个分区的消息失败了,我们可以使用另一个分区的消息服务

replica.fetch.max.byte=5048576 --kafka每条消息容纳的最大大小

 

 

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

# segments don't drop below log.retention.bytes.

#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=536870912  --消息持久化的最大大小

 

# 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=60000

 

# By default the log cleaner is disabled and the log retention policy will default to just delete segments after their retention expires.

# If log.cleaner.enable=true is set the cleaner will be enabled and individual logs can then be marked for log compaction.

log.cleaner.enable=false  --不使用log压缩

 

############################# 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.2.211:2181,192.168.2.212:2181,192.168.2.213:2181   --zk地址

 

# Timeout in ms for connecting to zookeeper

zookeeper.connection.timeout.ms=1000000

 

7.启动kafka服务

[root@localhost bin]# ./kafka-server-start.sh -daemon ../config/server.properties

[root@localhost bin]# jps

27413 Kafka

27450 Jps

17884 QuorumPeerMain

 

8.验证kafka集群

[root@localhost bin]# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 1 --topic test

Created topic "test".

 

9.在service1上开启producer程序

./kafka-console-producer.sh --broker-list 192.168.2.211:9092 --topic test

[root@localhost bin]# ./kafka-console-producer.sh --broker-list 192.168.2.211:9092 --topic test

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

 

 

10. 在service2上开启consumer程序

[root@localhost bin]# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

 

11.在producer中发送消息:hello honghu

[root@localhost bin]# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

hello honghu

 

12. 在consumer中接受到消息

[root@localhost bin]# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

hello honghu

 

 

 

 

 

 

 

 

6
0
分享到:
评论
6 楼 springcloud关注者 2017-10-20  
6696 写道
很详细,学些了

一起学习~~~~
5 楼 springcloud关注者 2017-10-20  
Swifie 写道
作者能否再出一些spring cloud的文章

会的,后面还有很多关于spring cloud的文章,现在只是冰山一角
4 楼 springcloud关注者 2017-10-20  
Taylorshirley 写道
分析的很到位~谢谢分享~

不客气,一起学习
3 楼 Taylorshirley 2017-10-20  
分析的很到位~谢谢分享~
2 楼 Swifie 2017-10-20  
作者能否再出一些spring cloud的文章
1 楼 6696 2017-10-20  
很详细,学些了

相关推荐

    搭建kafka集群详细教程

    总之,搭建Kafka集群涉及多个步骤,包括Zookeeper集群的配置、Kafka的安装与配置、主题创建以及服务启动。正确配置和管理Kafka集群对于实现高效、稳定的数据流处理至关重要。随着对Kafka的深入理解和实践,你可以...

    介绍kafka及kafka集群安装

    通过本文档的学习,我们不仅深入了解了 Kafka 的架构原理和使用方法,还掌握了 Kafka 集群的安装部署过程。此外,我们还学习了 Kafka 生产者和消费者的 Java API 使用方法,以及 JMS 规范的相关概念。这些知识对于...

    Kafka2.3.0集群安装

    下面是Kafka集群安装的详细步骤和相关知识点: 一、Kafka集群安装前提 在安装Kafka集群之前,需要安装Scala,因为Kafka是使用Scala编写的。Scala是Java虚拟机(JVM)上的函数式编程语言,提供了强大的函数式编程...

    kafka集群安装

    ### Kafka集群安装与配置详解 #### 一、概述 在分布式计算环境中,消息队列扮演着重要的角色。...通过上述步骤,用户可以轻松地部署一个稳定可靠的Kafka集群,为后续的数据处理和分析打下坚实的基础。

    使用sasl的kafka集群的搭建使用

    Kafka集群搭建和使用过程涉及多个技术要点和配置项,包括SASL安全机制、ACL权限设置、Kafka基础概念以及安装配置步骤等。下面将详细介绍这些知识点。 首先,SASL(Simple Authentication and Security Layer)是为C...

    Kafka集群搭建(3台机)

    搭建Kafka集群涉及到对虚拟机的安装配置、JDK环境的搭建、Zookeeper的安装配置等关键步骤。下面详细介绍各个知识点。 首先,虚拟机的安装是搭建Kafka集群的基础。文中提到了使用VMWare来安装三台虚拟机,并分配了...

    kakfa,kafka集群安装部署全量安装包

    **Kafka集群安装部署全量指南** Apache Kafka是一款开源流处理平台,由LinkedIn开发并贡献给了Apache软件基金会。它设计为一个高吞吐量、分布式的消息队列系统,用于处理实时数据流。Kafka通常与ZooKeeper一起使用...

    kafka集群搭建文档

    本篇文档将详细介绍如何在Linux环境中搭建Kafka集群,同时结合Hadoop和Spark的分布式安装,构建一个完整的数据处理平台。 首先,搭建Kafka集群的基础条件包括: 1. 至少一台Linux服务器,但为了高可用性,推荐多台...

    kafka集群部署文档(部署,运维,FAQ)

    #### 六、Kafka集群的部署步骤 1. **环境准备**:选择合适的硬件配置,确保足够的磁盘空间和内存资源。 2. **软件安装**:从官方下载地址([http://kafka.apache.org/downloads](http://kafka.apache.org/downloads)...

    kafka集群部署步骤

    ### Kafka集群部署步骤详解 #### 一、安装Java环境(JDK 1.8) Kafka作为基于Java语言开发的消息中间件,其运行环境需要Java支持。为了确保Kafka能够正常运行,首先需要在每台服务器上安装Java环境。推荐使用JDK ...

    Kafka集群安装配置.docx

    下面是 Kafka 集群安装配置的详细步骤和知识点: 一、环境准备 * 系统版本:CentOS Linux release 7 64 位 * 服务器:3 台服务器,IP 分别为 10.10.10.11、10.10.10.12 和 10.10.10.13 * Kafka 安装路径:/data * ...

    快速部署单机kafka集群(win环境)

    本文不讲kafka集群原理,只谈部署步骤。 默认读者已对kafka有最基本的认知,纯粹作为部署笔记,方便回忆。 另外本文是基于Windows部署的,Linux的步骤是基本相同的(只是启动脚本位置不同)。 kafka集群类型: ...

    Kafka分布式集群安装部署.doc

    (1)Kafka集群无法在跨网络的环境中正常工作:解决方法是分清内网和外网的区别,确保Kafka集群可以在跨网络的环境中正常工作。 (2)Kafka集群数据节点不均衡错误:解决方法是创建topic时,确保数据节点的均衡分配...

    Kafka集群配置样例_3节点_源码

    本篇将详细解析如何在Linux环境下配置一个3节点的Kafka集群,特别关注`server.properties`配置文件中的`zookeeper.connect`设置。 首先,我们需要理解Kafka集群的基础架构。Kafka集群由多个Brokers(即服务器)组成...

    kafka集群搭建.pdf

    kafka集群搭建需要完成以下步骤: 1. 准备工作,关闭防火墙和配置hosts和hostname。 2. Java环境配置,解压安装Java安装包和配置环境变量。 3. ZooKeeper安装,解压安装ZooKeeper安装包和创建ZooKeeper数据目录。 4...

    Kafka集群安装部署-自带zookeeper

    【Kafka集群安装部署-自带zookeeper】 Apache Kafka是一个分布式流处理平台,它被设计用于构建实时数据管道和流应用程序。Kafka的核心概念包括topic、producer...理解这些概念和步骤是构建稳定、高效Kafka集群的关键。

    kafka集群搭建及测试.docx

    本文档将详细介绍如何在三台Ubuntu 16虚拟机上搭建Kafka集群,并进行基本的测试,确保其正常运行。 **1. 准备工作** 在开始之前,你需要准备三台配置了Ubuntu 16.04操作系统的虚拟机,IP地址分别为192.168.172.145...

    Kafka集群及Kafka-Manager安装部署.docx

    ### Kafka集群及Kafka-Manager安装部署 #### 一、Kafka集群的安装与配置 **1. 工作环境准备** - **JDK**:确保安装了JDK 1.8.0_60版本。这一步骤至关重要,因为Kafka依赖于Java运行时环境。 - **Zookeeper**...

    Kafka自带zookeeper安装步骤整合.docx

    Linux下Kafka自带zookeeper安装步骤单点/集群整合

Global site tag (gtag.js) - Google Analytics