采用rpm的安装方式:
$ wget https://dl.grafana.com/enterprise/release/grafana-enterprise-7.5.13-1.x86_64.rpm$ sudo rpm -Uvh grafana-enterprise-7.5.13-1.x86_64.rpm
开启Grafana服务(默认服务端口3000)
$ systemctl daemon-reload$ systemctl start grafana-server$ systemctl status grafana-server
安装的详细细节:
Installs binary to /usr/sbin/grafana-server
Copies init.d script to /etc/init.d/grafana-server
Installs default file (environment vars) to /etc/sysconfig/grafana-server
Copies configuration file to /etc/grafana/grafana.ini
Installs systemd service (if systemd is available) name grafana-server.service
The default configuration uses a log file at /var/log/grafana/grafana.log
The default configuration specifies an sqlite3 database at /var/lib/grafana/grafana.db
Grafana的介绍与使用
Install on RPM-based Linux (CentOS, Fedora, OpenSuse, Red Hat)
$ wget https://studygolang.com/dl/golang/go1.17.6.linux-amd64.tar.gz$ tar -xvf go1.17.6.linux-amd64.tar.gz$ mkdir -p $HOME/gopath//用于存放go get的安装包$ vim ~/.bashrc添加GOROOT=$HOME/goGOPATH=$HOME/gopathexport PATH=$GOROOT/bin:$PATHexport GOPATH$ 、~/.bashrc
查看go版本:
$ go versiongo version go1.17.6 linux/amd64
CentOS7安装Go环境
Go语言Centos7安装
安装nodejs 14:
$ wget https://nodejs.org/download/release/v14.9.0/node-v14.9.0-linux-x64.tar.gz$ tar -xvf node-v14.9.0-linux-x64.tar.gz$ wget https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-v1.22.17.tar.gz$ tar -zxvf yarn-v1.22.17.tar.gz$ vim ~/.bashrc添加NODEJS=$HOME/node-v14.9.0-linux-x64YARN_HOME=$HOME/yarn-v1.22.17export PATH=$YARN_HOME/bin:$NODEJS/bin:$PATH$ 、~/.bashrc
查看nodejs、npm和yarn版本:
$ node -vv14.9.0$ npm -v6.14.8$ yarn -v1.22.17
CentOS7 安装 nodejs
在centos7下安装nodejs14
centos7 安装nodejs和yarn最新版本
$ go get -u github.com/grafana/grafana-plugin-sdk-go
直接执行以上命令会报错go get: module github.com/grafana/grafana-plugin-sdk-go: Get "https://proxy.golang.org/github.com/grafana/grafana-plugin-sdk-go/@v/list": dial tcp 142.251.42.241:443: i/o timeout
因为默认的GOPROXY指定的网站无法访问:
$ go env GOPROXYGOPROXY="https://proxy.golang.org,direct"
更改GOPROXY为国内代理,并再次执行该命令:
$ go env -w GOPROXY=https://goproxy.cn$ go get -u github.com/grafana/grafana-plugin-sdk-gogo: downloading github.com/grafana/grafana-plugin-sdk-go v0.125.0go: downloading github.com/magefile/mage v1.11.0go: downloading github.com/magefile/mage v1.12.1
Go proxy 设置
go get命令——一键获取代码、编译并安装
go get
go安装依赖包(go get, go module)
由于上一步骤中已经下载了mage安装包,所以可直接安装:
$ cd ~/gopath/pkg/mod/github.com/magefile/mage@v1.12.1$ go run bootstrap.go
报错Error: error creating generated mainfile: open mage_output_file.go: permission denied exit status 1
这是因为mage@v1.12.1文件夹及其中的文件只有可读属性:
$ ll ~/gopath/pkg/mod/github.com/magefiledr-xr-xr-x、 9 dongxw dongxw 4096 Feb 8 16:22 mage@v1.11.0dr-xr-xr-x、10 dongxw dongxw 4096 Feb 8 16:40 mage@v1.12.1
为其添加可写属性后,即可执行成功:
$ go run bootstrap.go Running target: Installexec: go "env" "GOBIN"exec: go "env" "GOPATH"exec: git "rev-parse" "--short" "HEAD"fatal: Not a git repository (or any parent up to mount point /home)Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).exec: git "describe" "--tags"fatal: Not a git repository (or any parent up to mount point /home)Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).exec: go "build" "-o" "/home/dongxw/gopath/bin/mage" "-ldflags=-X "github.com/magefile/mage/mage.timestamp=2022-02-08T16:40:51+08:00" -X "github.com/magefile/mage/mage.commitHash=" -X "github.com/magefile/mage/mage.gitTag=dev"" "github.com/magefile/mage"
此时mage的可执行文件已经安装在$GOPATH/bin路径下。在~/.bashrc文件中更改PATH:
PATH=$GOPATH/bin:$PATH
https://github.com/magefile/mage
6、下载datasource plugin到Grafana的plugins文件夹下测试了两种datasource plugin,分别为keck-observatory-epics-grafana-datasource和sasaki77-archiverappliance-datasource。
6.1 下载keck-observatory-epics-grafana-datasource$ wget https://github.com/KeckObservatory/epics-grafana-datasource.zip$ sudo unzip epics-grafana-datasource-master.zip -d /var/lib/grafana/plugins
6.2 下载sasaki77-archiverappliance-datasource$ wget https://github.com/sasaki77/archiverappliance-datasource/releases/archiverappliance-datasource-1.3.3.tar.gz$ tar -zxvh archiverappliance-datasource-1.3.3.tar.gz$ cd /var/lib/grafana/plugins$ sudo mv /home/dongxw/archiverappliance-datasource-1.3.3 .
7、构建plugin 7.1 使用keck-observatory-epics-grafana-datasource$ cd /var/lib/grafana/plugins/epics-grafana-datasource-master/$ mage -v$ yarn install --ignore-enginesyarn install v1.22.17[1/4] Resolving packages...[2/4] Fetching packages...[3/4] linking dependencies...warning "@grafana/toolkit > @grafana/eslint-config@1.0.0-rc1" has incorrect peer dependency "eslint-plugin-jsdoc@^21.0.0".warning "@grafana/toolkit > @grafana/ui > storybook-dark-mode@0.4.0" has unmet peer dependency "@storybook/api@>= 5.x".warning "@grafana/toolkit > @grafana/ui > storybook-dark-mode@0.4.0" has unmet peer dependency "@storybook/addons@>= 5.x".warning "@grafana/toolkit > @grafana/ui > storybook-dark-mode@0.4.0" has unmet peer dependency "@storybook/components@>= 5.x".warning "@grafana/toolkit > @grafana/ui > storybook-dark-mode@0.4.0" has unmet peer dependency "@storybook/core-events@>= 5.x".warning "@grafana/toolkit > @grafana/ui > storybook-dark-mode@0.4.0" has unmet peer dependency "@storybook/theming@>= 5.x".warning "@grafana/toolkit > @grafana/ui > @grafana/slate-react > slate-react-placeholder@0.2.9" has unmet peer dependency "slate-react@>=0.22.0".[4/4] Building fresh packages...Done in 271.61s.$ yarn buildyarn run v1.22.17$ grafana-toolkit plugin:build鉅?Preparing Created: /var/lib/grafana/plugins/epics-grafana-datasource-master/.prettierrc.js鉁?Preparing鉁?Linting鉅?Running tests Using standard jest plugin config /var/lib/grafana/plugins/epics-grafana-datasource-master/node_modules/@grafana/toolkit/src/config/jest.plugin.config.local.jsNo tests found, exiting with code 0鉁?Running tests鉅?Compiling..、 Starting type checking service... Using 1 worker with 2048MB memory limit鉅?Compiling..、 Browserslist: caniuse-lite is outdated、Please run: npx browserslist@latest --update-db鉅?Compiling..、 Hash: 91397ae504d2f08e5a19 Version: webpack 4.41.5 Time: 7132ms Built at: 02/08/2022 5:06:26 PM Asset Size Chunks Chunk Names LICENSE 11.1 KiB [emitted] README.md 1.79 KiB [emitted] img/logo.svg 13.7 KiB [emitted] module.js 16.8 KiB 0 [emitted] module module.js.LICENSE.txt 808 bytes [emitted] module.js.map 81.7 KiB 0 [emitted] [dev] module plugin.json 942 bytes [emitted] Entrypoint module = module.js module.js.map [0] external "react" 42 bytes {0} [built] [1] external "@grafana/ui" 42 bytes {0} [built] [2] ../node_modules/lodash/isObject.js 733 bytes {0} [built] [6] ../node_modules/lodash/identity.js 370 bytes {0} [built] [10] ../node_modules/lodash/eq.js 799 bytes {0} [built] [11] ../node_modules/lodash/isArrayLike.js 830 bytes {0} [built] [13] ../node_modules/lodash/_isIndex.js 759 bytes {0} [built] [15] external "@grafana/data" 42 bytes {0} [built] [16] external "@grafana/runtime" 42 bytes {0} [built] [17] ../node_modules/lodash/defaults.js 1.71 KiB {0} [built] [18] ../node_modules/lodash/_baseRest.js 559 bytes {0} [built] [19] ../node_modules/lodash/_overRest.js 1.07 KiB {0} [built] [35] ../node_modules/lodash/_isIterateeCall.js 877 bytes {0} [built] [36] ../node_modules/lodash/keysIn.js 778 bytes {0} [built] [51] ./module.ts + 5 modules 21.6 KiB {0} [built] | ./module.ts 296 bytes [built] | ./DataSource.ts 1.6 KiB [built] | ./ConfigEditor.tsx 2.58 KiB [built] | ./QueryEditor.tsx 6.97 KiB [built] | ../node_modules/tslib/tslib.es6.js 10 KiB [built] | ./types.ts 91 bytes [built] + 37 hidden modules 鉁?Compiling...Done in 17.13s.$ mage -vRunning dependency: github.com/grafana/grafana-plugin-sdk-go/build.Build.Backend-fmRunning dependency: github.com/grafana/grafana-plugin-sdk-go/build.Build.Darwin-fmRunning dependency: github.com/grafana/grafana-plugin-sdk-go/build.Build.Linux-fmRunning dependency: github.com/grafana/grafana-plugin-sdk-go/build.Build.Windows-fmexec: go build -o dist/gpx_epics-grafana-datasource_darwin_amd64 -tags netgo -ldflags -w ./pkgexec: go build -o dist/gpx_epics-grafana-datasource_windows_amd64.exe -tags netgo -ldflags -w ./pkgexec: go build -o dist/gpx_epics-grafana-datasource_linux_amd64 -tags netgo -ldflags -w ./pkg
7.2 使用sasaki77-archiverappliance-datasource$ cd /var/lib/grafana/plugins/archiverappliance-datasource-1.3.3/########## build frontend ##########$ yarn install --ignore-engines # 若未加--ignore-engines,则会提示node版本错误$ yarn dev # Build plugin in development modeyarn run v1.22.17$ grafana-toolkit plugin:dev鉁?Linting鉅?Bundling plugin in dev mode Starting type checking service... Using 1 worker with 2048MB memory limit鉅?Bundling plugin in dev mode Browserslist: caniuse-lite is outdated、Please run: npx browserslist@latest --update-db鉅?Bundling plugin in dev mode Hash: 0c3dd2d9e1067553ff8f Version: webpack 4.41.5 Time: 15185ms Built at: 02/09/2022 3:24:35 PM Asset Size Chunks Chunk Names CHANGELOG.md 3.2 KiB [emitted] LICENSE 1.09 KiB [emitted] README.md 8.3 KiB [emitted] dark.js 3.85 KiB dark [emitted] dark dark.js.map 3.62 KiB dark [emitted] [dev] dark img/EPICS_Logo.png 2.47 KiB [emitted] light.js 3.86 KiB light [emitted] light light.js.map 3.62 KiB light [emitted] [dev] light module.js 4.35 MiB module [emitted] [big] module module.js.map 3.09 MiB module [emitted] [dev] module plugin.json 1.1 KiB [emitted] styles/dark.css 679 bytes dark [emitted] dark styles/dark.css.map 1.05 KiB dark [emitted] [dev] dark styles/light.css 680 bytes light [emitted] light styles/light.css.map 1.05 KiB light [emitted] [dev] light Entrypoint module [big] = module.js module.js.map Entrypoint light = styles/light.css light.js styles/light.css.map light.js.map Entrypoint dark = styles/dark.css dark.js styles/dark.css.map dark.js.map [../node_modules/ms/index.js] 2.95 KiB {module} [built] [../node_modules/tslib/tslib.es6.js] 10 KiB {module} [built] [../node_modules/uuid/dist/esm-browser/index.js] 412 bytes {module} [built] [./DataSource.ts] 23.6 KiB {module} [built] [./aafunc.ts] 6.6 KiB {module} [built] [./components/ConfigEditor.tsx] 1.81 KiB {module} [built] [./components/QueryEditor.tsx] 11.9 KiB {module} [built] [./components/index.ts] 91 bytes {module} [built] [./module.ts] 479 bytes {module} [built] [./styles/dark.css] 39 bytes {dark} [built] [./styles/light.css] 39 bytes {light} [built] [?86c8] css ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src??ref--6-2!./styles/dark.css 642 bytes {dark} [?fe0f] css ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src??ref--6-2!./styles/light.css 642 bytes {light} [@grafana/data] external "@grafana/data" 42 bytes {module} [built] [@grafana/runtime] external "@grafana/runtime" 42 bytes {module} [built] + 1040 hidden modules Child mini-css-extract-plugin ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src/index.js??ref--6-2!styles/dark.css: Entrypoint mini-css-extract-plugin = * [../node_modules/css-loader/dist/cjs.js?!../node_modules/postcss-loader/src/index.js?!./styles/dark.css] ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src??ref--6-2!./styles/dark.css 1.91 KiB {mini-css-extract-plugin} [built] [../node_modules/css-loader/dist/runtime/api.js] 2.46 KiB {mini-css-extract-plugin} [built] Child mini-css-extract-plugin ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src/index.js??ref--6-2!styles/light.css: Entrypoint mini-css-extract-plugin = * [../node_modules/css-loader/dist/cjs.js?!../node_modules/postcss-loader/src/index.js?!./styles/light.css] ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src??ref--6-2!./styles/light.css 1.91 KiB {mini-css-extract-plugin} [built] [../node_modules/css-loader/dist/runtime/api.js] 2.46 KiB {mini-css-extract-plugin} [built] 鉁?Bundling plugin in dev modeDone in 27.52s.$ yarn build # Build plugin in production modeyarn run v1.22.17$ grafana-toolkit plugin:build Using Node.js [object Object] Using @grafana/toolkit [object Object]鉁?Preparing鉁?Lintingts-jest[config] (WARN) The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` insteadts-jest[config] (WARN) The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` insteadts-jest[config] (WARN) The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` instead PASS src/specs/utils.test.ts (19.9 s) PASS src/components/QueryEditor.test.tsx (80.99 s) PASS src/specs/aafunc.test.ts (101.021 s) PASS src/components/FunctionParams.test.tsx (8.707 s) PASS src/components/FunctionParam.test.tsx PASS src/components/Functions.test.tsx (9.757 s) PASS src/components/FunctionElem.test.tsx PASS src/components/ConfigEditor.test.tsx PASS src/components/FunctionAdd.test.tsx PASS src/specs/datasource.test.ts (126.526 s)Test Suites: 10 passed, 10 totalTests: 88 passed, 88 totalSnapshots: 12 passed, 12 totalTime: 130.383 sRan all test suites with tests matching "".鉁?Running tests鉅?Compiling..、 Starting type checking service... Using 1 worker with 2048MB memory limit鉅?Compiling..、 Browserslist: caniuse-lite is outdated、Please run: npx browserslist@latest --update-db鉅?Compiling..、 Hash: 2a1c1058abae74a680f6 Version: webpack 4.41.5 Time: 24365ms Built at: 02/09/2022 3:27:50 PM Asset Size Chunks Chunk Names CHANGELOG.md 3.2 KiB [emitted] LICENSE 1.09 KiB [emitted] README.md 8.3 KiB [emitted] dark.js 1010 bytes 0 [emitted] dark dark.js.map 4.53 KiB 0 [emitted] [dev] dark img/EPICS_Logo.png 2.47 KiB [emitted] light.js 1010 bytes 1 [emitted] light light.js.map 4.53 KiB 1 [emitted] [dev] light module.js 256 KiB 2 [emitted] [big] module module.js.LICENSE.txt 399 bytes [emitted] module.js.map 1.45 MiB 2 [emitted] [dev] module plugin.json 1.1 KiB [emitted] styles/dark.css 545 bytes 0 [emitted] dark styles/light.css 542 bytes 1 [emitted] light Entrypoint module [big] = module.js module.js.map Entrypoint light = styles/light.css light.js light.js.map Entrypoint dark = styles/dark.css dark.js dark.js.map [0] external "react" 42 bytes {2} [built] [1] external "lodash" 42 bytes {2} [built] [3] external "@grafana/data" 42 bytes {2} [built] [4] external "@grafana/ui" 42 bytes {2} [built] [7] external "@grafana/runtime" 42 bytes {2} [built] [15] ../node_modules/react-autosuggest/dist/index.js 68 bytes {2} [built] [19] external "rxjs" 42 bytes {2} [built] [35] ../node_modules/ms/index.js 2.95 KiB {2} [built] [36] ../node_modules/lodash/defaults.js 1.71 KiB {2} [built] [94] ./styles/light.css 39 bytes {1} [built] [95] ./styles/dark.css 39 bytes {0} [built] [96] ./module.ts + 313 modules 1.2 MiB {2} [built] | ./module.ts 479 bytes [built] | ./DataSource.ts 23.6 KiB [built] | ./components/index.ts 91 bytes [built] | ../node_modules/tslib/tslib.es6.js 10 KiB [built] | ./types.ts 643 bytes [built] | ./aafunc.ts 6.6 KiB [built] | ./utils.ts 3.1 KiB [built] | ./components/QueryEditor.tsx 11.9 KiB [built] | ./components/ConfigEditor.tsx 1.81 KiB [built] | ../node_modules/uuid/dist/esm-browser/validate.js 141 bytes [built] | ../node_modules/uuid/dist/esm-browser/stringify.js 1.43 KiB [built] | ../node_modules/uuid/dist/esm-browser/v4.js 544 bytes [built] | ./dataProcessor.ts 5.54 KiB [built] | ./components/Functions.tsx 3.73 KiB [built] | ../node_modules/uuid/dist/esm-browser/rng.js 1.02 KiB [built] | + 299 hidden modules [99] ../node_modules/uuid/dist/esm-browser/index.js 412 bytes [built] [] css ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src??ref--6-2!./styles/dark.css 642 bytes {0} [] css ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src??ref--6-2!./styles/light.css 642 bytes {1} + 723 hidden modules Child mini-css-extract-plugin ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src/index.js??ref--6-2!styles/dark.css: Entrypoint mini-css-extract-plugin = * [0] ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src??ref--6-2!./styles/dark.css 1.91 KiB {0} [built] [1] ../node_modules/css-loader/dist/runtime/api.js 2.46 KiB {0} [built] Child mini-css-extract-plugin ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src/index.js??ref--6-2!styles/light.css: Entrypoint mini-css-extract-plugin = * [0] ../node_modules/css-loader/dist/cjs.js??ref--6-1!../node_modules/postcss-loader/src??ref--6-2!./styles/light.css 1.91 KiB {0} [built] [1] ../node_modules/css-loader/dist/runtime/api.js 2.46 KiB {0} [built] 鉁?Compiling...Done in 163.80s.######### build backend #########$ mage -vRunning dependency: github.com/grafana/grafana-plugin-sdk-go/build.Build.LinuxARM-fmRunning dependency: github.com/grafana/grafana-plugin-sdk-go/build.Build.Linux-fmRunning dependency: github.com/grafana/grafana-plugin-sdk-go/build.Build.LinuxARM64-fmRunning dependency: github.com/grafana/grafana-plugin-sdk-go/build.Build.Darwin-fmRunning dependency: github.com/grafana/grafana-plugin-sdk-go/build.Build.Windows-fmexec: go build -o dist/gpx_archiver-datasource-backend_linux_arm64 -ldflags -w -s -extldflags "-static" ./pkgexec: go build -o dist/gpx_archiver-datasource-backend_linux_arm -ldflags -w -s -extldflags "-static" ./pkgexec: go build -o dist/gpx_archiver-datasource-backend_windows_amd64.exe -ldflags -w -s -extldflags "-static" ./pkgexec: go build -o dist/gpx_archiver-datasource-backend_darwin_amd64 -ldflags -w -s -extldflags "-static" ./pkgexec: go build -o dist/gpx_archiver-datasource-backend_linux_amd64 -ldflags -w -s -extldflags "-static" ./pkg
8、更改Grafana配置并重启其服务$ sudo vi /etc/grafana/grafana.ini 去掉allow_loading_unsigned_plugins注释并作如下更改:allow_loading_unsigned_plugins = sasaki77-archiverappliance-datasource # 或keck-observatory-epics-grafana-datasource$ systemctl restart grafana-server
9、打开网页端进行相应设置 打开web浏览器,访问http://localhost:3000,进入Grafana登录页面,用户名和密码都为admin;参考sasaki77-archiverappliance-datasource的设置方式进行datasource的添加和设置。 【其它参考文章】 Grafana 的插件开发
Grafana容器的文件路径、数据保存、配置文件的位置及环境变量的使用
Grafana 插件开发从零到一
Grafana入门系列