之前有部署过kafka,但是用的比较少,以后可能用的比较多了,所以编写整理了下kafka和zookeeper的开机启动服务的编写
之前部署的笔记可以查看这里:https://sulao.cn/post/489.html
我部署的目录是/usr/local/kafka,脚本约定部署目录为此目录,如果不一样可以直接修改下面服务里的路径
zookeeper开机启动服务脚本
#vi /usr/lib/systemd/system/zookeeper.service [Unit] Description=zookeeper project After=network.target [Service] Type=simple ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh Restart=on-failure PrivateTmp=true [Install] WantedBy=multi-user.target
保存退出,然后给服务脚本754权限
chmod 754 /usr/lib/systemd/system/zookeeper.service
加载配置并添加到开机启动
systemctl daemon-reload systemctl enable zookeeper
kafka开机启动服务器脚本
#vi /usr/lib/systemd/system/kafka.service [Unit] Description=kafka project After=network.target zookeeper.service [Service] Type=simple ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh Restart=on-failure PrivateTmp=true [Install] WantedBy=multi-user.target
保存退出,然后给服务脚本754权限
chmod 754 /usr/lib/systemd/system/kafka.service
加载配置并添加到开机启动
systemctl daemon-reload systemctl enable kafka
然后我们重启服务器测试下
netstat -ntpl #查看端口监听
看到zookeeper监听的2181和kafka监听的9092端口都已经起来了