Mastering Ubuntu Server: Explore the versatile, powerful Linux Server distribution Ubuntu 22.04 with this comprehensive guide
By Jay LaCroix
()
About this ebook
Ubuntu Server is taking the server world by storm - and for a good reason! The server-focused spin of Ubuntu is a stable, flexible, and powerful enterprise-class distribution of Linux with a focus on running servers both small and large.
Mastering Ubuntu Server is a book that will teach you everything you need to know in order to manage real Ubuntu-based servers in actual production deployments. This book will take you from initial installation to deploying production-ready solutions to empower your small office network, or even a full data center. You'll see examples of running an Ubuntu Server in the cloud, be walked through set up popular applications (such as Nextcloud), host your own websites, and deploy network resources such as DHCP, DNS, and others. You’ll also see how to containerize applications via LXD to maximize efficiency and learn how to build Kubernetes clusters. This new fourth edition updates the popular book to cover Ubuntu 22.04 LTS, which takes advantage of the latest in Linux-based technologies.
By the end of this Ubuntu book, you will have gained all the knowledge you need in order to work on real-life Ubuntu Server deployments and become an expert Ubuntu Server administrator who is well versed in its feature set.
Jay LaCroix
My name is Jeremy "Jay" LaCroix, and I am a computer technician that has taken an interest in writing. My latest story is titled "Escape to Planet 55" (which is a complete rewrite of "What it Means to be Human" and I am very pleased with it. I hope that my story will be of value to someone.
Read more from Jay La Croix
Mastering Ubuntu Server Rating: 5 out of 5 stars5/5Linux Mint Essentials Rating: 3 out of 5 stars3/5Mastering Ubuntu Server.: Master the art of deploying, configuring, managing, and troubleshooting Ubuntu Server 18.04 Rating: 0 out of 5 stars0 ratings
Related to Mastering Ubuntu Server
Related ebooks
Linux Basics for SysAdmin: Learn core linux concepts and command-line skills to kickstart your system administration career Rating: 0 out of 5 stars0 ratingsFundamentals of Linux: Explore the essentials of the Linux command line Rating: 0 out of 5 stars0 ratingsUnix / Linux FAQ: with Tips to Face Interviews Rating: 0 out of 5 stars0 ratingsLINUX FOR NOVICES: A Beginner's Guide to Mastering the Linux Operating System (2023) Rating: 0 out of 5 stars0 ratingsI am Linux : Being A Ultra Linux User Rating: 0 out of 5 stars0 ratingsInstant Debian - Build a Web Server Rating: 0 out of 5 stars0 ratingsArch Linux: Fast and Light! Rating: 3 out of 5 stars3/5Linux System Programming Techniques: Become a proficient Linux system programmer using expert recipes and techniques Rating: 0 out of 5 stars0 ratingsMastering Linux Administration: A Comprehensive Guide: The IT Collection Rating: 5 out of 5 stars5/5SvelteKit Up and Running: Leverage the power of a next-generation web framework to build high-performance web apps with ease Rating: 0 out of 5 stars0 ratingsVue.js 3 for Beginners: Learn the essentials of Vue.js 3 and its ecosystem to build modern web applications Rating: 0 out of 5 stars0 ratingsInstant IntroJs Rating: 0 out of 5 stars0 ratingsSimple Computer Security: Disinfect Your PC Rating: 0 out of 5 stars0 ratingsArchitecting CSS: The Programmer’s Guide to Effective Style Sheets Rating: 0 out of 5 stars0 ratingsPython Apps on Visual Studio Code: Develop apps and utilize the true potential of Visual Studio Code (English Edition) Rating: 0 out of 5 stars0 ratingsCybersecurity - Attack and Defense Strategies: Infrastructure security with Red Team and Blue Team tactics Rating: 5 out of 5 stars5/5OpenAI API Cookbook: Build intelligent applications including chatbots, virtual assistants, and content generators Rating: 0 out of 5 stars0 ratingsIntroducing VirtualBox & Debian: MyOwnGeek, #1 Rating: 0 out of 5 stars0 ratingsExploring Chromebook - 2023 Edition: The Illustrated, Practical Guide to using Chromebook Rating: 0 out of 5 stars0 ratingsLinux Hacking 101: A Beginner’s Guide to Ethical Hacking with Linux and Kali Linux Rating: 0 out of 5 stars0 ratingsManage Partitions with GParted How-to Rating: 5 out of 5 stars5/5Network Engineer's Bible: Mastering 100 Protocols For Communication, Management, And Security Rating: 0 out of 5 stars0 ratingsSoftware Engineering for Absolute Beginners: Your Guide to Creating Software Products Rating: 0 out of 5 stars0 ratingsFoundations of Python Network Programming Rating: 4 out of 5 stars4/5Lighttpd Rating: 4 out of 5 stars4/5Regex Quick Syntax Reference: Understanding and Using Regular Expressions Rating: 0 out of 5 stars0 ratingsVue.js 3 Design Patterns and Best Practices: Develop scalable and robust applications with Vite, Pinia, and Vue Router Rating: 0 out of 5 stars0 ratings
Operating Systems For You
The Windows Command Line Beginner's Guide: Second Edition Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Windows 11 All-in-One For Dummies Rating: 5 out of 5 stars5/5Hacking : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Ethical Hacking Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Bash Command Line Pro Tips Rating: 5 out of 5 stars5/5Make Your PC Stable and Fast: What Microsoft Forgot to Tell You Rating: 4 out of 5 stars4/5Hacking for Beginners: Mastery Guide to Learn and Practice the Basics of Computer and Cyber Security Rating: 0 out of 5 stars0 ratingsExploring Windows 11: The Illustrated, Practical Guide to Using Microsoft Windows Rating: 0 out of 5 stars0 ratingsiPhone For Dummies Rating: 0 out of 5 stars0 ratingsHelp! iOS 17 - iPhone: How to Use iOS17 Rating: 0 out of 5 stars0 ratingsLinux All-In-One For Dummies Rating: 2 out of 5 stars2/5OneNote: The Ultimate Guide on How to Use Microsoft OneNote for Getting Things Done Rating: 1 out of 5 stars1/5Mac Unlocked: Everything You Need to Know to Get Cracking in macOS Big Sur Rating: 0 out of 5 stars0 ratingsLearn SQL Server Administration in a Month of Lunches Rating: 3 out of 5 stars3/5Raspberry Pi Cookbook for Python Programmers Rating: 0 out of 5 stars0 ratingsMacBook Pro User Manual: 2022 MacBook Pro User Guide for beginners and seniors to Master Macbook Pro like a Pro Rating: 0 out of 5 stars0 ratingsPowerShell: A Beginner's Guide to Windows PowerShell Rating: 4 out of 5 stars4/5iPhone Unlocked Rating: 0 out of 5 stars0 ratingsThe Mac Terminal Reference and Scripting Primer Rating: 4 out of 5 stars4/5RHCSA Red Hat Enterprise Linux 8 (UPDATED): Training and Exam Preparation Guide (EX200), Second Edition Rating: 5 out of 5 stars5/5macOS Sonoma For Dummies Rating: 0 out of 5 stars0 ratingsUbuntu Linux Toolbox: 1000+ Commands for Power Users Rating: 3 out of 5 stars3/5PowerShell: A Comprehensive Guide to Windows PowerShell Rating: 4 out of 5 stars4/5Easy Linux For Beginners Rating: 2 out of 5 stars2/5Linux Bible Rating: 0 out of 5 stars0 ratingsThe Linux Command Line Beginner's Guide Rating: 4 out of 5 stars4/5The Darknet Superpack Rating: 0 out of 5 stars0 ratings
Reviews for Mastering Ubuntu Server
0 ratings0 reviews
Book preview
Mastering Ubuntu Server - Jay LaCroix
Mastering Ubuntu Server
Fourth Edition
Explore the versatile, powerful Linux Server distribution Ubuntu 22.04 with this comprehensive guide
Jay LaCroix
BIRMINGHAM—MUMBAI
Mastering Ubuntu Server
Fourth Edition
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Senior Publishing Product Manager: Aaron Tanna
Acquisition Editor – Peer Reviews: Saby Dsilva
Project Editor: Namrata Katare
Content Development Editor: Liam Thomas Draper
Copy Editor: Safis Editing
Technical Editor: Aditya Sawant
Proofreader: Safis Editing
Indexer: Manju Arasan
Presentation Designer: Ganesh Bhadwalkar
First published: July 2016
Second edition: May 2018
Third edition: December 2020
Fourth edition: September 2022
Production reference: 2210223
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80323-424-3
www.packt.com
Contributors
About the author
Based in Michigan, Jay LaCroix is an educator and technologist, specializing in Linux. After a successful tech career, Jay recently stepped away from corporate IT in order to launch his own company, LearnLinuxTV. There, Jay has produced hundreds of Linux-related training videos that are viewed by a half million people per month on average. In addition, Jay also writes books on Linux, with this one being a recent example.
Outside of technology, Jay also enjoys retro-gaming and martial arts.
I would like to thank all of my readers and subscribers for making all of this possible. It’s an amazing honor that you’ve chosen me to lead you on your Linux journey! Also thanks to Tom Lawrence for encouraging me and giving me lots of advice. Last (but by no means least), thanks to my partner Alan, my sons, and all of my family and friends.
About the reviewers
Paride Legovini is a core Ubuntu developer, a Debian developer, and currently an Ubuntu Server software engineer at Canonical. He does packaging, Quality Assurance, and maintains the testing and continuous integration infrastructure of team-developed projects, like cloud-init and the Ubuntu Advantage tools, which includes automated integration testing done on all the major clouds. He has also joined the release engineering team for all the new Ubuntu releases since 2019, being responsible for the quality of Ubuntu Server.
His professional past is in academia, with an MSc in Physics, a Ph.D. in Geophysics, and his professional roles often been at the intersection between science and IT in different research institutions.
He spent 2014 in Antarctica, where he was in charge of maintenance and data acquisition, storage, backup, and transmission for several international scientific projects at the Concordia research station during the polar winter. The role leveraged Paride’s all-around tinkerer nature, sometimes requiring operating a power tool, a soldering iron, and a Unix shell, not necessarily in that order.
I would like to thank the Debian project for giving the world a universal operating system for anybody to run, study, modify, and share. Debian realized the promise that free software would empower people, and has had a significant impact on my life and career. Thanks also to Canonical for popularizing GNU/Linux and for allowing me to participate in this review, to Jay LaCroix for turning what is clearly genuine passion into such an enjoyable book, and to Packt for inviting me to be a reviewer.
Mario Splivalo’s amazement with computers started back when Commodore 64 dominated the user-space.
He took his first steps using BASIC on his dad’s Commodore 64 before quickly shifting to assembler. He gradually moved to PCs where he discovered a great love for programming, systems design, and database administration. He switched to Linux (Knoppix, then Ubuntu) in the early 2000s and never looked back. He continued as a database administrator, programmer, and system administrator.
Mario spent five years with Canonical working mainly as an OpenStack engineer. It was a great experience that helped Mario to see how Ubuntu is created from the inside
, and participate in its development.
Currently, Mario works as a consultant dealing with databases extending into modern cloud-based architectures.
Join our community on Discord
Join our community’s Discord space for discussions with the author and other readers:
https://packt.link/LWaZ0
Contents
Preface
Who this book is for
What this book covers
To get the most out of this book
Share your thoughts
Deploying Ubuntu Server
Technical requirements
Determining your server’s role
Choosing a device for our server
Physical server
Physical desktop
Laptop
Virtual machine
Virtual private server
Raspberry Pi
Obtaining installation media
Creating a bootable flash drive
Planning the partitioning layout
Installing Ubuntu Server
Installing Ubuntu on a Raspberry Pi
Summary
Relevant tutorials
Managing Users and Permissions
Understanding the purpose of users and groups
Understanding when to use root
Using sudo to run privileged commands
Creating and removing users
Using useradd
Using adduser
Removing users
Understanding the /etc/passwd and /etc/shadow files
Understanding the /etc/passwd file
Understanding the /etc/shadow file
Distributing default configuration files with /etc/skel
Switching users
Managing groups
Managing passwords and password policies
Locking and unlocking user accounts
Setting password expiration information
Setting a password policy
Configuring administrator access with sudo
Setting permissions on files and directories
Viewing permissions
Changing permissions
Changing the ownership of objects
Summary
Relevant videos
Further reading
Managing Software Packages
Understanding Linux package management
Understanding the differences between Debian and Snap packages
Debian packages
Snap packages
Installing and removing software
Managing Debian packages with apt
Managing Snap packages with snap
Searching for packages
Managing package repositories
Adding additional repositories
Adding Personal Package Archives
Backing up and restoring Debian packages
Cleaning up orphaned apt packages
Taking advantage of hardware enablement updates
Summary
Relevant video
Further reading
Navigating and Essential Commands
Learning essential Linux commands
Understanding the Linux filesystem layout
Viewing the contents of files
Viewing application log files
Summary
Relevant video
Further reading
Managing Files and Directories
Copying, moving, and renaming files and directories
Editing files with the Nano and Vim text editors
Editing with Nano
Editing with Vim
Input and output streams
Using symbolic and hard links
Summary
Relevant videos
Boosting Your Command-line Efficiency
Understanding the Linux shell
Understanding Bash history
Learning some useful command-line tricks
Understanding variables
Writing simple scripts
Putting it all together – Writing an rsync backup script
Summary
Relevant videos
Further reading
Controlling and Managing Processes
Managing jobs
Understanding the ps command
Viewing running processes with ps
Configuring arguments to ps
Changing the priority of processes
Dealing with misbehaving processes
Managing system processes
Scheduling tasks with cron
Summary
Relevant videos
Further reading
Monitoring System Resources
Viewing disk usage
Using df
Diving deeper into disk usage
Monitoring memory usage
Understanding server memory
Managing swap
Understanding load average
Viewing resource usage with htop
Summary
Relevant videos
Further reading
Managing Storage Volumes
Adding additional storage volumes
Formatting and partitioning storage devices
Creating a partition
Formatting partitions
Mounting and unmounting volumes
Understanding the /etc/fstab file
Analyzing the contents of /etc/fstab
Adding to the /etc/fstab file
Backing up and restoring volumes
Utilizing LVM
Getting started with LVM
Formatting logical volumes
Removing volumes with LVM
Understanding LVM snapshots
Summary
Relevant videos
Further reading
Connecting to Networks
Setting the hostname
Managing network interfaces
Assigning static IP addresses
Understanding Linux name resolution
Getting started with OpenSSH
Installing OpenSSH
Issuing commands with OpenSSH
Getting started with SSH key management
Generating public and private keys
Copying your public key to a remote server
Utilizing an SSH agent
Changing the passphrase of an OpenSSH key
Simplifying SSH connections with a config file
Summary
Relevant videos
Further reading
Setting Up Network Services
Planning your IP address scheme
Setting up a DHCP server for serving IP addresses
Adding a DNS server
Setting up external DNS with bind
Setting up internal DNS and adding hosts
Setting up an internet gateway
Summary
Further reading
Sharing and Transferring Files
File server considerations
Sharing files with Windows users via Samba
Setting up NFS shares
Transferring files with rsync
Transferring files with SCP
Summary
Relevant videos
Further reading
Managing Databases
Preparations for setting up a database server
Installing MariaDB
Understanding the MariaDB configuration files
Managing MariaDB databases
Setting up a secondary database server
Summary
Further reading
Serving Web Content
Installing and configuring Apache
Installing additional Apache modules
Securing Apache with TLS
Installing and configuring NGINX
Setting up and configuring Nextcloud
Summary
Relevant videos
Further reading
Automating Server Configuration with Ansible
Understanding the need for configuration management
Why Ansible?
Creating a Git repository
Getting started with Ansible
Making your servers do your bidding
Setting up an inventory file and configuring Ansible settings
Configuring client servers
Putting it all together – automating web server deployment
Using Ansible’s pull method
Summary
Relevant videos
Further reading
Virtualization
Prerequisites and considerations
Setting up a virtual machine server
Creating virtual machines
Bridging the virtual machine network
Simplifying virtual machine creation with cloning
Managing virtual machines via the command line
Summary
Relevant video
Further reading
Running Containers
What is containerization?
Understanding the differences between Docker and LXD
Installing Docker
Managing Docker containers
Automating Docker image creation with Dockerfiles
Managing LXD containers
Summary
Relevant videos
Further reading
Container Orchestration
Container orchestration
Preparing a lab environment for Kubernetes testing
Utilizing MicroK8s
Installing MicroK8s on Linux
Installing MicroK8s on macOS
Installing MicroK8s on Windows
Interacting with MicroK8s
Setting up a Kubernetes cluster
Preliminary setup
Installing Kubernetes
Deploying containers via Kubernetes
Summary
Relevant videos
Further reading
Deploying Ubuntu in the Cloud
Understanding the difference between on-premises and cloud infrastructure
Important considerations when considering cloud computing as a potential solution
Becoming familiar with some basic AWS concepts
Creating an AWS account
Signing up for AWS
Implementing basic user security
Choosing a region
Deploying Ubuntu as an AWS EC2 instance
Setting up an IAM role for Session Manager
Creating an Ubuntu Server instance in AWS
Creating and deploying Ubuntu AMIs
Automatically scaling Ubuntu EC2 deployments with Auto Scaling
Creating a launch template
Creating an Auto Scaling group
Keeping costs down: understanding how to save money and make cost-effective decisions
Viewing billing information
Adding a billing alert
Removing unneeded backups
Running EC2 instances only when they’re needed
Stopping or terminating unneeded EC2 instances
Taking the cloud further: additional resources to grow your knowledge
Online training and labs
Certification
Keep experimenting and learning
AWS documentation
Summary
Further reading
Automating Cloud Deployments with Terraform
Why it’s important to automate your infrastructure
Introduction to Terraform and how it can fit within your workflow
Installing Terraform
Automating an EC2 instance deployment
Managing security groups with Terraform
Using Terraform to destroy unused resources
Combining Ansible with Terraform for a full deployment solution
Summary
Securing Your Server
Lowering your attack surface
Understanding and responding to CVEs
Installing security updates
Automatically installing patches with the Canonical Livepatch service
Securing OpenSSH
Installing and configuring Fail2ban
MariaDB best practices for secure database servers
Setting up a firewall
Encrypting and decrypting disks with LUKS
Locking down sudo
Summary
Further reading
Troubleshooting Ubuntu Servers
Evaluating the scope
Conducting a root cause analysis
Viewing system logs
Tracing network issues
Troubleshooting resource issues
Diagnosing defective RAM
Summary
Further reading
Preventing Disasters
Preventing disasters
Utilizing Git for configuration management
Implementing a backup plan
Utilizing bootable recovery media
Summary
Further reading
Other Books You May Enjoy
Index
Landmarks
Cover
Index
Preface
Linux is an exciting platform. You can literally find it everywhere—desktops, laptops, phones, embedded appliances, and especially servers. Linux servers power many famous technologies around the world, and have a massive presence in physical and cloud server environments. Linux servers are scalable, stable, and powerful.
Way back in 1991, a computer science student in Finland, named Linus Torvalds, created a kernel as a school project. He created the Linux kernel. And little did he know at the time, Linux would see us through some of the most exciting innovations in infrastructure design. Things like multicore processors, virtualization, containerization, and cloud computing (to name a few) have transformed data centers all over the world. And Linux has been a part of all of those advancements.
Ubuntu, a popular distribution of Linux, has been a major driving force in the adoption of Linux. Ever since its first release back in 2004, Ubuntu has made Linux more approachable for newcomers, while simultaneously offering powerful features to server administrators. Ubuntu can be found on notebooks and workstations, in addition to servers.
Ubuntu Server enables administrators to create efficient, flexible, and highly available servers that empower organizations with the power of open source. As Ubuntu administrators, we’re in good company—according to W3Techs, Ubuntu is the most widely deployed distribution on the web with regard to Linux. With the release of Ubuntu 22.04, this platform becomes even more exciting!
In this book, we will dive right into Ubuntu Server, and you will learn all the concepts needed to manage your servers and configure them to perform all kinds of neat tasks, such as serving web pages, managing virtual machines, running containers, automating configuration, sharing files with other users, and even running Ubuntu in the cloud.
We’ll start our journey with the first chapter, where we’ll walk through the installation of Ubuntu Server 22.04, which will serve as a foundation for the rest of the book. As we proceed through our journey, we’ll look at managing users, connecting to networks, and controlling processes. Later, we’ll implement important technologies, such as DHCP, DNS, Apache, MariaDB, and more. We’ll even set up our own Nextcloud server along the way.
Finally, the end of the book covers various things we can do to troubleshoot issues, as well as preventing and recovering from disasters.
Who this book is for
This book is intended for readers with intermediate or advanced-beginner Linux skills, who would like to learn all about setting up servers with Ubuntu Server. This book assumes that the reader knows the basics of Linux, such as editing configuration files and running basic commands. In addition, this book assumes a basic understanding of fundamental networking concepts, such as DHCP, DNS, IP Addresses, and so on. Also, this book assumes that the reader understands the purpose of basic network hardware, such as routers, switches, and similar hardware.
What this book covers
Chapter 1, Deploying Ubuntu Server, covers the installation process for Ubuntu Server. This chapter walks you through creating bootable media and the installation process.
Chapter 2, Managing Users and Permissions, covers user management in full. Topics here will include creating and removing users, configuring password policies, and using the
sudo
command, as well as group management and switching from one user to another.
Chapter 3, Managing Software Packages, takes the reader through the process of searching for, installing, and managing packages. This will include managing APT repositories and installing packages, and even a look at Snap packages.
Chapter 4, Navigating and Essential Commands, teaches you the essential commands needed necessary for navigating through directory trees, viewing the contents of log files, and perusing log files.
Chapter 5, Managing Files and Directories, expands on the knowledge gained from the previous chapter and rounds out your toolset of essential commands by going over how to edit, copy, move, and rename files.
Chapter 6, Boosting Your Command-line Efficiency, goes over additional tips, tricks, and techniques to enhance the reader’s usage of the command line. Topics here include managing output, investigating Bash history, and more.
Chapter 7, Controlling and Managing Processes, teaches the reader how to manage what is running on the server, as well as how to stop misbehaving processes. This will include having a look at htop, systemd, and managing jobs.
Chapter 8, Monitoring System Resources, goes over how to manage valuable system resources on your server, such as viewing disk and memory usage, as well as understanding load average and how it impacts your CPU.
Chapter 9, Managing Storage Volumes, takes a look at storage volumes. You’ll be shown how to view disk usage, format volumes, manage the
/etc/fstab
file, use LVM, and more. In addition, we’ll look at managing swap.
Chapter 10, Connecting to Networks, takes a look at networking in Ubuntu, specifically how to connect to resources from other nodes. We’ll look at assigning IP addresses, connecting to other nodes via OpenSSH, and name resolution.
Chapter 11, Setting Up Network Services, revisits networking with more advanced concepts. In this chapter, the reader will learn more about the technologies that glue our network together, such as DHCP and DNS. The reader will set up their own DHCP and DNS server, as well as installing NTP.
Chapter 12, Sharing and Transferring Files, is all about sharing files with others. Concepts will include the setup of Samba and NFS network shares, and we will even go over transferring files manually with
rsync
and
scp
.
Chapter 13, Managing Databases, takes the reader through the journey of setting up and managing databases via MariaDB. The reader will learn how to install MariaDB, how to set up databases, and how to create a secondary database server.
Chapter 14, Serving Web Content, takes a look at serving content with Apache. In addition, the reader will be shown how to secure Apache with an SSL certificate, manage modules, and even set up a Nextcloud server by the end of the chapter.
Chapter 15, Automating Server Configuration with Ansible, will show the reader how to set up a Git repository for holding configuration management scripts, how to use the powerful Ansible tool to automate common administrative tasks, and also how to use
ansible-pull
.
Chapter 16, Virtualization, is all about virtualization (unsurprisingly!). The reader will be walked through setting up their very own KVM installation, as well as how to manage virtual machines with virt-manager.
Chapter 17, Running Containers, discusses the subject of containers and shows the reader how to manage containers in both Docker and LXD.
Chapter 18, Container Orchestration, teaches you how to take containers to the next level and manage them with the power of Kubernetes. You’ll not only learn how to install Micro K8s, but also how to build your very own Kubernetes cluster from scratch.
Chapter 19, Deploying Ubuntu in the Cloud, shows you how to spin up Ubuntu servers in the cloud, with an introduction to Amazon Web Services (AWS).
Chapter 20, Automating Cloud Deployments with Terraform, goes over the process of automating the process of building cloud infrastructure using Terraform.
Chapter 21, Securing Your Server, takes a look at various things the reader can do to strengthen security on Ubuntu servers. Topics will include lowering the attack surface, securing OpenSSH, setting up a firewall, and more.
Chapter 22, Troubleshooting Ubuntu Servers, consists of topics relating to things we can do when our deployments don’t go according to plan. The reader will also investigate the problem space, view system logs, and trace network issues.
Chapter 23, Preventing Disasters, informs the reader of various strategies that can be used to prevent and recover from disasters. This includes a look at utilizing Git for configuration management, implementing a backup plan, and more.
To get the most out of this book
This book is for readers who already have some experience with Linux, though it doesn’t necessarily have to be with Ubuntu. Preferably, the reader will understand basic Linux command-line skills, such as changing directories, listing contents, and issuing commands as regular users or with root. It’s also preferred that the reader understands foundational networking concepts, such as the purpose of things like DHCP, DNS, as well as IP addressing. Even if you feel as though you need a refresher, you should read this book anyway—the opening chapters will cover many of these concepts.
In this book, we’ll take a look at real-world situations in which we can deploy Ubuntu Server. This will include the installation process, serving web pages, setting up databases, and much more. Specifically, the goal here is to be productive. Each chapter will teach the reader a new and valuable concept, using practical examples that are relative to real organizations. Basically, we focus on getting things done, rather than focusing primarily on theory. Although the theory that goes into Linux and its many distributions is certainly interesting, the goal here is to get you to the point where if a work colleague or client asks you to perform work on an Ubuntu-based server, you’ll be in a good position to get the task done. Therefore, if your goal is to get up and running with Ubuntu Server and learn the concepts that really matter, this book is definitely for you.
To follow along, you’ll either need a server on which to install Ubuntu Server, a virtual Ubuntu instance from a cloud provider, or a laptop or desktop capable of running at least one virtual machine.
Download the example code files
The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/Mastering-Ubuntu-Server-Fourth-Edition
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781803234243_ColorImages.pdf
Conventions used
There are a number of text conventions used throughout this book.
CodeInText
: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Anyway, back to our
/etc/passwd
file. The fifth column is designated for user info, most commonly the user’s first and last names."
A block of code is set as follows:
description: External access profile devices: eth0: name: eth0 nictype: bridged parent: br0 type: nic
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are highlighted:
- name: Start the apache2 services ansible.builtin.service: name: apache2 state: started
enabled: true
Any command-line input or output is written as follows:
sudo apt install docker.io
Bold: Indicates a new term, an important word, or words that you see on the screen. For instance, words in menus or dialog boxes appear in the text like this. For example: "Select System info from the Administration panel."
Warnings or important notes appear like this.
Tips and tricks appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: Email
and mention the book’s title in the subject of your message. If you have questions about any aspect of this book, please email us at
.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you reported this to us. Please visit http://www.packtpub.com/submit-errata, click Submit Errata, and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at
with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packtpub.com.
Share your thoughts
Once you’ve read Mastering Ubuntu Server, Fourth Edition, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
Download a free PDF copy of this book
Thanks for purchasing this book!
Do you like to read on the go but are unable to carry your print books everywhere?Is your eBook purchase not compatible with the device of your choice?
Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.
Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.
The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily
Follow these simple steps to get the benefits:
Scan the QR code or visit the link below
https://packt.link/free-ebook/9781803234243
Submit your proof of purchase
That’s it! We’ll send your free PDF and other benefits to your email directly
1
Deploying Ubuntu Server
Ubuntu Server is an extremely powerful distribution of Linux for servers and network appliances. Whether you’re setting up a high-end database or a small office file server, the flexible nature of Ubuntu Server will meet and surpass your needs. In this book, we’ll walk through all the common use cases to help you get the most out of this exciting platform. Ubuntu Server features a perfect mix of modern development frameworks and rock-solid stability, and its hardware support enables it to be installed on the latest server hardware.
In this chapter, I’ll guide you through the process of deploying Ubuntu Server from start to finish. We’ll begin with some discussion of best practices, and then we’ll obtain the software and create our installation media. Next, I’ll give you a step-by-step rundown of the entire installation procedure. By the end of this chapter, you’ll have an Ubuntu Server installation of your own to use throughout the remainder of this book. In addition, since Canonical (the makers of Ubuntu) now offers official support for Raspberry Pi, we’ll look at the process of setting that up as well.
In this chapter, we will cover:
Technical requirements
Determining your server’s role
Choosing a device for our server
Obtaining installation media
Creating a bootable flash drive
Installing Ubuntu Server
Installing Ubuntu Server on a Raspberry Pi
To get started, we’ll first take a look at some of the technical requirements for deploying a server with Ubuntu.
Technical requirements
To follow along with the examples in this book, you’ll need an Ubuntu Server installation to work with. In general, the following specifications are the estimated minimums to successfully install Ubuntu Server:
64-bit CPU
1 GB RAM
10-GB hard disk (16 GB or more is recommended)
64-bit CPU support is now a requirement, with the only exception being the Raspberry Pi version. This is because Canonical no longer makes versions of Ubuntu available for 32-bit PC and server processors. While this may seem like a downside, all computers sold today support 64-bit operating systems, and consumer CPUs have been 64-bit capable since at least 2003. Even if you have an older PC lying around that you don’t think is capable of running a 64-bit operating system, you’d be surprised—even the later models of the Pentium IV (which is quite old) support this, so this requirement shouldn’t be hard to meet. Don’t worry about the particulars of this right now, we’ll go through the requirements in more detail later on in this chapter.
Now that we understand the technical requirements of Ubuntu Server, let’s consider the role our server will play in our organization.
Determining your server’s role
You’re excited to set up an Ubuntu Server installation so you can follow along with the examples contained in this book. It is also important to understand how a typical server rollout is performed in the real world. Every server must have a purpose, or role. This role could be that of a database server, web server, file server, and so on. In a nutshell, the role is the value the server adds to you or your organization. Sometimes, servers may be implemented solely for the purpose of testing experimental code. And this is important too—having a test environment is a very common (and worthwhile) practice.
Once you understand the role your server plays within your organization, you can plan for its implementation. Is the system mission critical? How would it affect your organization if for some reason this server malfunctioned? Depending on the answer to this question, you may only need to set up a single server for this task, or you may wish to plan for redundancy such that the server doesn’t become a central point of failure. An example of this may be a DNS server, which would affect your colleagues’ ability to resolve local hostnames and access required resources. It may make sense to add a second DNS server to take over in the event that the primary server becomes unavailable for some reason.
Another item to consider is how confidential the data residing on a server is going to be for your environment. This directly relates to the installation procedure we’re about to perform, because you will be asked whether or not you’d like to utilize encryption. The encryption that Ubuntu Server offers during installation is known as encryption at rest, which refers to the data stored within the internal storage volumes on that server. If your server is destined to store confidential data (accounting information, credit card numbers, employee or client records, and so on), you may want to consider making use of this option.
Encrypting your hard disks is a really good idea to prevent miscreants with local access from stealing data. As long as the attacker doesn’t have your encryption key, they cannot steal this confidential information. However, it’s worth mentioning that anyone with physical access can easily destroy data (encrypted or not), so remember to keep your server room locked!
At this point in the book, I’m definitely not asking you to create a detailed implementation diagram or anything like that, but instead to keep in mind some concepts that should always be part of the conversation when setting up a new server. It needs to have a reason to exist, it should be understood how critical and confidential the server’s data will be, and the server should then be set up accordingly. Once you practice these concepts as well as the installation procedure, you can make up your own server roll-out plan to use within your organization going forward. All in all, understanding the purpose of each component in your infrastructure is a great mindset to adopt.
At this point, we now understand how we might identify a role for our server and how it will fit into our organization. In the next section, we’ll take a look at the process of actually installing Ubuntu Server, so we will have at least one test machine to use for the examples in this book.
Choosing a device for our server
I bet you’re excited to set up your very own installation of Ubuntu Server and dive in. But before we can do that, we have to decide what to actually install it on. For the purposes of this book, there isn’t a specific requirement in terms of hardware. You just need an Ubuntu Server installation of some sort, and it wouldn’t hurt to set up multiple servers if you can—you don’t need them all to be on the same device type. Having multiple servers will help you experiment with networking when we get to that point later on in the book. But for now, it’s only a matter of utilizing whatever you have at your disposal to get an Ubuntu installation going.
In particular, the following list includes the most common devices you can consider for your Ubuntu Server installation:
Physical server
Physical desktop
Laptop
Virtual machine
Virtual private server
Raspberry Pi
Let’s take a look at each of these options in more detail.
Physical server
Nowadays, it’s very easy to find used physical servers for an affordable price. Dell PowerEdge is a very common model, and the R610 and R710 specifically are good choices that are readily available second. These servers are commonly made available in the reseller market after companies upgrade to newer models. The R610 and R710 are a bit old, but their specs are still great for testing purposes. If you’re able to find a newer model (such as the R720) for a reasonable price, even better.
The downside with physical servers is that they take up a lot of room and can often be power-hungry (and noisy). Make sure to shut them down when not in use and look into the cost of electric services in your area—these servers can be very cheap to run or very expensive, depending on your electricity rates.
Physical desktop
If you don’t have access to a physical server, you might consider running Ubuntu Server on a desktop. It’s common for some computer users to hang onto their older PC after upgrading to something new and shiny. So rather than let your old desktop collect dust, why not put it to work? Sure, your older computer may not run today’s high-end games, but that doesn’t matter for our purposes. Ubuntu Server runs very well, even on older hardware. In fact, it’s quite common for home learners to use small form factor PCs, such as the Intel NUC, for this purpose. In addition, using a physical desktop has some advantages over physical servers as well. They often use much less power than server hardware, and they also tend to produce less noise.
When it comes to production servers (installations of Ubuntu Server for use within your organization), desktops are typically not a good pick. Depending on the model, actual server hardware might have additional hardware and features that might not be present with a desktop. For example, true server builds often feature true hardware RAID, Error Correction Code (ECC) memory, multiple processors, and more. Although a desktop tower typically lacks those features, if you install Ubuntu Server on your old PC it’s every bit as valid a server as an actual server chassis would be – though it wouldn’t scale well in a data center. Since we’re just learning though, that doesn’t matter for us for our current use-case.
Laptop
Another option worth considering is to install Ubuntu Server on a laptop. If you have an older laptop lying around that you’re no longer using, it might be a great option for learning Ubuntu Server. If you do decide to use a laptop for this purpose, then the same factors will apply to this as I wrote regarding using a desktop.
However, the reason I decided to give laptops their own section here is because there are some additional benefits with these that you can take advantage of. With a real data center server rack, you’ll typically have access to a Keyboard, Video, and Mouse (KVM). This might mean that you could have a physical monitor, keyboard, and mouse attached to the server, or a special device with all three built in. Servers within data centers will also have an Uninterruptible Power Supply (UPS) that will keep them running for a time, even when your power goes out.
When it comes to a laptop, it has those same features. Laptops have a built-in keyboard, mouse, and display. If the battery that’s installed in the laptop works, then you have a UPS as well. For those reasons, a laptop might even have an advantage over desktops overall.
However, just like desktop computers, laptops aren’t generally acceptable for use in an actual data center. For our use-case though, we only need one or more installations of Ubuntu Server for going through the examples in this book. And for that purpose, dedicating any computers you’re not currently using would be more than adequate.
Virtual machine
If you don’t have access to a physical machine, you might consider a Virtual Machine (VM). Most computers sold nowadays support the ability to run VMs. VirtualBox is a great solution, as it’s easy to use and available for all of the major operating systems. Just like Ubuntu itself, VirtualBox is available for free, so it’s typically the lowest-cost entry-point for getting started. Also, VirtualBox allows you to easily create snapshots of your Ubuntu installation, so you can create a point-in-time backup before going through an example in this book, and then restore it to repeat tasks as often as you’d like. The ability to utilize snapshots alone makes a VM especially attractive for our needs.
The downside to VirtualBox is that you’ll need to be able to dedicate at least 1 GB of RAM to your Ubuntu Server VM, and your CPU will need to support virtualization extensions, which you’ll need to enable in your computer’s settings if your device supports it.
VirtualBox can be downloaded here: https://www.virtualbox.org.
Virtual private server
Services such as Amazon Web Services, Google Cloud, Linode, Microsoft Azure, Digital Ocean, and others allow you to set up Ubuntu Server in the cloud for you to connect to and manage via OpenSSH. Choosing the Virtual Private Server (VPS) option has some benefits; you don’t need to find room for a large physical server, and you don’t need to worry about power usage either. Another benefit is that you won’t even need to go through the installation process in this chapter at all; the cloud provider will do that for you when you choose to deploy Ubuntu Server on their platform. The main downside, though, is that VPS instances are not free—you’ll need to look at the costs associated with running Ubuntu on such a server and decide if that cost makes sense. Some VPS services allow you to set up instances for as little as $5 USD per month, which can be lower than the cost of the electricity needed to run a physical server in some areas.
Raspberry Pi
Raspberry Pi units are quickly becoming a user favorite for server use cases. They are inexpensive (some models are available for less than $40 USD) and they also use very minimal electricity—you can leave them powered on 24/7 with a virtually unnoticeable difference in your power bill. In fact, they use about as much power as it takes to charge a high-end cellphone. Another benefit is that a Raspberry Pi is generally going to be more powerful than an entry-level VPS. The cheapest VPS instances typically have just 1 CPU core and 1 GB of RAM, but modern Raspberry Pis are produced with quad-core CPUs, as well as 2 GB, 4 GB, or 8 GB of RAM depending on which model you purchase. This means that a Raspberry Pi can possibly perform better than cheaper VPS instances. The downside to Raspberry Pi is that some applications are unavailable, since they utilize ARM CPUs instead of x86. This means that some examples in this book will not work on a Pi (although the majority will).
Once you’ve chosen a device to install Ubuntu Server on, we can continue. If you chose to utilize a VPS, you can move on to the next chapter, Chapter 2, Managing Users and Permissions, as you won’t need to walk through the installation process. In the case of the Raspberry Pi, if that’s your chosen platform, you can skip to the end of this chapter for a dedicated section about setting that up. For all other devices, continue reading for a walk-through for the Ubuntu Server Live Installer.
Obtaining installation media
It’s time to get started! If you’ve decided to utilize a physical server, desktop, laptop, or VM as your test server, then you’ll need to go through the installation process to set up Ubuntu. Don’t worry—it’s very easy to do and it might even be easier than you’d think, as there are fewer overall steps in the process when compared to older versions. If you’ve instead opted to use a VPS or Raspberry Pi, you won’t need to go through this process, as VPS providers do this for you and Raspberry Pi has a different setup method altogether (we’ll cover this later in the chapter, in the Installing Ubuntu on a Raspberry Pi section).
Assuming that you’ve decided to use a device that does require going through the installer, we’ll need to download Ubuntu Server and then create bootable installation media to install it. How you do this largely depends on your hardware. Does your device have an optical drive? Is it able to boot from USB? Refer to the documentation for your device to find out.
It’s recommended to utilize a flash drive for the installation if you can, preferably one that uses USB 3.0 or higher since you’d benefit from its faster speed compared to USB 2.0. The reason for the preference for using a flash drive is due to the fact that they are typically faster than a DVD.
However, if your device is older, you won’t have a choice, as legacy devices are not able to boot from USB at all. As a general rule, use a flash drive if you can and opt for a DVD only if you have no choice.
In the past, Ubuntu Server ISO images could be used to create either a bootable CD or DVD. Nowadays, writable CDs don’t have enough space to support the download size. Therefore, if you choose to burn to bootable optical media, you’ll need a writable DVD at a minimum.
Unfortunately, the differing age of servers within a typical data center introduces some unpredictability when it comes to how to boot installation media. When I first started with servers, it was commonplace for all standard rack servers to contain a 3.5-inch floppy disk drive, and some of the better ones even contained an optical drive. Nowadays, servers typically contain neither. If a server does have an optical drive, it could potentially go unused for an extended period of time and become faulty without anyone knowing until the next time someone goes to use it. Some servers boot from USB, others don’t. To continue, check the documentation for your hardware and plan accordingly. Your server’s capabilities will determine which kind of media you’ll need to create.
Regardless of whether we plan on creating a bootable USB or DVD, we only need to download a single file. Navigate to the following site in your web browser to get started: https://www.ubuntu.com/download/server.
From this page, we’re going to download Ubuntu 22.04 LTS by clicking on the Option 2 – Manual server installation button:
Figure 1.1: Ubuntu Server 22.04 download page
Next, you’ll be offered one or more versions of Ubuntu Server for download:
Figure 1.2: Revealing Ubuntu Server 22.04 download options
As of the time this chapter was being written, Ubuntu Server 22.04 is the latest version, and is shown as the primary download option. There may be other versions of Ubuntu Server listed on this page, such as 22.10 and 23.04, depending on when you’re reading this. New releases of Ubuntu are published every six months. However, this book only covers the Long Term Support (LTS) release, due to the fact that it benefits from five years of support.
By comparison, non-LTS versions (or interim releases
) are only supported for nine months and are therefore not an appropriate choice for production servers. Organizations don’t typically utilize non-LTS releases at all, except for testing upcoming features prior to general availability, so for our purposes, we’ll stick with the LTS version. Once the download is completed, we’ll end up with an ISO image we can use to create our bootable installation media.
If you’re setting up a VM, then the ISO file you download from the Ubuntu downloads page will be all you need; you won’t need to create a bootable DVD or flash drive. In that scenario, all you should need to do is create a VM, attach the ISO to the virtual optical drive, and boot it. From there, the installer should start, and you can proceed with the installation procedure outlined later in this chapter, in the Installing Ubuntu Server section. Going over the process of booting an ISO image on a VM differs from one virtualization solution to another, so detailing the process with each would be a very difficult task. Thankfully, the process is usually straightforward and you can find the details within the documentation of your hypervisor. In most cases, the process is as simple as attaching the downloaded ISO image to the VM and then starting it up.
If your device does not support booting from USB and you find yourself needing to create a bootable DVD, the process is typically just a matter of downloading the ISO file and then right-clicking on it. In the right-click menu of your operating system, you should have an option to burn to disk or some similar verbiage. This is true of Windows, as well as most graphical desktop environments of Linux where a disk-burning application is installed.
The exact procedure differs from system to system, mainly because there is a vast amount of software combinations at play here. For example, I’ve seen many Windows systems where the right-click option to burn a DVD was removed by an installed CD/DVD-burning application. In that case, you’d have to first open your CD/DVD-burning application and find the option to create media from a downloaded ISO file. As much as I would love to outline the complete process here, no two Windows PCs typically ship with the same CD/DVD-burning application. The best rule of thumb is to try right-clicking on the file to see whether the option is there, and, if not, refer to the documentation for your application. Keep in mind that a data disk is not what you want, so make sure to look for the option to create media from an ISO image or your disk will be useless for our purpose.
At this point, you should have an Ubuntu Server ISO image file downloaded. If you are planning on using a DVD to install Ubuntu, you should have that created as well. In the next section, I’ll outline the process of creating a bootable flash drive that can be used to install Ubuntu Server.
Creating a bootable flash drive
The process of creating a bootable USB flash drive with which to install Ubuntu used to vary greatly between platforms. The steps were very different depending on whether your workstation or laptop was currently running Linux, Windows, or macOS. Thankfully, a much simpler method has come about. Nowadays, I recommend the use of Etcher to create your bootable media. Etcher is fantastic in that it abstracts the method such that it is the same regardless of which operating system you use, and it distills the process to its most simple form.
Another feature I like is that Etcher is safe; it prevents you from destroying your current operating system in the process of mastering your bootable media. In the past, you’d use tools like the
dd
command on Linux to write an ISO file to a flash drive. However, if you set up the
dd
command incorrectly, you could effectively write the ISO file over your current operating system and wipe your entire hard drive. Etcher doesn’t let you do that.
Before continuing, you’ll need a USB flash drive that is either empty or one you don’t mind wiping. This process will completely erase its contents, so make sure the device doesn’t have information on it that you might need. The flash drive should be at least 2 GB or larger. Considering it’s difficult to find a flash drive for sale with less than 4 GB of space nowadays, this should be relatively easy to obtain.
To get started, head on over to https://www.balena.io/etcher/, download the latest version of the application from their site, and open it up. The window will look similar to the following screenshot once it launches:
Figure 1.3: Utilizing Etcher to create a bootable flash drive
At this point, click Flash from file, which will open up a new window that will allow you to select the ISO file you downloaded earlier. Once you select the ISO, click on Open:
Figure 1.4: Selecting an ISO image with Etcher
If your flash drive is already inserted into the computer, Etcher should automatically detect it. In the event that you have more than one flash drive attached, or Etcher selects the wrong one, you can click Change and select the flash drive you wish to use:
Figure 1.5: Selecting a different flash drive with Etcher
Finally, click Continue to get the process started. At this point, the flash drive will be converted into Ubuntu Server installation media that can then be used to start the installation process:
Figure 1.6: Etcher in the process of writing a flash drive
After a few minutes (the length of time varies depending on your hardware), the Flashing process will complete, and you’ll be able to continue and get some installations going. Before we get into that, though, we should have a quick discussion regarding partitioning.
Planning the partitioning layout
Partitioning your disk allows you to divide up your hard disk to dedicate specific storage allocations to individual applications or purposes. For example, you can dedicate a partition for the files that are shared by your Apache web server so changes to other partitions won’t affect it. You can even dedicate a partition for your network file shares—the possibilities are endless. Each partition is mounted (attached) to a specific directory, and any files sent to that directory are thereby sent to that separate partition. The names you create for the directories where your partitions are mounted are arbitrary; it really doesn’t matter what you call them. The flexible nature of storage on Linux systems allows you to be creative with your partitioning as well as your directory naming, since the Linux filesystem gives you more flexibility when it comes to mounting storage devices in specific folders.
Admittedly, we’re getting ahead of ourselves here. After all, we’re only just getting started and the point of this chapter is to help you set up a basic Ubuntu Server installation to serve as the foundation for the rest of the chapter. When going through the installation process, we’ll accept the defaults anyway. However, the goal of this section is to give you examples of the options you have for consideration later. At some point, you may want to get creative and play around with the partition layout.
With custom partitioning, you’re able to do some very clever things. For example, with the right configuration, you’ll be able to wipe and reload your distribution while preserving user data, logs, and more. This works because Ubuntu Server allows you to carve up your storage any way you want during installation. If you already have a partition with data on it, you can choose to leave it as is so you can carry it forward into a new install. You simply set the directory path where it’s mounted to be the same as before, restore your configuration files, and your applications will continue working as if nothing happened.
One very common example of custom partitioning in the real world is separating the
/home
directory into its own partition. Since this is where users typically store their files, you can set up your server such that a reload of the distribution won’t disturb their files. When they log in after a server refresh, all their files will be right where they left them. You could even place the files shared by your Apache web server on to their own partition and preserve those too. You can get very creative here.
It probably goes without saying, but when reinstalling Ubuntu, you should back up partitions that have data you don’t want to be wiped (even if you don’t plan on formatting the partitions). The reason being, one wrong move (literally a single checkbox) and you can easily wipe out all the data on that partition. Always back up your data when refreshing a server.
Another reason to utilize separate partitions may be to simply create boundaries or restrictions. If you have an application running on your server that is prone to filling up large amounts of storage, you can point that application to its own partition, limited by size. An example of where this could be useful is an application’s log files. Log files are the bane of any system administrator’s life when it comes to storage.
While helpful if you’re trying to figure out why something crashed, logs can fill up a hard disk very quickly if you’re not careful. In my experience, servers have been known to come to a screeching halt due to log files filling up all the available free space on a server where everything was on a single partition. The only boundary the application had was the entirety of the disk itself.
While there are certainly better ways of handling excessive logging (log rotating, disk quotas, and so on), a separate partition would certainly help. If the application’s log directory was on its own partition, it would be able to fill up that partition, but not the entire drive, which would cause issues but wouldn’t affect the entire server. As an administrator, it’s up to you to weigh the pros and the cons of these strategies to avoid server overload and develop a partitioning scheme that will best serve the needs of your organization.
Success when maintaining a server is a matter of efficiently managing resources, users, and security—a good partitioning scheme is certainly part of that. Sometimes it’s just a matter of making things easier on yourself so that you have less work to do should you need to reload your operating system. For the sake of following along with this book, it really doesn’t matter how you install or partition Ubuntu Server. The trick is simply to get it installed—you can always practice partitioning later. After all, part of learning is setting up a platform, observing any issues that may occur, and then fixing it up.
Here are some basic tips regarding partitioning:
At a minimum, a partition for the root filesystem (designated by a forward slash) is required.
The
/var
directory contains most log files and is therefore a good candidate for separation for the reasons mentioned previously in this section.
The
/home
directory stores all user files. Separating this into a separate partition can be beneficial as it gives you the possibility of having your user files survive a reinstall of Ubuntu.
If you’ve used Linux before, you may be familiar with the concept of a swap partition, which is a special partition that can act as RAM when your memory becomes full. This is no longer necessary—a swap file will be created automatically in newer Ubuntu releases.
When we perform our installation in the next section, we’ll choose the defaults for the partitioning scheme to get you started quickly. However, I recommend you come back to the installation process at some point in the future and experiment with it. You may come up with some clever ways to split up your storage. However, you don’t have to—having everything in one partition is fine too, depending on your needs.
Now that we have an understanding of what partitioning is, we should have all of the essential topics covered to enable us to actually get the installation of Ubuntu Server going. Let’s go ahead and work on that now.
Installing Ubuntu Server
At this point, we should be ready to get an installation of Ubuntu Server going. In the steps that follow, I’ll walk you through the process.
To get started, all you should need to do is insert the installation media into your server or device and follow the onscreen instructions to open the boot menu. The key you press at the beginning of the POST process differs from one machine to another, but it’s quite often F10, F11, or F12. Refer to your documentation if you are unsure, though most computers and servers tell you which key to press at the beginning. You may miss this window of opportunity the first few times, and that’s fine—to this day I still seem to need to restart the machine once or twice to hit the key in time.
Once you successfully boot your device while using your Ubuntu Server installation media, navigating the installer is relatively straightforward. You simply use the arrow keys to move up and down to select different options, and press Enter to confirm choices. The Esc key will allow you to exit from a sub-menu. Moving around within the installer is pretty easy once you get the hang of it.
Once the installer starts, you’ll see the first of many selection screens. The first option, Ubuntu Server, allows you to start the Ubuntu Server installer. The second option, Test memory, runs a special program that helps you determine if you have any physical defects with the RAM modules installed inside your device. I always recommend testing the memory of your device once per year at least, and especially before you install an operating system for the first time. Memory issues can be rare, but you’d be surprised. It might be a good idea to test your memory just to be safe.
If you wish to test the memory of your device, you can go ahead and do so. In order to move on though, we’ll need to choose the Ubuntu Server option in order to start the installer:
Figure 1.7: The initial boot screen for the Ubuntu Server installation media
Next, you’ll see a screen allowing you to select your language as in the following screenshot:
Figure 1.8: Language selection at the beginning of the installation process
If your language is anything other than English, you’ll be able to select that here. Once you’re satisfied with the chosen keyboard layout, you continue by selecting Done at the bottom of the screen.
After choosing your language, you’ll be brought to a screen that enables you to set your Keyboard configuration. If the proper keyboard layout wasn’t automatically selected, you can change it here.
Figure 1.9: Setting the layout of your keyboard
Next, we’ll see an option to install Ubuntu Server, or Ubuntu Server (minimized). For this, we’ll choose the first option. Choosing to install a minimized version of Ubuntu Server might be a good fit for creating smaller installations, however for this book, we’re going to focus on the normal installation type.
Figure 1.10: Choosing your installation type
Next, the Ubuntu Server installer will attempt to automatically detect the appropriate parameters for your network card. By default, it should detect the appropriate settings via Dynamic Host Control Protocol (DHCP). We’ll go over DHCP in a future chapter, specifically Chapter 11, Setting Up Network Services. For now, the defaults should be fine. Select Done