smokeping-guide/README.md
2020-07-25 18:35:35 +01:00

166 lines
5.0 KiB
Markdown

# Smokeping Guide
This guide will walk you through how to set up smokeping on a raspberry pi using docker and ubuntu server.
## Install Ubuntu Server
### Download Ubuntu Image
In our example we're using a pi 3, so we'll go and grab their Ubuntu install image from [here](https://ubuntu.com/download/raspberry-pi). When choosing the image, I recommend using 64 bit.
### Install Etcher
You can use any variety of programs for this, including something as basic as ```dd```, however for ease of use I recommend using [etcher](https://www.balena.io/etcher/). Once downloaded, install the program.
### Write image
Once etcher is installed, unzip the the Ubuntu Server image and use etcher to write it to an SD card. It will prompt you to type in a password, this is normal.
_If the SD card was already mounted it may fail, just retry and it should work fine._
### Edit pre-boot configuration files
Once etcher has finished, macos will automatically mount the boot partition of the SD card ready for use. Ubuntu server ships with two files in the boot partition to allow customisations such as network config and passwords before first boot:
[network-config](config_files/network-config)<br>
[user-data](config_files/user-data)
_These config files are only used on the first boot, modifying them after first boot will have no effect. If you want to re-apply you must re-flash the SD card or manually edit the pi's configuration files by logging in to it._
#### network-config
The [network-config](config_files/network-config) set up the network interfaces for options such as:
* DHCP
* Static IP
* Wifi Networks
For the purposes of this tutorial it is safe to leave it as standard - this will give the pi a dynamic DHCP address.
#### user-data
The [user-data](config_files/user-data) file is used for a variety of configuration items, such as setting up users, installing packages, configuring hostnames etc. For the purposes of this tutorial we are going to do the following things:
* Disable automatic password expiry for the default user
* set the hostname to _smokepi_
To do this, edit the ```user-data``` config file, find the following section and modify it from:
```
chpasswd:
expire: false
list:
- ubuntu:ubuntu
```
To:
```
chpasswd:
expire: true
list:
- ubuntu:ubuntu
hostname: smokepi
```
Optionally you could change the default user from _ubuntu_ to _adam_ and the default password from _ubuntu_ to _password1_ by changing it to this instead:
```
chpasswd:
expire: true
list:
- adam:password1
hostname: smokepi
```
### First boot
Once the pi has booted, we must wait for it to stop installing updates before we can continue. To check this, run the following command:
```bash
while true; do date; ps aux | grep unattended; sleep 5; done
```
This will start a never-ending command that will print all processes matching "unattended" back to the console. When updates are complete, it should simply return two lines that match.
### Install Docker
This section was taken from docker's own documentation available [here](https://docs.docker.com/engine/install/ubuntu/).
#### Install pre-requisites
First we must install the packages that Ubuntu needs in order to configure the docker repository:
```bash
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
```
#### Add Docker GPG key
Next we must install Docker's GPG key so that your pi trusts the docker packages it is about to install:
```bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
```
#### Add Docker repositories
Now we will install the docker packages. If you installed 64 bit Ubuntu (recommended), run:
```bash
sudo add-apt-repository \
"deb [arch=arm64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
```
If you installed 32 bit Ubuntu, run:
```bash
sudo add-apt-repository \
"deb [arch=armhf] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
```
#### Install Docker packages
Now we must install docker itself with the following commands:
```bash
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
```
#### Add ubuntu user to docker groups
Now we must add the _ubuntu_ user to the _docker_ group. Doing this ensures that you can run the `docker` command without prefixing it with `sudo`:
```bash
usermod -aG docker ubuntu
```
Once this is done you will need to disconnect and reconnect your ssh connection in order for your user's group membership to be picked up.
_If you changed the username in the [user-data](#user-data), change `ubuntu` for whichever username you chose._
### Test that docker is working
Finally you should check that docker is up and running by running `docker ps`. Below is what the output should look like when running the command:
```bash
ubuntu@smokepi:~/ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
```
#### Clear graphs
```
sudo rm -rf /opt/smokeping/data/*
```