← 返回文章列表
POST / 2024-11-21

grafana

安装grafana wget https://dl.grafana.com/oss/release/grafana-6.0.2-1.x86 64.rpm sudo yum localinstall grafana-6.0.2-1.x86 64.rpm or rpm -Uvh gr

安装grafana

wget https://dl.grafana.com/oss/release/grafana-6.0.2-1.x86_64.rpm

sudo yum localinstall grafana-6.0.2-1.x86_64.rpm

or

rpm -Uvh grafana-6.0.2-1.x86_64.rpm

systemctl daemon-reload

systemctl start grafana-server

systemctl stop grafana-server

systemctl restart grafana-server

systemctl status grafana-server

默认使用的sqlite数据库

查看数据库中包含的表

.tables

查看user表内容

select * from user;

重置admin用户的密码为默认admin

update user set password = ‘59acf18b94d7eb0694c61e60ce44c110c7a683ac6a8f09580d626f90f4a242000746579358d77dd9e570e83fa24faa88a8a6’, salt = ‘F3FAxVm33R’ where login = ‘admin’;

退出sqlite3

.exit

Introduction

In this tutorial, you’ll configure Grafana to run behind a reverse proxy.

When running Grafana behind a proxy, you need to configure the domain name to let Grafana know how to render links and redirects correctly.

  • In the Grafana configuration file, change 

server.domain to the domain name you’ll be using:

[server]

domain = example.com

Bash

  • Restart Grafana for the new changes to take effect.

You can also serve Grafana behind a sub path, such as http://example.com/grafana.

To serve Grafana behind a sub path:

  • Include the sub path at the end of the 

root_url.

  • Set 

serve_from_sub_path to true.

[server]

domain = example.com

root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/

serve_from_sub_path = true

Bash

Next, you need to configure your reverse proxy.

Configure NGINX

NGINX is a high performance load balancer, web server, and reverse proxy.

  • In your NGINX configuration file inside 

http section, add the following:

this is required to proxy Grafana Live WebSocket connections.

map $http_upgrade $connection_upgrade {

  default upgrade;

  ” close;

}

upstream grafana {

  server localhost:3000;

}

server {

  listen 80;

  root /usr/share/nginx/html;

  index index.html index.htm;

  location / {

    proxy_set_header Host $http_host;

    proxy_pass http://grafana;

  }

  # Proxy Grafana Live WebSocket connections.

  location /api/live/ {

    proxy_http_version 1.1;

    proxy_set_header Upgrade $http_upgrade;

    proxy_set_header Connection $connection_upgrade;

    proxy_set_header Host $http_host;

    proxy_pass http://grafana;

  }

}

nginx

  • Reload the NGINX configuration.

  • Navigate to port 80 on the machine NGINX is running on. You’re greeted by the Grafana login page.

For Grafana Live which uses WebSocket connections you may have to raise Nginx worker_connections option which is 512 by default – which limits the number of possible concurrent connections with Grafana Live.

Also, be aware that the above configuration will work only when the proxy_pass value for location / is a literal string. If you are using a variable here, read this GitHub issue. You will need to add an appropriate NGINX rewrite rule.

To configure NGINX to serve Grafana under a sub path, update the location block:

this is required to proxy Grafana Live WebSocket connections.

map $http_upgrade $connection_upgrade {

  default upgrade;

  ” close;

}

upstream grafana {

  server localhost:3000;

}

server {

  listen 80;

  root /usr/share/nginx/www;

  index index.html index.htm;

  location /grafana/ {

    rewrite  ^/grafana/(.*)  /$1 break;

    proxy_set_header Host $http_host;

    proxy_pass http://grafana;

  }

  # Proxy Grafana Live WebSocket connections.

  location /grafana/api/live/ {

    rewrite  ^/grafana/(.*)  /$1 break;

    proxy_http_version 1.1;

    proxy_set_header Upgrade $http_upgrade;

    proxy_set_header Connection $connection_upgrade;

    proxy_set_header Host $http_host;

    proxy_pass http://grafana;

  }

}