CentOS/Redhat安装node_exporter

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于CentOS/Redhat安装node_exporter的主要内容,如果未能解决你的问题,请参考以下文章

CentOS/Redhat安装node_exporter

如何在CentOS,RedHat上安装java

ELK Centos Redhat yum 安装

在 Linux Redhat/CentOS 上为 msodbcsql17 安装 unixODBC >= 2.3.1

centos7/redhat7安装mycli

Parallels 无法安装增强工具到CentOS8(Redhat8)