This is a personal project of mine that has excited me a lot. I have always been obsessed with Single Board Computers (SBC) and the amazing things we can do with them. One of the most popular SBC is Raspberry Pi. They have pioneered the hardware and software capabilities for SBCs. Now we can run an Ubuntu server on any Raspberry Pi device. With Raspberry Pi, you can easily set up a server cluster at home and even host your own website, provided you have a strong internet connection and uninterrupted power supply. A mobile power bank would suffice. You should also be careful about opening up your network to the public. Make sure you have a strong firewall and use a DMZ and compartmentalize. You'll get a clearer picture once I explain what I've done here.
Here's a diagram of the server cluster at home.
So I have 4 SBCs. 3 Raspberry Pis and 1 Asus tinker board. From the diagram, you can see that my SBC servers are on a different subnet (192.168.0.XXX) than the modem(192.168.1.XXX). Since I have a lot of servers running at home, I have made it a policy to not connect anything directly to my modem. Instead, I have a really awesome Tenda modem through which all devices connect to the internet. The only devices connected to the modem are the router and a Raspberry Pi Zero. The Raspberry Pi Zero is the smallest and cheapest SBC produced by them and probably available in the market as a whole. This is an exception to my "don't connect anything to the modem" rule. I use this tiny SBC as a router. I have an Nginx server running here which forwards all traffic to the specified port by the domain name. For example, all traffic coming to the domain deverything.xyz will be forwarded to 192.168.1.111:8025, which from the diagram you can see, is mapped to 192.168.0.25:8025 (aka my SBC server running an apache server).
Steps to install an ubuntu server and configure a static local IP on a raspberry pi.
- If you are using a Raspberry Pi, then you can use their own image burner which is the easier method. Otherwise, you will have to download the Iso or Img image manually and then write using the dd command.
dd bs=4M if=/path/to/tinkeros.img of=/dev/sdx status=progress && sync
- The next step is to turn on your Raspberry Pi like you would any regular computer; You connect to a monitor using the HDMI, mini HDMI, or micro HDMI cable depending on your Raspberry Pi version and also connect a keyboard. A mouse is not required if you are burning Ubuntu server OS.
- Login using the default username and password and update the password. You will probably be prompted, otherwise use passwd command.
- Now you have to take care of certain things if you want a fully functioning server.
- Install openssh-server
sudo apt install openssh-server
- Make sure you assign a static IP so that you can log in via ssh using the same local IP.
- Depending on whether you are using an ubuntu-based OS or not, the method of assigning static IP will be different. The following instructions are for using the ethernet port for connecting to the internet and not the wifi. Wifi is a bad idea even on a Raspberry pi server. Although if you want to use wifi, you will have to use the "nmcli" CLI tool to connect to wifi without a desktop interface.
- Ubuntu Based
Edit your /etc/netplan/50-cloud-init.yaml using nano, vim, emacs etc. Save. Apply. Reboot.
This is what your /etc/netplan/50-cloud-init.yaml should look like if you want the static IP as 192.168.0.44:# This file is generated from information provided by the datasource. Changes # to it will not persist across an instance reboot. To disable cloud-init's # network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: ethernets: eth0: addresses: [192.168.0.44/24] gateway4: "192.168.0.1" dhcp4: false nameservers: addresses: [8.8.8.8,8.8.4.4] version: 2
Then, sudo netplan apply sudo reboot ifconfig This should be your output, more or less.
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.25 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::dea6:32ff:fe12:4d3 prefixlen 64 scopeid 0x20<link> ether dc:a6:32:12:04:d3 txqueuelen 1000 (Ethernet) RX packets 430072 bytes 209483562 (209.4 MB) RX errors 0 dropped 138564 overruns 0 frame 0 TX packets 43585 bytes 4795018 (4.7 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 286 bytes 24682 (24.6 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 286 bytes 24682 (24.6 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- Or not
In most other cases you have to edit the /etc/network/interfaces.d/eth0 file. You can get this if running the "ifconfig" command. It will list the network interfaces on your system. Eth0 is the first ethernet interface.
Your /etc/network/interfaces.d/eth0 file should look like this.auto eth0 iface eth0 inet static address 192.168.0.44 netmask 255.255.255.0 gateway 192.168.0.1 dns-nameservers 8.8.8.8 8.8.4.4
- Ubuntu Based
- Depending on whether you are using an ubuntu-based OS or not, the method of assigning static IP will be different. The following instructions are for using the ethernet port for connecting to the internet and not the wifi. Wifi is a bad idea even on a Raspberry pi server. Although if you want to use wifi, you will have to use the "nmcli" CLI tool to connect to wifi without a desktop interface.
- Make sure you enable autologin. Otherwise, when your server restarts, it will wait for you to enter your password.
If you are using Raspbian OS, you have to follow the instructions here. Otherwise, you will have to enable it manually by editing the getty service. This is a service to get tty. Here's how you do it.sudo systemctl edit getty@tty1
# Paste the following lines in. [Service] ExecStart= ExecStart=-/sbin/agetty --autologin user --noclear %I 38400 linux
# Replace user with the username you want to login as. sudo systemctl enable getty@tty1.service sudo reboot
- You should have automatically logged in once it's rebooted. Now you should connect your device to a modem or router using an ethernet cable. Make sure your modem/router is on the same subnet as what you have defined in your interfaces or netplan file. In the above case, our subnet is an IP address range of 192.168.0.(1-255). So if your modem/router gateway address is 192.168.1.1, then your device would not be able to connect to any internal or external network. You can log in to your modem/router and check the settings and then configure your network interfaces. In some cases, it can be 10.0.0.1 or 10.0.1.1.
- Install openssh-server
- SSH into your Raspberry PI and install apache or Nginx to check if your web server is functioning.
ssh user@192.168.0.44
sudo apt install apache2
sudo systemctl start apache2 - Go to your browser and type in the IP address of your SBC. In this case 192.168.0.44. You should see the Apache static page.
- Now you can host anything on your personal home server.
- Install Jenkins
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \ /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install openjdk-11-jdk sudo apt-get install jenkins sudo systemctl start jenkins
- Jenkins should now be running on 192.168.0.44:8080
My home server
You can see a small chip on the right side, that's the Raspberry Pi Zero with an Nginx router running on it. All it does is forwards the traffic to the right port. For example, the config for jenkins.deverything.xyz is as follows.
server {
listen 80;
listen [::]:80;
server_name jenkins.deverything.xyz;
location / {
proxy_pass http://192.168.1.111:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
192.168.1.111 is the static IP address of my router. The router now forwards this to its own subnet as shown in the diagram. Port 8080 will go to 192.168.0.45:8080, which is the Jenkins server.
Let me know if you need help with setting up something similar. I'm happy to help. :)