Low Orbit Flux Logo 2 F

Better Otter Notes

These are the notes for the setup of my Raspberry Pi / ZFS based NAS / Mini home server.

Specs:

Raspberry Pi 4
Raspberry Pi OS ( 64 bit )
2 Kingston SATA SSDs
2 USB to SATA adapters

ZFS on USB SATA disks considerations and key points:

Objectives:

ZFS

Install ZFS:



sudo apt update
sudo apt install raspberrypi-kernel-headers zfs-dkms zfsutils-linux -y
sudo apt full-upgrade -y
sudo reboot
sudo apt autoremove && sudo apt clean

Check the disks:



lsblk
ls -la /dev/disk/by-id

Create a mirrored zpool:



sudo zpool create tank1 mirror /dev/disk/by-id/ata-KINGSTON_SA400S37240G_50026B7784E8AEAB /dev/disk/by-id/ata-KINGSTON_SA400S37240G_50026B7784E8AFD3

Check / verify:



zpool list
zpool status

Golang

The version of golang installed using the package manager was too old for Gogs. I removed it and re-installed using the manual method. Both methods are listed below.

Install using the package manager

Install the package:



apt update
apt install golang

Verify:



go
go version

Install manually

Pull the tar ball down from the web:



wget https://go.dev/dl/go1.21.5.linux-arm64.tar.gz

Unpack it:



sudo tar -C /usr/local -xzf go1.21.5.linux-arm64.tar.gz

Add these variables to the ~/.bashrc file for any user that needs to use go ( or place it in the system wide profile ).



vi .bashrc
PATH=$PATH:/usr/local/go/bin
GOPATH=$HOME/go

Source the bashrc file so this will be usable imediately.



source .bashrc

Check / verify:



go
go version

Gogs

Clone the repo and build it:



git clone --depth 1 https://github.com/gogs/gogs.git gogs
cd gogs
go build -o gogs

Test that it can be started ( and kill it when done testing ):



./gogs web

Verify that the URL is reachable and that the GUI loads ( don’t set it up yet though ):

http://better-otter:3000

Creaste a service user and place the home dir inside our data volume. Everything Gogs related will go here:



useradd -U -m -d /tank1/git git
passwd git

Move the gogs directory into it s final location in the git home dir ( on our data volume ):



mv gogs /tank1/git
chown git:git /tank1/git

Copy the systemd service file over:



cp /tank1/git/gogs/scripts/systemd/gogs.service /etc/systemd/system

Edit the systemd service file to look like this ( matching our system setup ):



vi /etc/systemd/system/gogs.service

[Unit]
Description=Gogs
After=syslog.target
After=network.target
After=postgresql.service

[Service]
Type=simple
User=git
Group=git
WorkingDirectory=/tank1/git/gogs
ExecStart=/tank1/git/gogs/gogs web
Restart=always
Environment=USER=git HOME=/tank1/git

ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

Reload systemd services. Then enable and start the gogs service.



systemctl daemon-reload
systemctl enable gogs
systemctl start gogs

Verify that it is up and running:



systemctl status gogs
ps -ef |grep -i gogs

Connect to our postgresql database and create a new DB:



psql -h better-otter -p 5432 -d testdb1 -U user1 -W
CREATE DATABASE gogs;
exit

Manually create and chown this directory:



mkdir -p /tank1/git/gogs/custom/conf
chown -R git:git /tank1/git

Access the UI from a web browser and continue setup:

http://better-otter:3000

Fix this setting if you mistakenly enabled the built in SSH server which conflicts with the SSH server already on the system:



vi /tank1/git/gogs/custom/conf/app.ini
START_SSH_SERVER = false

Restart Gogs:



systemctl restart gogs

Gogs passwords:

Samba

Install Samba:



sudo su -
apt update
apt install samba

Start / Enable the service:



systemctl enable smbd
systemctl start smbd
systemctl status smbd

Set a samba password for the samba user:



smbpasswd -a user1

Create a share config that looks like this:



vi /etc/samba/smb.conf
[storage1]
path = /storage1
valid users = user1
read only = no

Restart Samba:



systemctl restart smbd

Raspberry Pi Docker

Install docker using the system repo. This might not be the most up to date version.



sudo apt update
sudo apt install docker.io

Test it out with a hello world container:



sudo  docker run hello-world

Verify and show the completed / stopped container:



sudo docker ps -a  

Mongodb

This failed because apparently the mongodb container isn’t supported with more recent versions on Raspberry Pi. I’m planning to build mongo from source.

Pull down and run the MongoDB docker container:



sudo su -
docker pull mongodb/mongodb-community-server
docker run --name mongo -d mongodb/mongodb-community-server:latest


Connect to mongo on the container:




docker exec -it mongo mongosh

Test it with something like this:




db.runCommand(
   {
      hello: 1
   }
)

PostgreSQL

Install PostgreSQL using the package manager:



sudo apt update
sudo apt install postgresql
systemctl status postgresql

Log in as the postgres user:



sudo su postgres

Create a new database user:



createuser user1 -P --interactive

Connect to the DB server:



psql

Now exit out of the DB CLI and out of the postgres user account:



exit
exit

Connect to the DB server using the new DB user:



psql -d postgres -U user1 -W

Create a new test database:



CREATE DATABASE testdb1;

Connect to that new database:



\connect testdb1;

Create a new table:



CREATE TABLE table1 (name text, number text);

Insert some test values:



INSERT INTO table1 VALUES ('Greg', '123');

Run a test query:



SELECT * FROM table1;

Check the location of the hba_file. This could be a slightly different path depending on the version of postgresql. Just check it to be sure. _



SHOW hba_file;

Edit this config file and add a setting to allow the server to listen on any address.



sudo vi /etc/postgresql/xxxx/main/postgresql.conf
listen_addresses = '*'

Edit this other file and add a line like this to allow our new database server to connect from any IP.



/etc/postgresql/xxxx/main/pg_hba.conf
host    all             user1             0.0.0.0/0            scram-sha-256

Can now connect remotely like this:



psql -h better-otter -p 5432 -d testdb1 -U user1 -W

pgAdmin

I installed pgadmin and it wokred great. Not much to note here.

Nice tool: pgadmin3
Port: 5432