部署node_exporter

系统服务方式部署:

优点:不依赖其它软件

缺点:端口如果被占用则不可用

wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
tar xf node_exporter-1.5.0.linux-amd64.tar.gz 
rm -rf /usr/local/node_exporter
mv node_exporter-1.5.0.linux-amd64 /usr/local/node_exporter
mkdir -p /usr/lib/systemd/system/
cat > /usr/lib/systemd/system/node_exporter.service << EOF
[Unit]
Description=node_exporter
[Service]
Restart=on-failure
WorkingDirectory=/usr/local/node_exporter
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target
EOF

systemctl enable node_exporter && systemctl start node_exporter && systemctl status node_exporter

 

docker方式部署:

优点:端口可以随意定义

缺点:依赖docker工具

cat >/node_exporter <<'EOF'
#!/bin/bash

docker=`yum list installed | grep -w "docker-ce.x86_64" | wc -l`

if (( $docker == 0 ))
    then
    yum install -y wget &&
    wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo && 
    yum install -y docker-ce-19.03.9 docker-ce-cli-19.03.9 containerd.io docker-compose &&
    systemctl enable docker && systemctl start docker && systemctl status docker 
else 
    echo "" 
fi 

docker run --name node-exporter -d --restart=always -p "19100:9100" -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro"  prom/node-exporter
docker ps -a | grep node-exporter
exit 0
EOF

chmod +x node_exporter && ./node_exporter

 

如果docker起不来可以单独安装

yum-config-manager \
  --add-repo \
  https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce-19.03.9 docker-ce-cli-19.03.9 containerd.io docker-compose

mkdir -p /etc/docker/
cat >/etc/docker/daemon.json  <<EOF
{
  "log-driver":"json-file",
  "log-opts": {"max-size":"200m", "max-file":"10"}
}
EOF
cat /etc/docker/daemon.json
systemctl enable docker && systemctl start docker && systemctl status docker

 

posted @ 2023-04-08 18:17  缺个好听的昵称  阅读(138)  评论(0编辑  收藏  举报