1、kafka设置开机自启systemctl

#kafka启动:

./kafka/bin/kafka-server-start.sh -daemon ./kafka/config/server.properties
./kafka/bin/kafka-server-stop.sh  #有时候关不掉就kill -9

#/etc/systemd/system/kafka.service开机自启文件
[Unit]
Description=kafka.service
After=network.target remote-fs.target

[Service]
Type=forking
User=zaspace
Group=users
Environment=JAVA_HOME=/usr/local/jdk1.8.0_172
ExecStart=/home/kafka_2.12-1.1.0/bin/kafka-server-start.sh -daemon /home/kafka_2.12-1.1.0/config/server.properties
ExecStop=/home/kafka_2.12-1.1.0/bin/kafka-server-stop.sh
Restart=always
RestartSec=5
StartLimitInterval=0

[Install]
WantedBy=multi-user.target



2、kafka-manager设置开机自启systemctl:

#kafka-mananger启动
nohup bin/kafka-manager -Dconfig.file=conf/application.conf &



#/etc/systemd/system/kafka-manager.service文件内容
[Unit]
Description=kafka-manager.service
After=network.target remote-fs.target

[Service]
Type=forking
User=zaspace
Group=users
Environment=JAVA_HOME=/usr/local/jdk1.8.0_172
ExecStart=/home/kafka-manager-1.3.3.21/bin/start-kafkaManager.sh 
ExecStop=/home/kafka-manager-1.3.3.21/bin/stop-kafkaManager.sh
Restart=always
RestartSec=5
StartLimitInterval=0

[Install]
WantedBy=multi-user.target


##start-kafkaManager.sh内容
#!/bin/bash

# kafka-manager的安装目录
dir_home=/home/kafka-manager-1.3.3.21
rm -rf $dir_home/{RUNNING_PID,start-kafkaManager.log}
# 指定了web访问端口为9000
nohup $dir_home/bin/kafka-manager -Dconfig.file=$dir_home/conf/application.conf -Dhttp.port=9000 >> $dir_home/start-kafkaManager.log 2>&1 &




##stop-kafkaManager.sh内容
#!/bin/bash
PIDS=`ps -ef|grep kafka-manager |grep -v grep | awk '{print $2}'`

if [ "$PIDS" != "" ]; then
	kill -9 $PIDS
	#echo "进程号为:${PIDS}"
else
	exit 0
fi

3、zookeeper设置开机自启systemctl

##zk启动和关闭
./zookeeper/bin/zkServer.sh start
./zookeeper/bin/zkServer.sh stop

##/etc/systemd/system/zookeeper.service内容
[Unit]
Description=zookeeper.service
After=network.target

[Service]
Type=forking
User=zaspace
Group=users
Environment=ZOO_LOG_DIR=/home/zookeeper-3.4.14/bin
Environment=JAVA_HOME=/usr/local/jdk1.8.0_172
ExecStart=/home/zookeeper-3.4.14/bin/zkServer.sh start 
ExecStop=/home/zookeeper-3.4.14/bin/zkServer.sh stop
Restart=always
RestartSec=5
StartLimitInterval=0

[Install]
WantedBy=multi-user.target

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