CentOS/Redhat安装node_exporter

注:CentOS/Redhat 5要使用node_exporter 0.13版本,用0.16.0版本会报kernel太老,其它步骤同CentOS 6

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/run/prometheus

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

chown prometheus:prometheus /var/run/prometheus -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