Linux starts Kafka as a system service (systemctl start xxx) (the same applies to other services)

final effect:
Insert image description here

First review the command line startup method:

Kafka startup

Enter the kafka installation directory

1. First start the zookeeper service:

bin/zookeeper-server-start.sh config/zookeeper.properties

2. Start kafka again

bin/kafka-server-start.sh config/server.properties &

The above method is too cumbersome. It is easier to start it as a system service, such as:

systemctl start zookeeper && systemctl start kafka

The implementation method is introduced below:Pay attention to replacing (/usr/local/kafka_2.13-3.5.0) with your own kafka installation path

Step-01: Create service file

Create /usr/lib/systemd/system/zookeeper.servicea file and write the following content

[Unit]
Requires=network.target
After=network.target
[Service]
Type=simple
LimitNOFILE=1048576
ExecStart=/usr/local/kafka_2.13-3.5.0/bin/zookeeper-server-start.sh /usr/local/kafka_2.13-3.5.0/config/zookeeper.properties
ExecStop=/usr/local/kafka_2.13-3.5.0/bin/zookeeper-server-stop.sh
Restart=Always
[Install]
WantedBy=multi-user.target

Create /usr/lib/systemd/system/kafka.servicea file and write the following content

[Unit]
Requires=zookeeper.service
After=zookeeper.service
[Service]
Type=simple
LimitNOFILE=1048576
ExecStart=/usr/local/kafka_2.13-3.5.0/bin/kafka-server-start.sh /usr/local/kafka_2.13-3.5.0/config/server.properties 
ExecStop=/usr/local/kafka_2.13-3.5.0/bin/kafka-server-stop.sh
Restart=Always
[Install]
WantedBy=multi-user.target

Step-02: Restart the system service after completion:

systemctl daemon-reload

Step-03: Use instructions

The following can be used normally. The relevant commands are as follows:

systemctl enable zookeeper && systemctl enable kafka	#自启动
systemctl start zookeeper && systemctl start kafka		#启动服务
systemctl status zookeeper && systemctl status kafka	#查看服务状态

Guess you like

Origin blog.csdn.net/java_cpp_/article/details/132603939