DevProj

刻意练习,持续精进

服务

页面

标签

    关于

    记录下遇到各类问题的解决经验,希望对大家有所帮助。

    Prometheus 的安装与简单使用

    Prometheus 的安装与简单使用

    创建 prometheus 用户:

    sudo groupadd prometheus
    sudo useradd -g prometheus -M -s /sbin/nologin prometheus

    下载并解压安装包:

    wget https://github.com/prometheus/prometheus/releases/download/v2.15.2/prometheus-2.15.2.linux-amd64.tar.gz
    tar -zxvf prometheus-2.15.2.linux-amd64.tar.gz
    sudo mv prometheus-2.15.2.linux-amd64 /usr/prometheus

    创建 data 目录:

    cd /usr/local/prometheus
    sudo mkdir data
    sudo chown prometheus:prometheus -R .

    创建管理脚本:

    sudo vim /lib/systemd/system/prometheus.service

    填入以下内容:

    [Unit]
    Description=Prometheus Server
    Documentation=https://prometheus.io/docs/introduction/overview/
    After=network-online.target
    
    [Service]
    User=prometheus
    Restart=on-failure
    ExecStart=/usr/local/prometheus/prometheus \
      --config.file=/usr/local/prometheus/prometheus.yml \
      --storage.tsdb.path=/usr/local/prometheus/data
    ExecReload=/bin/kill -HUP $MAINPID
    [Install]
    WantedBy=multi-user.target

    启动服务:

    sudo systemctl start prometheus.service

    Grafana 的安装与简单使用

    Grafana 的安装介绍

    创建用户及用户组:

    $ sudo groupadd grafana
    $ sudo useradd -g grafana -M -s /sbin/nologin grafana

    下载并解压 Grafana:

    $ wget https://dl.grafana.com/oss/release/grafana-6.5.3.linux-amd64.tar.gz
    $ tar -zxvf grafana-6.5.3.linux-amd64.tar.gz
    $ sudo mv grafana-6.5.3.linux-amd64.tar.gz /usr/grafana

    拷贝配置文件:

    $ cd /usr/local/grafana
    $ sudo cp conf/defaults.ini conf/grafana.ini
    $ sudo chown grafana:grafana -R .

    添加管理脚本:

    sudo vim /lib/systemd/system/grafana-server.service

    填入以下内容:

    [Service]
    User=grafana
    Group=grafana
    Type=simple
    Restart=on-failure
    WorkingDirectory=/usr/local/grafana
    RuntimeDirectory=grafana
    ExecStart=/usr/local/grafana/bin/grafana-server \
                --config=/usr/local/grafana/conf/grafana.ini \
                --pidfile=/usr/local/grafana/conf/grafana-server.pid \
                --packaging=deb
    LimitNOFILE=10000
    TimeoutStopSec=20
    UMask=0027
    
    [Install]
    WantedBy=multi-user.target

    启动 Grafana 服务:

    $ sudo systemctl start grafana-server