Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Golang 1.10.3 + Datadog Agent v6 on Raspberry Pi 3 (armv7l Debian Jessie)

Background:

I had trouble running the Datadog Agent (v6) on my Raspberry Pi. Here's what I did to get it running.

Sections:

  1. Installing Go (skip if you already have Go 1.9+)
  2. Install/build the Datadog Agent

System Info:

pxpi is the Raspberry Pi's host name.

root@pxpi:/etc/datadog-agent# uname -a

Linux pxpi 4.14.50-v7+ #1122 SMP Tue Jun 19 12:26:26 BST 2018 armv7l GNU/Linux
root@pxpi:/etc/datadog-agent# cat /etc/*rel*

/usr/lib/arm-linux-gnueabihf/libarmmem.so
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

1. Install Go (Golang): without GVM

Note: I haven't tried gvm, but the corresponding guide is here: https://github.com/tgogos/rpi_golang#2-with-go-version-manager-gvm. The rest of this guide will show how to install Go without GVM.

Note: This is from this fork of tgogos/rpi_golang, which has instructions on how to install Go version 1.10.3.

Quick Summary:

  1. Use the pre-built binary in the repo to install Go 1.4.3
  2. Optionally use Go 1.4.3 to upgrade (build) Go 1.10.3

This presumes you're the root user. If you are not, you may need to append sudo to some of the following commands.

Optionally, ensure that the following directories do not exist as they may conflict with the process.

  • /usr/local/go
  • $HOME/go1.4

1. Clone the repo:

git clone https://github.com/tgogos/rpi_golang.git
cd rpi_golang/

2. Install either only 1.4.3 or upgrade to 1.10.3:

For 1.4.3 only:

If you have no intention of upgrading to 1.10.3, you can untar the binary in the repo into /usr/local.

# untar into /usr/local
tar -xzf go1.4.3.linux-armv7.tar.gz -C /usr/local

# Add to shell and .bashrc
export PATH=/usr/local/go/bin:$PATH
echo "export PATH=/usr/local/go/bin:$PATH" >> $HOME/.bashrc

# go version should now output something
go version

# If you're happy with 1.4, you can stop at this point.

You're done!

For 1.10.3:

If you would like to upgrade to 1.10.3, follow this to untar the binary from the repo into a different location, and use it to bootstrap the build:

Run rm -rf /usr/local/go if you accidentally made this directory already.

# We use the 1.4 binary in the repo to bootstrap building 1.10:
# While still in rpi_golang directory, make the alternate directory:
mkdir -p $HOME/go1.4

# Untar into that directory
tar -xzf go1.4.3.linux-armv7.tar.gz -C $HOME/go1.4 --strip-components=1

# Download and untar the 1.10.3 src into /usr/local
wget https://dl.google.com/go/go1.10.3.src.tar.gz
tar -xz -C /usr/local -f go1.10.3.src.tar.gz

Build 1.10.3:

cd /usr/local/go/src

time GOROOT_BOOTSTRAP=$HOME/go1.4 ./make.bash

Output:

A successful output will look something like:

root@pxpi:/usr/local/go/src# time GOROOT_BOOTSTRAP=$HOME/go1.4 ./make.bash

Building Go cmd/dist using /root/go1.4.
Building Go toolchain1 using /root/go1.4.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.


Building packages and commands for linux/arm.
---
Installed Go for linux/arm in /usr/local/go
Installed commands in /usr/local/go/bin

real    8m42.421s
user    18m36.579s
sys     0m44.624s


# go version:
root@pxpi:/usr/local/go/src# go version
go version go1.10.3 linux/arm

Set up your paths and environment variables:

Add the following to your .bashrc, .bash_profile, .zshrc, or what have you.

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

Don't forget to source it or reload your shell.


Install datadog-agent

Building for 32-bit ARM requires the Puppy variant of the datadog agent. See: https://github.com/DataDog/datadog-agent/issues/1069

1. Install dependencies:

  • Python2.7
  • invoke
  • Go 1.9+
  • dep

1. Install system dependencies:

This presumes you are root or have sudo access. Optionally what you already have:

