Windows下部署Grafana的前端与后端开发环境的过程
Grafana地址:https://github.com/grafana/grafana
依赖项:
Go 1.10
NodeJS LTS
go是后端,NodeJS是前端的。
首先我们搭建后端环境:
1、安装GO,设置环境变量信息等。
2、后端编译要用到GCC,所以需要安装GCC
以上步骤可参考,写的非常详细。:https://studygolang.com/articles/11384?fr=sidebar
3、grafana在github上给的后端构建命令如下:
Building the backend
go get github.com/grafana/grafana cd $GOPATH/src/github.com/grafana/grafana go run build.go setup go run build.go build
如果能用官方的命令是最好,方便快捷。
但是在国内并不一定访问的挺好,可能通过命令下载不下来。
所以本人是在浏览器中直接下载下来,然后自己组织构建目录的。反正就是别怕出错随便搞有错就修改。
例如:
golang.dep的目录结构:src\github.com\golang\dep
grafana主目录:src\github.com\grafana\grafana
然后进入grafana主目录:src\github.com\grafana\grafana
执行命令:go run build.go setup
setup执行成功后,就执行build命令:go run build.go build
这2条命令的成功执行结果大概如此:
PS E:\goworkspace\grafana\src\github.com\grafana\grafana> go run build.go setup Version: 5.3.0-pre1, Linux Version: 5.3.0, Package Iteration: 1532831485pre1 go get -v github.com/golang/dep go install -v ./pkg/cmd/grafana-server github.com/grafana/grafana/pkg/api/pluginproxy github.com/grafana/grafana/pkg/api github.com/grafana/grafana/pkg/cmd/grafana-server PS E:\goworkspace\grafana\src\github.com\grafana\grafana> go run build.go build Version: 5.3.0-pre1, Linux Version: 5.3.0, Package Iteration: 1532831534pre1 rm -r ./bin/windows-amd64/grafana-server.exe rm -r ./bin/windows-amd64/grafana-server.exe.md5 go version go version go1.10.3 windows/amd64 Targeting windows/amd64 go build -ldflags -w -X main.version=5.3.0-pre1 -X main.commit=unknown-dev -X main.buildstamp=1532831534 -o ./bin/windows-amd64/grafana-server.exe ./pkg/cmd/grafana-server rm -r ./bin/windows-amd64/grafana-cli.exe rm -r ./bin/windows-amd64/grafana-cli.exe.md5 go version go version go1.10.3 windows/amd64 Targeting windows/amd64 go build -ldflags -w -X main.version=5.3.0-pre1 -X main.commit=unknown-dev -X main.buildstamp=1532831539 -o ./bin/windows-amd64/grafana-cli.exe ./pkg/cmd/grafana-cli PS E:\goworkspace\grafana\src\github.com\grafana\grafana>成功执行后,会在grafana主目录生成构建生成的4个文件:
src\github.com\grafana\grafana\bin\windows-amd64
需要将这几个文件复制到bin目录下,grafana-server.exe才能启动。
访问地址:http://localhost:3000/login
得到结果是:html/template: "index" is undefined,应该是前端还没有构建访问不通。
如果想验证后端是否正常编译成功,可以将这4个文件复制到用grafana提供的安装包安装后的bin目录中,覆盖原内容,然后启动,就会使用我们编译后的后台内容。
打开golang就可以愉快的开发GO了。
搭建前端编译环境:
1、安装NodeJS
查看安装的版本:
PS E:\goworkspace\grafana\src\github.com\grafana\grafana> node -v v8.11.3 PS E:\goworkspace\grafana\src\github.com\grafana\grafana> npm -v 5.6.0 PS E:\goworkspace\grafana\src\github.com\grafana\grafana>
2、编译代码
官方提供的命令
npm install -g yarn yarn install --pure-lockfile npm run watch
网络环境好的话,非常方便,一路下来非常顺利。不好的话就自己看着办吧,主要麻烦就在依赖上,找百度吧。
进入grafana主目录:E:\goworkspace\grafana\src\github.com\grafana\grafana
执行:npm install -g yarn
PS E:\goworkspace\grafana\src\github.com\grafana\grafana> npm install -g yarn C:\Users\Administrator\AppData\Roaming\npm\yarnpkg -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js C:\Users\Administrator\AppData\Roaming\npm\yarn -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js + yarn@1.9.2 updated 1 package in 34.167s PS E:\goworkspace\grafana\src\github.com\grafana\grafana>
然后执行:yarn install --pure-lockfile
网络便宜,访问github都不通,基本上就是有的通,有的不通,有时候通,有时候又不行,全看心情:
PS E:\goworkspace\grafana\src\github.com\grafana\grafana> yarn install --pure-lockfile yarn install v1.9.2 [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.4: The platform "win32" is incompatible with this module. info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... [-/4] ⠠ waiting... [2/4] ⠐ node-sass [-/4] ⠐ waiting... error E:\goworkspace\grafana\src\github.com\grafana\grafana\node_modules\phantomjs-prebuilt: Command failed. Exit code: 1 Command: node install.js Arguments: Directory: E:\goworkspace\grafana\src\github.com\grafana\grafana\node_modules\phantomjs-prebuilt Output: PhantomJS not found on PATH Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip Saving to C:\Users\Administrator\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip Receiving... Error making request. Error: connect ETIMEDOUT 52.216.17.104:443 at Object._errnoException (util.js:992:11) at _exceptionWithHostPort (util.js:1014:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
这个错,网上的各种方法都试了不行,包括使用了淘宝镜像,cnpm,最后还是会去请求这个下载路径。
在最后参考了这篇文章:https://www.cnblogs.com/linyihai/p/7143719.html
其实它请求的那个路径,我在浏览器也访问不了,下载不成,最后放到XL里面,几十K的下载了老半天,才下载下来,然后把它丢到他要保存的缓存目录里面:
C:\Users\Administrator\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip
再执行:yarn install --pure-lockfile
果然不报phantomjs的错误了,又出来个新的:
................ gyp verb could not find "msbuild.exe" in PATH - finding location in registry gyp info spawn C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe gyp info spawn args [ 'build/binding.sln', gyp info spawn args '/nologo', gyp info spawn args '/p:Configuration=Release;Platform=x64' ] �ڴ˽��������һ������һ����Ŀ����Ҫ���ò������ɣ�����ӡ�/m�����ء� ������ʱ��Ϊ 2018/7/29 ������ 11:16:50�� �ڵ� 1 �ϵ���Ŀ��E:\goworkspace\grafana\src\github.com\grafana\grafana\node_modules\node-sass\build\binding.sln��(Ĭ��Ŀ��)�� ValidateSolutionConfiguration: �������ɽ���������á�Release|x64���� MSBUILD : error MSB3428: δ�ܼ��� Visual C++ �����VCBuild.exe����Ҫ��������⣬1) ��װ .NET Framework 2.0 SDK��2) ��װ Microsoft Visual Studio 2005���� 3) ������������װ��������λ�ã��뽫��λ����ӵ�ϵͳ·���С� [E:\goworkspace\grafana\src\github.com\grafana\grafana\node_modules\node-sass\build\binding.sln] �����������Ŀ��E:\goworkspace\grafana\src\github.com\grafana\grafana\node_modules\node-sass\build\binding.sln��(Ĭ��Ŀ��)�IJ��� - ʧ�ܡ� ����ʧ�ܡ� ��E:\goworkspace\grafana\src\github.com\grafana\grafana\node_modules\node-sass\build\binding.sln��(Ĭ��Ŀ��) (1) -> (_src_\libsass Ŀ��) -> MSBUILD : error MSB3428: δ�ܼ��� Visual C++ �����VCBuild.exe����Ҫ��������⣬1) ��װ .NET Framework 2.0 SDK��2) ��װ Microsoft Visual Studio 2005���� 3) ������������װ��������λ�ã��뽫��λ����ӵ�ϵͳ·���С� [E:\goworkspace\grafana\src\github.com\grafana\grafana\node_modules\node-sass\build\binding.sln] 0 ������ 1 ������ ����ʱ�� 00:00:00.42 gyp ERR! build error gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (E:\goworkspace\grafana\src\github.com\grafana\grafana\node_modules\node-gyp\lib\build.js:258:23) gyp ERR! stack at emitTwo (events.js:126:13) gyp ERR! stack at ChildProcess.emit (events.js:214:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12) gyp ERR! System Windows_NT 10.0.16299 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "E:\\goworkspace\\grafana\\src\\github.com\\grafana\\grafana\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd E:\goworkspace\grafana\src\github.com\grafana\grafana\node_modules\node-sass gyp ERR! node -v v8.11.3 gyp ERR! node-gyp -v v3.6.2
这个问题百度老半天,试了好多种没有解决,自己去找吧。过程是很不爽的。
2018-07-29前端环境没有搞好。
上一篇: Windows下部署Grafana的前端与后端开发环境的过程
下一篇: mac brew软件管理