rocketmq-exporter配置为系统服务-自启动

1、rocketmq-exporter配置为系统服务自启动

① 创建并进入编辑

vi /usr/lib/systemd/system/rocketmq_exporter.service

② 复制下面内容至rocketmq_exporter.service,保存退出(ansible脚本templates需要这个模板文件)

将namesrvAddr 配置成变量替换

[Unit]
Description=rocketmq-exporter
After=network.target
[Service]
Type=forking
User=root
ExecStart=/root/java/jdk1.8.0_181/bin/java -jar /root/rocketmq-exporter/rocketmq-exporter-0.0.2-SNAPSHOT-exec.jar --rocketmq.config.namesrvAddr=192.168.244.133:9876
ExecStop=kill -9 pid
Restart=on-failure
[Install]
WantedBy=multi-user.target

加入需要运行脚本 设置jdk环境,运行sh脚本的参考以下方式:

rocketmq_exporter.service

[Unit]
Description=rocketmq-exporter
After=network.target
[Service]
Type=forking
User=root
ExecStart=/root/rocketmq_exporter_start.sh
ExecStop=kill -9 pid
Restart=on-failure
[Install]
WantedBy=multi-user.target

/root/rocketmq_exporter_start.sh

#!/bin/bash

echo ---------- rocketmq exporter start ------------
export JAVA_HOME=/root/java/jdk1.8.0_181
java -jar /root/rocketmq-exporter/rocketmq-exporter-0.0.2-SNAPSHOT-exec.jar --rocketmq.config.namesrvAddr=192.168.244.133:9876

sleep 3s
echo 'start rocketmq exporter ok'
2、配置生效 服务启动

以下步骤可以写成shell脚本

#!/bin/bash


① 重新加载配置文件

$ systemctl daemon-reload

② 启动服务

$ systemctl start rocketmq_exporter

③ 设置服务开机自启动

$ systemctl enable rocketmq_exporter --now

你可能感兴趣的:(windows,linux,rocketmq,exporter,rocketexporter)