龙芯电脑编译grafana过程
1、环境说明
操作系统:loongnix-server8.3
golang环境:yum install golang-1.18
go env -w GOPROXY=http://goproxy.loongnix.cn:3000,direct go env -w GOSUMDB=off
export GOPATH=/opt/gocode
mkdir $GOPATH/src/github.com/grafana/
2、下载源码
git项目地址:https://github.com/grafana/grafana
cd $GOPATH/src/github.com/grafana/grafana wget https://github.com/grafana/grafana/archive/refs/tags/v8.5.10.tar.gz
tar -zxvf v8.5.10.tar.gz
mv grafana-8.5.10/ grafana
cd grafana
3、后端编译
go run build.go setup
可能遇到问题一、
verifying golang.org/x/sys@v0.0.0-20220615213510-4f61da869c0c: checksum mismatch downloaded: h1:MJo64JfF5ptBALteqspGD/SCPpZEi2PhHN9XkEKz8TA= go.sum: h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU=
解决办法:
[root@localhost grafana]# rm -rf go.sum
[root@localhost grafana]# go mod tidy
可能遇到问题二、
........ github.com/grafana/grafana/pkg/components/dashdiffs imports github.com/yudai/gojsondiff tested by github.com/yudai/gojsondiff.test imports github.com/onsi/gomega imports github.com/onsi/gomega/matchers imports github.com/onsi/gomega/matchers/support/goraph/bipartitegraph imports github.com/onsi/gomega/matchers/support/goraph/edge loaded from github.com/onsi/gomega@v1.16.0, but go 1.16 would select v1.17.0 ........
解决办法:
go mod tidy -go=1.16 && go mod tidy -go=1.17
go mod tidy
继续编译:
go run build.go setup
完成后出现:
............
github.com/grafana/grafana/pkg/util/converter
github.com/grafana/grafana/pkg/services/alerting/notifiers
github.com/grafana/grafana/pkg/tsdb/prometheus/querydata
github.com/grafana/grafana/pkg/tsdb/prometheus
github.com/grafana/grafana/pkg/extensions
github.com/grafana/grafana/pkg/services/alerting/conditions
exit status 2
exit status 1
执行成功后继续执行:
可能遇到问题三、
/opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:59:26: X86 undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512BF16) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:60:28: X86.HasAVX512BITALG undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512BITALG) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:61:24: X86.HasAVX512BW undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512BW) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:62:24: X86.HasAVX512CD undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512CD) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:63:24: X86.HasAVX512DQ undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512DQ) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:64:24: X86.HasAVX512ER undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512ER) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:65:23: X86.HasAVX512F undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512F) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:66:26: X86.HasAVX512IFMA undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512IFMA) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:67:24: X86.HasAVX512PF undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512PF) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:68:26: X86.HasAVX512VBMI undefined (type struct{_ cpu.CacheLinePad; HasAES bool; HasADX bool; HasAVX bool; HasAVX2 bool; HasBMI1 bool; HasBMI2 bool; HasERMS bool; HasFMA bool; HasOSXSAVE bool; HasPCLMULQDQ bool; HasPOPCNT bool; HasRDRAND bool; HasRDSEED bool; HasSSE2 bool; HasSSE3 bool; HasSSSE3 bool; HasSSE41 bool; HasSSE42 bool; _ cpu.CacheLinePad} has no field or method HasAVX512VBMI) /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go:68:26: too many errors exit status 2 exit status 1
解决办法:
vi /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu/x86/x86.go
去掉相关HasAVX512BF16...所有的代码
wq!保存
vi /opt/gocode/pkg/mod/github.com/segmentio/asm@v1.1.1/cpu.go
import (
"github.com/segmentio/asm/cpu/arm"
"github.com/segmentio/asm/cpu/arm64"
"github.com/segmentio/asm/cpu/x86"
"github.com/segmentio/asm/cpu/loongarch64" 增加
)
var (
// X86 is the bitset representing the set of the x86 instruction sets are
// supported by the CPU.
X86 = x86.ABI()
// ARM is the bitset representing which parts of the arm instruction sets
// are supported by the CPU.
ARM = arm.ABI()
// ARM64 is the bitset representing which parts of the arm64 instruction
// sets are supported by the CPU.
ARM64 = arm64.ABI()
LOONGARCH64=loongarch64.ABI() 增加
)
wq!保存
可能遇到的问题4、
[root@localhost grafana]# go mod tidy go: github.com/grafana/loki@v1.6.2-0.20211015002020-7832783b1caa requires github.com/influxdata/telegraf@v1.16.3 requires github.com/hashicorp/consul@v1.2.1 (replaced by github.com/hashicorp/consul@v1.10.2): reading http://goproxy.loongnix.cn:3000/github.com/hashicorp/consul/@v/v1.10.2.mod: 404 Not Found
解决办法:
go env -w GOPROXY=https://goproxy.cn,direct
go mo tidy
可能遇到问题5、
pkg/cmd/grafana-server/commands/cli.go:170:19: undefined: server.Initialize
解决办法:
make gen-go
继续编译
go run build.go build
编译完成后,会看到文件目录下多了个bin文件夹
-rwxr-xr-x 1 root root 43583104 8月 26 16:20 grafana-cli -rw-r--r-- 1 root root 33 8月 26 16:20 grafana-cli.md5 -rwxr-xr-x 1 root root 90639640 8月 26 16:20 grafana-server -rw-r--r-- 1 root root 33 8月 26 16:20 grafana-server.md5
4、前端编译
npm install -g yarn
yarn install --pure-lockfile npm install -g grunt-cli grunt
但还是有很多的报错,是因为npm包里有不兼容loongarch64架构的代码,可以修改后解决,这里投机取巧了以下,使用以下替代办法:
替代办法:
wget https://dl.grafana.com/oss/release/grafana-8.5.10.linux-amd64.tar.gz
tar -zxvf grafana-8.5.10.linux-amd64.tar.gz
cd grafana-8.5.10/bin
rm -rf *
然后将第三步编译的grafana-server、grafana-cli拷贝到bin目录下即可
cd bin
./grafana-server
5、浏览器中测试
http://ip:3000 登录即可