手动编译
1. 编译环境搭建(Ubuntu 18):
git 安装
sudo apt-get install git
go 安装
安装步骤:https://learnku.com/go/t/47176
安装 node.js
nvm 控制 node.js 的版本,npm 和 yarn 管理 js 包。
-
安装 nvm
-
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash下载 nvm 安装包和进行安装提示内容: => Downloading nvm as script to '/home/dhbm/.nvm' => Appending nvm source string to /home/dhbm/.bashrc => Appending bash_completion source string to /home/dhbm/.bashrc => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion -
设置环境
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm -
查看版本是否安装成功:
nvm --version,如果提示nvm: command not found,输入source ~/.bashrc即可解决
-
-
安装 node.js。ps:grafana-7.5.7 需要和 node.js-v12.xx 版本配套
- 使用
nvm ls-remote查看所有远端版本 - 使用
nvm install xxx安装某个版本,比如nvm install v12.12.0安装 12.12 版本的 node.js,新版本的 node.js 自带 npm,所以无需再安装 npm - 使用
nvm ls查看已经安装的版本 - 有多个版本的话可以使用
nvm use切换到某个版本,如nvm use v5.3.0使用 5.3.0,nvm use system使用系统版本
- 使用
-
安装 yarn:
npm install -g yarn
2. 下载源代码
3. 编译后端
cd xx/grafana,进入源码根目录go run build.go setup,安装依赖go run build.go build,生成 bin 文件
4. 编译前端
- 安装依赖,
yarn install --pure-lockfile(可以使用 npm 安装依赖) - 编译,
npm run build(也可以使用yarn run build进行编译)
5. 运行 grafana
注意,后端编译好之后 bin 文件在 /bin/linux-amd64 下,如果想运行需要将 grafana-server 文件移到 /bin 目录下,然后输入 sudo xx/grafana/bin/grafana-server web 即可启动 grafana
打包
如果想将编译好的 grafana 部署到另外一台服务器,可以将编译好的内容进行打包:go run build.go build package,打包好的压缩包在 grafana/dist 目录下,将这个压缩包传输到其他服务器解压缩即可运行