Remember to tip your server.

Gianmaria Piergianni

- "What could go wrong?"
He said to himself, unknowingly. meme

Introduction

Hi everyone. Long time no see!
I'll have to excuse myself for disappearing for so long. It has been difficult to keep up with university admission tests and my final year of high school so I did not have much time to work on this blog. However my tech journey did not stop during this time frame.

You may remeber that last time we met we worked on writing and hosting a simple website without spending more than a couple euros. This time instead I will show you a "proper" homelab that I was able to build thanks to our sponsor using the money I got from INPS (the Italian national institute for social security).

One last thing, if you want to learn more about networking, hosting and get that nerd high I cannot stress enough how fun self-hosting can be. You do not need expensive hardware to start but beware you might end up losing track of time working on your server and go to sleep at 3AM on a weekday.

Hardware

Let's start our journey from the hardware.
Picking the right pieces to build your dream homelab is all but easy and there are a number of factor you have to take into account. Personally I wanted it to be powerful enough to run a minecraft server for me and my friends and a streaming service for my family (therefore I needed a CPU with an integrated graphic card) without it being too power hungry given the current condition of electricity prices in Italy.

After some research I stubled upon this video by 'Wolfgang's Channel' which suggested a Motherboard + CPU mini ITX which had enough SATA ports for all the disks I wanted to add and more.
The aforementioned CPU is an Intel Pentium N6005 with a low TDP of about 10W to which I connected three used 6TB hard disks (buy them new if you can), one 250GB NVME ssd (the cheapest stick since it will only contain the OS and a couple of containers) and 16GB of DDR4 SO-DIMM RAM which I intend on upgrading to 32GB as soon as possible.

To power it all I initally intended on using a PicoPSU but I soon realized that I had made some mistakes when calculating the total power draw of the system and I had to buy a proper PSU from Amazon.

If you want to replicate my setup I will give you a couple of tips to pick what best suits you:

  1. Do not save money on the PSU (the risk is not worth the reward)
  2. Memory can still be quite expensive and HDD are incredibly power hungry (do you really need 40TB to store all your data?)
  3. Avoid old network equipment (the money saved will go into your electricity bill)


Taking everything into account, I spent about 600€ for the whole build as I was able to save some money by repurposing some parts from old computers I had lying around.

Proxmox Installation

As for the hypervisor to run on the server I chose proxmox because it is an open source solution with a free tier (which is more than enough for an home project) and makes it easy to create virtual machines and container with ease.

As I was quite overwhelmed by the amount of services I had to setup (and struggled to understand the difference between a container and a virtual machine) I loosely followed this tutorial. However, as I mentioned earlier, the sketchy "power supply" I was using could not handle the energy consumption of three hard drives spinning up and -because all the electronics are exposed- it would power off if it came into contact with anything.

While I ordered my new PSU I finished setting up Proxmox (despite it not liking my peripherals if I connect them to the USB 3.0 ports) which took more time than I expected as I typed the wrong subnet mask during the setup and could not figure out why it was impossible to find the web UI.

As the new PSU arrived I finished setting up truenas inside a vm and created my first pool. To have more control over the hard disks I passed them through the virtual machine and set up an SMB share and a routine to backup my google drive (I currently use my school's google account to have virtually infinite space to store files on but I am afraid that they will cut me off as soon as I finish my fifth year). Unfortunately, due to network limitations, the transfer speed I can currently achieve is around 10.5-11 Mb/s which is mediocre at best.

Random Services

After creating the SMB share i had some issues attaching to it from my linux machine. For anyone struggling to do it (just like I did) you can simply create a folder where you want to mount the share and the add to /etc/fstab something along the lines of:


//192.168.X.X/path_to_folder_on_server /path_on_local_machine -o username=add_your_username,password=add_your_password,vers=2.0,file_mode=0777,dir_mode=0777
              
The file and directory mode are set to 777 as this is my local machine and I am the only one using it at all times, beware of giving access and modifying rights to all users and remember to set dump and fsck variables! (I have them on 0 and 1).

Now that all the necessary stuff is set up and working we can start looking into some random services which may prove useful to have.

  1. First and foremost, this website.

  2. I won't go into too much details as I've already talked about my website long enough in the previous article. I just created an ArchLinux container, compiled the website executable for x64 and wrote a systemd script that runs it whenever I have to reboot the server.

  3. Minecraft server

  4. As I don't have a static IP and don't want to pay for any subscription I had to improvise a bit. I used ngrok to make the minecraft server available outside of my local network.
    Coincidentally, I found out that whenever you start ngrok it will host a webpage on port 4040 with some information on your session. The only logical thing to do was to write a quick bash script that restarts the server, curls the new link and sends it to a discord channel via webhook.
    
    
    #!/bin/bash
    
    # Start a new tmux session named "ngrok"
    tmux new-session -d -s ngrok
    
    # Send the ngrok command to the tmux session
    tmux send-keys -t ngrok 'ngrok tcp 25565' C-m
    
    # Wait for ngrok to initialize (adjust the sleep duration as needed)
    sleep 5
    
    # Get the public URL from ngrok
    public_url=$(curl localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url' | sed 's/^.\{6\}//')
    
    # Send the public URL to Discord webhook
    curl -X POST -H "Content-Type: application/json" -d '{"content":"'"$public_url"'"}' webook link
    

  5. PiHole, Unbound and portainer

  6. Last but not least I added two Debian 11 containers, one that serves as DHCP router (even though for logical complexity I should move it to an entirely different machine) and one with Portainer where I have most of the random docker containers that I use (jellyfin,silverbullet, qbittorent)


    Last but not least, I wanted to give some credit to this awesome article that guided me through creating a start page for my server. I picked homepage in the end and I can say without remorse that it has been serving me well!