34,79 €
Ubuntu Server has taken the data centers by storm. Whether you're deploying Ubuntu for a large-scale project or for a small office, it is a stable, customizable, and powerful Linux distribution that leads the way with innovative and cutting-edge features. For both simple and complex server deployments, Ubuntu's flexible nature can be easily adapted to meet to the needs of your organization. With this book as your guide, you will learn all about Ubuntu Server, from initial deployment to creating production-ready resources for your network. The book begins with the concept of user management, group management, and filesystem permissions. Continuing into managing storage volumes, you will learn how to format storage devices, utilize logical volume management, and monitor disk usage. Later, you will learn how to virtualize hosts and applications, which will cover setting up KVM/QEMU, as well as containerization with both Docker and LXD. As the book continues, you will learn how to automate configuration with Ansible, as well as take a look at writing scripts. Lastly, you will explore best practices and troubleshooting techniques when working with Ubuntu Server that are applicable to real-world scenarios.
By the end of the book, you will be an expert Ubuntu Server administrator who is well-versed in its advanced concepts.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 836
Veröffentlichungsjahr: 2018
Copyright © 2018 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.
Commissioning Editor: Gebin GeorgeAcquisition Editor: Heramb BhavsarContent Development Editor: Nithin George VargheseTechnical Editor: Vishal Kamal MewadaCopy Editor: Safis EditingProject Coordinator: Virginia DiasProofreader: Safis EditingIndexer: Rekha NairGraphics: Tom ScariaProduction Coordinator: Nilesh Mohite
First published: July 2016 Second edition: May 2018
Production reference: 1240518
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78899-756-0
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Jay LaCroix is a technologist and open source enthusiast, specializing in Linux. He currently works as a senior solutions architect and holds a master's degree in information systems technology management from Capella University. In addition, Jay also has a YouTube channel, available at LearnLinux.tv, where he posts instructional tutorial videos. He has also written Linux Mint Essentials and Mastering Linux Network Administration, also published by Packt Publishing.
David Diperna is a cloud engineer who graduated from Oakland University with degrees in computer science and psychology. He has two AWS certifications, and he works on multiple projects building scalable infrastructure and custom solutions for different apps running on Linux.
His work requires a wide array of skill sets, but he specializes in metric and logging systems, such as Graphite and Elastic Stack, for application performance monitoring and analysis.
Matthew Huber has been working in the tech industry for 20 years, specializing in Unix and Linux operating systems. He has helped defined system standards and led migration teams, and he was a Solaris subject matter expert for big three automakers. He is currently a cloud engineer, designing and implementing solutions in AWS.
He was on the board of directors of i3Detroit and led a team in designing and competing in electric vehicles in the Power Racing Series.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Mastering Ubuntu Server Second Edition
Dedication
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
About the author
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Conventions used
Get in touch
Reviews
Deploying Ubuntu Server
Technical requirements
Setting up our lab
Determining your server's role
Deciding between 32- and 64-bit installations
Obtaining Ubuntu Server installation media
Creating a bootable Ubuntu Server flash drive
Planning the partitioning layout
Installing Ubuntu Server
Installing Ubuntu Server on Raspberry Pi 3
Summary
Questions
Further reading
Managing Users
Understanding when to use root
Creating and removing users
Understanding the /etc/passwd and /etc/shadow files
Distributing default configuration files with /etc/skel
Switching users
Managing groups
Managing passwords and password policies
Configuring administrator access with sudo
Setting permissions on files and directories
Summary
Questions
Further reading
Managing Storage Volumes
Understanding the Linux filesystem
Using symbolic and hard links
Viewing disk usage
Adding additional storage volumes
Partitioning and formatting volumes
Mounting and unmounting volumes
Understanding the /etc/fstab file
Managing swap
Utilizing LVM volumes
Understanding RAID
Summary
Questions
Further reading
Connecting to Networks
Setting the hostname
Managing network interfaces
Assigning static IP addresses
Understanding NetworkManager
Understanding Linux name resolution
Getting started with OpenSSH
Getting started with SSH key management
Simplifying SSH connections with a config file
Summary
Questions
Further reading
Managing Software Packages
Understanding Linux package management
Taking advantage of hardware enablement updates
Understanding the differences between Debian and Snap packages
Installing and removing software
Searching for packages
Managing package repositories
Backing up and restoring Debian packages
Cleaning up orphaned apt packages
Making use of Aptitude
Summary
Questions
Controlling and Monitoring Processes
Showing running processes with the ps command
Managing jobs
Dealing with misbehaving processes
Utilizing htop
Managing system processes
Monitoring memory usage
Scheduling tasks with cron
Understanding load average
Summary
Questions
Further reading
Setting Up Network Services
Planning your IP address scheme
Serving IP addresses with isc-dhcp-server
Setting up DNS with bind
Creating a secondary (slave) DNS server
Setting up an internet gateway
Keeping your clock in sync with NTP
Summary
Questions
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
Mounting remote directories with SSHFS
Summary
Questions
Further reading
Managing Databases
Preparations for setting up a database server
Installing MariaDB
Understanding the MariaDB configuration files
Managing MariaDB databases
Setting up a slave database server
Summary
Questions
Serving Web Content
Installing and configuring Apache
Installing additional Apache modules
Securing Apache with SSL
Installing and configuring NGINX
Setting up failover with keepalived
Setting up and configuring Nextcloud
Summary
Questions
Further reading
Learning Advanced Shell Techniques
Understanding the Linux shell
Understanding Bash history
Learning some useful command-line tricks
Redirecting output
Understanding variables
Writing simple scripts
Putting it all together: Writing an rsync backup script
Summary
Questions
Further reading
Virtualization
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
Questions
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
Questions
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
Putting it all together – Automating web server deployment
Using Ansible's pull method
Summary
Questions
Further reading
Securing Your Server
Lowering your attack surface
Understanding and responding to CVEs
Installing security updates
Automatically installing patches with the Canonical Livepatch service
Monitoring Ubuntu servers with Canonical's Landscape 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
Questions
Further reading
Troubleshooting Ubuntu Servers
Evaluating the problem space
Conducting a root cause analysis
Viewing system logs
Tracing network issues
Troubleshooting resource issues
Diagnosing defective RAM
Summary
Questions
Preventing and Recovering from Disasters
Preventing disasters
Utilizing Git for configuration management
Implementing a backup plan
Replacing failed RAID disks
Utilizing bootable recovery media
Summary
Questions
Further Reading
Using the Alternate Installer
Obtaining the Alternate Installer
Installing via the Alternate Installer
Setting up software RAID
Summary
Assessments
Chapter 1 – Deploying Ubuntu Server
Chapter 2 – Managing Users
Chapter 3 – Managing Storage Volumes
Chapter 4 – Connecting to Networks
Chapter 5 – Managing Software Packages
Chapter 6 – Controlling and Monitoring Processes
Chapter 7 – Setting Up Network Services
Chapter 8 - Accessing and sharing files
Chapter 9 - Sharing and Transferring Files
Chapter 10 – Serving Web Content
Chapter 11 – Learning Advanced Shell Techniques
Chapter 12 – Virtualization
Chapter 13 – Running Containers
Chapter 14 – Automating Server Configuration with Ansible
Chapter 15 – Securing Your Server
Chapter 16 – Troubleshooting Ubuntu Servers
Chapter 17 – Preventing and Recovering from Disasters
Other Books You May Enjoy
Leave a review - let other readers know what you think
Ubuntu is an exciting platform. You can literally find it everywhere—desktops, laptops, phones, and especially servers. The server edition 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 a good company—according to W3Techs, Ubuntu is the most widely deployed distribution on the web with regard to Linux. With the release of Ubuntu 18.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, and sharing data with other users.
We'll start our journey right in the first chapter, where we'll walk through the installation of Ubuntu Server 18.04, which will serve as the 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.
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.
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, covers user management in full. Topics here will include creating and removing users, password policies, the sudo command, as well as group management and switching from one user to another.
Chapter 3, 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 and creating links.
Chapter 4, 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, as well as name resolution.
Chapter 5, 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 6, Controlling and Monitoring 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, managing jobs, and understanding the load average.
Chapter 7, 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 our own DHCP and DNS server, as well as installing NTP.
Chapter 8, Sharing and Transferring Files, is all about sharing files with others. Concepts will include the set up of Samba and NFS network shares, and we will even go over transferring files manually with rsync and scp.
Chapter 9, 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 slave database server.
Chapter 10, 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 set up keepalived. Installing Nextcloud is also covered.
Chapter 11, Learning Advanced Shell Techniques, goes over additional tips, tricks, and techniques to enhance the reader's usage of command lines. Topics here include managing output, setting up aliases, investigating Bash history, and more.
Chapter 12, 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 13, Running Containers, discusses the subject of containers and show the reader how to manage containers in both Docker and LXD.
Chapter 14, 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 to automate common administrative tasks, and also how to use ansible-pull.
Chapter 15, Securing Your Server, takes a look at various things the reader can do to strengthen security on Ubuntu servers. Topics will include concepts such as lowering the attack surface, securing OpenSSH, setting up a firewall, and more.
Chapter 16, Troubleshooting Ubuntu Servers, consists of topics relating to things we can do when our deployments don't go exactly according to plan. The reader will also investigate the problem space, view system logs, and trace network issues.
Chapter 17, Preventing and Recovering from 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.
Appendix, Using the Alternate Installer, shows the reader how to utilize an alternative installer for Ubuntu that can be used to set up more advanced installations, such as Ubuntu on RAID.
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. Even if you don't have these skills, 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, not 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.
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: "I added an IP address of 192.168.0.101 with a CIDR mask of /24."
A block of code is set as follows:
# This file describes the network interfaces available on your system# For more information, see netplan(5).network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: yes
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
# This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets: enp0s3:
dhcp4: no addresses: [192.168.0.101/24] gateway4: 192.168.1.1 nameservers: addresses: [192.168.1.1,8.8.8.8]
Any command-line input or output is written as follows:
sudo ip link set enp0s3 down
sudo ip link set enp0s3 up
Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "At this point, you'll click Select image, 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."
Feedback from our readers is always welcome.
General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].
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 would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
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 [email protected] 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 authors.packtpub.com.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packtpub.com.
Ubuntu Server is an extremely powerful distribution 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. In this chapter in particular, I'll guide you through the process of deploying Ubuntu Server on to your system. We'll start off with some discussion on 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. I'll even show you the process of installing Ubuntu Server on a Raspberry Pi 3 for good measure.
In particular, we will cover:
Setting up our lab
Determining your server's role
Deciding between 32- and 64-bit installations
Obtaining Ubuntu Server installation media
Creating a bootable Ubuntu Server flash drive
Planning the partition layout
Installing Ubuntu Server
Installing Ubuntu Server on Raspberry Pi 3
For this chapter (and all others) we will need either a physical computer or virtual machine with the following specs:
One CPU core
512 MB RAM
10 GB hard disk (16 or more recommended)
Don't worry about the specifics for now; we will discuss these requirements further in this chapter.
The first thing for us to do is to set up our environment. For the purposes of this book, it really doesn't matter what kind of hardware you use, if you even use physical hardware at all (a virtual machine or cloud instance will suffice). If you have physical server hardware available to you, then by all means use it (though not everyone has the money or even the available space to set up a complete lab). Nowadays, processing power and memory is cheaper than it's ever been, and the typical home PC is capable of running several virtual machines. Even better, software such as VirtualBox is free, so even if you have no budget at all, there are definitely options available to you. Perhaps you already have a server or two in your rack at work just waiting to be deployed; in which case, this will be even more exciting and fun. In the case of VirtualBox, it can be downloaded from here: https://www.virtualbox.org.
While I always prefer physical hardware, virtual machines have one major advantage. Not only are they easy to create and destroy at will, they are perfect for testing new or proposed solutions because you can easily take a snapshot of a VM and restore it if an experiment blows up in your face. In my case, it's common for me to create a virtual machine of a Linux distribution, fully update it, and then take a snapshot before making any changes. That way, I always have a base version of the OS to fall back on if I muck it up. Testing software rollouts on virtual machines before graduating a solution to production is a good habit to get into anyway.
This book makes no assumptions regarding your environment, because the hardware you have access to differs from person to person. While the installation procedure for Ubuntu Server differs based on hardware (for example, perhaps your server isn't capable of booting from USB install media, forcing you to use a DVD), all other concepts contained throughout the book will be the same regardless.
With that said, once we run through the install procedure, feel free to install Ubuntu Server on as many devices or VMs as you can. Later on in our journey, we'll go through several examples of networking, including copying files from one server to another. If you have more than one installation, these exercises will be easier. You can set up multiple virtual machines, physical servers, or any combination of the two.
If you don't have access to a physical server, and your PC isn't powerful enough to handle virtual machines very well, consider setting up a Virtual Private Server (VPS) from providers such as Linode and DigitalOcean, which both have Ubuntu Server available as an option for a small monthly fee. See the following URLs for more information on two popular VPS providers:
DigitalOcean
:
https://www.digitalocean.com
Linode
:
https://www.linode.com
Cloud providers are great if you wish to get a server up and running quickly or if your goal is to set up a server to be available in the cloud. With that said, all you need to do is have Ubuntu Server installed on something (basically anything at all) and you're ready to follow along.
While at this point your goal is most likely to set up an Ubuntu Server installation for the purposes of following along with the concepts contained within this book, it's also important to understand how a typical server rollout is performed in the real world. Every server must have a purpose, also known as its role. This role could be that of a database server, web 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 importance. 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 colleague's 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 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 miscreant 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 definitely keep your server room locked!
At this point in the book, I'm definitely not asking you to create a detailed flow chart 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.
Before we grab our installation media and get started, I thought I would write a bit about the diminishing availability of 32-bit installation media in the Linux world. When the first edition of this book was published, I wrote about the choice between 32- and 64-bit installations. Nowadays, whether to use 64-bit installation media is no longer much of an option, with various distributions of Linux dropping support for 32-bit downloads. In the case of Ubuntu Server 18.04, you are now only able to download 64-bit installation images as 32-bit downloads of Ubuntu Server have been removed.
This may seem like a polarizing decision on Canonicals' part, but it's really not as bad as it may seem. Not being able to download 32-bit installation images from Canonical doesn't mean that you can't run 32-bit software; it just means that your overall system will be running a 64-bit kernel. This is great, considering you'll benefit fully by being able to more efficiently utilize the RAM in your server.
In addition, 64-bit capable processors have been on the market for well over a decade. Even if you think your hardware may be too old to utilize 64-bit software, it will more than likely support it just fine. Consider this—several versions of the Pentium 4 processor support 64-bit software, and that processor has become ancient history in computer years. One scenario that may suffer due to the decision to decommission 32-bit media is installation on netbooks, but most people don't run server applications from such a device, so that doesn't affect us at all in terms of this book.
All in all, the decision to migrate away from 32-bit is a good move in the name of progress, and it shouldn't impact us at all when setting up new servers. However, I mentioned it here simply because I wanted to make you aware of it. If you are downloading a modern version of Ubuntu Server today, you're downloading the 64-bit version (and you probably won't notice a difference).
It's time to get started! At this point, we'll need to get our hands on Ubuntu Server and then create bootable installation media to install it. How you do this largely depends on your hardware. Does your server have an optical drive? Is it able to boot from USB? Refer to the documentation for your server to find out. In most cases, it's a very good idea to create both a bootable DVD and USB media of Ubuntu Server while you're at it. That way, regardless of how your server boots, you'll have what you need.
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 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 and only ship with an optical drive if you ask for one nicely while placing your order. If a server does have an optical drive, it typically will 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 18.04 LTS by clicking on the Download button. There may be other versions of Ubuntu Server listed on this page, such as 18.10 and 19.04, for example. However, we're only interested in the Long Term Support (LTS) release, due to the fact that it benefits from five years of support (non-LTS versions are only supported for nine months). Non-LTS releases are useful for testing future software versions, but when in doubt, stick with LTS. 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 virtual machine, 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 case, 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. Going over the process of booting an ISO image on a virtual machine differs from hypervisor to hypervisor, so detailing the process on each would be beyond the scope of this book. Thankfully, the process is usually straightforward and you can find the details within the documentation of your hypervisor or from performing a quick Google search. In most cases, the process is as simple as attaching the downloaded ISO image to the virtual machine, and then starting it up.
As I mentioned before, I recommend creating both a bootable USB and bootable DVD. This is due to the fact that you'll probably run into situations where you have a server that doesn't boot from USB, or perhaps your server doesn't have an optical drive and the USB flash drive is your only option. In addition, the Ubuntu Server boot media also makes great recovery media if for some reason you need to rescue a server. 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 disc or some similar verbiage. This is true of Windows, as well as most graphical desktop environments of Linux when a disc burning application installed. If in doubt, Brasero is a good disc-burning utility to download for Linux, and other operating systems generally have this option built-in nowadays.
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 disc is not what you want, so make sure to look for the option to create media from an ISO image or your disc will be useless.
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.
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. In the first edition, I outlined the process on all three major platforms. Thankfully, a much simpler method has come about since the publication of the first edition. 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 OS 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 out everything. Etcher doesn't let you do that.
To get started, head on over to https://etcher.io, 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:
At this point, you'll click Select image, 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:
If your flash drive is already inserted into the computer, Etcher should automatically detect it:
In the event you have more than one flash drive attached, or Etcher selects the wrong one, you can click Changeand select the flash drive you wish to use:
Finally, you can click Flash!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:
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.
One of the many joys of utilizing Linux for server platforms is how flexible the partitioning is. 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.
Admittedly, we're probably 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're 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.
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 administrator when it comes to storage. While helpful if you're trying to figure out why something crashed, logs can fill up a hard disk if you're not careful. In my experience, I've seen servers 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.
While there are certainly better ways of handling excessive logging (log rotating, disk quotas, and so on), a separate partition also would have helped. 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. A full log partition will certainly cause issues, but it wouldn't have been able to affect the entire server. As an administrator, it's up to you to weigh the pros and the cons 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—and 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, figuring out how to break it in epic ways, and then fixing it up.
Here are some basic tips regarding partitioning:
At minimum, a partition for the root filesystem (designated by a forward slash) is required.
The
/var
directory contains most log files, and is a ripe candidate for separation.
The
/home
directory stores all user files. Separating this into a separate partition can be beneficial.
If you've used Linux before, you may be familiar with the concept of a
swap partition
. 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.
At this point, we should be ready to get an installation or two 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 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'll probably 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.
When you first boot from the Ubuntu Server install media, you'll see an icon near the bottom that looks like the following (it will go away after a few seconds):
This icon is your indication that you can press Enter here to select additional options, such as your language. If you don't press Enter within a few seconds, this will be bypassed and the default options (such as the English language) will be chosen automatically. If you do press Enter, you'll see the following screenshot:
If your language is anything other than English, you'll be able to select that here. You can also press F6 to view additional options, which you would only explore in a situation in which your hardware wasn't working properly. Most people won't need to do this, however.
After choosing your language, you'll be brought to the installation menu. (If you didn't press Enter when the previously mentioned icon was on the screen, this screen will be bypassed and you won't see it). The installation menu will give you additional options. To start the installation process, press Enter to choose the first option (Install Ubuntu Server), though a few of the other options may be useful to you:
First, this menu also offers you an option to Check disc for defects. Although I'm sure you've done well in creating your media, all it takes is for a small corruption in the download and you would end up with invalid media. This is extremely rare—but it does happen from time to time. If you have the extra time, it may make sense to verify your media.
Second, this menu gives you the option to Test memory. This is an option I've found myself using far more often than I'd like to admit. Defective RAM on computers and servers is surprisingly common and can cause all kinds of strange things to happen. For one, defective RAM may cause your installation to fail. Worse, your installation could also succeed—and I say that's worse due to the fact you'd find out about problems later (after spending considerable time setting it up) rather than right away. While doing a memory test can add considerable time to the installation process, I definitely recommend it on physical servers, especially if the hardware is new and hasn't ever been tested at all. In fact, I make it a process to test the RAM of all my servers once or twice a year, so this media can be used as a memory tester any time you need one.
From this point forward, we will progress through the various screens to customize our installation. I'll guide you along the way.
To navigate the installer, 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. The installer is pretty easy to navigate once you get the hang of it. Anyway, after you enter the actual installation process, the first screen will ask you to select a language. Go ahead and do so:
The next screen will allow you to choose your keyboard layout. If you use a keyboard other than an English (US) keyboard, you can select that here. Press down key to highlight Done and press Enter when you've finished:
At the next screen, you will have the option to install Ubuntu Server, or a MAAS region or rack controller. MAAS, or Metal as a Service, is beyond the scope of this book, but it offers some very interesting features, such as additional options for scaling and provisioning your servers. After you become proficient with Ubuntu Server, it may be worth learning later. I have included a link to the documentation for MAAS at the end of this chapter, should you desire to learn more about it. For now, choose the first option, Install Ubuntu:
Next, the installer will automatically try to configure your network connection via DHCP. This is often correct, so you shouldn't need to do anything here unless you have more than one network card and you'd like to use one other than the default. In my case, it defaulted to device enp0s3(which is correct) but the interface name will be different depending on your hardware. If you do need to change this, you can select the defaulted interface name, pressEnter, and select a different one. When you're finished, arrow down to done and pressEnter:
The next screen will give you a chance to configure your server's disk. At this screen, if you want to implement a custom partitioning scheme, you can do that here. The option Manualwill allow you to do just that. However, that is beyond the scope of this chapter as we're just trying to get an installation off the ground, so chooseUse An Entire Diskto continue:
After selecting Use An Entire Disk, the next screen will allow you to choose a disk on which to install Ubuntu Server. In my case, I only have one disk, and you probably do as well. But if you have more than one, select the drive to be used as the main drive for the distribution. We can always configure any other drives you may have later. In fact, we will take a look at storage volumes inChapter 3, Managing Storage Volumes. Simply pressEnterafter highlighting the appropriate disk:
Next, the Ubuntu installer will give you an overview of the partitioning it will perform. The defaults are fine, so simply press Enter. You'll be asked to confirm one last time; when you are, arrow down to continue and pressEnter:
At the next screen, you'll fill out information relative to the default user account. Fill out your information on this screen, as I have in the sample screenshot. One important thing to keep in mind is that the user you create here will have administrative access. You can always create other users later on, but the user you create here will have special privileges. When finished, arrow down to done and pressEnter:
At this point, the installation will continue on, and may even be well on its way before you're finished filling out your user information. You'll see a screen similar to the following when everything is finished. Press Enterto reboot the server into the new installation:
At this point, your server will reboot and then Ubuntu Server should start right up. Congratulations! You now have your own Ubuntu Server installation!
The Raspberry Pi 3 has become quite a valuable asset in the industry. These tiny computers, now with four cores and 1 GB of RAM, are extremely useful in running one-off tasks and even offering a great place to test code without disrupting existing infrastructure. In my lab, I have several Pis on my network, each one responsible for performing specific tasks or functions. It's a very useful platform.
Thankfully, Ubuntu Server is quite easy to install on a Raspberry Pi. In fact, it's installed in much the same way as Raspbian, which is the distribution most commonly used on the Pi. Ubuntu Server is available for Raspberry Pi models 2 and 3. All you'll need to do is download the SD card image and then write it directly to your microSD card (your SD card needs to be at least 4 GB). Once you've done that, you can boot the Pi and log in. The default username and password is ubuntu for both.
To get started, you'll first download the SD card image from here: https://wiki.ubuntu.com/ARM/RaspberryPi.
Then, check that it is compatible with your model of Raspberry Pi. The image will be in a compressed .xz format, which you'll need to extract with your operating system's decompressing utility (in Linux you can use the unxz command, which you get from the xz-utils package).
Next, we do the actual writing of the SD card. For this, we return to our old friend Etcher, which we used earlier in this chapter to master our USB media. Another feature of Etcher is that it allows us to master SD cards for the Raspberry Pi as well. Go ahead and open Etcher, and select the Ubuntu Server Pi image in much the same way as you selected the Ubuntu Server ISO file earlier. Next, make sure your SD card is inserted, and click Flash! and you should be good to go as soon as the process concludes. Once the process finishes, simply insert the SD card into your Pi and power it on. That's all there is to it!
In this chapter, we covered the installation process in great detail. As with most Linux distributions, Ubuntu Server is scalable and able to be installed on a variety of server types. Physical servers, virtual machines, and even the Raspberry Pi, have a version of Ubuntu Server available. The process of installation was covered step by step, and you should now have an Ubuntu Server of your own to configure as you wish. Also in this chapter, we covered partitioning, creating boot media, determining the role of your server, as well as some best practices.
In the next chapter, I'll show you how to manage users. You'll be able to create them, delete them, change them, and even manage password expiration and more. I'll also cover permissions so that you can determine what your users are allowed to do on your server. See you there!
In our first chapter, we covered the installation process that will serve as the foundation for the rest of the book. However, there were still some useful concepts that we'll want to remember. Take a look at the following questions and test your knowledge:
Determining your server's _________ will help you plan for its use on your network.
Ubuntu Server installation media is created from an ___ file, which you can download from the Ubuntu website.
Name at least one provider for VPS solutions (if you can name more than one, even better).
What type of encryption is used when encrypting your Ubuntu installation?
What is an LTS release of Ubuntu? Why is it important?
Which tool is useful for creating bootable USB flash drives and optical media for installation?
At minimum, your Ubuntu Server installation requires a partition for ________ .
At the end of some chapters, I will list resources you can use to explore additional concepts relative to the content of the chapter. While not required, you should definitely explore them as these resources will go over additional content that didn't fit the scope of the chapter but are still useful for expanding your knowledge even further:
Ubuntu installation documentation
:
https://help.ubuntu.com/community/Installation
Etcher user documentation
:
