自动化监控运维(三) node_exporter 构建

一、 二进制安装

二、 基于容器构建

2.1 容器构建

vim Dockerfile

FROM centos:centos7.9.2009

ARG NODE_EXPORTER_HOME=/usr/local/node-exporter

# Add file
COPY ./node_exporter-1.7.0.linux-amd64.tar.gz /opt

# tar file and rename to "prometheus"
RUN mkdir -p ${NODE_EXPORTER_HOME}
RUN tar -xzvf /opt/node_exporter-1.7.0.linux-amd64.tar.gz -C /usr/local/node-exporter --strip-components=1

RUN groupadd -r node_exporter && \
useradd -g node_exporter -s /bin/bash -c "node_exporter user" node_exporter && \
chown -R node_exporter:node_exporter /usr/local/node-exporter

# port
EXPOSE 9100

WORKDIR ${NODE_EXPORTER_HOME}

USER node_exporter

ENTRYPOINT [ "./node_exporter" ]

2.2 容器编排

vim docker-compose.yml

version: "3"
services:
node_exporter:
image: node_exporter:latest
user: "node_exporter"
ports:
- "9100:9100"
container_name: node_exporter
restart: always
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.rootfs=/rootfs'
- '--path.sysfs=/host/sys'
- '--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($$|/)'
networks:
default:
driver: bridge