kafka安装

  • 安装zoopkeeper
    • 解压后进入目录

         cd zookeeper-3.4.13/conf
      
    • 复制zookeeper的配置文件

       cp zoo_sample.cfg zoo.cfg   
      
    • 返回上级进入bin目录下,键入如下命令(配置文件是conf/zoo.cfg)

      ./zkServer.sh start 
      
  • 安装kafka
    • 解压tar
      tar -zxfv kafka_2.10-0.9.0.0.tgz
      
    • 修改config/server.properties配置(主要是这个)
    listeners=PLAINTEXT://ip:9092
    zookeeper.connect=localhost:2181
    #我的配置:
    listeners=PLAINTEXT://192.168.10.16:9092
    zookeeper.connect=localhost:2181
    
    

启动kafka

 ./bin/kafka-server-start.sh ./config/server.properties &
  • 查看是否启动

    netstat -tunlp|egrep "(2181|9092)"
    

创建topic

# 创建topic test
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic test

查看topic

./kafka-topics.sh --list --zookeeper localhost:2181

  • 开机启动
  • cd /lib/systemd/system
  • 创建文件
    • vi zookeeper.service
    [Unit]
     Description=zookeeper
     After=network.target
     
     [Service]
     Type=forking
     ExecStart=/usr/local/soft/zookeeper/bin/zkServer.sh start
     ExecStop=/usr/local/soft/zookeeper/bin/zkServer.sh stop
     PrivateTmp=true
     
     [Install]
     WantedBy=multi-user.target
    
    
    • vi kafka.service
    [Unit]
     Description=kafka
     After=network.target
     
     [Service]
     Type=forking
     ExecStart=/usr/local/soft/kafka_2.11-1.0.2/bin/kafka-server-start.sh /usr/local/soft/kafka_2.11-1.0.2/config/server.properties
     ExecStop=/usr/local/soft/kafka_2.11-1.0.2/bin/kafka-server-stop.sh
     PrivateTmp=true
     
     [Install]
     WantedBy=multi-user.target
    
    
  • 刷新配置。

systemctl daemon-reload

  • zookeeper、kafka服务加入开机自启。

systemctl enable zookeeper

systemctl enable kafka

  • 启动

systemctl start zookeeper
systemctl start kafka

  • 查看设置

  • systemctl list-unit-files|grep -E “kafka|zook”

      kafka.service                                 enabled 
      zookeeper.service                             enabled 
    
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页