prometheus + grafana 可视化监控

    安装教程

    第一种

    参考官网安装

    prometheus 安装见 https://prometheus.io/docs/prometheus/latest/installation/

    grafana 安装见 https://grafana.com/grafana/download

    第二种

    便捷安装

    prometheus:

    apt install prometheus
    

    grafana:

    sudo apt-get install -y adduser libfontconfig1
    wget https://cdn.jansora.com/lib/grafana/9.1.7/grafana-enterprise_9.1.7_amd64.deb
    sudo dpkg -i grafana-enterprise_9.1.7_amd64.deb
    
    

    配置

    vim /etc/grafana/grafana.ini

    # 配置 grafana mysql 为后端
    [database]
    # You can configure the database connection by specifying type, host, name, user and password
    # as separate properties or as on string using the url properties.
    
    # Either "mysql", "postgres" or "sqlite3", it's your choice
    ;type = sqlite3
    ;host = 127.0.0.1:3306
    ;name = grafana
    ;user = root
    # If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
    ;password =
    
    type = mysql
    host = 127.0.0.1:3306
    name = grafana
    user = grafana
    password = 111
    
    
    # 配置服务
    [server]
    # Protocol (http, https, h2, socket)
    ;protocol = http
    
    # The ip address to bind to, empty will bind to all interfaces
    ;http_addr =
    
    # The http port  to use
    http_port = 3000
    

    重启 grafana

    systemctl restart grafana-server.service

    grafana 默认的用户名和密码都是 admin

    配置 nginx 转发

    需要注意的是 grafana 转发的 proxy_set_header Host $http_host; 一定要配置

    
    server {
        listen 443 ssl http2;
        server_name  prometheus.jansora.com;
    
        ssl_protocols    TLSv1 TLSv1.1 TLSv1.2;
        ssl_certificate     /etc/nginx/certs/lets-encrypt-jansora.com/jansora.com.cer;
        ssl_certificate_key /etc/nginx/certs/lets-encrypt-jansora.com/jansora.com.key;
    
          auth_basic "请输入用户和密码"; # 验证时的提示信息
          auth_basic_user_file /etc/nginx/passwd/jansora; # 认证文件
    
    
        location / {
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://127.0.0.1:9090;
        }
    }
    
    server {
        listen 443 ssl http2;
        server_name  grafana.jansora.com;
    
        ssl_protocols    TLSv1 TLSv1.1 TLSv1.2;
        ssl_certificate     /etc/nginx/certs/lets-encrypt-jansora.com/jansora.com.cer;
        ssl_certificate_key /etc/nginx/certs/lets-encrypt-jansora.com/jansora.com.key;
    
    
        location / {
              proxy_pass_header Server;
              proxy_set_header Host $http_host;
              proxy_redirect off;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Scheme $scheme;
          proxy_pass http://127.0.0.1:3000;
        }
    }
    
    

    评论栏