1. 程式人生 > >CentOS/Redhat安裝node_exporter

CentOS/Redhat安裝node_exporter

CentOS/Redhat安裝node_exporter

注:CentOS/Redhat 5會報kernel太老

node_exporter下載網址:

https://prometheus.io/download/

node_exporter-0.16.0.linux-amd64.tar.gz

我這邊以/home示例,請根據實際情況具體調整

CentOS 7:

tar zxfv node_exporter-0.16.0.linux-amd64.tar.gz -C /home/

mv /home/node_exporter-0.16.0.linux-amd64 /home/node_exporter

vi /etc/systemd/system/node_exporter.service

[Unit]
Description=Prometheus Node Exporter
After=network.target

[Service]
ExecStart=/home/node_exporter/node_exporter
User=nobody

[Install]
WantedBy=multi-user.target

:wq

systemctl start node_exporter

systemctl enable node_exporter

CentOS 6:

tar zxfv node_exporter-0.16.0.linux-amd64.tar.gz -C /home/

mv /home/node_exporter-0.16.0.linux-amd64 /home/node_exporter

yum install daemonize (如果沒搭建本地yum,可自行下載適配的rpm包手動安裝)

useradd prometheus -s /sbin/nologin

mkdir /var/log/prometheus

mkdir /var/rum/prometheus

chown prometheus:prometheus /var/log/prometheus -R

chown prometheus:prometheus /var/run/promethus -R

vi /etc/init.d/node_exporter

#!/bin/bash
#

Comments to support chkconfig
chkconfig: 2345 98 02
description: prometheus service script
#

Source function library.
. /etc/init.d/functions

Default variables
prog_name="prometheus"
config_file="/space/${prog_name}/${prog_name}.yml"
prog_path="/space/${prog_name}/${prog_name}"
data_path="/space/${prog_name}/data"
pidfile="/var/run/${prog_name}.pid"
prog_logs="/var/log/${prog_name}.log"
options="--web.listen-address=10.29.60.62:9090 --config.file=${config_file} --web.enable-lifecycle --storage.tsdb.path=${data_path}"
DESC="Prometheus Server"

Check if requirements are met
[ -x "${prog_path}" ] || exit 1

RETVAL=0

start(){
action $"Starting $DESC..." su -s /bin/sh -c "nohup $prog_path $options >> $prog_logs 2>&1 &" 2> /dev/null
RETVAL=$?
PID=$(pidof ${prog_path})
[ ! -z "${PID}" ] && echo ${PID} > ${pidfile}
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog_name
return $RETVAL
}

stop(){
echo -n $"Shutting down $prog_name: "
killproc -p ${pidfile}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog_name
return $RETVAL
}

restart() {
stop
start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status $prog_path
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
esac

:wq

chmod +x /etc/init.d/node_exporter

vi /etc/sysconfig/node_exporter

ARGS=""
:wq

/etc/init.d/node_exporter start

ps -ef | grep node_exporter

chkconfig --level 35 node_exporter on