安装启动node_exporter
需在被监控server上安装node_exporter。下载node_exporter,下载地址:https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar xzvf /root/node_exporter-0.18.1.linux-amd64.tar.gz
mv /root/node_exporter-0.18.1.linux-amd64 /opt/prometheus/
创建prometheus用户,用于启动node_exporter.service服务。
useradd -s /sbin/nologin -M prometheus
创建/usr/lib/systemd/system/node_exporter.service文件。
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动:
systemctl start node_exporter.service
systemctl enable node_exporter.service
每台机器手动安装太繁琐,而且效率低,还要考虑防火墙端口等问题。这里附上各个机器安装node_exporter的脚本。
vim install_node_exporter_prometheus.sh
#!/bin/bash
#Author: Joey-Yu
cat << EOF
+------------------------------------------------------------------+
| ** Welcome to install prometheus node_exporter for CentOS 7 OS|
+------------------------------------------------------------------+
EOF
function format() {
echo -e "\033[32m Success!!! \033[0m\n"
echo "#########################################################"
}
#mkdir dir
echo "set prometheus node-exporter dir"
dir=/opt/prometheus/
if [ ! -d $dir ]; then
mkdir -p /opt/prometheus/
fi
format
#download node_exporter-0.18.1.linux-amd64.tar.gz
echo "download and tar prometheus node_exporter-0.18.1.linux-amd64.tar.gz in root"
#cd /root && wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
node_exporter_file=/root/node_exporter-0.18.1.linux-amd64.tar.gz
if [ ! -f $node_exporter_file ]; then
echo "no node_exporter-0.18.1.linux-amd64.tar.gz in root!"
exit
else
cd /root/
tar xzvf /root/node_exporter-0.18.1.linux-amd64.tar.gz
mv /root/node_exporter-0.18.1.linux-amd64 /opt/prometheus/
format
fi
# useadd prometheus
echo "useadd prometheus user"
useradd -s /sbin/nologin -M prometheus
format
# chown prometheus and ln -s
echo "chown prometheus and ln -s"
cd /opt/prometheus/
chown -R prometheus.prometheus /opt/prometheus/node_exporter-0.18.1.linux-amd64/
ln -s /opt/prometheus/node_exporter-0.18.1.linux-amd64/ /opt/prometheus/node_exporter
format
# config prometheus /usr/lib/systemd/system/node_exporter.service
echo "touch /usr/lib/systemd/system/node_exporter.service"
touch /usr/lib/systemd/system/node_exporter.service
cat > /usr/lib/systemd/system/node_exporter.service << EOF
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl start node_exporter.service
systemctl enable node_exporter.service
format