美文网首页
CentOS主机监控-Prometheus-Alertmanag

CentOS主机监控-Prometheus-Alertmanag

作者: 国服最坑开发 | 来源:发表于2023-07-18 10:33 被阅读0次

    0x00 Node_Exporter 安装

    1、从官网下载 node_exporter

    wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
    tar -zxf node_exporter-1.6.1.linux-amd64.tar.gz
    mv node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin
    

    2、安装启动本地服务

    useradd --no-create-home --shell /bin/false node_exporter
    chown node_exporter:node_exporter /usr/local/bin/node_exporter
    

    创建服务

    vim /etc/systemd/system/node_exporter.service
    
    [Unit]
    Description=Node Exporter
    After=network.target
    
    [Service]
    User=node_exporter
    Group=node_exporter
    Type=simple
    ExecStart=/usr/local/bin/node_exporter
    
    [Install]
    WantedBy=multi-user.target
    

    3、启动验证

    systemctl daemon-reload
    systemctl start node_exporter
    # 验证服务
    curl localhost:9100/metrics
    

    4、prometheus监控

    在prometheus 服务器上执行

    vim /etc/prometheus/prometheus.yml
    
    - job_name: 'nodeexporter'
      static_configs:
      - targets: ['clientIP:9100']
    
    # 重启
    systemctl restart prometheus
    

    0x01 Prometheus Server 安装

    1、创建用户、数据目录

    groupadd --system prometheus
    useradd -s /sbin/nologin --system -g prometheus prometheus
    # 数据目录
    mkdir -p /apps/data_base/prometheus_base
    chown -R prometheus:prometheus /apps/data_base/prometheus_base
    

    2、下载执行文件

    wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz
    tar -zxf prometheus-2.45.0.linux-amd64.tar.gz
    cd prometheus-2.45.0.linux-amd64
    mv prometheus promtool /usr/local/bin/
    mkdir /etc/prometheus
    mv prometheus.yml /etc/prometheus/
    mv consoles/ console_libraries/  /etc/prometheus/
    

    3、配置启动参数

    不用动

    4、配置系统服务

    vim /etc/systemd/system/prometheus.service

    [Unit]
    Description=Prometheus
    Documentation=https://prometheus.io/docs/introduction/overview/
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    Type=simple
    Environment="GOMAXPROCS=1"
    User=prometheus
    Group=prometheus
    ExecReload=/bin/kill -HUP $MAINPID
    ExecStart=/usr/local/bin/prometheus \
      --config.file=/etc/prometheus/prometheus.yml \
      --storage.tsdb.path=/apps/data_base/prometheus_base \
      --web.console.templates=/etc/prometheus/consoles \
      --web.console.libraries=/etc/prometheus/console_libraries \
      --web.listen-address=0.0.0.0:9090 \
      --web.external-url=
    
    SyslogIdentifier=prometheus
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    

    说明:

    • Environment="GOMAXPROCS=1", 1 改为主机CPU的核心数
    • --storage.tsdb.path=/apps/data_base/prometheus_base  这里修改为数据目录

    5、启动服务

    systemctl daemon-reload
    systemctl start prometheus
    systemctl enable prometheus
    

    查看状态:

    systemctl status prometheus
    

    验证

    curl localhost:9090
    

    0x02 Alertmanager

    1、准备

    自行下载、解压

    mv alertmanager amtool /usr/local/bin/
    mkdir -p /etc/alertmanager
    mv alertmanager.yml /etc/alertmanager/
    mkdir -p /apps/data_base/alertmanager
    

    2、配置服务

    vim /etc/systemd/system/alertmanager.service

    [Unit]
    Description=alertmanager server daemon
    Documentation=https://prometheus.io/docs/introduction/overview/
    After=network.target[Service]
    
    
    [Service]
    Type=simple
    ExecStart=/usr/local/bin/alertmanager --config.file=/etc/alertmanager/alertmanager.yml --storage.path=/apps/data_base/alertmanager
    ExecReload=/bin/kill -HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    KillMode=process
    Restart=on-failure
    RestartSec=42s[Install]
    
    [Install]
    WantedBy=multi-user.target
    

    3、启动服务

    systemctl daemon-reload
    systemctl start alertmanager
    systemctl enable alertmanager
    systemctl status alertmanager
    

    curl localhost:9093

    0x04 Grafana

    1、yum 安装

    wget -q -O gpg.key https://rpm.grafana.com/gpg.key
    sudo rpm --import gpg.key
    
    vim /etc/yum.repos.d/grafana.repo
    
    [grafana]
    name=grafana
    baseurl=https://rpm.grafana.com
    repo_gpgcheck=1
    enabled=1
    gpgcheck=1
    gpgkey=https://rpm.grafana.com/gpg.key
    sslverify=1
    sslcacert=/etc/pki/tls/certs/ca-bundle.crt
    
    yum install grafana
    

    2、启动

    systemctl start grafana-server
    systemctl enable grafana-server
    systemctl status grafana-server
    

    localhost:3000

    相关文章

      网友评论

          本文标题:CentOS主机监控-Prometheus-Alertmanag

          本文链接:https://www.haomeiwen.com/subject/hxjkudtx.html