• 2分钟快速批量部署node_exporter


    root用户登录,进入/root目录
    创建一个用于安装和启动 node_exporter 的脚本。

    vi install_node_exporter.sh
    填写以下内容并保存

    #!/bin/bash
    
    # 下载 node_exporter 包
    wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
    
    # 解压 node_exporter 包
    tar xvf node_exporter-1.6.1.linux-amd64.tar.gz
    
    # 在 /opt 目录下创建 prometheus 文件夹
    mkdir -p /opt/prometheus
    
    # 移动解压后的文件夹到 /opt/prometheus 下,并重命名为 node_exporter
    mv node_exporter-1.6.1.linux-amd64 /opt/prometheus/node_exporter
    
    # 创建一个新用户,用于运行 node_exporter 服务
    useradd -M -s /usr/sbin/nologin prometheus
    
    # 修改文件和文件夹的所有权
    chown prometheus:prometheus -R /opt/prometheus/node_exporter
    
    # 创建 systemd 服务文件
    cat > /etc/systemd/system/node_exporter.service <<EOF
    [Unit]
    Description=node_exporter
    Documentation=https://prometheus.io/
    After=network.target
    
    [Service]
    User=prometheus
    Group=prometheus
    ExecStart=/opt/prometheus/node_exporter/node_exporter
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
    # 重新加载 systemd 配置,启动和开机自启动 node_exporter 服务
    systemctl daemon-reload
    systemctl start node_exporter.service
    systemctl enable node_exporter.service
    
    # 打印服务状态
    systemctl status node_exporter.service
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    您可以将上述内容保存到一个 .sh 文件中,例如 install_node_exporter.sh,然后给予执行权限并运行:

    chmod +x install_node_exporter.sh
    ./install_node_exporter.sh
    
    • 1
    • 2

    注意:运行此脚本需要 root 权限。使用前,请确保您知道每个命令的含义和作用,以避免可能的问题。

    如果觉得下载慢的话就把第一行去掉,手动上传,然后执行脚本

    您提供的内容看起来是一个用于安装和启动 node_exporter 的步骤。以下是一个简化的 shell 脚本:

    #!/bin/bash
    
    # 解压 node_exporter 包
    tar xvf node_exporter-1.6.1.linux-amd64.tar.gz
    
    # 在 /opt 目录下创建 prometheus 文件夹
    mkdir -p /opt/prometheus
    
    # 移动解压后的文件夹到 /opt/prometheus 下,并重命名为 node_exporter
    mv node_exporter-1.6.1.linux-amd64 /opt/prometheus/node_exporter
    
    # 创建一个新用户,用于运行 node_exporter 服务
    useradd -M -s /usr/sbin/nologin prometheus
    
    # 修改文件和文件夹的所有权
    chown prometheus:prometheus -R /opt/prometheus/node_exporter
    
    # 创建 systemd 服务文件
    cat > /etc/systemd/system/node_exporter.service <<EOF
    [Unit]
    Description=node_exporter
    Documentation=https://prometheus.io/
    After=network.target
    
    [Service]
    User=prometheus
    Group=prometheus
    ExecStart=/opt/prometheus/node_exporter/node_exporter
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
    # 重新加载 systemd 配置,启动和开机自启动 node_exporter 服务
    systemctl daemon-reload
    systemctl start node_exporter.service
    systemctl enable node_exporter.service
    
    # 打印服务状态
    systemctl status node_exporter.service
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    您可以将上述内容保存到一个 .sh 文件中,例如 install_node_exporter.sh,然后给予执行权限并运行:

    chmod +x install_node_exporter.sh
    ./install_node_exporter.sh
    
    • 1
    • 2

    注意:运行此脚本需要 root 权限。使用前,请确保您知道每个命令的含义和作用,以避免可能的问题。

  • 相关阅读:
    网工内推 | 网络安全工程师,上市公司,13薪,食宿有补贴
    Java 复习笔记 - 常用API 上
    ​【原创】基于SSM的物流管理系统(物流管理系统毕业设计源代码)
    跨境电商如何更好地备战销售旺季?
    大数据开发集群搭建
    普洱茶上市?澜沧古茶通过港股聆讯
    从零开始做一款Unity3D游戏<二>——移动,相机控制与碰撞
    获取页面高度 height scroll
    MySQL入门指南6(视图,用户管理,存储引擎,数据类型)
    【视频去噪】基于全变异正则化最小二乘反卷积是最标准的图像处理、视频去噪研究(Matlab代码实现)
  • 原文地址:https://blog.csdn.net/u011197085/article/details/134090678