Creating our own cloud, look at the infrastructure

Without a server, you won’t do much. At the end of this post, you should have your infrastructure ready to rock

Server

It might sounds obvious but to self host your own set of applications, you need a server. That’s probably the first choice you’ll have to make throughout your journey:

where do you host the server(s)?

You have to choose between two options:

  1. Host it at home: the only advantage is you have a direct access to your machine. A few things about this:
    • real servers make real noises. Even if you think it’s cool because it feels pro, you don’t want this at home if you’re not living alone on an island, it can be very noisy. My advice is to keep it cheap and simple by using whichever hardware you already have, you’ll know when you need more, until then, relax and don’t invest much.
    • don’t think it’s free, you’ll still be paying for electricity and that won’t be necessarily cheaper than a machine on the cloud
    • you’ll have to setup a bunch of things:
      • setup your router so that HTTP/HTTPS traffic coming from the internet will be forward to your server (that’s what we call port forwarding)
      • request a fixed IP to your internet provider. If that’s not possible, you can look at dyndns but keep in mind those solutions are flaky by design.
    • pay attention to your internet connection. Outside LAN, if your connection isn’t great, you might end up with slow unresponsive applications. If you care about this, I would advice to go with the rental option
  2. Rent it from a hosting company: the choice will be between a VPS (which stands for virtual private server, aka a virtual machine) or a dedicated server with various support level agreement. If you’re hesitating between both, the rule of thumb is to start with a small VPS and get more when you need more. There’s no point in having a large machine if it stays idle all the time.

Tips: Weigh the pro and cons and make a decision.

Tips: If you go with option 2 I would recommend Digital Ocean. Everything has been so far cheap, nice and easy. On the plus side, you can also have 2 month free credit with their cheapest machine if you create an account with this link. I’ve also used Vultr and EC2 without problems. If you consider using OVH, for your own sake, run away. I’ve been using them for 5 years without an inch until recently where:

  • I needed to use their support which is unresponsive, takes forever to get something done and automatically close tickets even if the issue isn’t solve
  • they refused to provide me with an invoice in plain English for a new contract
  • they decided to sue me on the basis I needed to pay another year of a service I didn’t want to renew. If you decide to go ahead anyway, at least pay attention to all their newsletter bullshit as you’ll get problems if you don’t (like me)

OS

Choosing an OS is like choosing between white/dark and milk chocolate. There’s no absolute truth, it’s only a matter of taste. Anything could do the job but Linux will be our pick to follow this guide. Like for chocolate, your favorite milk chocolate could be Lindt, in the Linux world, this is what we called “distribution”. In this guide, the instructions will be given for the Linux distribution called Ubuntu server.

Tips: Pick any Linux distribution you’re already familiar with. There’s no absolute obligation for this but try to pick a server distribution over a desktop one as there are a few differences that makes them better for the task.

Tips: There’s a wide range of offering for container based orchestration. You might see a lot of buzzwords with CoreOS, Kubernetes, Swarm, … I will ignore those offerings as:

  • I don’t need scalability for self hosting. Those tools are design to solve problems I don’t have.
  • Those techs are bleeding edge
  • I don’t have a deep knowledge about those out of toy projects made over the week end

Get yourself a domain name

Imagine a world where you’d access google by typing in your browser: http://216.58.203.110/. That would be quite hard to remind. Essentially a domain name is a convenient way for your users to access a service. DNS servers are server which make the translation between a friendly name and an ip address.

It’s not a must have but it’s definitely recommended to purchase one. It cost a few bucks per year and the most popular provider is GoDaddy I’ve used them a lot in the past and never got any problem. If you get a domain with this link I will earn a few bucks which is a great way to show support if you like this post and want more in the future.

In the very likely scenario where you have 1 machine and 1 IP address, I would recommend to do the following once you’ve purchased a domain name:

  1. Create an A record: yourdomain.com -> ip address
  2. Create a CNAME record: www.yourdomain.com -> yourdomain.com
  3. Everytime you want to create a new service, generate the corresponding configuration: new CNAME record: application_name.yourdomain.com -> yourdomain.com

The reason for doing this is to make your life easier. The day you change your server or something happen with your IP address, you’ll simply have to update your A record and call it a day.

Tips: If you really don’t want to invest in a domain name, you have 2 options to access your services:

  • you’ll have to type in your browser the ip address of your server followed by the port the application is running (eg: http:/24.34.12.234:1010). Good luck to explain this to a non tech savvy guy over the phone. It won’t be user friendly, slower (no gzip compression) and less secure (no web application firewall).
  • you can trick your OS dns resolution by editing your host file (/etc/hosts in linux and OSX). Example: if you add: “192.168.0.17 selfhosted.com” in your host file, typing selfhosted.com in your browser will bring you to 192.168.0.17. It will be better than the approach above but anybody who needs to access your applications will have to update their host file as well. As a side note, this tip can also be applied to block advertising in your browser without any third party plugin :).

Before getting deeper

Being able to connect to your server is an absolute requirement, for this, SSH is your friends. In this section, we’ll initiate a connection to the server getting a prompt from which you can execute commands.

If you chose to go with:

  • a cloud provider, wait until you receive the credentials to your newly created machine. Those credentials will be the one you can use to initiate an SSH connection to your server.
  • home hosting, plug a screen and a keyboard in your server and process with the installation of the operating system of your choosing. Once complete, you will need to install the so called SSH server by typing:
sudo apt-get update
sudo apt-get install openssh-server

To connect to your server, you will need something called an SSH client. If you are:

  • a Linux / OSX user: it is very likely the SSH client is already pre installed. fire up a terminal and type:
ssh username@host_ip
# replace username by your actual username, it might be 'root' by default
# replace host_ip by the ip adress of your machine
  • a windows user: give a try to putty, enter the ip address of your machine and connect

If everything is working fine, you should be welcome with a message and a prompt you can type commands from. For example:

whoami
date