zoukankan      html  css  js  c++  java
  • kafka Windows安装

    1:安装JDK、

    2:安装Zookeeper

     下载地址:https://zookeeper.apache.org/releases.html

        下载后,解压放在目录D:igdata(本文所用的目录)下,关于zookeeper以及kafka的目录,路径中最好不要出现空格,比如D:Program Files,尽量别用,运行脚本时会有问题。

    ①进入zookeeper的相关设置所在的文件目录,例如本文的:D:igdatazookeeper-3.4.10conf

    ②将"zoo_sample.cfg"重命名为"zoo.cfg"

    ③打开zoo.cfg(至于使用什么编辑器,根据自己喜好选即可),找到并编辑:

    dataDir=/tmp/zookeeper  to  D:/bigdata/zookeeper-3.4.10/data D:\bigdata\zookeeper-3.4.10\data(路径仅为示例,具体可根据需要配置)

    这里注意,路径要么是"/"分割,要么是转义字符"\",这样会生成正确的路径(层级,子目录)。

    ④与配置jre类似,在系统环境变量中添加:

        a.系统变量中添加ZOOKEEPER_HOME=D:igdatazookeeper-3.4.10

        b.编辑系统变量中的path变量,增加%ZOOKEEPER_HOME%in

    ⑤在zoo.cfg文件中修改默认的Zookeeper端口(默认端口2181)

    这是本文最终的zoo.cfg文件的内容:

      1. # The number of milliseconds of each tick  
      2. tickTime=2000  
      3. # The number of ticks that the initial   
      4. # synchronization phase can take  
      5. initLimit=10  
      6. # The number of ticks that can pass between   
      7. # sending a request and getting an acknowledgement  
      8. syncLimit=5  
      9. # the directory where the snapshot is stored.  
      10. # do not use /tmp for storage, /tmp here is just   
      11. # example sakes.  
      12. dataDir=D:/bigdata/zookeeper-3.4.10/data  
      13. #dataDir=D:\bigdata\zookeeper-3.4.10\data  
      14. # the port at which the clients will connect  
      15. clientPort=2181  
      16. # the maximum number of client connections.  
      17. # increase this if you need to handle more clients  
      18. #maxClientCnxns=60  
      19. #  
      20. # Be sure to read the maintenance section of the   
      21. # administrator guide before turning on autopurge.  
      22. #  
      23. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance  
      24. #  
      25. # The number of snapshots to retain in dataDir  
      26. #autopurge.snapRetainCount=3  
      27. # Purge task interval in hours  
      28. # Set to "0" to disable auto purge feature  
      29. #autopurge.purgeInterval=1 

    ⑥打开cmd窗口,输入zkserver,运行Zookeeper,运行结果如下:

    Zookeeper已经安装完成,已在2181端口运行。

    3 安装kafka

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

        要下载Binary downloads这个类型,不要下载源文件,这种方便使用。下载后,解压放在D:igdata目录下。

    ①进入kafka配置文件所在目录,D:igdatakafka_2.11-0.9.0.1config

    ②编辑文件"server.properties",找到并编辑:

     log.dirs=/tmp/kafka-logs  to  log.dirs=D:/bigdata/kafka_2.11-0.9.0.1/kafka-logs 或者 D:\bigdata\kafka_2.11-0.9.0.1\kafka-logs

    同样注意:路径要么是"/"分割,要么是转义字符"\",这样会生成正确的路径(层级,子目录)。错误路径情况可自行尝试,文件夹名为这种形式:bigdatakafka_2.11-0.9.0.1kafka-logs

    ③在server.properties文件中,zookeeper.connect=localhost:2181代表kafka所连接的zookeeper所在的服务器IP以及端口,可根据需要更改。本文在同一台机器上使用,故不用修改。

    ④启动kafka:

    在命令行中输入:.inwindowskafka-server-start.bat .configserver.properties   回车。

    kafka会按照默认配置,在9092端口上运行,并连接zookeeper的默认端口2181。

    3 增加kafka用户

    (1)
    # 添加下面的配置  ip和端口改成自己需要
    listeners=SASL_PLAINTEXT://xx.xx.xx.xx:8123
    security.inter.broker.protocol=SASL_PLAINTEXT
    sasl.enabled.mechanisms=PLAIN
    sasl.mechanism.inter.broker.protocol=PLAIN

    (2)

    在config目录添加kafka_server_jaas.conf 文件 此文件是服务端 设置用户名  和密码

    KafkaServer {
        org.apache.kafka.common.security.plain.PlainLoginModule required
        username="kafka"
        password="kafkapswd"
        user_kafka="kafkapswd"
        user_mooc="moocpswd";
    };

    其中 Kafka 定义了关键字KafkaServer字段用于指定服务端登录配置。该配置通过org.apache.
    org.apache.kafka.common.security.plain.PlainLoginModule由指定采用PLAIN 机制, 定义了两个用户, 用户通
    过usemame 和password 指定该代理与集群其他代理初始化连接的用户名和密码, 通过“ user_ "
    为前缀后接用户名方式创建连接代理的用户名和密码,例如, user_mooc = "moocpswd” 是指
    用户名为mooc, 密码为moocpswd
     

    (3)

    在config目录添加kafka_client_jaas.conf

    KafkaClient {
            org.apache.kafka.common.security.plain.PlainLoginModule required
            username="mooc"
            password="moocpswd";
    };
     (4)

    修改目录/usr/local/kafka_2.12-1.1.1/bin 下的 kafka-server-start.sh文件 。 我的做法也是复制出来一份 ,然后进行修改

    kafka-server-start-saal.sh  添加以下文件

    if [ "x$KAFKA_OPTS"  ]; then
        export KAFKA_OPTS="-Djava.security.auth.login.config=/usr/local/kafka_2.12-1.1.1/config/kafka_server_jaas.conf"
    fi

    (5)

    修改目录/usr/local/kafka_2.12-1.1.1/bin 下的  kafka-console-producer.sh 和 kafka-console-consumer.sh 文件

    也是 都各自复制一份 在复制上面进行修改

    if [ "x$KAFKA_OPTS"  ]; then
        export KAFKA_OPTS="-Djava.security.auth.login.config=/usr/local/kafka_2.12-1.1.1/config/kafka_client_jaas.conf"
    fi


     

  • 相关阅读:
    【动态规划】 EditDistance
    招聘
    算法01 C语言设计
    keras04
    电影《邪不压正》打动我的
    Eclipse
    6.面向对象编程(下)2
    获取一个1-100之间的随机数
    java如何使用帮助文档api
    3.java基础语法(下)
  • 原文地址:https://www.cnblogs.com/mrray/p/10895863.html
Copyright © 2011-2022 走看看