# For all:
sudo apt-get update

# Python 2.7
sudo apt-get install python2.7-dev

# Install snmpd -- not sure if this is needed for the Puppy agent
sudo apt-get install libsnmp-base libsnmp-dev snmp-mibs-downloader

# Install systemd dev -- again, not sure if this is built against on the Puppy agent
sudo apt-get install libsystemd-dev

2. Installing invoke:

pip install invoke

3. Installing dep:

Dep does not support ARM binaries. You must go get it.

go get -u github.com/golang/dep/cmd/dep

The following should now work if $GOPATH is set up correctly. If it is not set up correctly, do so now. Remember that go env will print out Go env vars which is not necessarily the same as your shell's.

root@pxpi:/etc/datadog-agent# dep
Dep is a tool for managing dependencies for Go projects

Usage: "dep [command]"
[...]

2. Download/clone datadog agent source

The current README's example states to clone the directory (especially if you would like the master branch) but I'm guessing go get -u github.com/DataDog/datadog-agent should work as essentially the same:

git clone https://github.com/DataDog/datadog-agent.git $GOPATH/src/github.com/DataDog/datadog-agent

3. Building the agent

Building for 32-bit ARM requires the Puppy variant of the datadog agent. See: https://github.com/DataDog/datadog-agent/issues/1069

cd $GOPATH/src/github.com/DataDog/datadog-agent

invoke deps
invoke agent.build --puppy

Check if it runs:

From https://github.com/DataDog/datadog-agent/blob/master/README.md#run:

cd $GOPATH/src/github.com/DataDog/datadog-agent

# Might error out unless you set an API key in 
# ./bin/agent/dist/datadog.yaml
# You can also export it as `DD_API_KEY`
# e.g. export DD_API_KEY=1234

./bin/agent/agent -c bin/agent/dist/datadog.yaml

# OR
# DD_API_KEY=<KEY HERE> ./bin/agent/agent -c bin/agent/dist/datadog.yaml

5. Postinstall (optional):

Move and/or copy files into expected directories

This depends on your preferences, but this is how I decided to finalize my install:

Move $GOPATH/src/github.com/DataDog/datadog-agent/ into /opt/ (to be compatible with normal package distributions).

cd $GOPATH/src/github.com/DataDog/
mv datadog-agent /opt/

Copy the config files into /etc/datadog-agent and edit as necessary:

mkdir -p /etc/datadog-agent/

cd /opt/datadog-agent/bin/agent/dist
cp -r . /etc/datadog-agent/

Edit /etc/datadog-agent/datadog.yaml to add your API key.

Configure a user:

I didn't need to do this part since I have a specific user/group setup for my development machines, but this is to illustrate how you might.

This is similar to how it's done in the Dockerfile.

The difference here is that I didn't add it to the root group, but you can choose to do what you'd like.

# create user if it does not yet exist
adduser --system --no-create-home --disabled-password --ingroup dd-agent dd-agent

# Give permissions to relevant directories
chown -R dd-agent:dd-agent /etc/datadog-agent/ /opt/datadog-agent/ /var/log/datadog/
chmod g+r,g+w,g+X -R /etc/datadog-agent/ /var/log/datadog/

(To add dd-agent to the root group, you can do the following instead of the above adduser command, then chown accordingly):

adduser --system --no-create-home --disabled-password --ingroup root dd-agent
chown -R dd-agent:root /etc/datadog-agent/ /opt/datadog-agent/ /var/log/datadog/

With guidance from this file, here's the systemd service for the puppy agent:

root@pxpi:~# cat /lib/systemd/system/datadog-agent.service

[Unit]
Description="Datadog Agent"
After=network.target

[Service]
Type=simple
PIDFile=/opt/datadog-agent/run/agent.pid
User=dd-agent
Restart=on-failure
ExecStart=/opt/datadog-agent/bin/agent/agent start -p /opt/datadog-agent/run/agent.pid

[Install]
WantedBy=multi-user.target

For more post-install steps on Debian-ish systems, you can also take a look at the omnibus postinstall script in the datadog agent repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.