Creating a VPS with cloud-init
Level 3 · First boot and the way back in
The five choices you make for a new VPS. Place, system, plan and SSH key, plus a cloud-init file that sets it up on first boot.
Course contentsLesson 4 of 7
Level 1 · Choosing the hosting
Level 2 · Plans and the shared machine
Level 3 · First boot and the way back in
Level 4 · The network around the server
After this lesson you can
- Make the five choices to create a VPS
- Write a short cloud-init file
- Check that cloud-init has finished
12 mincovers 2 glossary entries
Worth reading first: VPS Plans and Billing
What you choose when you make a server
Making a VPS takes five choices in the host's web panel, and about a minute of waiting. You pick a place, a system such as Ubuntu, a plan, and the SSH key you will log in with. Last, you can paste a short cloud-init file that sets the server up the first time it starts. Then you press create.
The place is the city or country where the machine sits. Pick one near your users. Every message has to travel there and back. A server in Frankfurt answers a user in Paris much faster than one in Sydney.
When the server starts, the host gives it a public IP address. That is the number other computers use to reach it. It shows up in the panel within a minute, and billing starts at the same time.
Adding an SSH key at this step means you can log in with the key from the first minute. With no key, many hosts email a root password instead. A key is safer, because there is no password for anyone to guess.
cloud-init is the tool that reads your setup file on the very first boot. The file can add users, put in keys, install programs and run commands. It starts with the line #cloud-config. It runs once, so every server made from the same file comes out the same.
It runs in the background after the server starts. So it may still be busy when you first log in. cloud-init status --wait waits until it is done. If a program did not install, look in its log. The log is the file /var/log/cloud-init-output.log.
A common mistake is a bad space in the cloud-init file. It is written in a format where the gaps at the start of each line carry meaning. One wrong gap, and the whole file is skipped with no warning in the panel. Check the log after the first boot.
#cloud-config
package_update: true
packages:
- nginx
- fail2ban
runcmd:
- systemctl enable --now nginxWorked example
Jack makes three web servers
Jack needs three servers that are set up the same way. Doing it by hand would take him about 40 minutes each.
He writes one 12-line cloud-init file and pastes it in when he makes each server. Five minutes after the third one starts, all three serve the same page.
The words for this lesson2
Check yourself
Your cloud-init file did not install nginx. Where do you look first?
Finished this lesson?
Marking it complete also marks its 2 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.