Grafana的安装配置 和 使用nginx反向代理grafana
grafana安装和配置
grafana安装非常简单:(https://grafana.com/grafana/download)
对于有apt的服务器:
# apt install -y software-properties-common # only for debian9
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
apt update
apt install grafana
配置:
配置文件为 /etc/grafana/grafana.ini
,注意如下内容:
...
[server]
domain = www.parclabcn.com
enforce_domain = true
root_url = %(protocol)s://%(domain)s/grafana
...
[security]
admin_password = xxxx
然后访问 www.parclabcn.com/grafana 登录,用户名admin,密码为上面设置的admin_password。
或者用docker:
首先复制一个grafana的配置文件到 /root/docker-grafana/grafana.ini
(docker cp),然后做和上述同样的修改。
拉取镜像并运行:
docker run -d \
--name=grafana \
--restart=always \
-v /etc/localtime:/etc/localtime:ro \
-v /root/docker-grafana/grafana.ini:/etc/grafana/grafana.ini \
-p 3000:3000 \
grafana/grafana:6.4.3
Nginx设置如下:
location /grafana {
root html;
index index.html index.htm;
add_header 'Access-Control-Allow-Origin' '*';
add_header Access-Control-Allow-Methods GET,POST,OPTIONS,DELETE;
add_header 'Access-Control-Allow-Headers' 'userId,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
proxy_pass http://127.0.0.1:3000;
rewrite ^/grafana/(.*) /$1 break;
proxy_set_header Host $host;
#server_name_in_redirect off;
#proxy_set_header Host $host:$server_port;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header REMOTE-HOST $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
访问 ip/grafana 即可看到grafana界面。
参考:(配置都不全对,仅做参考)
https://blog.csdn.net/felix_yujing/article/details/72793863 (nginx配置不对,少了rewrite)
https://my.oschina.net/kcw/blog/2980304 (grafana的root_url不对)