当前位置:   article > 正文

Centos7安装单机版Kafka

Centos7安装单机版Kafka

下载

链接:https://pan.baidu.com/s/1W8lVEF6Y-xlg6zr3l9QAbg?pwd=hbkt

提取码:hbkt

上传到服务器/opt目录

安装

  1. # kafka安装目录为 /opt/kafka
  2. cd /opt;
  3. mkdir kafka;
  4. mv kafka_2.13-2.7.0.tgz ./kafka;
  5. cd kafka;
  6. #解压
  7. tar -zxvf kafka_2.13-2.7.0.tgz;
  8. cd kafka_2.13-2.7.0;

启动内置zookeeper

  1. cd /opt/kafka/kafka_2.13-2.7.0;
  2. #注意启动方式为前台启动 窗口不能关闭
  3. ./bin/zookeeper-server-start.sh config/zookeeper.properties;
  4. # 后台运行启动方式为
  5. ./bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
  6. #关闭zookeeper
  7. bin/zookeeper-server-stop.sh

启动kafka server

  1. cd /opt/kafka/kafka_2.13-2.7.0;
  2. #前端启动方式为
  3. ./bin/kafka-server-start.sh config/server.properties;
  4. #后台启动方式为
  5. ./bin/kafka-server-start.sh -daemon config/server.properties
  6. #关闭kafka
  7. bin/kafka-server-stop.sh

开放防火墙端口

  1. firewall-cmd --add-port=9092/tcp --permanent;
  2. firewall-cmd --reload;

设置自启动

设置kafka.service

vim /lib/systemd/system/kafka.service

内容为

  1. [Unit]
  2. Description=Apache Kafka server (broker)
  3. Documentation=http://kafka.apache.org/documentation.html
  4. Requires=network.target remote-fs.target
  5. After=network.target remote-fs.target kafka-zookeeper.service
  6. [Service]
  7. Type=simple
  8. User=root
  9. Group=root
  10. Environment="JAVA_HOME=/opt/jdk1.8.0_201"
  11. ExecStart=/opt/kafka/kafka_2.13-2.7.0/bin/kafka-server-start.sh /opt/kafka/kafka_2.13-2.7.0/config/server.properties
  12. ExecStop=/opt/kafka/kafka_2.13-2.7.0/bin/kafka-server-stop.sh
  13. Restart=on-abnormal
  14. [Install]
  15. WantedBy=multi-user.target

上面的 kafka-zookeeper.service 是后面要创建的 zookeeper 服务的名称

Environment 为 java 的安装位置,需要修改成自己的位置

ExecStart 为启动命令,可以直接复制上面测试的时候的启动命令

ExecStop 为停止命令,也可以直接复制上面的

其他就不需要做修改

设置kafka-zookeeper.service

vim /lib/systemd/system/kafka-zookeeper.service

内容为

  1. [Unit]
  2. Description=Apache Kafka Zookeeper server
  3. Documentation=http://zookeeper.apache.org
  4. Requires=network.target remote-fs.target
  5. After=network.target remote-fs.target
  6. [Service]
  7. Type=simple
  8. User=root
  9. Group=root
  10. Environment="JAVA_HOME=/opt/jdk1.8.0_201"
  11. ExecStart=/opt/kafka/kafka_2.13-2.7.0/bin/zookeeper-server-start.sh /opt/kafka/kafka_2.13-2.7.0/config/zookeeper.properties
  12. ExecStop=/opt/kafka/kafka_2.13-2.7.0/bin/zookeeper-server-stop.sh
  13. Restart=on-abnormal
  14. [Install]
  15. WantedBy=multi-user.target

跟上面的 kafka 配置一样,将启动命令和停止命令的路径修改成自己的即可

设置开机启动

  1. systemctl daemon-reload
  2. systemctl enable kafka-zookeeper
  3. systemctl start kafka-zookeeper
  4. systemctl stop kafka-zookeeper
  5. systemctl enable kafka
  6. systemctl start kafka
  7. systemctl stop kafka
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/400649
推荐阅读
相关标签
  

闽ICP备14008679号