当前位置: 首页 > news >正文

14.kafka开机自启动配置

要在Linux(RHEL7.7)系统中设置kafka开机自启动,可以创建一个系统服务单元文件。以下是为详细配置部署,假设你已经安装了kafka并且可以通过kafka-server-start.sh命令启动它。

1.进入/lib/systemd/system目录

命令:

cd /lib/systemd/system

[root@rhel77 system]# cd /lib/systemd/system
[root@rhel77 system]# pwd
/lib/systemd/system
[root@rhel77 system]# 

2.创建kafka.service

命令:

touch kafka.service

[root@rhel77 system]# touch kafka.service 
[root@rhel77 system]# ls kafka.service 
kafka.service
[root@rhel77 system]# 

3.编辑kafka.service文件,添加如下内容并保存

[Unit]
Description=Kafka
After=network.target
After=zookeeper.service[Service]
Type=forking
User=root
Group=rootEnvironment=KAFKA_HOME=/opt/kafka_2.13-3.3.2ExecStart=/opt/kafka_2.13-3.3.2/bin/kafka-server-start.sh -daemon /opt/kafka_2.13-3.3.2/config/server.properties
ExecStop=/opt/kafka_2.13-3.3.2/bin/kafka-server-stop.sh
Restart=on-failure
TimeoutSec=600
LimitNOFILE=4096[Install]
WantedBy=multi-user.target

请确保将User和Group替换为运行kafka进程的用户和组。同样,将Environment、ExecStart、ExecStop设置合适的环境路径。

4.重新加载systemd管理器配置,使新的服务单元生效

命令:

systemctl daemon-reload

[root@rhel77 system]# systemctl daemon-reload
[root@rhel77 system]# 

5.启用kafka服务以在启动时运行

命令:

systemctl enable kafka

[root@rhel77 system]# systemctl enable kafka
[root@rhel77 system]# cd /etc/systemd/system/multi-user.target.wants/
[root@rhel77 multi-user.target.wants]# ls -l kafka.service 
lrwxrwxrwx 1 root root 37 Dec  2 16:11 kafka.service -> /usr/lib/systemd/system/kafka.service
[root@rhel77 multi-user.target.wants]# 

6.启动kafka服务(须先启动zookeeper)

命令:

systemctl start kafka

[root@rhel77 multi-user.target.wants]# systemctl start kafka
[root@rhel77 multi-user.target.wants]# 
[root@rhel77 multi-user.target.wants]# systemctl status kafka
● kafka.service - KafkaLoaded: loaded (/usr/lib/systemd/system/kafka.service; enabled; vendor preset: disabled)Active: active (running) since Mon 2024-12-02 16:53:47 CST; 3s agoProcess: 21633 ExecStop=/opt/kafka_2.13-3.3.2/bin/kafka-server-stop.sh (code=exited, status=0/SUCCESS)Process: 21664 ExecStart=/opt/kafka_2.13-3.3.2/bin/kafka-server-start.sh -daemon /opt/kafka_2.13-3.3.2/config/server.properties (code=exited, status=0/SUCCESS)Main PID: 21997 (java)Tasks: 75CGroup: /system.slice/kafka.service└─21997 java -Xmx1G -Xms1G -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+E...Dec 02 16:53:47 rhel77 systemd[1]: Starting Kafka...
Dec 02 16:53:47 rhel77 systemd[1]: Started Kafka.
[root@rhel77 multi-user.target.wants]# 

7.端口验证

命令:

netstat -antulp |grep 9092

[root@rhel77 multi-user.target.wants]# netstat -antulp |grep 9092
tcp6       0      0 :::9092                 :::*                    LISTEN      21997/java          
tcp6       0      0 192.168.10.249:46694    192.168.10.249:9092     ESTABLISHED 21997/java          
tcp6       0      0 192.168.10.249:9092     192.168.10.249:46694    ESTABLISHED 21997/java          
[root@rhel77 multi-user.target.wants]# 

8.停止kafka

命令:

systemctl stop kafka

[root@rhel77 multi-user.target.wants]# systemctl stop kafka
[root@rhel77 multi-user.target.wants]# systemctl status kafka
● kafka.service - KafkaLoaded: loaded (/usr/lib/systemd/system/kafka.service; enabled; vendor preset: disabled)Active: failed (Result: exit-code) since Mon 2024-12-02 16:55:36 CST; 2s agoProcess: 22099 ExecStop=/opt/kafka_2.13-3.3.2/bin/kafka-server-stop.sh (code=exited, status=0/SUCCESS)Process: 21664 ExecStart=/opt/kafka_2.13-3.3.2/bin/kafka-server-start.sh -daemon /opt/kafka_2.13-3.3.2/config/server.properties (code=exited, status=0/SUCCESS)Main PID: 21997 (code=exited, status=143)Dec 02 16:53:47 rhel77 systemd[1]: Starting Kafka...
Dec 02 16:53:47 rhel77 systemd[1]: Started Kafka.
Dec 02 16:55:36 rhel77 systemd[1]: Stopping Kafka...
Dec 02 16:55:36 rhel77 systemd[1]: kafka.service: main process exited, code=exited, status=143/n/a
Dec 02 16:55:36 rhel77 systemd[1]: Stopped Kafka.
Dec 02 16:55:36 rhel77 systemd[1]: Unit kafka.service entered failed state.
Dec 02 16:55:36 rhel77 systemd[1]: kafka.service failed.
[root@rhel77 multi-user.target.wants]# 

http://www.lryc.cn/news/532413.html

相关文章:

  • 11 享元(Flyweight)模式
  • PHP JSON操作指南
  • 【学习笔记】计算机图形学的几何数学基础知识
  • Python因为网络原因安装依赖库报错
  • 什么是卸荷器?风力发电为什么要用卸荷器
  • SQL Server详细使用教程(包含启动SQL server服务、建立数据库、建表的详细操作) 非常适合初学者
  • 大数据学习之Spark分布式计算框架RDD、内核进阶
  • Unity 加载OSGB(webgl直接加载,无需转换格式!)
  • tcp/ip网络协议,tcp/ip网络协议栈
  • 【Debug】the remote host closed the connection错误信息分析
  • SpringBoot扩展篇:@Scope和@Lazy源码解析
  • “AI隐患识别系统,安全多了道“智能护盾”
  • 通向AGI之路:人工通用智能的技术演进与人类未来
  • 论文阅读:InstanceDiffusion: Instance-level Control for Image Generation
  • 7.攻防世界 wzsc_文件上传
  • 以为是响应式对象丢失导致数据没有回显
  • 来 Gitcode 免费体验 DeepSeek 蒸馏模型,开启 AI 探索新旅程
  • 2.Mkdocs配置说明(mkdocs.yml)【最新版】
  • 云轴科技ZStack+海光DCU:率先推出DeepSeek私有化部署方案
  • 扩增子分析|零模型2——基于βNTI的微生物随机性和确定性装配过程(箱线图和柱状图R中实现)
  • 专题:剑指offer
  • DeepSeek 部署过程中的问题
  • DeepSeek R1本地化部署 Ollama + Chatbox 打造最强 AI 工具
  • 应急场景中的数据融合与对齐
  • 手机上运行AI大模型(Deepseek等)
  • Mellanox网卡信息查看
  • 【漫画机器学习】083.安斯库姆四重奏(Anscombe‘s quartet)
  • TCP | RFC793
  • 2025蓝桥杯JAVA编程题练习Day2
  • 《解锁GANs黑科技:打造影视游戏的逼真3D模型》