如何配置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命令容易報錯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章