Prometheus之node_exporter安装和设置开机启动服务--centos6.5

centos6.5:

1.下载地址:

把node_exporter包下载到/opt目录下

cd /opt

wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-arm64.tar.gz

2.tar解压包

tar -zxvf node_exporter-0.18.1.linux-arm64.tar.gz
mv node_exporter-0.18.1.linux-arm64 node_exporter
修改权限  chmod 777 node_exporter
nohup /opt/exporter/node_exporter &
访问:curl http://IP:9100/metrics

3.设置开机自启动

脚本 (1)vim /etc/init.d/node_exporter

#!/bin/bash
#
#	/etc/rc.d/init.d/node_exporter
#
# chkconfig: 2345 80 80
#
# config: /etc/prometheus/node_exporter.conf
# pidfile: /var/run/prometheus/node_exporter.pid

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


RETVAL=0
PROG="node_exporter"
DAEMON_SYSCONFIG=/etc/sysconfig/${PROG}
DAEMON=/usr/bin/${PROG} #要把安装目录下/opt/node_exporter/node_exporter可执行文件拷贝到/usr/bin目录下
PID_FILE=/var/run/prometheus/${PROG}.pid
LOCK_FILE=/var/lock/subsys/${PROG}
LOG_FILE=/var/log/prometheus/node_exporter.log
DAEMON_USER="prometheus"
FQDN=$(hostname)
GOMAXPROCS=$(grep -c ^processor /proc/cpuinfo)

. ${DAEMON_SYSCONFIG}

start() {
  if check_status > /dev/null; then
    echo "node_exporter is already running"
    exit 0
  fi

  echo -n $"Starting node_exporter: "
  daemonize -u ${DAEMON_USER} -p ${PID_FILE} -l ${LOCK_FILE} -a -e ${LOG_FILE} -o ${LOG_FILE} ${DAEMON} ${ARGS}
  RETVAL=$?
  echo ""
  return $RETVAL
}

stop() {
    echo -n $"Stopping node_exporter: "
    killproc -p ${PID_FILE} -d 10 ${DAEMON}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${LOCK_FILE} ${PID_FILE}
    return $RETVAL
}

check_status() {
    status -p ${PID_FILE} ${DAEMON}
    RETVAL=$?
    return $RETVAL
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
	check_status
        ;;
    reload|force-reload)
        reload
        ;;
    restart)
        stop
        start
        ;;
    *)
        N=/etc/init.d/${NAME}
        echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
        RETVAL=2
        ;;
esac

exit ${RETVAL}

 

(2)vim /etc/sysconfig/node_exporter
ARGS=""

4.创建启动脚本中对应文件和目录

chmod 777 /etc/init.d/node_exporter
cp  /opt/node_exporter/node_exporter /usr/bin/node_exporter 
chmod 777 /opt/node_exporter/node_exporter
chmod 777 /usr/bin/node_exporter 
groupadd -r prometheus
mkdir -p /usr/hostonnet/prometheus/
useradd -r -g prometheus -s /sbin/nologin -d /usr/hostonnet/prometheus/ -c "prometheus Daemons" prometheus
chown -R prometheus:prometheus /usr/hostonnet/prometheus/
mkdir -p /var/run/prometheus/
chmod 777 /var/run/prometheus/
touch /var/run/prometheus/node_exporter.pid
chmod 777 /var/run/prometheus/node_exporter.pid 
mkdir -p /var/log/prometheus/
touch /var/log/prometheus/node_exporter.log
chmod 777 /var/log/prometheus
chmod 777 /var/log/prometheus/node_exporter.log
chown prometheus:prometheus /var/log/prometheus/node_exporter.log
cd /etc/init.d/
./node_exporter start
chkconfig node_exporter on
ps -ef|grep node_exporter
ss -ntlp|grep 9100

 

你可能感兴趣的:(Prometheus)