Manually compile

1. Build the compilation environment (Ubuntu 18) :

Git installed

sudo apt-get install git

Go to install

Installation steps: https://learnku.com/go/t/47176

Installation node. Js

NVM controls node.js versions, and NPM and YARN manage JS packages.

  1. Install the NVM

    1. Wget – qO – https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | download bash NVM installation package and install

      Tips:  => 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_completionCopy the code
    2. Set up the environment

      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
      Copy the code
    3. Run the following command to check whether the version is installed successfully: NVM –version. If the message “NVM: command not found” is displayed, enter source ~/. Bashrc

  2. Installation node. Js. Ps: grafana-7.5.7 requires compatibility with Node.js-v12.xx

    1. usenvm ls-remoteView all remote versions
    2. usenvm install xxxInstall a version, such asNVM install v12.12.0Install Node.js version 12.12. The new version of Node.js comes with NPM, so there is no need to install NPM
    3. usenvm lsView the installed version
    4. It can be used if there are multiple versionsnvm useSwitch to a version, for exampleNVM use v5.3.0Use 5.3.0,nvm use systemUsing the System Version
  3. Install yarn: NPM install -g yarn

Download the source code

3. Compile the backend

  1. cd xx/grafanaGo to the source code root directory
  2. go run build.go setup, install dependencies
  3. go run build.go buildTo generate the bin file

4. Compile the front end

  1. Install dependencies,yarn install --pure-lockfile(NPM can be used to install dependencies)
  2. Compile,npm run build(Also availableyarn run buildCompile)

5. Run grafana

If you want to run grafana-server, you need to move the grafana-server file to the /bin directory. To start grafana, enter sudo xx/grafana/bin/grafana-server web

packaging

If you want to deploy grafana to another server, you can package the compiled content: go run build.go build package. The package is in the grafana/dist directory, and the package is decompressed to run on another server