前言
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/1190000008653668centos參考:
https://segmentfault.com/a/1190000015430583由于預設的node版本低,此處需要更新為大于8,本文檔中使用的是11.14.0
3、安裝yarn:
https://yarnpkg.com/lang/en/docs/install/#debian-stable4、下載下傳項目代碼
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.org2、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/144264、請確定代碼是在這個路徑$GOPATH/src/github.com/grafana/grafana,否則執行go指令容易報錯