我是在centos7上面編譯,安裝部署了一套go環境,核心配置見/etc/profilenode
[root@base-node beats]# cat /etc/profileexport GOROOT=/usr/local/goexport GOPATH=/usr/local/app/goProjectexport GOBIN=$GOPATH/binexport PATH=$PATH:$GOROOT/binexport PATH=$PATH:$GOPATH/bin[root@base-node beats]#
Golang交叉編譯各個平臺的二進制文件
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build main.go #這裏會編譯出來一個二進制main文件
若是你想編譯出來其餘版本的程序文件,你能夠參考這段代碼linux
# mac上編譯linux和windows二進制
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build
# linux上編譯mac和windows二進制
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build
# windows上編譯mac和linux二進制
SET CGO_ENABLED=0 SET GOOS=darwin SET GOARCH=amd64 go build main.go
SET CGO_ENABLED=0 SET GOOS=linux SET GOARCH=amd64 go build main.go
若是想編譯出來其餘平臺的二進制filebeat,能夠參考這個表格android
GOOS - Target Operating System | GOARCH - Target Platform | |
android | arm | |
darwin | 386 | |
darwin | amd64 | |
darwin | arm | |
darwin | arm64 | |
dragonfly | amd64 | |
freebsd | 386 | |
freebsd | amd64 | |
freebsd | arm | |
linux | 386 | |
linux | amd64 | |
linux | arm | |
linux | arm64 | |
linux | ppc64 | |
linux | ppc64le | |
linux | mips | |
linux | mipsle | |
linux | mips64 | |
linux | mips64le | |
netbsd | 386 | |
netbsd | amd64 | |
netbsd | arm | |
openbsd | 386 | |
openbsd | amd64 | |
openbsd | arm | |
plan9 | 386 | |
plan9 | amd64 | |
solaris | amd64 | |
windows | 386 | |
windows | amd64 |
這裏有幾個注意的點git
一、我下載了filebeat-6.8.6-linux-x86_64.tar.gz , 而後我將上面編譯出來的二進制main文件, 替換掉壓縮包裏面filebeat文件github
二、這裏會報一個錯誤,經過修改libbeat/common/file/stderr_other.go文件解決golang
[root@base-node beats]# cat libbeat/common/file/stderr_other.go// Licensed to Elasticsearch B.V. under one or more contributor// license agreements. See the NOTICE file distributed with// this work for additional information regarding copyright// ownership. Elasticsearch B.V. licenses this file to you under// the Apache License, Version 2.0 (the "License"); you may// not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing,// software distributed under the License is distributed on an// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY// KIND, either express or implied. See the License for the// specific language governing permissions and limitations// under the License.// +build !windowspackage fileimport ( "os" "golang.org/x/sys/unix")// RedirectStandardError causes all standard error output to be directed to the// given file.func RedirectStandardError(toFile *os.File) error { return unix.Dup2(int(toFile.Fd()), 2)}[root@base-node beats]#
經過一下比較發現問題出在libbeat/common/file/stderr_other.go文件sql
diff --git a/libbeat/common/file/stderr_other.go b/libbeat/common/file/stderr_other.goindex 99ad24c..2731322 100644--- a/libbeat/common/file/stderr_other.go+++ b/libbeat/common/file/stderr_other.go@@ -21,11 +21,11 @@ package file import ( "os"- "syscall"+ "golang.org/x/sys/unix" ) // RedirectStandardError causes all standard error output to be directed to the // given file. func RedirectStandardError(toFile *os.File) error {- return syscall.Dup2(int(toFile.Fd()), 2)+ return unix.Dup2(int(toFile.Fd()), 2) }
https://github.com/elastic/elasticsearchexpress
https://www.tecmint.com/install-pip-in-linux/apache
https://qiita.com/caad1229/items/325ca5c8ad198b0ebce7windows
https://forum.armbian.com/topic/13833-build-and-install-filebeat-on-arm-and-arm64-devices-using-armbian/
https://github.com/oscarlpez/filebeat-6.6.0-armv7
https://www.blog.lijinghua.club/article/golang-cross-compilation
https://www.blog.lijinghua.club/article/golang-cross-compilation
https://studygolang.com/articles/14376
https://www.jianshu.com/p/8f0646e3858c
本文分享自微信公衆號 - 架構師智庫(beijing-tmt)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。