Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wjx0912/03779bf38dff53e72fae2ae2a2104ce1 to your computer and use it in GitHub Desktop.
Save wjx0912/03779bf38dff53e72fae2ae2a2104ce1 to your computer and use it in GitHub Desktop.
Cross-compile Elastic Filebeat for ARM with docker. Works on Raspberry Pi 2 and 3.

Elastic does not provide Filebeat binaries for ARMv7. Luckily, Filebeat can easily be cross-compiled with:

# ----- Instantiate an immutable Go container for cross-compilation ----- #
mkdir build && cd $_
docker run -it --rm -v `pwd`:/build golang:1.11.4 /bin/bash

# ----- Inside Go container ----- #
go get github.com/elastic/beats
cd /go/src/github.com/elastic/beats/filebeat/
git checkout -b v6.5.4
GOARCH=arm go build
GOARCH=arm64 go build
cp filebeat /build
exit

# ----- Verify the output file ----- #
file filebeat
#filebeat: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped

The newly built Filebeat binary can then be uploaded to the remote PCM3, for example with http://transfer.sh

On the PCM3:

@wjx0912
Copy link
Author

wjx0912 commented Dec 20, 2018

before go get, set proxy for docker
export https_proxy=192.168.1.93:1080
export http_proxy=192.168.1.93:1080

@mystdeim
Copy link

I got error:

root@6b3f8de648f0:/go/src/github.com/elastic/beats/filebeat# GOARCH=arm go build
# github.com/elastic/beats/filebeat/input/kafka
input/kafka/input.go:201:10: undefined: strings.ReplaceAll

How did you compile?

@chapinb
Copy link

chapinb commented Jan 7, 2020

Looks like its an issue where golang in apt repos is currently v1.11.6, where strings.ReplaceAll became available in go v1.12 (per codewars/codewars.com#1861). Following this gist, I was able to get things working: https://gist.github.com/bigsan/c936451ed1a5b18bb8b0d7e8cc3e7212

@joariasl
Copy link

joariasl commented Jul 3, 2020

I have extended the file with the systemd configuration to start as service https://gist.github.com/joariasl/153a1d5253dc938429e2e5936339959a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment