Updated content in old posts.

This commit is contained in:
Hamza Ahmed
2024-01-05 23:54:51 +00:00
parent c916352195
commit cf68a1d2cc
10 changed files with 745 additions and 639 deletions
+203 -198
View File
@@ -3,229 +3,218 @@ title: Building a Docker Swarm With Pi's 👾 👾 👾 👾
date: 2021-12-12T17:23:32Z
author: "ahmza"
draft: false
weight:
weight:
tags: ["Homelab","Docker","Docker Swarm","Raspberry Pi","Pi4"]
tags: ["Homelab", "Docker", "Docker Swarm", "Raspberry Pi", "Pi4"]
description: "Pis are very capable computers, when banded together they're almost unstoppable"
canonicalURL: "https://blog.ahmza.com/Page%28/posts/building-a-docker-swarm-with-pis.md%29"
cover:
image: "/webp/posts/pi-docker-swarm/feature-anim.webp" # image path/url
alt: "Pi Docker Swarm" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
image: "/webp/posts/pi-docker-swarm/feature-anim.webp" # image path/url
alt: "Pi Docker Swarm" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
showtoc: true
searchHidden: false
---
> This post is no longer valid as the cluster runs Kubernetes. The build process
> is the same
## **Intro**
The _Raspberry Pi_ from it's first iteration has been a great hit.
Adopted by many as the computer of choice for projects, and for
very good reason. The Pi is a fully fledged computer that fits in
your pocket and the most recent edition has blown fans away with
the flagship model boasting an ARM64 CPU and 8GB of RAM.
Now one _Raspberry Pi 4 8GB_ is more than powerful enough for most
workloads and in some cases totally unnecessary, **so you may even
get away with a single 4GB model**. However taking into consideration
their relatively low price and power consumption why not go all out
and build a cluster.
The _Raspberry Pi_ from it's first iteration has been a great hit. Adopted by
most as the computer of choice for projects. The Pi is a fully fledged computer
that fits in your pocket and the most recent edition boasts an ARM64 CPU and 8GB
of RAM.
> **You can never have too many _Raspberry Pis_, just
not enough Ideas**
Now one _Raspberry Pi 4 8GB_ is more than powerful enough for most workloads,
**so you may even get away with a single 4GB model**. Taking into consideration
their low price and power consumption why not go all out and build a cluster.
My excuse to build a Pi cluster is, I would like to migrate the
services currently running on a **bare metal server that sucks
a lot of power to a low power solution.** What better way to do that
than a Pi cluster.
My excuse to build a Pi cluster: I would like to migrate the services running on
a **bare metal server that sucks a lot of power to a low power solution.**
### **My Setup**
* 4 x _Raspberry Pi 4 8GB_
* 4 x 32GB SD cards
* 4 x PoE hats
* 1 x 5 port PoE Switch
![Cluster](/img/pi-docker-swarm/cluster.webp)
- 4 x _Raspberry Pi 4 8GB_
- 4 x 32GB SD cards
- 4 x PoE hats
- 1 x 5 port PoE Switch
![Cluster(fix this image)](/img/pi-docker-swarm/cluster.webp)
### **Point of this post**
Hopefully after following this post you will have setup _Docker
swarm_ on a cluster of Pis **- stay even if you currently only have
one -** and understand how to bend it to your will 🦾.
### **Why** ***Docker Swarm*** 🧐
After following this post you will have setup _Docker swarm_ on a cluster of Pis
**- stay even if you have one -** and understand how to bend it
to your will 🦾.
### **Why** **_Docker Swarm_** 🧐
While we can manage each docker node - _Raspberry Pi_ - individually
, **_Docker swarm_ enables us to manage all the devices from a single
main node** making managing the cluster a lot easier.
Think of _Docker swarm_ as a set of 🤖 hands which will run tasks on
each individual node for us. These tasks can consist of:
* Cluster Management
* Deployment and Scaling across the cluster
* Multi-host networking
* load balancing
* etc...
each individual node for us. Some of these tasks are:
### **Well why not** ***Kubernetes***
Although _Kubernetes_ is awesome, **it adds a bunch of complexity that
is simply not needed in a home lab environment** where we only have
a small cluster. As well as that, from my experience creating
```docker-compose``` files is a lot easier than writing manifests.
**_Docker swarm_ can do everything I want it to and requires less
effort** which is great if you're like me 🥱 😂
- Cluster Management
- Deployment and Scaling across the cluster
- Multi-host networking
- load balancing
### **Well why not** **_Kubernetes_**
Although _Kubernetes_ is awesome, it adds a bunch of complexity I'm not ready
for. As well as that, from my experience creating _docker-compose_ files is a
lot easier than writing manifests. **In the future I will try _Kubernetes_**
### **Required Stuff**
> The links below are reccomendations/stuff I used
* [_Raspberry Pi_ 4B](https://thepihut.com/products/raspberry-pi-4-model-b?variant=31994565689406) (Reccomend 4-8 @ 8GB)
* [_Raspberry Pi_ PoE Hats](https://thepihut.com/products/power-over-ethernet-poe-hat-d-for-raspberry-pi) (If you can find the [PoE+](https://thepihut.com/products/raspberry-pi-poe-plus-hat) version get them)
* [Cluster Case](https://thepihut.com/products/cluster-case-for-raspberry-pi) (Get any case you want)
* [PoE switch](https://www.amazon.co.uk/gp/product/B076982FVC/) (Get one that has enough ports for the nuber of pis you want)
* [RJ45 Ethernet Cable](https://www.amazon.co.uk/gp/product/B00C4U030G) (Reccomend short cables as it will look neater)
* [Micro SD cards](https://www.amazon.co.uk/gp/product/B08J4HJ98L) (Get enough cards for the number of Pis, Get the biggest cards you can afford)
**This is without a doubt an expensive project**, however in my eyes
it's the cost of another server 😂 and the best part about this
project is **you can add to the cluster over time** spreding the cost
which is how I managed to purchase all the hardware. A suggestion
would be to **buy equipment that allows you room to grow** so an 8 port
PoE switch instead of a 4 port if you know you will scale to 8
nodes
- [_Raspberry Pi_ 4B](https://thepihut.com/products/raspberry-pi-4-model-b?variant=31994565689406) (Reccomend 4-8 @ 8GB) (Or newer)
- [_Raspberry Pi_ PoE Hats](https://thepihut.com/products/power-over-ethernet-poe-hat-d-for-raspberry-pi) ([PoE+](https://thepihut.com/products/raspberry-pi-poe-plus-hat)) (Check compatibility with Pi Version)
- [Cluster Case](https://thepihut.com/products/cluster-case-for-raspberry-pi) (Get any case you want)
- [PoE switch](https://www.amazon.co.uk/dp/B0769C24T1/) (get one with enough 1Gb ports for the number of pis you want)
- [RJ45 Ethernet Cable](https://www.amazon.co.uk/gp/product/B00C4U030G) (Recommend short cables as it will look neater)
- [Micro SD cards](https://www.amazon.co.uk/gp/product/B08J4HJ98L) (Get enough cards for the number of Pis, Get the biggest cards you can afford)
If you build this then you can safely say another server is not
needed. This cluster should be more than capable to serve all your
home needs even if you only have 2 nodes. Put it this way, if you
have 4 8GB nodes then you have a combined total of:
* 32GB of RAM
* 16 physical CPU cores @ 1.5GHz
**This is an expensive project**, but the best part is **you can add to the
cluster over time** spreading the cost, which is how I managed to buy all the
hardware. If I could start again though I would **buy equipment that allows room
to grow** so an 8 port PoE switch instead of a 4 port if you know you will scale
to 8 nodes
This cluster should be capable of serving most of your needs even with 2 nodes.
Put it this way, if you have 4 x 8GB nodes then you have a combined total of:
- 32GB of RAM
- 16 physical CPU cores @ 1.5GHz (You can OverClock !!)
#### **Money Saving Tips**
* Just get 1-2 nodes to start
* cut PoE and use normal power cables
* Use Raspberry Pis with less memmory eg 4GB
* Grab a really cheap case or make one using [these](https://www.amazon.co.uk/dp/B091KJNZLB/)
* Use smaller SD Cards try not to go below 32GB (Reccomended 64GB If money saved elsewhere)
- 1-2 nodes to start
- Drop PoE and use normal power cables
- Raspberry Pis with less memory i.e 4GB
- Cheaper case or make one using [these](https://www.amazon.co.uk/dp/B091KJNZLB/)
- Smaller SD Cards try not to go below 32GB (Recommended 64GB If money saved elsewhere)
## **BUILD TIME !!**
Pull yourself up by your bootstraps were jumping into this one
runnig 💨
### **Image the SD Cards**
So interesting fact the CPUs used in the raspberry pi 4 use an ARM64
archetecture. When looking for images of Raspbian you will only find
32bit variants which will work however will not make use of all the
hardware which is just a waste. 64bit images exist however are well
hidden, Dont fear 😨 **you can download the latest images from the
[raspberrypi.org index](https://downloads.raspberrypi.org/raspios_arm64/images/)**
To write the cards I use the [**Raspberry Pi imager**](https://www.raspberrypi.com/software/).
once you have **rpi-imager** installed and you have the 64bit raspbian
image, open ```sudo rpi-imager``` and on the "CHOOSE OS" section go to
the bottom and select use custom image.
The CPU in a RaspberryPi 4 is the ARM64 architecture. When selecting Raspbian
pick the 64-BIT option. 32bit variants will work but not make use of the hardware
capabilities.[RaspberryPi Imager](https://www.raspberrypi.com/software/)
> We dont need to unzip the file as the tool is clever enough to
handle that for us
when prompted with **"Use OS Customisation"** go with **"Edit Settings"**.
General:
**Before removing the SD card, mount the boot partition - usually the
first partition, look for a file called cmdline.txt - and create an
empty file called ssh** ```sudo touch ssh``` this basically enables
SSH on the Pis first boot allowing us to access the Pis in a totally
headless manner.
- Set the hostname
- Set a username and password
- Set Locale settings
Services:
- Enable SSH
- Allow public-key authentication only
- Set your SSH Key
> If you dont have an SSH key, read my post on SSH [Securing
> SSH](https://blog.ahmza.com/posts/securing-ssh/)
### Assemble the cluster
So assembly is very dependant on the kit you bought, and more
often than not the stuff needed here comes with instructions or is
self explanitory. So go ahead and assemble the cluster 🛠
**There is an order of operations that I reccomend:**
* Install PoE hats onto the Pis
* Install the SD Cards into the Pis
* Assemble the case and install Pis
* plug in ethernet cables
Assembly depends on the case you bought, instructions should be included. Go
ahead and piece together the cluster 🛠
**Now allow the Pis to boot for a few minutes so it can resize the
**There is an order of operations that I recommend:**
- Install PoE hats onto the Pis
- Install the SD Cards into the Pis
- Assemble the case and install Pis
- plug ethernet cables in
**Now allow the Pis to boot for a few minutes**
### **Sort out the Network bits**
This is the easy part, there are two methods you can use to set a
static IP address, one is on your DHCP server and the other is on
the device itself. Personally I prefer to set static IPs on the
device itself so I will cover that here.
To find the current ip of your Pis you can go to your DHCP server
and look for the DHCP leases for the Pis.
There are two methods you can use to set a static IP address, one is on your
DHCP server and the other is on the device itself. Personally I prefer to set
static IPs on the device itself so I will cover that here.
To find the current ip of your Pis you can go to your DHCP server and look for
the DHCP leases for the Pis.
> there are naming conventions for naming primary and secondary
things but this is your cluster so be creative with it, I have my
primary node named ```Goob``` and the secondary nodes named ```Doris1```
```Doris2``` and ```Doris3```
[reference](https://www.youtube.com/watch?v=oFb7FVe8sdQ)
> things but this is your cluster so be creative with it, I have my
> primary node named `Goob` and the secondary nodes named `Doris1` > `Doris2` and `Doris3` > [reference](https://www.youtube.com/watch?v=oFb7FVe8sdQ)
**SSH to the Pi** then open and edit the following files
* /etc/hosts
* edit this line with your hostname: ```127.0.1.1 goob```
* /etc/hostname
* edit this file with your hostname: ```goob```
* /etc/dhcpcd.conf
* knowing we will be using only static IPs here I delete
everything in the file add the following
* ```
interface eth0
static ip_address=10.10.10.20/24
static routers=10.10.10.1
static domain_name_servers=10.10.10.1
```
**Now reboot the pi** ```sudo shutdown -r now```
**Once the Pis are back up log into each one and change the default
passwords** you may also want to create a new user for yourself but
thats totally optional.
- /etc/dhcpcd.conf
\_ knowing we will be using only static IPs here I delete
everything in the file add the following
```
interface eth0
static ip_address=<your-Pi-ip>/24
static routers=<your-router-ip>
static domain_name_servers=<your-dns-ip-usually-same-as-router>
```
### **Provision with** ***Ansible***
you want to **create an _Ansible_ control node** and that is as simple as
installing a package onto your machine. _Ansible_ is built using python
which makes it easy to install as **we can use the python pip package
manger.** To check you have it installed do ```pip --version``` if
it's not installed do the following
**Now reboot the pi**
```bash
sudo shutdown -r now
```
```curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py```
### **Provision with** **_Ansible_**
```python get-pip.py --user```
Ansible will allow us to setup our RaspberryPi Cluster from a remote machine
where we only administer the commands once and Ansible will replicate across the
cluster.
**once you have pip installed proceed to installing _Ansible_**
> Make sure pipx is installed. [Install
> Instructions](https://pipx.pypa.io/stable/)
[Docs](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)
Install Ansible
[Install Docs](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-and-upgrading-ansible-with-pipx)
```pip install ansible```
```bash
pipx install --include-deps ansible
```
Now that _Ansible_ is installed we can create a runbok that defines the
steps _Ansible_ needs to take on the remote machine to correctly
provision it. This playbook is written in yaml so get ready to make
sure your indents are correct 😬
A playbook defines steps _Ansible_ needs to take on the remote machine to
provision it. Playbooks are written in yaml so get ready to make sure your
indents are correct 😬
**Creating the playbook**
now you can copy what I have and it should work - after changing a
thing or two - which is fine however I encourage you to copy what I
have, read the [Docs](https://docs.ansible.com/ansible/latest/user_guide/index.html)
and make any changes you feel are necessary.
Copy what I have and it should work -- after changing a thing or two -- I
encourage you to read the Ansible
[Docs](https://docs.ansible.com/ansible/latest/user_guide/index.html) and make
any changes you feel are necessary.
> Check the [git repo](https://gitlab.com/AHMZA/pi-docker-swarm-ansible-deploy/-/tree/main) for the most up to date yaml file im using.
> Check this [Gitlab Repo](https://gitlab.com/ahmza/ansible-playbooks/-/tree/main/docker-swarm?ref_type=heads) for the most up to date playbook.
**This script assumes you are using SSH keys, which you should but if
not you can skip the whole "Configure SSH" block,**
***I RECCOMEND YOU USE SSH KEYS*** - [read this](https://blog.ahmza.com/posts/securing-ssh/)
**_I RECCOMEND YOU USE SSH KEYS_** - [read this](https://blog.ahmza.com/posts/securing-ssh/)
**Create the deploy.yml**
```bash
# Open the yaml file in a text editor
vim deploy.yml
```
```yaml
---
- hosts: piCluster
become: yes
tasks:
- name: Configure SSH
block:
- name: Auth local SSH Keys
ansible.posix.authorized_key:
user: <pi_user>
@@ -239,7 +228,7 @@ not you can skip the whole "Configure SSH" block,**
copy:
src: ./pi_rsa
dest: /home/<pi_user>/.ssh/id_rsa
mode: '0600'
mode: "0600"
owner: <pi_user>
group: <pi_user>
@@ -247,11 +236,10 @@ not you can skip the whole "Configure SSH" block,**
copy:
src: ./pi_rsa.pub
dest: /home/<pi_user>/.ssh/id_rsa.pub
mode: '0644'
mode: "0644"
owner: <pi_user>
group: <pi_user>
- name: Check for any updates and install them
apt:
update_cache: true
@@ -266,14 +254,12 @@ not you can skip the whole "Configure SSH" block,**
- vim
- curl
- name: Check Docker is installed
shell: "docker --version"
register: docker_version
- name: Install Docker
block:
- name: Download Docker script
command: curl -fsSL https://get.docker.com -o get-docker.sh
@@ -297,7 +283,6 @@ not you can skip the whole "Configure SSH" block,**
when: docker_version.stdout.find('Docker version')
- name: check Docker compose is installed
shell: "docker-compose --version"
register: dc_version
@@ -306,7 +291,6 @@ not you can skip the whole "Configure SSH" block,**
command: sudo pip3 -v install docker-compose
when: dc_version.stdout.find('docker-compose version')
- name: wait for network on boot
command: raspi-config nonint do_boot_wait 0
@@ -315,49 +299,57 @@ not you can skip the whole "Configure SSH" block,**
```
The steps this playbook takes are as follows:
1. Copy your SSH keys to the pi authorized_keys
2. Copy same Pi ssh key between the Pis for intercommunication
3. Check for and Install updates
4. Install any build dependancies
4. Install any build dependencies
5. Check if Docker is Installed
* Download the Docker Script
* Install Docker from script
* Enable the Docker service
* Add user to Docker group
- Download the Docker Script
- Install Docker from script
- Enable the Docker service
- Add user to Docker group
6. Check if docker-compose is installed
* Install docker-compose (This will take a while on each pi so be patient, grab a coffee)
9. Change raspi config to wait for network before boot
10. Reboot
- Install docker-compose (This will take a while on each pi so be patient, grab a coffee)
7. Change raspi config to wait for network before boot
8. Reboot
take some time to read through the playbook, read the docs and try to
understand whats going on. Change the usernames to your username.
**Make the hosts file in the same directory as the deploy.yml**
``` yaml
[piCluster]
10.10.10.20
10.10.10.21
10.10.10.22
**Create an inventory hosts file in the same directory as the deploy.yml**
```bash
# Open file in a text editor
vim hosts
```
* `[piCluster]` - specifies a group of hosts
* `10.10.10.xx` - specifies the Pis IP
```yaml
[piCluster]
<ip address 1>
<ip address 2>
<ip address 3>
```
- **_[piCluster]_** - specifies a group of hosts
- **_<ip address>_** - change these to the Pis IP addresses
**create the Pi Intercommunication keys**
``` bash
```bash
ssh-keygen
# Please note the ".pi_rsa" here
Enter file in which to save the key (/home/ahmza/.ssh/id_rsa): .pi_rsa
```
* save the keys in the same directory the deploy.yml file is
**heres the command to run the playbook.**
`ansible-playbook -i hosts -kK deploy.yml -c paramiko`
**_ansible-playbook -i hosts -kK deploy.yml_**
* `ansible-playbook` - the command to run the playbook
* `-i hosts` - specifies the host/inventory file
* `-kK` - asks you for password for the SSH connection(-k) and the sudo password(-K)
* `deploy.yml` - the _Ansible_ playbook
* `-c paramiko` - Use the paramiko connection method, I found this works best with ssh keys
- _ansible-playbook_ - the command to run the playbook
- _-i hosts_ - specifies the host/inventory file
- _-kK_ - asks you for password for the SSH connection(-k) and the sudo password(-K)
- _deploy.yml_ - the _Ansible_ playbook
You can do so much with _Ansible_, for example mount network shares etc,
if you can do it in the cli you can do it in _Ansible_ !!
@@ -366,35 +358,35 @@ Now that the _Ansible_ script is done we can go ahead and actually
configure all the Pis into the cluster.
### **Creating/Joining the swarm**
Creating and joining the cluster is easy - It is manual and tedious so
this is something you could impliment into the ansible playbook using
multiple host groups.
Creating and joining the cluster is easy - It is manual and tedious so this is
something you could implement into the _Ansible_ playbook using host groups.
**Follow these steps to create the swarm:**
1. ssh to the main Pi, this will be the manager node.
2. run `docker swarm init`
* This will return a command and token. Make sure to copy them
- This will return a command and token. Make sure to copy them
3. exit the main Pi
4. ssh to one of the worker nodes
5. paste and run the copied command
6. do the same on the remaining worker nodes
You should now have a correctly configured cluster !!
You should now have a configured cluster !!
### **Optional Step - Portainer**
Portainer is a webgui that will allow us to manage the cluster, it will
### **Optional Step - _Portainer_**
_Portainer_ is a webgui that will allow us to manage the cluster, it will
make deploying and destroying containers across the cluster a breeze.
I do understand that all of what portainer does can simply be accomplished
in the command line, however portainer just makes it less hastle to manage.
**Install Portainer**
**Install _Portainer_**
Firstly we want to download the yaml file that will be used to deploy
the portainer contiainer on our cluster.
the _Portainer_ container on our cluster.
`curl -L https://downloads.portainer.io/portainer-agent-stack.yml -o portainer-agent-stack.yml`
Now we can actually deploy portainer to the cluster using the following
Now we can actually deploy _Portainer_ to the cluster using the following
command:
`docker stack deploy -c portainer-agent-stack.yml portainer`
@@ -412,10 +404,10 @@ to create a private repository to host any images that you need to run
across the cluster.
to create this private repository create a file called docker-compose.yml
in a folder called repository or whatever and enter the following.
``` yaml
in a folder new folder called repository and enter the following.
version: '3.9'
```yaml
version: "3.9"
services:
registry:
image: registry:2
@@ -428,26 +420,39 @@ services:
**Be sure to change pi-user to your pi user**
**create a file /etc/docker/daemon.json and eter the following**
``` json
```bash
vim /etc/docker/daemon.json
```
```json
{
"insecure-registries": ["localhost:5000", "<pi-address>:5000"]
"insecure-registries": ["localhost:5000", "<pi-address>:5000"]
}
```
where `pi-address` is the ip address of the main swarm node.
**restart the docker service with `sudo systemctl restart docker`**
where **_pi-address_** is the ip address of the main swarm node.
\*\*restart the docker service
```bash
sudo systemctl restart docker
```
now we need to deploy the registry to the stack like we did with portainer
`docker stack deploy -c docker-compose.yml registry`
```bash
docker stack deploy -c docker-compose.yml registry
```
and we should have a private registry setup that we can use to push our
custom docker images to.
## **Conclusion**
Well done, you have successfully setup a docker swarm cluster on a bunch
of Pis and along the way you managed to learn a bit about SSH, Ansible,
docker-compose, yaml and networking on Pis. The next step would be to
setup a few containers but I'll leave that to you, dont be affraid to
play around and even ruin the cluster, you can always rebuild it so have
play around and even ruin the cluster, you can always rebuild it have
fun 😊
+48 -69
View File
@@ -3,56 +3,48 @@ title: HUGO Static Site Generator
date: 2021-12-26T00:23:22Z
author: "ahmza"
draft: false
weight:
weight:
tags: ["blog","website","web development","HUGO"]
tags: ["blog", "website", "web development", "HUGO"]
description: "HUGO is a static site generator. No idea what that is ? Check out this post to learn more !"
canonicalURL: "https://blog.ahmza.com/Page%28/posts/hugo-static-site-generator.md%29"
cover:
image: "/img/hugo/feature.webp" # image path/url
alt: "HUGO logo" # alt text
caption: "The HUGO logo" # display caption under cover
relative: false # when using page bundles set this to true
image: "/img/hugo/feature.webp" # image path/url
alt: "*HUGO* logo" # alt text
caption: "The *HUGO* logo" # display caption under cover
relative: false # when using page bundles set this to true
---
## **Introduction**
Hugo is a static site generator, which basically means it's a tool that
_HUGO_ is a static site generator, which basically means it's a tool that
allows us to pre-compile all of our website into static HTML, CSS and
JS. The main benefit of using such methods to crate a site is speed. A
JS. The main benefit of using such methods to crate a static site is speed. A
Static site takes a lot less time to load than a site that uses
databases for example.
## **Disadvantages**
Some of the disadvantages I have come across are as follows:
Some of the disadvantages (for me):
* A lot more backend work
* Harder to manage content
* Editing and creating content can be a pain
- A lot more infrastructure setup (for my setup)
- Editing and creating content can be a pain
**This is to no fault of hugo itself but to the unnecessary complexity
in my infrastructure!!** Deploying the site in my environment was a
challenge as I had to get the site files from gitlab and build a docker
image that would compile the site as well as create an image to be
deployed in my [docker swarm.](https://blog.ahmza.com/posts/building-a-docker-swarm-with-pis)
I do feel I made this more complicated than it needed to be, however now
that I have it working the workflow is great.
**This is to no fault of _HUGO_ itself but the complexity of my infrastructure!!**
Deploying the site in my environment was a challenge as I had to get the site
files from gitlab and build a docker image that would compile the site as well
as create an image to be deployed in my [docker
swarm.](https://blog.ahmza.com/posts/building-a-docker-swarm-with-pis) I do feel
I made this more complicated than it needed to be, but now that I have it
working the workflow is great.
The content is manually managed meaning you have to create edit and
delete posts yourself. HUGO does a great job at making this as pleasant
of an experience as possible but coming from a CMS (Content Management
System) it is a lot more involved.
Because there is no integrated webui or CMS for Hugo, the experience
Because there is no integrated webui or CMS for _HUGO_, the experience
you get when creating content will vary person to person depending on
the environment you use to create the content. When using a CMS I took
dragging and dropping images for granted where now I have to explicitly
define full paths to images which can get me out of the flow of writing
content, however it's finding solutions for these challenges that makes
this interesting.
content. Finding solutions for these challenges that makes this interesting.
## **Then Why?**
@@ -62,47 +54,34 @@ total size of the content on this site including images is ~5mb which
is considerably smaller than a full CMS and database alone with no
content.
Some advantages of static sites in general:
* Security
* Reliability
* Scalability
* Low Resource Requirement
Although the pursuit of speed brought me to HUGO, here are a few things
that kept me:
* Git
* Markdown
* Simplicity
* Live Preview
As mentioned before my initial reason for switching to a static site
generator was speed and how lightweight the final product is, at the
time of writing this the total size of the content on this site
including images is ~5mb which is considerably smaller than a full CMS
and database alone with no content.
I have recently started to use git a lot more and I'm able to
implement a content versioning system that can follow me everywhere and
on any device very easily. It also means there is always a backup of my
site on gitlab and I don't need to worry about backing up databases.
Markdown makes life a lot easier, Its quick, easy and doesn't require
me to right click or use buttons. Markdown is also very transferable,
scroll up to the top of this page and hit the "Suggest Changes" button
and you will see how a markdown file can be interpreted by not only
HUGO but gitlab too and so many other tools.
{{< video label="i love it" webm="/webm/i-love-it.webm" >}}
Regarding themes, HUGO allows you to easily create your own, or just as
easily implement other peoples themes.
Some advantages of static sites in general:
Although at the start HUGO seemed difficult to me I managed to learn it
pretty quickly and appreciate the simplicity it brings to the table. I
wouldn't say my workflow is perfect by any means but I feel HUGO makes
it easy to develop a smooth workflow.
- Security
- Reliability
- Scalability
- Low Resource Requirement
Although the pursuit of speed brought me to _HUGO_, here are a few other great
reasons:
- Git
- Markdown
- Simplicity
- Live Preview
I have recently started to use git a lot more and I'm able to implement a
content versioning system that can follow me everywhere.
Markdown is quick, gives me what I need and doesn't require me to right click.
_HUGO_ allows you to import pre-made themes or if your feeling up to it, make
your own.
Although at the start _HUGO_ seemed difficult to me I managed to learn and
appreciate the simplicity it brings to the table. My workflow is not perfect but
I feel _HUGO_ makes it easy to develop a smooth workflow.
Live Preview allows you to start up a light weight web server locally
and has an auto refresh feature so whenever a change is made the web
@@ -110,7 +89,7 @@ page refreshes so you can see changes without manually refreshing.
## **Conclusion**
This post is a quick intro to HUGO and why I choose to use it, However
there is another post on setting up a HUGO site from start to finish.
You've had a quick intro to _HUGO_ and why I choose to use it, I wrote another
post on setting up a _HUGO_ site from start to finish.
[Setting Up a HUGO Site](https://blog.ahmza.com/posts/setup-a-hugo-site)
[Setting Up a _HUGO_ Site](https://blog.ahmza.com/posts/setup-a-hugo-site)
+160 -118
View File
@@ -3,38 +3,34 @@ title: Minecraft Server on Docker ⛏ 🐳
date: 2022-05-24T09:33:35+01:00
author: "ahmza"
draft: false
weight:
weight:
tags: ["Games", "Docker", "ARM"]
description: "Ever wanted to build a Minecraft server in docker !! Start here"
canonicalURL: "https://blog.ahmza.com/Page%28/posts/minecraft-server-on-docker.md%29"
cover:
image: "/webp/posts/mc-docker/feature-anim.webp" # image path/url
alt: "Minecraft Loves Docker" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
image: "/webp/posts/mc-docker/feature-anim.webp" # image path/url
alt: "Minecraft Loves Docker" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
showtoc: true
searchHidden: false
---
## **Introduction**
Minecraft is a great game and when it comes to multiplayer, a dedicated
server is the way to go (here's why[^1]). Myself and a few others
recently decided to start playing this game again, and I took the
opportunity to deploy the server in my lab.
Minecraft is a great game and better with friends. A dedicated server allows you
to do that[^1].
A Minecraft server does not require a ton of resources to run, However
from my experience the more resources you can throw at it the better,
especially when you start to introduce mods and more than a few players.
A Minecraft server does not require a ton of resources to run, but from my
experience the more resources you can throw at it the better when you start to
introduce mods and more players.
I run our server on my main PC within WSL and Docker. This allows me to
leverage the system resources in my PC 🦾 leaving the [Pi Cluster](https://blog.ahmza.com/posts/building-a-docker-swarm-with-pis/)
to handle the rest of the stuff in my lab. The only reason I opted to
go this route is that I don’t want our server to be limited by hardware
resources as well as the Minecraft server effecting the overall
performance of the Pis.
I run our server on my main PC. This allows me to leverage the system resources
in my PC 🦾 leaving the [Pi
Cluster](https://blog.ahmza.com/posts/building-a-docker-swarm-with-pis/) system
resources to handle the rest of the stuff in my lab.
## **Prerequisites**
@@ -63,80 +59,92 @@ performance of the Pis.
## **Building the Container**
Now we have the formalities sorted, we can get to work on creating the
docker container for Minecraft.
1. **Create a directory in which you will keep the Minecraft server files**
- `mkdir minecraft-server`
- `cd minecraft-server`
```bash
# Make the folder
mkdir minecraft-server
# Ender the folder
cd minecraft-server
```
2. **Create an environment file to be used by the Docker Container**
- The *.env* file allows us to specify variables which we can use
across the build process.
- `touch .env`
- Edit the file in a text editor, i.e. vim `vim .env`
```bash
CONTAINER_NAME=minecraft-server
SERVER_MEM=4096 #change this to your desired value (in MB)
SERVER_JAR=minecraft_server.1.18.2.jar
```
- The _.env_ file allows us to specify variables used in the build process.
```bash
# Create a .env file
touch .env
# Open in a text editor
vim .env
# Enter the following variables
CONTAINER_NAME=minecraft-server
SERVER_MEM=4096 #change this to your desired value (in MB)
SERVER_JAR=minecraft_server.<version>.jar # change the version
```
3. **Create the docker-compose.yml file**
- The *docker-compose.yml* file specifies the container that we
want to build, outlining the build context (Dockerfile),
setting the variables (from .env), configuring storage volumes
for persistence as well as ports and the container name.
- `touch docker-compose.yml`
- Edit the file in a text editor[^3], I.e. vim `vim docker-compose.yml`
```bash
version: "3"
- The _docker-compose.yml_ file specifies the container that we want to build [^3]
services:
minecraft-server:
build:
context: .
args:
SERVER_MEM: ${SERVER_MEM}
SERVER_JAR: ${SERVER_JAR}
volumes:
- .server-data:/server
ports:
- 25565:25565
- 25575:25575
container_name: ${CONTAINER_NAME}
restart: unless-stopped
```bash
# Create the file
touch docker-compose.yml`
# Open in a text editor
vim docker-compose.yml
```
volumes:
server-data:
```
```yaml
version: "3"
services:
minecraft-server:
build:
context: .
args:
SERVER_MEM: ${SERVER_MEM}
SERVER_JAR: ${SERVER_JAR}
volumes:
- .server-data:/server
ports:
- 25565:25565
- 25575:25575
container_name: ${CONTAINER_NAME}
restart: unless-stopped
volumes:
server-data:
```
4. **Create the Dockerfile file**
- The Dockerfile builds the container. We take the 17-jre base
image apply our variables change the working directory to
/server and start the jar file, effectively starting the
Minecraft server.
- `touch Dockerfile`
- Edit the file in a text editor, i.e. vim `vim Dockerfile`
```bash
FROM eclipse-temurin:17-jre
ARG SERVER_MEM
ARG SERVER_JAR
- The Dockerfile builds the container image.
ENV SERVER_MEM=${SERVER_MEM}
ENV SERVER_JAR=${SERVER_JAR}
```bash
# Create the file
touch Dockerfile`
# Open the file in a text editor
vim Dockerfile
```
WORKDIR /server
```Dockerfile
FROM eclipse-temurin:17-jre
CMD echo "Minecraft Server is starting\n" && java -Xms128M -Xmx${SERVER_MEM}M -jar ${SERVER_JAR} nogui
```
ARG SERVER_MEM
ARG SERVER_JAR
ENV SERVER_MEM=${SERVER_MEM}
ENV SERVER_JAR=${SERVER_JAR}
WORKDIR /server
CMD echo "Minecraft Server is starting\n" && java -Xms128M -Xmx${SERVER_MEM}M -jar ${SERVER_JAR} nogui
```
## **Setup the Server files**
We’re almost there, just a few steps left !!
The curious among you may have realised when trying to start the
container that it fails with the error below:
The curious among you may have realised when trying to start the container that
it fails with the error below:
```bash
Minecraft Server is starting
@@ -147,62 +155,96 @@ Error: Unable to access jarfile server.jar
This is because we have not downloaded the server jar file yet, that is
our next step.
1. **Navigate to one of the following sites:**[^4]
- [Vanilla Minecraft Server](https://www.minecraft.net/en-us/download/server) - instructions found here[^5]
- [Fabric Mod loader server](https://fabricmc.net/use/server/) - instructions found here [^6]
1. **Navigate to one of the following sites:**[^4]
- [Vanilla Minecraft Server](https://www.minecraft.net/en-us/download/server) - instructions found here[^5]
- [Fabric Mod loader server](https://fabricmc.net/use/server/) - instructions found here [^6]
2. **Create a folder in the Minecraft-server folder called .server-data**
- `mkdir .server-data`
- `cd .server-data`
```bash
mkdir .server-data
cd .server-data
```
3. **Download the jar file - This will depend on the option above so read the instructions**
4. **Go back to the root minecraft-server folder**
- `cd ..`
```bash
cd ..
```
5. **Run the container**
- `docker compose up` (use CTRL+C to exit)
- Once the server unpacks all the files you will see this:
```bash
minecraft-server | Starting net.minecraft.server.Main
minecraft-server | [18:05:50] [ServerMain/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
minecraft-server exited with code 0
```
7. **Accept the EULA**
- Go into the .server-data folder
1. `cd .server-data`
- Edit the file named eula.txt in a text editor i.e. vim `vim eula.txt`
1. Simply change `eula=false` to `eula=true`
8. **While in the .server-data folder make any changes you want**
- Some files to note in here are
- **server.properties** - properties like server name, game mode, world type etc…
- **ops.json** - list of server operators (easier to set ingame)
- **whitelist.json** - list of players allowed to join the server everyone else rejected access.
9. **Run the container**
- `docker compose up -d` (the -d means detatched so we can run the server in the background)
- `docker logs minecraft-server --follow` Will show us the progress of the server startup (to exit out of this do CTRL+C)
- If you see something like the following then you’re a winner 🥳
```bash
[18:17:01] [Server thread/INFO]: Time elapsed: 25529 ms
[18:17:01] [Server thread/INFO]: Done (34.571s)! For help, type "help"
```
This will create our eula.txt as well as other files needed.
```bash
docker compose up # use CTRL+C to exit
```
```bash
minecraft-server | Starting net.minecraft.server.Main
minecraft-server | [18:05:50] [ServerMain/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
minecraft-server exited with code 0
```
6. **Accept the EULA**
```bash
# enter the .server-data folder
cd .server-data
# edit eula.txt in a text editor
vim eula.txt
# change `eula=false` to `eula=true`
eula=true
```
7. **While in the .server-data folder make any changes you want**
- Notable files:
- **server.properties** - properties like server name, game mode, world type etc…
- **ops.json** - list of server operators (easier to set ingame)
- **whitelist.json** - list of players allowed to join the server everyone else rejected access.
8. **Run the container**
```bash
# -d flag allows the container to run in detached mode i.e in the background
docker compose up -d
```
```bash
# monitor the logs as the server starts. CTRL+C to exit
docker logs minecraft-server --follow
# If you see the bottom line then your server is up and running
[18:17:01] [Server thread/INFO]: Time elapsed: 25529 ms
[18:17:01] [Server thread/INFO]: Done (34.571s)! For help, type "help"
```
## Conclusion
Well done you have successfully setup a Minecraft server, now go play !!
There is a lot of cool stuff you can do with a Minecraft server for
example installing mods or creating scripts to manage the server, this
will be covered in the next post so keep an eye out for it !!
Well done you have setup a Minecraft server, now go play !!
There is a lot of cool stuff you can do from this point, for example installing
mods or creating scripts to manage the server.
[^1]: Hosting your own dedicated server allows you to modify every aspect of the server as you see fit. I.E you can modify the server-properties, you can implement a whitelist not to mention being able to add any mods you want
[^1]:
Hosting your own dedicated server allows you to modify every aspect of the
server as you see fit. I.E you can modify the server-properties, you can
implement a whitelist not to mention being able to add any mods you want
[^2]: Requirements Gathered from here [https://minecraft.fandom.com/wiki/Server/Requirements/Dedicated#Unix\_.28Linux.2C\_BSD.2C\_macOS.29](https://minecraft.fandom.com/wiki/Server/Requirements/Dedicated#Unix_.28Linux.2C_BSD.2C_macOS.29)
[^2]: Requirements Gathered from here [https://minecraft.fandom.com/wiki/Server/Requirements/Dedicated#Unix\_.28Linux.2C_BSD.2C_macOS.29](https://minecraft.fandom.com/wiki/Server/Requirements/Dedicated#Unix_.28Linux.2C_BSD.2C_macOS.29)
[^3]:
Yaml is very picky 😞 when it comes to formatting so if you encounter any
errors double check your formatting !!
[^3]: Yaml is very picky 😞 when it comes to formatting so if you encounter any errors double check your formatting !!
[^4]:
I have left Forge out as it is a more involved process plus Fabric is
better 😜
[^4]: I have left Forge out as it is a more involved process plus Fabric is better 😜
[^5]:
Right click the green link that says something like minecraft_server.x.xx.x.jar and copy the link address
[^5]: Right click the green link that says something like minecraft_server.x.xx.x.jar and copy the link address
`curl -o server.jar \<link you copied here\>`
curl -o server.jar \<link you copied here\>
[^6]:
Select the Minecraft version, Fabric Loader Version and the Installer Version of your choice. I tend to go with the latest.
[^6]: Select the Minecraft version, Fabric Loader Version and the Installer Version of your choice. I tend to go with the latest.
Copy the curl command under CLI download
`Copy the curl command under CLI download`
+159 -120
View File
@@ -10,50 +10,59 @@ description: "Ever wanted to make your SSH connections more secure. Read this"
canonicalURL: "https://blog.ahmza.com/Page%28/posts/securing-ssh.md%29"
cover:
image: "/webp/posts/secure-ssh/feature-anim.webp"
alt: "ssh-alt image" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
image: "/webp/posts/secure-ssh/feature-anim.webp"
alt: "ssh-alt image" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
showtoc: true
searchHidden: false
---
# **Introduction**
SSH is a widely used protocol to access remote devices. The problem
with SSH is at the authentication stage, Brute force attacks are one of
the ways an SSH connection can be compromised. A malicious actor will
constantly hammer the remote host with different passwords until it can
gain access. With further configuration of SSH we can make the service
a lot more secure.
SSH is a widely used protocol to access remote devices. The problem with SSH is
at the authentication stage, Brute force attacks are one of the ways an SSH
connection is compromised. A malicious actor will constantly hammer the
remote host with different passwords until it can gain access. With further
configuration of SSH we can make the service a lot more secure.
# **Configure SSH**
{{< video label="this is fine" webm="/webm/this-is-fine.webm" >}}
> **Famous last words:** Configuring SSH like many things in Linux is
as simple as editing a few config files
> **Famous last words:** Configuring SSH like many things in Linux is as simple
> as editing a few config files
Always be sure to **create a backup file** it's very easy to end up
locking yourself out of a device.
I would recommend practising on a machine that is not critical.
Always **create a backup file**, You can end up locking yourself out of a
device. Try this on a machine that is not critical.
## **Create SSH Keys**
SSH keys use public and private key encryption for authentication.
To create a set of keys, **on the client do:**
``` bash
ssh-keygen
```bash
ssh-keygen -t ecdsa -C <username>@<hostname>
```
You will be asked where you want to save the keys, **I recommend the \
default location** for less hair pulling later.
``` bash
- -t ecdsa - sets the key encryption type to _ecdsa_
- -C - Comment or name of the _SSH_ key. **Replace content in <>**
Where you want to save the keys, **I recommend the default location**
```bash
Enter file in which to save the key (/home/user/.ssh/id_rsa):
```
You will be asked to enter a password for the ssh keys, be sure to use
a strong password.
``` bash
Password for the ssh key, please use a strong password.
```bash
Enter passphrase (empty for no passphrase):
```
Once that is done you will see a confirmation screen like the one below
Once done you will see a confirmation screen like the one below
```
Output
Your identification has been saved in /home/user/.ssh/id_rsa
@@ -75,16 +84,16 @@ The key's randomart image is:
```
## **Copy SSH Keys**
> **Quick note:** user@host is the **username** on the **remeote host**
you would like to copy your public key to.
``` bash
```bash
ssh-copy-id user@host
```
> **Quick note:** user@host is the **username** on the **remeote host** you
> would like to copy your public key to.
**If asked to confirm the connection to the remote host answer yes**, this
happens when a new machine with an unknown identity wants to connect to
the client.
happens when a new machine with an unknown identity wants to connect.
```
Output
@@ -93,8 +102,7 @@ ECDSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
```
You will then be asked to **enter a password** for the user on the remote
host
**Enter a password** for the user on the remote host
```
Output
@@ -103,42 +111,48 @@ Output
user@host's password:
```
If successful you should be able to access the device using the SSH key
Access the remote device using the SSH key
To verify this, SSH to the device and **it should ask for the Keys's
password not the users**
To verify this, SSH to the device and **it should ask for the Keys password not
the users**
``` bash
```bash
Enter passphrase for key '/home/user/.ssh/id_rsa':
```
## **Modify SSH Config**
create a backup
``` bash
```bash
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
```
open the original file in a text editor
``` bash
**NeoVim BTW!!**
```bash
sudo vim /etc/ssh/sshd_config
```
For a new user this might be daunting. Take your time and you will be
For a new _Linux_ user this might be daunting. Take your time and you will be
fine 😊
{{< video label="thats a big one" webm="/webm/thats-a-big-one.webm" >}}
**Lines we want to modify**
> **Quick note:** you may need to uncomment some lines as well as add a
few
> **Note:** uncomment lines as well as add missing lines
* Protocol 2 - add to line 15
* Port 2222 - modify line 17
* PermitRootLogin no - modify line 36
* Max Auth Tries 5 - modify line 38
* PasswordAuthentication no - modify line 60
* PermitEmptyPasswords no -modify line 61
* AllowUsers ahmza - add line 67
* ClientAliveInterval 180 - modify line 104
- Protocol 2
- Port 2222
- PermitRootLogin no
- Max Auth Tries 5
- PasswordAuthentication no
- PermitEmptyPasswords no
- AllowUsers <user>
- ClientAliveInterval 180
```
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
@@ -203,7 +217,7 @@ MaxAuthTries 5
PasswordAuthentication no
PermitEmptyPasswords no
AllowUsers ahmza
AllowUsers <user>
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
@@ -273,65 +287,74 @@ Subsystem sftp /usr/lib/openssh/sftp-server
{{< video label="not so bad" webm="/webm/wasnt-so-bad.webm" >}}
**Now lets explain what we just did**
* **Protocol 2** - released in 2006, SSH2 introduced improved
encryption algorithms.
* **Port 2222** - The port number can be whatever number you want.
Choose something other than 22 this will help hide your device from malicious actors
* **PermitRootLogin no** - If the root account were to be compromised
then the attacker has full control of the system so we stop it from being able to log in.
* **MaxAuthTries 5** - After 5 failed attempts the remote host blocks
requests from that IP for a period of time.
* **PasswordAuthentication no** - We have the SSH key installed so we
no longer need to have password authentication.
* **PermitEmptyPasswords no** - We don't want to allow empty passwords
to be used as authentication for obvious reasons.
* **AllowUsers username** - Add the usernames of users you want to be
able to connect to the remote host and other users trying to connect
will be dropped.
* **Client Alive Interval 180** - Drop the connection after a certain
period of inactivity
## **Check were able to connect**
- **Protocol 2** - released in 2006, SSH2 introduced improved encryption
algorithms.
- **Port 2222** - The port number can be whatever number you want. Choose
something other than 22 this will help hide your device from malicious actors
- **PermitRootLogin no** - If the root account gets compromised then the
attacker has full control so we stop root from logging in over ssh.
- **MaxAuthTries 5** - After 5 failed attempts the remote host blocks requests
from that IP for some of time.
- **PasswordAuthentication no** - The SSH key is installed, no need to have
password authentication.
- **PermitEmptyPasswords no** - Don't allow empty passwords
- **AllowUsers username** - Add the users you want to connect to the remote
host, others will be dropped.
- **Client Alive Interval 180** - Drop the connection after 180s of inactivity
## **Check ability to connect**
restart sshd service
``` bash
```bash
sudo systemctl restart sshd
```
**Keep the current SSH connection open** and create a new session.
If you are able to connect to the remote hosts then you are all set. If
not then you still have the initial connection to the remote host to
roll back the changes and troubleshoot.
If you connect to the remote host then you're set. If not then you still have
the initial connection to the remote host to roll back the changes and
troubleshoot.
# **Success**
{{< video label="clap" webm="/webm/clap.webm" >}}
# **Setting up** ***Fail2Ban***
_Fail2Ban_ is an intrusion prevention tool. Although we are slowing
bots down with MaxAuthTries the attacker is still able to carry on
brute forcing. Which is what Fail2Ban is for, it actually blocks the
connections from that IP.
# **Setting up** **_Fail2Ban_**
_Fail2Ban_ is an intrusion prevention tool. Although we slow down attackers with
with MaxAuthTries they can still carry on brute forcing. Which is what Fail2Ban
does, it actually blocks the connections from that IP.
## **Install** **_Fail2Ban_**
## **Install** ***Fail2Ban***
**We will install Fail2Ban on the remote host**
First upgrade any packages, then **install** ***Fail2Ban***
``` bash
First upgrade any packages, then **install** **_Fail2Ban_**
```bash
sudo apt update && sudo apt upgrade
sudo apt install fail2ban
```
Now we need to enable the service so it starts when the remote host
starts
``` bash
```bash
sudo systemctl enable --now fail2ban
```
## **Configure** ***Fail2Ban***
The Fail2Ban config file we want to edit is called **jail.local** located in **/etc/fail2ban/**
## **Configure** **_Fail2Ban_**
The config file we want to edit is **jail.local** located in **/etc/fail2ban/**
open jail.local in your editor of choice
``` bash
```bash
sudo vim /etc/fail2ban/jail.local
```
The config for _Fail2Ban_ is a lot shorter than sshd so this should be
quick
The config for _Fail2Ban_ is nice and short
```
[DEFAULT]
bantime = 8h
@@ -349,80 +372,96 @@ quick
**[Default]** - Settings in here apply to all jails
* **bantime** - how long the ban will last
* **ignoreip** - IP addresses to ignore
* **ignoreself** - stops from locking itself out
- **bantime** - how long the ban will last
- **ignoreip** - IP addresses to ignore
- **ignoreself** - stops from locking itself out
**[sshd]** - this is the jail for sshd
* **enabled** - decides weather the jail is active or not
* **port** - the port number the service
* **filter** - tells the jail which filter to use from /etc/fail2ban/filter.d
* **logpath** - where the log you want fail2ban to read is
* **maxretry** - Times the client can attempt a login before being banned
* **findtime** - An amount of time which maxretry must occur to trigger a
ban for example in 10 minutes if 3 failed login attempts are made the
ban the IP
- **enabled** - decides weather the jail is active or not
- **port** - the port number the service
- **filter** - tells the jail which filter to use from /etc/fail2ban/filter.d
- **logpath** - where the log you want fail2ban to read is
- **maxretry** - Times the client can attempt a login before being banned
- **findtime** - An amount of time which maxretry must occur to trigger a ban
for example in 10 minutes if 3 login attempts fail ban the IP
**Restart** ***Fail2Ban*** to load the configuration
``` bash
**Restart** **_Fail2Ban_** to load the configuration
```bash
sudo systemctl restart fail2ban
```
## **Testing** ***Fail2Ban***
## **Testing** **_Fail2Ban_**
To test Fail2Ban lets create a test user and set a password for the
user
``` bash
```bash
sudo useradd test
sudo passwd test
```
**open the sshd config**
``` bash
```bash
sudo vim /etc/ssh/sshd_config
```
modify the line **PasswordAuthentication** to say **yes** and add the test user to **AllowUsers**
``` bash
Modify the line **PasswordAuthentication** to say **yes** and add the test user
to **AllowUsers**
```bash
PasswordAuthentication yes
AllowUsers user test
```
**restart the sshd service**
``` bash
```bash
sudo systemctl restart sshd
```
Attempt to login to the remote host using the test account using an
incorrect password. After 3 failed attempts it should say connection
refused.
``` bash
Attempt to login to the remote host using the test account using an incorrect
password. After 3 failed attempts it should say connection refused.
```bash
ssh test@host -p 2222
```
_Fail2Ban_ should do something along the lines of ...
{{< video label="you shall not pass" webm="/webm/you-shall-not-pass.webm" >}}
log back in as your normal user, remove the test user and restore the
sshd config.
log back in as your normal user, remove the test user and restore the sshd
config.
**To remove the user**
``` bash
```bash
sudo userdel test
```
**restore the /etc/ssh/sshd_config file**
``` bash
```bash
sudo vim /etc/ssh/sshd_config
```
Set **PasswordAuthentication** back to **no** and remove test from **AllowUsers**
``` bash
```bash
PasswordAuthentication no
AllowUsers user
```
# **Conclusion**
well done, you managed to make it through all that !! At least now you
can be reassured that if them pesky brute-force attackers decide to
target your machine they wont have a fun time being in Jail 🤣 sorry
bad joke.
well done, you managed to make it through all that !! At least now you can be
reassured that if them pesky brute-force attackers decide to target your machine
they can have a fun time in Jail 🤣 sorry bad joke.
By now you have managed to setup an ssh key for a client and copy it to
a remote host, re-configure the sshd config to lockdown authentication
and last but not least install and configure Fail2Ban to block pesky
attackers.
and install and configure Fail2Ban to block pesky attackers.
{{< video label="proud" webm="/webm/proud.webm" >}}
+75 -51
View File
@@ -3,57 +3,66 @@ title: Setup a HUGO Site
date: 2022-12-31T22:03:52Z
author: "ahmza"
draft: false
weight:
weight:
tags: ["blog","website","web development","HUGO"]
tags: ["blog", "website", "web development", "HUGO"]
description: "Always wanted to setup a static website. Look no further !! In this post we go over the basics of setting up a HUGO site"
canonicalURL: "https://blog.ahmza.com/Page%28/posts/setting-up-a-hugo-site.md%29"
cover:
image: "/img/hugo/feature.webp" # image path/url
alt: "HUGO Logo" # alt text
caption: "The HUGO logo" # display caption under cover
relative: false # when using page bundles set this to true
image: "/img/hugo/feature.webp" # image path/url
alt: "HUGO Logo" # alt text
caption: "The HUGO logo" # display caption under cover
relative: false # when using page bundles set this to true
---
## **Introduction**
Hugo is a static site generator, a tool that allows us to pre-compile our website into static HTML, CSS and JS.
The main benefit of using such methods is speed.
A Static site takes a lot less time to load than a site that uses databases.
_HUGO_ is a static site generator, a tool that allows us to pre-compile our
website into static HTML, CSS and JS. The main benefit of an _ssg_ is speed. A
Static site takes a lot less time to load than a site that uses databases.
For more information on HUGO read my other post [Hugo Static Site Generator](https://blog.ahmza.com/posts/hugo-static-site-generator/)
For more information on HUGO read my other post [Hugo Static Site
Generator](https://blog.ahmza.com/posts/hugo-static-site-generator/)
## **Prerequisites**
- Git
## **Installing HUGO**
[Official steps](https://gohugo.io/installation/)
The HUGO binary is what we will use throughout the creation of our project to initially setup our site then create posts etc...
This step will vary depending on your operating system and distribution.
I will show the steps for MacOS and Arch based Linux distros.
The _HUGO_ binary is used to initialize our site then create posts etc... Below
are the steps for _MacOS_ and _Arch_ based _Linux_ distros.
### _MacOS_
### MacOS
- Install [homebrew](https://brew.sh/)
``` bash
```bash
brew install hugo
```
### Arch
``` bash
### _Arch_
```bash
sudo pacman -S hugo
```
### Confirm Installation
``` bash
```bash
hugo version
```
## Create your site
This assumes a few steps for you, i.e the theme used. The settings in this guide will mimic the base config of my site
``` bash
This assumes choices for you, i.e the theme used.
> The settings in this guide will mimic the base config of my site
```bash
hugo new site -f yml <your-sitename>
cd <your-sitename>
git init
@@ -62,34 +71,34 @@ echo "theme: 'PaperMod'" >> config.yml
```
## Create Content
We will now begin adding new content to our website. Lets create our first post.
Lets start by creating a template for our posts.
``` bash
```bash
vim archetypes/posts.md
```
Paste the following base template
``` markdown
```markdown
---
title: {{ replace .TranslationBaseName "-" " " | title }}
date: {{ .Date }}
title: { { replace .TranslationBaseName "-" " " | title } }
date: { { .Date } }
author: "<author>"
draft: true
weight:
weight:
tags: [""]
description: ""
canonicalURL: "{{ .Page | absURL }}"
cover:
image: "<image path/url>" # image path/url
alt: "<alt text>" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
image: "<image path/url>" # image path/url
alt: "<alt text>" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
---
## **Introduction**
@@ -98,27 +107,32 @@ cover:
```
If the posts folder does not exist, create it
``` bash
```bash
mkdir content/posts
```
Create and edit a post
``` bash
> pick an editor of your choice. **I use NVIM BTW**
```bash
hugo new posts/<post-name>.md
vim content/posts/<post-name>.md
```
## Start the server
Now that we have created our site, installed a theme and created a post lets start the server.
Now that we have created our site, installed a theme and created a post lets
start the server.
``` bash
```bash
hugo server -D
```
*The -D flag tells hugo server to build drafts. (notice how we have a draft: option in our posts template.)*
*Of course once you have finished a post you set draft to false like so draft: false*
You will be shown something like the following:
_The -D flag tells hugo server to build drafts. (notice how we have a draft:
option in our posts template.) Of course once you have finished a post you set
draft to false like so draft: false_
```
➜ hugo server -D
@@ -146,22 +160,25 @@ Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
```
*Notice the second line to the bottom. Web Server... This line gives you a localhost url that you can use in your browser to view your site locally.*
_Notice the second line to the bottom. Web Server... This line gives you a
localhost URL that you can use in your browser to view your site locally._
## Configure Site
Open the config.yml file in a text editor.
``` bash
```bash
vim config.yml
```
**Important changes you need to make**
- baseURL - this is the URL your site will be accessed externally. In my case. https://blog.ahmza.com
- title - is the title of your page.
- baseURL - External URL. In my case. https://blog.ahmza.com
- title - Title of your site.
Here is my config.yml with bits redacted so you can fill them in
``` yaml
```yaml
baseURL: "<your sites URL>"
title: <your site title>
paginate: 5
@@ -305,23 +322,30 @@ markup:
```
## Run the server again
Run the server and check out your hard work. Change settings make posts etc. Have fun !!
``` bash
Run the server and check out your hard work. Change settings make posts etc.
Have fun !!
```bash
hugo server -D
```
## Publish your site
Once you are happy with your site, you may want to publish it to the internet.
In the next post [Publishing your HUGO site](https://blog.ahmza.com/posts/publishing-your-hugo-site/)
I will cover a basic method of publishing your site as well as a more complicated but automated workflow that I use.
In the next post [Publishing your HUGO
site](https://blog.ahmza.com/posts/publishing-your-hugo-site/) I will cover a
basic method of publishing your site as well as a more complicated but automated
workflow that I use.
## **Conclusion**
Through this post you have learned to create your own HUGO site as well as create and edit posts.
We also learned about
Through this post you have learned to create your own HUGO site as well as
create and edit posts. We also learned about
- archetypes
- Mark posts as drafts (expand on this
- The hugo built in server (still need to add this))
- Mark posts as drafts
- The _HUGO_ built in server
- webp + webm (still need to add this)
- shortcodes (still need to add this)
+32 -25
View File
@@ -3,69 +3,76 @@ title: Setup WSL 🪟 ❤️ 🐧
date: 2022-02-23T11:57:08Z
author: "ahmza"
draft: false
weight:
weight:
tags: ["windows", "linux", "wsl"]
description: ""
canonicalURL: "https://blog.ahmza.com/Page%28/posts/setup-wsl.md%29"
cover:
image: "webp/posts/wsl/feature-anim.webp" # image path/url
alt: "Windows Loves Linux" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
image: "webp/posts/wsl/feature-anim.webp" # image path/url
alt: "Windows Loves Linux" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
showtoc: true
searchHidden: false
---
## **Introduction**
WSL stands for *Windows Subsystem for Linux* which means we have the
Linux kernel inside of windows. This is huge news for developers or people
who just want to try Linux.
WSL stands for _Windows Subsystem for Linux_ which means we have the Linux
kernel inside of windows. This is huge news for developers or people who just
want to try Linux.
## **Prerequisites**
* Enable virtualisation in BIOS
- Enable virtualisation in BIOS
## **Setup**
Open Powershell in Administrator mode
``` powershell
```powershell
wsl --install
```
> You may be required to restart the device, I Highly recommend you do
> You may have to restart the device, I Highly recommend you do
Go to the Microsoft store and search for a Linux distribution. I prefer
to use the "Ubuntu" distro.
to use the "Ubuntu" distribution.
![Microsoft Store](/img/WSL/ubuntu.webp)
Once that is installed, go ahead and run the distribution, after it
finishes setting itself up it will ask you for a username and password.
These credentials are separate from the host system so you can make them
whatever you want.
Once installed, go ahead and run the distribution, after it finishes setting
itself up it will ask you for a username and password. These credentials are
separate from the host system so you can make them whatever you want.
And that's it you have WSL and a Linux distribution setup, now go and do
something awesome.
## **Optional**
I use the windows terminal app to run the Ubuntu distribution, it makes
customising the environment a lot easier. To download it head over to the
Microsoft store and search for Windows Terminal and download it.
![Microsoft Store](/img/WSL/winterm.webp)
When you login to WSL it will not default to your home directory which gets
very annoying. So to fix that go to Windows Terminal Settings (Be sure to
look around there are some cool features) look for Ubuntu or your
distributions name and change the Starting directory to
``` powershell
\\wsl$\Ubuntu\home\ahmza
```
> Be sure to change "Ubuntu" to your distributions name
When you login to WSL it will not default to your home directory. To fix that go
to the Windows Terminal Settings look for Ubuntu or your distributions name and
change the Starting directory to
> Be sure to change "ahmza" to your username
```powershell
\\wsl$\<distro>\home\<username>
```
> Be sure to change "<distro>" to your distributions name
> Be sure to change "<username>" to your username
![winterm-settings](/img/WSL/winterm-settings.webp)
## **Conclusion**
Well done you have managed to setup WSL and use Linux inside of windows.
No go and enjoy the freedom of Linux !!
+11 -8
View File
@@ -3,26 +3,27 @@ title: Twitch Layoffs
date: 2023-03-29T12:39:05+01:00
author: "ahmza"
draft: true
weight:
weight:
tags: ["career","twitch"]
tags: ["career", "twitch"]
description: ""
canonicalURL: "https://blog.local.ahmza.com/Page%28/posts/twitch-layoffs.md%29"
cover:
image: "webp/posts/twitch-layoffs/feature-anim.webp" # image path/url
alt: "Bleed Purple" # alt text
caption: "Bleed Purple" # display caption undercover
relative: false # when using page bundles set this to true
image: "webp/posts/twitch-layoffs/feature-anim.webp" # image path/url
alt: "Bleed Purple" # alt text
caption: "Bleed Purple" # display caption undercover
relative: false # when using page bundles set this to true
---
# Mon 20 Mar 2023
The news was broken to all Twitch employees that there was going to be a mass layoff that would nuke 1/5th of Twitch's workforce,
Just over 400 employees. We were not given a date that this would happen we were just told that it would be by the end of the week
or early the next week.
# Fri 24 Mar 2023
The day started with an announcement that Twitch would layoff 1/5th of its workforce. The anticipation of this moment through the
whole week left hundreds of us with a sick feeling in our stomachs. They had split the layoffs up between APAC, EMEA, And AMER.
APAC on the chopping block first. We saw people loose access and numbers from our #general Slack channel dither. Each Region had
@@ -31,7 +32,7 @@ wave of people and have hopes that you might just be one of the people to surviv
Luckily I was one of the folk that was able to keep their jobs this time. But 1/5th of the workforce has surely affected every person
that works at twitch. We all lost somebody we worked with or reported to and so morale has tanked this past week, and you can see it.
The #general channel is almost a bone yard.
The #general channel is almost a bone yard.
In my team, the GSOC we lost our technicians, these amazing folk made our lives -- the engineers -- much easier we no longer needed
to worry about emails and phone calls. Now that the Techs have gone this workload has been thrown back at us, and it has shaken up
@@ -40,8 +41,10 @@ it comes to work will we miss these people, The two Technicians that I worked wi
interactions.
# Conclusion
If you're reading this, and you are a recruiter then please take into account ex-twitch employees effected by this tragic event.
Shout outs to:
- [Anastasia Limantzakis](https://www.linkedin.com/in/anastasia-limantzakis/)
- [Viktoria (Viki) Bagley](https://www.linkedin.com/in/viktoria-bagley-97a669206/)
+15 -13
View File
@@ -25,20 +25,22 @@ I'd like to say thank you for visiting this site.
### A bit about me
I'm based in the UK, and like most people -- probably you -- I'm
interested in learning new technologies and techniques.
As a tinkerer, I'm always looking to expand my knowledge. My passion for
learning leads me down many paths, including this website, giving me the
opportunity to learn how web servers work and the intricacies of neighboring
systems.
I get bored, so to keep myself busy I learn new stuff. This site exists because
I wanted to learn how web servers work and along the way I learned a lot about
neighboring moving parts.
I'm eager to share my knowledge with others and see them succeed in their own
pursuits.
I'm enthusiastic about learning and love when people sharing my findings.
I am slowly building my network of people whom I can share my progress with and
collaborate.
Tinkering began watching programs like "How it's Made" and "Myth Busters". This
sparked curiosity and led me to experiment with breaking things myself. As I got
older, I chased the white rabbit further and further.
I have always tinkered and naturally gained an interest for technology, I don't
limit myself to one part of tech I try to dabble in a bit of everything. one
hobby that has stuck with me is photography where you have to understand the
camera and its limits to adapt to different situations.
I also enjoy nurturing my creative side which allows me to step away from the
mechanical aspects of technology. And pottery is my medium. Throwing at the
wheel is a form of meditation that allows me to connect with my own creativity.
You can see some of my photography on my Instagram.
My goal is to use my passion for sharing and learning to make a positive impact.
To keep looking for new challenges and opportunities to grow, and inspire others
to do the same.
+41 -36
View File
@@ -3,27 +3,27 @@ title: You Need to Learn Linux 🐧
date: 2021-12-17T19:16:50Z
author: "ahmza"
draft: false
weight:
weight:
tags: ["Linux"]
description: "Here's why you should learn Linux"
canonicalURL: "https://blog.ahmza.com/Page%28/posts/you-need-to-learn-linux.md%29"
cover:
image: "/webp/posts/learn-linux/feature-anim.webp" # image path/url
alt: "learn-linux" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
image: "/webp/posts/learn-linux/feature-anim.webp" # image path/url
alt: "learn-linux" # alt text
caption: "<text>" # display caption under cover
relative: false # when using page bundles set this to true
showtoc: true
searchHidden: false
---
## **Introduction**
**You need to learn *Linux*** !!
**You need to learn _Linux_** !!
Without a doubt you will come across *Linux* at some point in your IT career and
having baseline knowledge is helpful. *Linux* can seem daunting, it's
Without a doubt you will come across _Linux_ at some point in your IT career and
having baseline knowledge is helpful. _Linux_ can seem daunting, it's
fundamentally different compared to windows. but with a bit of time you can
master the basics and unlock its true power.
@@ -31,27 +31,28 @@ master the basics and unlock its true power.
## **But Why**
- ***Linux* is everywhere**, from data centres to your smart fridge. A lot of
developers at Google use *Linux*. In fact access to the full codebase is given
on *Linux*.
- **_Linux_ is everywhere**, from data centres to your smart fridge. A lot of
developers at Google use _Linux_. In fact access to the full codebase is given
on _Linux_.
- **Power user?** The ability to personalise all aspects of the system **make it
your** system. This can result in you chasing the white rabbit, but the feeling
of booting into a system that's yours from start to finish is something else.
your** system. This can result in you chasing the white rabbit, but the feeling
of booting into a system that's yours from start to finish is something else.
- **Make it pretty** - You can create something that's **functional and beautiful**
[r/unixporn](https://www.reddit.com/r/unixporn/)
[r/unixporn](https://www.reddit.com/r/unixporn/)
**Lightweight and extensible** limiting the fluff. Making *Linux* by default a
**Lightweight and extensible** limiting the fluff. Making _Linux_ by default a
lot faster than other operating systems.
## **Ok but what about ...**
- **Application Support** - Some popular applications you use may not be
available e.g Microsoft Office and the Adobe suite. All is not lost though,
there are alternatives if you can spend the time learning new software.
- **Drivers** - More often than not *Linux* just works. Edge cases could rise
that you might struggle with, don't give up Google it and dig in !!
- **Application Support** - Some popular applications you use may not be
available e.g Microsoft Office and the Adobe suite. All is not lost though,
there are alternatives if you can spend the time learning new software.
- **Drivers** - More often than not _Linux_ just works. Edge cases could rise
that you might struggle with, don't give up Google it and dig in !!
## **How can you start**
@@ -61,54 +62,58 @@ that you might struggle with, don't give up Google it and dig in !!
**This is the full send option.** It may take you a while to acclimate but I feel
this is the fastest option to success as you force yourself into learning.
*Linux* Distributions I have enjoyed using:
_Linux_ Distributions I have enjoyed using:
- [Ubuntu](https://ubuntu.com/download/desktop) - Beginner friendly
- [Manjaro](https://manjaro.org) - OS Basics set up, provides more flexibility
- [Arch Linux](https://wiki.archlinux.org/title/installation_guide) - Jump in the deep end, go from start to finish and learn all about *Linux's* moving parts
- [Arch Linux](https://wiki.archlinux.org/title/installation_guide) - Jump in the deep end, go from start to finish and learn all about _Linux's_ moving parts
### ***MacOS* Terminal**
### **_MacOS_ Terminal**
**If you do not own a *MacBook* skip this due to cost 💸**
**If you do not own a _MacBook_ skip this due to cost 💸**
*MacOS* is *UNIX* based, **if you own a *MacBook* download a Terminal Emulator**
_MacOS_ is _UNIX_ based, **if you own a _MacBook_ download a Terminal Emulator**
-- [iterm2](https://iterm2.com/) or [kitty](https://sw.kovidgoyal.net/kitty/binary/)
both great options -- install [Homebrew](https://brew.sh/) and get going.
### ***Windows WSL***
*WSL* installs the *Linux Kernel* and allows you to use the *Linux* terminal
within *Windows*. This does have its limitations but a low bar to entry.
### **_Windows WSL_**
_WSL_ installs the _Linux Kernel_ and allows you to use the _Linux_ terminal
within _Windows_. This does have its limitations but a low bar to entry.
### **Virtual machines**
Virtualising *Linux* is another great option. VMs are quick to spin up and remove
Virtualising _Linux_ is another great option. VMs are quick to spin up and remove
providing the ability to try out a handful of distributions with ease. This does
come with the condition of having a device that can handle virtual machines
meaning:
- A CPU capable of virtualization
- enough free RAM for the VMs
### **Buy a secondary device**
Have another cheap laptop or desktop to run *Linux*. This will cost you a bit
Have another cheap laptop or desktop to run _Linux_. This will cost you a bit
more than the options above. If you're considering a second device then look
at the Thinkpad lineup. These laptops are rugged and highly upgradeable.
Two Thinkpad Models I own:
- T440P
- T480 *(Non S model)*
- T480 _(Non S model)_
## Conclusion
**Why are you still reading go and get stuck in with *Linux* 💨**
**Why are you still reading go and get stuck in with _Linux_ 💨**
{{< video label="do it" webm="/webm/do-it.webm" >}}
**Learning *Linux* is a journey that will take time. Enjoy the experience of
**Learning _Linux_ is a journey that will take time. Enjoy the experience of
learning and uncovering it's hidden powers.**
I have linked some great resources for other great *Linux* related content that
I have linked some great resources for other great _Linux_ related content that
helped me:
- [DT YouTube Channel](https://www.youtube.com/channel/UCVls1GmFKf6WlTraIb_IaJg) -
Covers *Linux* related topics
- [r/unixporn](https://www.reddit.com/r/unixporn/) - Get inspired and make *Linux* pretty
Covers _Linux_ related topics
- [r/unixporn](https://www.reddit.com/r/unixporn/) - Get inspired and make _Linux_ pretty
- [Arch Wiki](https://wiki.archlinux.org/) - Although specific to Arch, it's a great knowledge base