linux下通过systemd配置开机自启

1.创建对应服务的启动脚本,放在/etc/systemd/system,名字为服务名.service

[Unit]
Description=Kafka Server
After=network.target //在什么服务后启动

[Service]
Type=simple
User=root //根据需求设置,大多数root即可
Group=root //同上
ExecStart=启动命令
ExecStop=关闭命令
Restart=always

[Install]
WantedBy=multi-user.target

2.赋予权限

chmod 777 自启脚本绝对路径

3.重新加载systemd配置

systemctl daemon-reload

4.使用以下命令启用Kafka服务,使其在系统启动时自动运行:

systemctl enable kafka

5.使用以下命令启动Kafka服务:

systemctl start kafka

6.Kafka将在系统启动时自动启动,并以指定的用户身份运行。你可以使用以下命令检查服务状态:

systemctl status kafka

你可能感兴趣的:(中间件,linux,运维,服务器)