在/etc/rc.local文件中编辑需要执行的脚本或者命令,我个人习惯用这个,因人而异,有的项目可能需要热加载配置文件,用服务会更好
#普罗米修斯启动,需要后面接config配置文件路径选项 nohup /root/linux_jiankong/prometheus/prometheus --config.file=/root/linux_jiankong/prometheus/prometheus.yml & #node_exporte启动 nohup /root/linux_jiankong/node_exporter/node_exporter --web.listen-address=:9100 & #启动influxdb数据库 influxd -config influxdb.conf #启动grafana systemctl start grafana-server.service
sudo groupadd -r prometheus sudo useradd -r -g prometheus -s /sbin/nologin -M -c "prometheus Daemons" prometheus
如果没创建prometheus组合用户,则Service的User就不用写
cat > /etc/systemd/system/prometheus.service <<EOF [Unit] Description=prometheus After=network.target [Service] Type=simple User=prometheus ExecStart=自己本地路径/prometheus --config.file=/自己本地路径/prometheus.yml --storage.tsdb.path=自己本地路径声明的data目录/data Restart=on-failure [Install] WantedBy=multi-user.target EOF
systemctl daemon-reload
systemctl start prometheus.service
systemctl status prometheus.service
systemctl enable prometheus.service
换种方式啊,其实一样的
vim /etc/systemd/system/node_exporter.service [Unit] Description=node_exporter Monitoring System Documentation=node_exporter Monitoring System [Service] ExecStart=自己本地路径/node_exporter --web.listen-address=:9100 [Install] WantedBy=multi-user.target #设置开机自启 systemctl daemon-reload systemctl start node_exporter.service systemctl status node_exporter.service systemctl enable node_exporter.service
prometheus、node_exporter设置开机自启动
原文:https://www.cnblogs.com/gltou/p/15153878.html