Prometheus node_exporter设置开机启动服务

Posted y_zilong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Prometheus node_exporter设置开机启动服务相关的知识,希望对你有一定的参考价值。

1、nohup后台启动

ps -ef |grep node_exporter

nohup /apps/usr/node_exporter/node_exporter --web.listen-address=":9100" &

2、centos6.5后台启动

vim /etc/init.d/node_exporter

#!/bin/bash
#
#********************************************************************
#Author:            yzl
#QQ:                calm_yzl@163.com
#Date:              2021-11-30
#FileName:         node_exporter.sh
#URL:               yzil.cn
#Description:      The test script
#Copyright (C):     2021 All rights reserved
#********************************************************************

node_exporter=/apps/usr/node_exporter/node_exporter
RETYAL=0
prog="node_exporter"

. /etc/rc.d/init.d/functions
. /etc/sysconfig/network

[ $NETWORKING = "no" ] && exit 0

[ -x $node_exporter ] || exit 0

start() 

[ -x $node_exporter ] || \\
          echo ¡°FATAL: No such programme¡±;exit 4; 

#process_num=$(ps uax|grep node_exporter|grep -v grep|grep -v init.d|grep -v ansible|wc -l)
/apps/usr/nagios/libexec/check_tcp -H 127.0.0.1 -p 9100 -t 1 > /dev/null 2>&1
if [ $? -eq 0  ]; then
	echo "node_exporter alredy running!" ; exit 2
fi
 echo -n $"Starting $prog:"

nohup $node_exporter > /dev/null 2>&1 &

         RETVAL=$?
         echo

         [ $RETVAL = 0 ] && touch /var/lock/subsys/node_exporter

         return $RETVAL


stop() 
         echo -n $"Stoping $prog:"
         killproc $node_exporter
         RETVAL=$?
         echo
         [ $RETVAL = 0 ] && rm -f /var/lock/subsys/node_exporter


case "$1" in
start)
         start
         ;;
stop)
         stop
         ;;
restart)
         stop
         start
         ;;
status)
         status $prog
         RETVAL=$?
         ;;
*)
         echo $"Usage:$progstart|stop|restart|status|help"
         exit 1
esac
exit $RETVAL


cd /etc/init.d/
./node_exporter start
chkconfig node_exporter on
ps -ef|grep node_exporter
ss -ntlp|grep 9100

3、centos 7后台启动,创建一个.service文件

cat << EOF > /usr/lib/systemd/system/node_exporter.service 
[Service]
User=prometheus
Group=prometheus
ExecStart=/apps/usr/node_exporter/node_exporter

[Install]
WantedBy=multi-user.target

[Unit]
Description=node_exporter
After=network.target 
EOF

systemctl enable --enable node_exporter
[root@ecloud-elk-08 ~]# cat /usr/lib/systemd/system/node_exporter.service
[Service]
ExecStart=/apps/usr/node_exporter/node_exporter
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

systemctl enable --enable node_exporter

4、创建Prometheus组和用户

sudo groupadd -r prometheus
sudo useradd -r -g prometheus -s /sbin/nologin -M -c "prometheus Daemons" prometheus

以上是关于Prometheus node_exporter设置开机启动服务的主要内容,如果未能解决你的问题,请参考以下文章

grafana+prometheus+node_exporter+linux

Prometheus+node_exporter+grafana

Prometheus node_exporter设置开机启动服务

prometheus+node_exporter监控系统搭建

Prometheus客户端节点监控node_exporter

Prometheus Node_exporter