天天看点

如何配置grafana开发环境

前言

grafana是一款功能强大的数据可视化软件,支持多种数据源。本文将介绍如何配置grafana开发环境,可对其进行汉化等处理。

如果不二次开发,可参照文档直接安装已编译的版本:

https://grafana.com/grafana/download

下文介绍的配置方法可用于修改grafana源码

安装前的准备

本文环境:ubuntu

1、安装go,并配置GOPATH环境变量:

sudo apt-get install golang

vi ~/.profile

最后面增加一行:export GOPATH='/root/go'

使配置生效:source ~/.profile

2、node安装和版本升级:

ubuntu参考:

https://segmentfault.com/a/1190000008653668

centos参考:

https://segmentfault.com/a/1190000015430583

由于默认的node版本低,此处需要升级为大于8,本文档中使用的是11.14.0

3、安装yarn:

https://yarnpkg.com/lang/en/docs/install/#debian-stable

4、下载项目代码

git项目地址:

https://github.com/grafana/grafana

本文中没有直接使用go get github.com/grafana/grafana

而是先将代码clone下来,然后必须将代码放到:$GOPATH/src/github.com/grafana/grafana

编译和运行

1、前端环境

npm install -g node-gyp

进入文件夹:$GOPATH/src/github.com/grafana/grafana

安装依赖:yarn install --pure-lockfile

执行编译:yarn start

编译完成后,在public文件夹会看到多了个build文件夹

2、后端环境

go run build.go setup

go run build.go build

编译完成后,会看到多了个bin文件夹

3、运行

bin/grafana-server start

修改代码

比如修改public/app/core/utils/rangeutil.ts 将display字段翻译为中文

打一个包

go run build.go build package

打包好的deb文件在dist文件夹下

在另外的服务器安装

sudo dpkg -i grafana_xxxx.deb 

安装后的文件位置:

项目文件/usr/share/grafana

配置文件/etc/grafana/grafana.ini

可能遇到的问题

1、yarn install --pure-lockfile特别慢

vi ~/.npmrc

写入以下内容

sass_binary_site =

https://npm.taobao.org/mirrors/node-sass/

phantomjs_cdnurl =

https://npm.taobao.org/mirrors/phantomjs/

registry =

http://registry.npm.taobao.org

2、yarn install --pure-lockfile有报错:

An unexpected error occurred: "https://registry.yarnpkg.com/@types/react/-/react-16.8.8.tgz: getaddrinfo EAI_AGAIN registry.yarnpkg.com:443".

可能是执行这行命令中断过,下次执行就报错了,可以删除yarn.lock文件和node_modules文件夹后重新执行

3、pkg/setting/setting.go:225:35: undefined: http.SameSite

因为go版本过低:

https://community.grafana.com/t/build-from-source-problem/14426

4、请确保代码是在这个路径$GOPATH/src/github.com/grafana/grafana,否则执行go命令容易报错