精华内容
下载资源
问答
  • kafka源码环境

    2019-05-06 16:55:50
    本文主要讲述的是如何搭建Kafka源码环境,主要针对的Windows操作系统下IntelliJ IDEA编译器,其余操作系统或者IDE可以类推。 1.安装和配置JDK 确认JDK版本至少为1.7,最好是1.8及以上。使用java -version命令来...

    本文主要讲述的是如何搭建Kafka的源码环境,主要针对的Windows操作系统下IntelliJ IDEA编译器,其余操作系统或者IDE可以类推。

    1.安装和配置JDK

    确认JDK版本至少为1.7,最好是1.8及以上。使用java -version命令来查看当前JDK的版本,示例如下:

     

    C:\Users\hidden> java -version
    java version "1.8.0_112"
    Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
    

     

    2.下载并安装配置Gradle

    下载地址为:https://gradle.org/releases/,笔者使用的版本是3.1。一般只需要将下载的包解压,然后再将$的路径添加到环境变量中即可,其中GRADLE_HOME/bin的路径添加到环境变量Path中即可,其中$GRADLE_HOME指的是Gradle的根目录。可以使用gradle -v命令来验证Gradle是否已经配置完成,示例如下:

     

    C:\Users\hidden>gradle -v
    
    ------------------------------------------------------------
    Gradle 3.1
    ------------------------------------------------------------
    
    Build time:   2016-09-19 10:53:53 UTC
    Revision:     13f38ba699afd86d7cdc4ed8fd7dd3960c0b1f97
    
    Groovy:       2.4.7
    Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
    JVM:          1.8.0_112 (Oracle Corporation 25.112-b15)
    OS:           Windows 10 10.0 amd64
    

     

    3.下载并安装配置Scala

    下载地址为:http://www.scala-lang.org/download/all.html,目前最新的版本是2.12.4,不过笔者这里使用的版本是2.11.11。如Gradle一样,只需要解压并将$的路径添加到环境变量即可,其中SCALA_HOME/bin的路径添加到环境变量Path即可,其中$SCALA_HOME指的是Scala的根目录。可以使用scala -version命令来验证scala是否已经配置完成,示例如下:

     

    C:\Users\hidden>scala -version
    Scala code runner version 2.11.11 -- Copyright 2002-2017, LAMP/EPFL
    

     

    4. 构建Kafka源码环境

    Kafka下载地址为:http://kafka.apache.org/downloads,目前最新的版本是1.0.0。将下载的压缩包解压,并在Kafka的根目录执行gradle idea命令进行构建,如果你使用的是Eclipse,则只需采用gradle eclipse命令构建即可。构建细节如下所示:

     

    D:\IntelliJ IDEA Files\kafka-sources\kafka-1.0.0-src>gradle idea
    Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
    Building project 'core' with Scala version 2.11.11
    :ideaModule
    :ideaProject
    (......省略若干......)
    :streams:examples:ideaModule
    :streams:examples:idea
    
    BUILD SUCCESSFUL
    
    Total time: 1 mins 11.991 secs
    

     

    之后将Kafka导入到IDEA中即可。不过这样还没有结束,对于IDEA而言,还需要安装Scala插件,在Setting->Plugin中搜索scala并安装,可以参考下图,笔者这里是已经安装好的状态:

    这里写图片描述

    5. 配置Kafka源码环境

    前面几个步骤执行完成后就可以很舒适的阅读Kafka的源码,但是如果需要启动Kafka的服务还需要一些额外的步骤。

    首先确保gradle.properties配置文件中的scalaVersion与安装的一致。gradle.properties配置文件的细节如下:

     

    group=org.apache.kafka
    # NOTE: When you change this version number, you should also make sure to update
    # the version numbers in tests/kafkatest/__init__.py and kafka-merge-pr.py.
    version=1.0.0
    scalaVersion=2.11.11
    task=build
    org.gradle.jvmargs=-XX:MaxPermSize=512m -Xmx1024m -Xss2m
    

     

    如果更改了scalaVersion,需要重新执行gradle idea命令来重新构建。虽然很多时候在操作系统中安装其他版本的Scala也并没有什么问题,比如安装2.12.4版本。但是有些情况下运行Kafka时会出现一些异常,而这些异常却又是由于Scala版本不一致而引起的,比如会出现下面示例中的报错:

     

    [2017-11-13 17:09:21,119] FATAL  (kafka.Kafka$)
    java.lang.NoSuchMethodError: scala.collection.TraversableOnce.$init$(Lscala/collection/TraversableOnce;)V
        at kafka.message.MessageSet.<init>(MessageSet.scala:72)
        at kafka.message.ByteBufferMessageSet.<init>(ByteBufferMessageSet.scala:129)
        at kafka.message.MessageSet$.<init>(MessageSet.scala:32)
        at kafka.message.MessageSet$.<clinit>(MessageSet.scala)
        at kafka.server.Defaults$.<init>(KafkaConfig.scala:52)
        at kafka.server.Defaults$.<clinit>(KafkaConfig.scala)
        at kafka.server.KafkaConfig$.<init>(KafkaConfig.scala:686)
        at kafka.server.KafkaConfig$.<clinit>(KafkaConfig.scala)
        at kafka.server.KafkaServerStartable$.fromProps(KafkaServerStartable.scala:28)
        at kafka.Kafka$.main(Kafka.scala:82)
        at kafka.Kafka.main(Kafka.scala)
    

     

    所以为了省去一些不必要的麻烦,还是建议读者在安装Scala版本之前先查看下Kafka源码中gradle.properties文件中配置的scalaVersion。

    再确保了scalaVersion之后,需要将config目录下的log4j.properties文件拷贝到core/src/main/scala目录下,这样可以让Kafka在运行时能够输出日志信息,可以参考下图:

    这里写图片描述

    之后还需要配置server.properties文件,一般只需要修改以下一些配置项:

     

    # 是否允许topic被删除,设置为true则topic可以被删除,
    # 开启这个功能方便Kafka在运行一段时间之后,能够删除一些不需要的临时topic
    delete.topic.enable=true
    # 禁用自动创建topic的功能
    auto.create.topics.enable=false
    # 存储log文件的目录,默认值为/tmp/kafka-logs
    # 示例是在Windows环境下运行,所以需要修改这个配置,注意这里的双反斜杠。
    log.dir=D:\\kafka\\tmp\\kafka-logs
    # 配置kafka依赖的zookeeper路径地址,这里的前提是在本地开启了一个zookeeper的服务
    # 如果本地没有zookeeper服务,可以参考下一节中zookeeper的安装、配置及运行
    zookeeper.connect=localhost:2181/kafka
    

     

    之后配置Kafka的启动参数,详细参考下图:

    这里写图片描述

    这里配置Main class为kafka.Kafka,并制定启动时所需要的配置文件地址,即:config/server.properties。配置JMX_PORT是为了方便搜集Kafka自身的Metrics数据。

    如此便可以顺利的运行Kafka服务了(第一次启动时会有一个耗时较长的编译过程),部分启动日志如下:

     

    [2017-11-14 00:24:14,472] INFO KafkaConfig values:
        advertised.host.name = null
        advertised.listeners = null
        advertised.port = null
        authorizer.class.name =
    (......省略若干......)
    [2017-11-14 00:24:35,001] INFO Registered broker 0 at path /brokers/ids/0 with addresses: EndPoint(LAPTOP-1IN9UPT7,9092,ListenerName(PLAINTEXT),PLAINTEXT) (kafka.utils.ZkUtils)
    [2017-11-14 00:24:35,019] INFO Kafka version : 1.0.0 (org.apache.kafka.common.utils.AppInfoParser)
    [2017-11-14 00:24:35,020] INFO Kafka commitId : e89bffd6b2eff799 (org.apache.kafka.common.utils.AppInfoParser)
    [2017-11-14 00:24:35,021] INFO [Kafka Server 0], started (kafka.server.KafkaServer)
    

     

    6. Zookeeper的安装、配置及启动

    Kafka需要使用Zookeeper来管理元数据,比如记录topic、partitions(分区)以及replica(副本)的分配信息。由于这里只是阐述如何构建Kafka的源码环境搭建,所以这里的Zookeeper的安装也以极简为主,即采用单机配置。Zookeeper下载地址为:http://zookeeper.apache.org/releases.html,下载之后解压,然后将$目录下的重命名为,其中ZOOKEEPER_HOME目录下的conf/zoo_sample.cfg重命名为zoo.cfg,其中$ZOOKEEPER_HOME指的是ZooKeeper的根目录。

    修改$ZOOKEEPER_HOME/conf/zoo.cfg配置,示例配置如下(其余配置可以不做修改):

     

    dataDir=D:\\zookeeper-3.4.10\\tmp\\zookeeper\\data
    

     

    将$ZOOKEEPER_HOME/bin配置到Path中,之后直接运行zkServer命令即可开启Zookeeper服务。示例如下:

     

    C:\Users\hidden>zkServer
    
    C:\Users\hidden>call "C:\Program Files\Java\jdk1.8.0_112"\bin\java "-Dzookeeper.log.dir=D:\zookeeper-3.4.10\bin\.." "-Dzookeeper.root.logger=INFO,CONSOLE" -cp "D:\zookeeper-3.4.10\bin\..\build\classes;D:\zookeeper-3.4.10\bin\..\build\lib\*;D:\zookeeper-3.4.10\bin\..\*;D:\zookeeper-3.4.10\bin\..\lib\*;D:\zookeeper-3.4.10\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "D:\zookeeper-3.4.10\bin\..\conf\zoo.cfg"
    2017-11-14 00:44:20,135 [myid:] - INFO  [main:QuorumPeerConfig@134] - Reading configuration from: D:\zookeeper-3.4.10\bin\..\conf\zoo.cfg
    2017-11-14 00:44:20,147 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
    2017-11-14 00:44:20,147 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
    2017-11-14 00:44:20,147 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
    2017-11-14 00:44:20,150 [myid:] - WARN  [main:QuorumPeerMain@113] - Either no config or no quorum defined in config, running  in standalone mode
    2017-11-14 00:44:20,250 [myid:] - INFO  [main:QuorumPeerConfig@134] - Reading configuration from: D:\zookeeper-3.4.10\bin\..\conf\zoo.cfg
    2017-11-14 00:44:20,250 [myid:] - INFO  [main:ZooKeeperServerMain@96] - Starting server
    

     

    666. 彩蛋

    如果你对 Kafka 并发感兴趣,欢迎加入我的知识一起交流。

    展开全文
  • kafka源码环境的搭建

    2021-04-30 00:09:31
    一:kafka源码环境的搭建

    一:kafka源码环境的搭建

    1:kafka源码的下载

    下载地址:http://kafka.apache.org/downloads.html

    记住下载源码

    注意下载的kafka源码对应的是2.8.0,则需要下载对应的Scala版本和gradle版本

    查看gradle.properties文件

    scala对应的版本是2.13.5,经过尝试gradle对应的版本是6.8.1

    2:jdk的下载与安装

    这个比较简单,不会的自己百度。

    3:maven的下载与安装

    这个比较简单,不会的自己百度。

    4:scala的下载与安装

    参考我之前的博客链接

    5:gradle的下载与安装

    参考我之前的博客链接

    6:kafka源码的编译

    进入对应的目录下(如我本地的目录F:\idea resource code\kafka-2.8.0-src)执行gradle idea命令,当编译成功之后导入到idea中即可。

    然后设置jdk、sdk等等。

    导入之后的效果如图

     

     

    展开全文
  • 1.3 win下Kafka源码环境搭建

    万次阅读 2021-03-20 11:29:38
    本文目的:1 搭建win下kafka调试环境,2,看kafka源码 1 本文环境 win10专业版 JDK 1.8 scala 2.13.4 gradle 3.5 kafka 1.0.0 源码 2 前置软件准备 2.1 JDK 安装省略(如果有本地有多个jdk环境,可以参考这里...

    本文目的:1 搭建win下kafka调试环境,2,看kafka源码

    1 本文环境

    1. win10专业版
    2. JDK 1.8
    3. scala 2.11.11
    4. gradle 4.8.1
    5. kafka 0.11.0.3-rc0 源码

    2 前置软件准备

    2.1 JDK

    安装省略(如果有本地有多个jdk环境,可以参考这里进行配置切换),检查版本如下
    在这里插入图片描述


    2.2 scala

    安装看这里,检查版本如下

    当前社区编译 Kafka 支持 3 个 Scala 版本,分别是 2.11、2.12 和 2.13。2.11 应该很快就会不支持了,而 2.13 又是刚刚推出的版本,因此我推荐你安装 Scala 2.11 版本。

    也可以先确定kafka版本,然后在kafka目录下的gradle.properties中看scalaVersion

    在这里插入图片描述

    2.3 gradle

    安装看这里(注意最好设置好远程私服地址+本地仓库地址),检查版本如下

    建议安装4.x版本的gradle,也可以先确定kafka版本,然后在build.gradle 里找到gradleVersion。即使该版本kafka建议对应的gradle版本

    在这里插入图片描述


    2.4 kafka源码

    1. 直接从官网下载,我下载的是kafka-1.0.0-src.tgz
    2. 从github上下载,然后切出自己想要的分支版本
    //clone 到本地
    >git clone https://github.com/bigData-lab/kafka.git
    //因为我要1.0.0版本的kafka,所以先看tag或远程的版本
    >git tag //查看标签
    >git branch -r //查看远程分支名
    
    >git checkout -b v0.11.0.3-rc0 0.11.0.3-rc0
    
    

    3 win下编译kafka

    3.1 scala版本检查

    首先确保gradle.properties配置文件中的scalaVersion与安装的一致。gradle.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.
    
    group=org.apache.kafka
    # NOTE: When you change this version number, you should also make sure to update
    # the version numbers in tests/kafkatest/__init__.py and kafka-merge-pr.py.
    version=1.0.0
    scalaVersion=2.11.11
    task=build
    org.gradle.jvmargs=-XX:MaxPermSize=512m -Xmx1024m -Xss2m
    

    3.2 构建idea工程

    在kafka的目录下执行

    Gradlew是包装器,自动下载包装器里定义好的gradle 版本,保证编译环境统一,gradle 是用本地的gradle版本。

    // 1.因为我本地已经配置好了kafka所需的各种环境,所以直接gradle idea
    // 2. 我之前已经gradle idea过了,中间会有很多下载耗时较长(分钟级别)。下图展示仅仅是为了演示步骤
    >gradle idea
    

    如下图
    在这里插入图片描述


    4 配置Kafka源码环境

    前面几个步骤执行完成后就可以很舒适的阅读Kafka的源码,但是如果需要启动Kafka的服务还需要一些额外的步骤。

    4.1 导入idea

    1. 安装scala插件(之前已经安装了scala,所以下图是update)
      在这里插入图片描述

    2. 配置gradle

    在这里插入图片描述

    1. 导入编译后的kafka
      在这里插入图片描述

    2. 配置日志
      将config目录下的log4j.properties文件拷贝到core/src/main/scala目录下,这样可以让Kafka在运行时能够输出日志信息,可以参考下图:
      在这里插入图片描述
      修改修改log4j.properties,增加kafka日志路径kafka.logs.dir

    kafka.logs.dir=D:\\idea-workspace\\github\\kafka\\logs
    
    1. 配置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
    
    # 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 seperated list of directories under which to store log files
    log.dirs=D:\\idea-workspace\\github\\kafka\\logs\\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 for 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 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 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=localhost:2181
    
    # Timeout in ms for connecting to zookeeper
    zookeeper.connection.timeout.ms=6000
    
    
    ############################# 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
    
    
    # 是否允许topic被删除,设置为true则topic可以被删除,
    # 开启这个功能方便Kafka在运行一段时间之后,能够删除一些不需要的临时topic
    delete.topic.enable=true
    # 禁用自动创建topic的功能
    auto.create.topics.enable=false
    

    漫长的构建过程

    在这里插入图片描述

    1. 配置kafka启动参数

    这里配置Main class为kafka.Kafka,并制定启动时所需要的配置文件地址,即:config/server.properties。配置JMX_PORT是为了方便搜集Kafka自身的Metrics数据

    在这里插入图片描述

    在这里插入图片描述


    5 Zookeeper的安装、配置及启动

    Kafka需要使用Zookeeper来管理元数据,比如记录topic、partitions(分区)以及replica(副本)的分配信息。

    所以这里的Zookeeper的安装也以极简为主(详细安装见这里),即采用单机配置。Zookeeper下载地址为:http://zookeeper.apache.org/releases.html,下载之后解压,然后将conf/zoo_sample.cfg重命名为zoo.cfg,其中$ZOOKEEPER_HOME指的是ZooKeeper的根目录。

    修改$ZOOKEEPER_HOME/conf/zoo.cfg配置,示例配置如下(其余配置可以不做修改):

    # 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=D:\\ProgramFiles\\zookeeper-3.4.12\\data
    dataLogDir=D:\\ProgramFiles\\zookeeper-3.4.12\\logs
    # 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
    

    简要介绍 zoo.cfg 文件

    • tickTime:默认3000ms,作一种基本单元,用它的倍数来表示系统内部的时间间隔配置,比如
    • 2*tickTime 是客户端会话的超时时间
    • 1*tickTime 是客户端 zk 服器端的心跳时
    • dataDir:无默认配置,必配置;用于配置储快照文件的目录,如果没有配置 dataLogDir,那么事务日志也会储在目录
    • clientPort:zk 的运行端口,默认是 2181
      启动
    Windows:直接双击 zkServer.cmd
    Linux: zkServer.sh start
    

    在这里插入图片描述

    如果zk不是默认的,需要修改 kafka的config/server.poroperties 文件的zookeeper.connect属性


    最后kafka启动成功

    在这里插入图片描述


    6 使用kafka

    1. 启动zk
    2. 从idea中启动kafka.scala (相当kafka的server)
    3. 创建topic
    --create -topic waterWang-test --zookeeper localhost:2181 --partitions 2 --replication-factor 1
    

    如下图填写配置
    在这里插入图片描述
    创建topic成功
    在这里插入图片描述

    展开全文
  • kafka源码环境搭建

    2018-07-07 10:57:11
    kafka源码环境搭建基于 JDK 1.8.0_161 kafka-0.10.0.1 scala-2.12.6 zookeeper-3.4.12 gradle-4.5开发工具 IDEA 2018.1.51.首先需要依次配置环境变量 JDK 1.8.0_161、kafka-0.10.0.1、scala-2.12.6、zookeeper...
    kafka源码环境搭建
    
    基于
        JDK 1.8.0_161
        kafka-0.10.0.1
        scala-2.12.6
        zookeeper-3.4.12
        gradle-4.5
    开发工具 IDEA 2018.1.5

    1.首先需要依次配置环境变量
        JDK 1.8.0_161、kafka-0.10.0.1、scala-2.12.6、zookeeper-3.4.12、gradle-4.5
    2.启动zookeeper
        首先拷贝一份%ZOOKEEPER_HOME%\conf\zoo_sample.cfg 修改为zoo.cfg,修改zoo.cfg里面的dataDir=/tmp/zookeeper日志存储目录
        执行 zkserver

    C:\Users\chenjianfei>zkserver
    
    C:\Users\chenjianfei>call "D:\jdk1.8.0_161"\bin\java "-Dzookeeper.log.dir=D:\zookeeper-3.4.12\bin\.." "-Dzookeeper.root.logger=INFO,CONSOLE" -cp "D:\zookeeper-3.4.12\bin\..\build\classes;D:\zookeeper-3.4.12\bin\..\build\lib\*;D:\zookeeper-3.4.12\bin\..\*;D:\zookeeper-3.4.12\bin\..\lib\*;D:\zookeeper-3.4.12\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "D:\zookeeper-3.4.12\bin\..\conf\zoo.cfg"
    2018-07-07 10:25:49,583 [myid:] - INFO  [main:QuorumPeerConfig@136] - Reading configuration from: D:\zookeeper-3.4.12\bin\..\conf\zoo.cfg
    2018-07-07 10:25:49,583 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
    2018-07-07 10:25:49,583 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
    2018-07-07 10:25:49,583 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
    2018-07-07 10:25:49,583 [myid:] - WARN  [main:QuorumPeerMain@116] - Either no config or no quorum defined in config, running  in standalone mode
    2018-07-07 10:25:49,645 [myid:] - INFO  [main:QuorumPeerConfig@136] - Reading configuration from: D:\zookeeper-3.4.12\bin\..\conf\zoo.cfg
    2018-07-07 10:25:49,645 [myid:] - INFO  [main:ZooKeeperServerMain@98] - Starting server
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:zookeeper.version=3.4.12-e5259e437540f349646870ea94dc2658c4e44b3b, built on 03/27/2018 03:55 GMT
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:host.name=DESKTOP-6FVEB35
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:java.version=1.8.0_161
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:java.vendor=Oracle Corporation
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:java.home=D:\jdk1.8.0_161\jre
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:java.class.path=D:\zookeeper-3.4.12\bin\..\build\classes;D:\zookeeper-3.4.12\bin\..\build\lib\*;D:\zookeeper-3.4.12\bin\..\zookeeper-3.4.12.jar;D:\zookeeper-3.4.12\bin\..\lib\audience-annotations-0.5.0.jar;D:\zookeeper-3.4.12\bin\..\lib\jline-0.9.94.jar;D:\zookeeper-3.4.12\bin\..\lib\log4j-1.2.17.jar;D:\zookeeper-3.4.12\bin\..\lib\netty-3.10.6.Final.jar;D:\zookeeper-3.4.12\bin\..\lib\slf4j-api-1.7.25.jar;D:\zookeeper-3.4.12\bin\..\lib\slf4j-log4j12-1.7.25.jar;D:\zookeeper-3.4.12\bin\..\conf
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:java.library.path=D:\jdk1.8.0_161\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;D:\app\chenjianfei\product\11.2.0\client_1\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;D:\jdk1.8.0_161\bin;D:\apache-maven-3.5.2\bin;D:\Git\cmd;D:\gradle-4.5\bin;D:\scala-2.12.6\bin;D:\zookeeper-3.4.12\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users\chenjianfei\AppData\Local\Microsoft\WindowsApps;;.
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:java.io.tmpdir=C:\Users\CHENJI~1\AppData\Local\Temp\
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:java.compiler=<NA>
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:os.name=Windows 10
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:os.arch=amd64
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:os.version=10.0
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:user.name=chenjianfei
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:user.home=C:\Users\chenjianfei
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:Environment@100] - Server environment:user.dir=C:\Users\chenjianfei
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:ZooKeeperServer@835] - tickTime set to 2000
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:ZooKeeperServer@844] - minSessionTimeout set to -1
    2018-07-07 10:25:58,833 [myid:] - INFO  [main:ZooKeeperServer@853] - maxSessionTimeout set to -1
    2018-07-07 10:25:59,067 [myid:] - INFO  [main:ServerCnxnFactory@117] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
    2018-07-07 10:25:59,067 [myid:] - INFO  [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181

    3.IDEA 安装scala插件


    4.指定gradle插件位置

    5.IDEA导入kafka源码

        import 项目->选择gradle 完成


    6.kafka服务启动准备

    7.创建kafka producer启动准备

    8.创建kafka consumer启动准备

    9.依次启动

        kafka->producer->consumer

    10.在producer控制台输入hello kafka,可以在consumer接收到hello kafka




    展开全文
  • Linux Kafka源码环境搭建
  • Mac搭建Kafka源码环境

    2020-04-14 13:36:05
    Mac搭建Kafka源码环境源码环境准备gradlescala构建 源码 git clone https://github.com/apache/kafka.git kafka代码库 环境准备 gradle brew install gradle 安装后验证 gradle -version scala scala官网地址 ...
  • Kafka源码环境搭建

    2019-04-13 14:19:55
    Kafka源码环境搭建https://blog.csdn.net/u013256816/article/details/78533725版权声明:本文为博主原创文章,未经博主朱小厮允许不得转载。 https://blog.csdn.net/u013256816/article/details/78533725 欢迎...
  • 构建kafka源码环境中的问题 在第一次构建kafka源码环境时,遇到很多问题,就此跟大家分享一下。 关键词:grandle,构件环境,idea 默认前置配置都已经完成并且未出错 1.JAVA配置成功 2.Gradle配置成功 3.scala配置...
  • kafka 源码环境构建Sending messages between components, reliably and quickly, is a core requirement for most distributed systems. Apache Kafka is a popular choice as it enables that — it offers low ...
  • 今天在搭建kafka源码环境,由于是新手并且不熟悉gradle,花了一个下午才搭建完成,记录一下遇到的问题,有类似问题的同学可以参考。PS:如何搭建的问题不再叙述。 Mac 上 Class JavaLaunchHelper is implemented in ...
  • 本文主要讲述的是如何搭建Kafka源码环境,主要针对的Windows操作系统下IntelliJ IDEA编译器,其余操作系统或者IDE可以类推。 1.安装和配置JDK 确认JDK版本至少为1.7,最好是1.8及以上。使用java -version命令来...
  • 1.官网下载kafka源码包,http://kafka.apache.org/downloads,这里版本为0.11.0.1。 2.下载下来的源码执行gradle idea,没有安装gradle的需要先安装。生成Idea工程并导入 3.kafka是scala编写,因此需要安装scala...
  • Kafka 源码环境搭建

    2019-05-10 09:53:55
    4. 构建Kafka源码环境 Kafka下载地址为: kafka.apache.org/downloads ,目前最新的版本是1.0.0。将下载的压缩包解压,并在Kafka的根目录执行gradle idea命令进行构建,如果你使用的是Eclipse,则只需采用gradle ...
  • kafka源码环境搭建好之后,需要在IntelliJ IDEA开发工具中以debug方式启动kafka服务器来测试消息的生产和消费。 但是在启动kafka.Kafka类中的main方法(也就是运行 kafka-0.10.0.1-src\core\src\main\scala\kafka\...
  • 下面就来演示如何在windows环境下来编译kafka源码,并通过IntelliJ IDEA开发工具搭建kafka的源码环境,以方便在本地通过debug调试来研究kafka的内部实现机制。 具体步骤: (1)安装jdk,版本为1.8.0_131,配置...
  • kafka源码环境准备

    千次阅读 2015-09-30 11:14:31
    之后进入kafka源码包的根目录,执行 o honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.7/userguide/gradle_daemon.html. ...
  • Kafka 源码包含测试代码 scala 代码接近15万行,Java 代码包括测试代码45万多行,主要集中在client模块下,据说是因为 Kafka新加入的代码贡献者Java开发不少,client 模块用Java重写了。 ZooKeeper 源码没下测试...
  • 一.kafka源码构建 完成上述准备工作后,我们在 http://kafka.apache.org/ 下载自己所需的kafka版本,我在这里下载了kafka-0.10.0.1。解压到指定目录后,打开cmd进入该目录,输入gradle idea命令进行构建,构建...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 18,971
精华内容 7,588
关键字:

kafka源码环境