我是在centos7上面编译,安装部署了一套go环境,核心配置见/etc/profile

[root@base-node beats]# cat /etc/profile
export GOROOT=/usr/local/go
export GOPATH=/usr/local/app/goProject
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
export PATH=$PATH:$GOPATH/bin
[root@base-node beats]#

Golang交叉编译各个平台的二进制文件

CGO_ENABLED=0  GOOS=linux  GOARCH=arm64 go build main.go  #这里会编译出来一个二进制main文件

如果你想编译出来其他版本的程序文件,你可以参考这段代码

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,可以参考这个表格

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

这里有几个注意的点 1、我下载了filebeat-6.8.6-linux-x86_64.tar.gz , 然后我将上面编译出来的二进制main文件, 替换掉压缩包里面filebeat文件 2、这里会报一个错误,通过修改libbeat/common/file/stderr_other.go文件解决

[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 !windows
package file
import (
    "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文件

diff --git a/libbeat/common/file/stderr_other.go b/libbeat/common/file/stderr_other.go
index 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/elasticsearch https://www.tecmint.com/install-pip-in-linux/ https://qiita.com/caad1229/items/325ca5c8ad198b0ebce7 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