Ubuntu Server Essentials - Sample Chapter
Ubuntu Server Essentials - Sample Chapter
Ubuntu Server Essentials - Sample Chapter
P U B L I S H I N G
pl
C o m m u n i t y
$ 29.99 US
19.99 UK
Sa
m
E x p e r i e n c e
D i s t i l l e d
ee
Abdelmonam Kouka
While studying for engineering and during all of his professional experience, he was
an open source activist; he was a member/co-founder of the Ubuntu-tn community,
Sabily community, and the APOS association. He has also been a member of Linux
Arabic Community, Arabeyes, CULLT, DFSA, and a lot of other open source clubs,
associations, and initiatives.
He is also the author of Learning Zimbra Server Essentials, Packt Publishing, 2013.
Preface
Ubuntu Server Essentials is a practical, hands-on guide that provides you with a
clear step-by-step process to install and manage an Ubuntu Server, which will help
you take advantage of the real power that is behind Ubuntu without being an expert
in it.
This fast-paced book is for administrators who wish to discover the essentials of the
latest version of the Ubuntu Server. The purpose of this book is to guide the readers
so that they can deploy and configure Ubuntu servers in their office environments.
First of all, we will start by explaining how to install the Ubuntu Server. Then, we
will move on to cover the most useful aspect of the command-line interface that
comes with it. Meanwhile, we will have a look at how to administrate and configure
an Ubuntu Server. This knowledge will be extended with the help of a chapter
dedicated to this topic. After that, we will discuss how to deploy services on an
Ubuntu Server and secure it. Before finishing, we will discover the virtualization and
Cloud computing facilities provided by Ubuntu. Finally, we will explore some very
useful tips related to an Ubuntu Server.
Preface
Chapter 6, Tips and Tricks for Ubuntu Server, contains some of the most useful tips
and tricks that every Ubuntu administrator needs.
[1]
I started writing this book just after Ubuntu 15.04 (Vivid Vervet) was released
on April 23, 2015. Currently, there are two major releasesthe LTS one that was
released last year (LTS stands for long-term support), which is version 14.04, and
the latest version 15.04. It is not a big deal if you choose either of these two versions
to perform the tasks in the coming chapters, since it will make no difference. So,
we decided to use the latest version as a reference for our samples, especially
because the next LTS release will be based on it. (Note that only the LTS releases
are supported for 5 years by Canonical, and the non-LTS releases have a support of
only 9 months. That's why we normally choose the LTS versions for Ubuntu Server
deployments.) When there is a notable difference between these two versions, we
will mention it.
Now, let's take a look at some information related to the latest version:
It uses the latest versions of OpenStack, LXC (Linux Containers), LXD, Juju,
libvirt, QEMU, Open vSwitch, Ceph, cloud-init, Docker, and HA-related
package updates.
System requirements
System requirements depend on the services that may need to be deployed in the
future and installed on the server. For demonstration/test purposes, we need a
minimal configuration of 300 MHz CPU, 192 MB of RAM, and a 1.5 GB hard disk. This
light configuration allows us to deploy Ubuntu Server on an old computer or even
a little virtual machine. This limited footprint is basically due to the absence of the X
Windows System (graphic interface), which is not needed in a server environment.
[2]
Chapter 1
In a production environment, you should be careful about your actual needs in terms
of resources (the CPU, RAM, and hard disk) and the estimation growth of those
needs. To do this, you need to make a good measure of dimensions based on the
services that you are going to deploy.
In the case of the samples in this book, we will use the 64-bit version of Ubuntu
Server 15.04, and we will install it on a virtual box machine that has 1 GB of RAM
and 2 TB of hard disk.
Note that if you are using a used computer/server, you should back
up your data before installing or upgrading Ubuntu. Partitioning tools
used in the installation process are reliable and can be used for many
years without any problems in general, but sometimes, they can perform
catastrophic actions.
Additional resources
This book comprises only the essentials. It contains exactly what you need to know
to perform a specific task. If you need more information about and an in-depth
understanding of Ubuntu, you can have a look at the official documentation by
visiting https://help.ubuntu.com.
You should download the CD image according to your system architecture.
The whole list exists at http://releases.ubuntu.com/15.04/.
[3]
[4]
Chapter 1
If you just press the Enter key when selecting the default Install
Ubuntu Server option, you will start the installation process.
Some people prefer starting with the third option, Check disk for
defects, to verify that the burn process of the ISO file on the CD
was done correctly.
You can use the fifth option, Boot from first hard disk, to bypass
the boot from the CD in case you forgot it by mistake in the
CD-ROM driver.
In most of the cases, all that you need to do is launch the installation
by pressing the Enter key when selecting the default Install Ubuntu
Server option, but there are some cases where you need some
special options, either because of some specific hardware-related
need of your machine, or because you need to customize the kernel
parameters of the server for future use. For this purpose, Ubuntu
gives you a lot of possibilities via the bottom menu on the boot splash
screen, which can be accessed via the function keys.
If you press F1, you will see an interactive help screen with
documentation for the rest of the options.
The real power and control over the boot process is available once
you press the F6 key. Here, you can see a menu of the common
arguments that help the CD boot on difficult hardware. If you press
the Esc key, you will move from this menu to the boot prompt. You
can type extra kernel boot parameters that you might need for your
hardware, as shown in the following screenshot:
6. Just after launching the installation process, you will be asked to choose the
language of the installation procedure, which will be the default language of
the server that you wish to install. Select the one that you want by using the
up/down arrow keys on your keyboard and then press the Enter key. You
will also be asked for the location of the server (based on this, the system
will fix the server time settings). Then, you have a choice of either letting
the installer detect your keyboard layout, or you entering it manually.
[6]
Chapter 1
7. After performing these steps, the installer starts the installation process by
detecting the hardware and loading some packages. Then, it moves on to
configure the network settings by using DHCP (Dynamic Host Configuration
Protocol) and asking for the hostname that you would like to give to your
server. If you wouldn't like to use DHCP for network configuration, choose
go back or simply press the Esc button to go to the first interface of network
configuration, where you will find the Configure the network manually
option, as shown in the following screenshot:
By making this choice, you will be asked via different interfaces to enter your
IP address, Netmask, the default Gateway, and DNS.
Note that if you enter wrong information by mistake and you
realize just after pressing the Enter key, don't worry. You can
go back easily to the previous interface and re-enter the correct
data. All that you need to do is choose Go Back or simply press
the Esc button.
Also note that this data is not a tattoo, and you can change it
later. We will have a look at how to do this in the next chapter.
[7]
8. At this point, we have almost finished the network settings part. We will be
asked for the hostname in the next screen, and then we will move on to the
user settings. First of all, you will be asked about the full username. Then, you
will get an interface that asks for the Ubuntu username, which will be used
for authentication with a proposition derived from the full username that you
entered before. You can accept the proposition or modify it. Finally, you will
be asked to enter and re-enter a password for this user. Be careful in this step
because the keys entered will be hidden, as shown in the following screenshot.
Therefore, it is important to remember the keys that you have entered:
Next, you will be asked whether you would like to encrypt your home
directory. Don't do that unless you know what you are doing. At the end
of this step, you will be asked to check your time zone. Change it in case
it is incorrect.
9. Now, the most critical part of the installation arrivespartitioning!
If you are using a new hard disk, you will see a screen, as shown in
the following screenshot:
[8]
Chapter 1
If you are using a used hard disk, you will receive an interface that is a
little different. It contains in general the same four options with the options
related to the reuse of the existing partitions. The first three options are the
recommended ones for a newbie. In our case, we will choose the Guideduse
entire disk and set up LVM option. The Manual option will be covered in the
Advanced installation section.
On pressing the Enter key, you will be taken to the next screen, where you
will be asked to choose the disk that you would like to partition. You will
then be taken to an interface, which will ask for your permission to write
changes on the disk with the No option selected. We of course need to make
changes to the disk. We should just verify that we created a backup of our
data on the disk before moving on. The next step is to select the Yes option
and press the Enter key. Before you finish this step, you will be asked to enter
the size of each volume group that you will be using for this partitioning.
You can answer with a number followed by a symbol such as MB, GB,
and TB, or simply use a percentage. Finally, you will get a summary of the
partitioning step, which needs to be confirmed before it is applied, as shown
in the following screenshot. Select the Yes option and press the Enter key:
[9]
10. At this point, the real installation process starts. During the installation, the
installer needs only the CD, but if there is an Internet connection, it can be
used to download software lists and install the latest updates. For that, it
will ask you to either enter the proxy settings if you have one, or to keep this
field empty.
After this step, the installer will start downloading the software list (we will
cover this later in the next chapter). This step can take some time, depending
on your Internet speed:
During this step, you will be asked about the update policy. Personally,
I recommend that you deactivate the automatic installation of updates.
It is better when the administrator manages the installation of updates
manually depending on the servers that are running on Ubuntu Server.
11. One of the useful facilities that are given by the Ubuntu installer is the ability
to choose to install server packages such as the SSH and DNS server. You
can choose one of them by pressing the space bar, and you can continue the
installation process by pressing the Enter key. In our case, we will decide
not to install a server at this step. We will have a look at how to do this in
a later chapter:
[ 10 ]
Chapter 1
12. Finally, you will be asked to confirm the installation of the GRUB
boot loader to the Master Boot Recorder (MBR). Then, you will get
the following notification at the end of the installation process:
[ 11 ]
do-release-upgrade --check-dist-upgrade-only: The --check-distupgrade-only option checks for a new version. If a new version is found,
[ 12 ]
Chapter 1
Using RAID
The RAID technology (an acronym for Redundant Array of Inexpensive Disks)
refers to the techniques used to distribute data across multiple hard drives (creating
a storage unit from several hard disks). The unit thus created has an improved fault
tolerance (high availability) or a greater performance (the capacity/write speed).
The distribution of data on several hard drives allows you to increase the safety and
reliability of the associated services.
For more information about this technology, you can take a tour at
http://www.tldp.org/HOWTO/Software-RAID-HOWTO.html.
In this section, we will see how to install Ubuntu Server using two RAID1 partitions
on two different hard disks, one for the root and the other for Swap:
1. In the Partition disk step, select manual. Then, select one by one all the disks
that you want and which should be a part of the RAID partitions (in our case,
only two disks). For each disk, create a new empty partition table on it.
2. Select the free space on the first drive. Then, choose Create a new partition.
Set the size that you want for Swap; it should be twice the RAM size and up
to 2 GB. Then, choose Primary and select Beginning. The physical volume
for RAID option should be chosen in the Use as: line. Finally, select Done
setting up partition.
3. With the remaining free space, perform the same steps for the root partition.
The only exception is that after setting the size, choose Continue and then
select Primary. Also, select the Bootable flag: line to change the value to on.
4. Return to the Partition Disks step and select Configure Software RAID
at the beginning of the page. Then, choose yes to write the modifications
to disk.
5. In the Create MD device setup and for this example, choose RAID1, but if
you are applying another architecture, choose the one that fits your needs.
6. Now, enter the number of hard drives that you have chosen for the array
(in our case, we have two active devices). Then, select Continue.
7. Next, enter the number of spare devices (choose the default setting for
RAID1, which is 0) and then select Continue.
8. At this step, choose the partitions that you wish to use. For the Swap
partition, choose sda1 and sdb1. Select Continue to go to the next step.
9. Repeat steps 3 to 7 to prepare the root partition, and at the end, choose sda2
and sdb2. Finally, select Finish.
[ 13 ]
We should now have a list of RAID devices and hard drives. The next remaining
steps are required to format and set the mount point for the RAID devices. Deal with
the RAID devices as a local hard disk; format and mount accordingly:
1. Getting back to the initial partitioning page again, we will see our newly
created RAID devices #0 and #1 partitions.
2. Under the RAID1 device #0 partition, select #1 and press the Enter key.
3. In the Use as: file, select swap area and then apply this partition by using
the Done setting up partition entry.
4. Under the RAID1 device #1 partition, select #1 and press the Enter key.
5. In the Use as: file, select Ext4 journaling file system.
6. In the Mount point field, choose / (the root file system). You can change
the other options as you wish. Then, apply that partition by using the Done
setting up partition entry.
7. Finally, select Finish partitioning and write changes to disk.
The installation process will then continue normally.
Using LVM
LVM (Logical Volume Manager) allows the creation and the management of
logical volume on Linux. The use of logical volumes somehow replaces the disks'
partitioning. This is a much more flexible system as it allows you, for instance, to
reduce the size of a file system to expand another one regardless of their location
on disks.
For more information about this technology, you can take a tour at
http://tldp.org/HOWTO/LVM-HOWTO/.
In this section, we will have a look at the partitioning step of Ubuntu Server
installation process with the /srv partition mounted on a LVM volume. This section
will be divided into two partsthe first part is during the Ubuntu installation within
only one PV (physical volume), which will be a part of the VG (volume group), and
the second part will be after the Ubuntu installation. While performing this process,
we will demonstrate how to add a second PV to the VG:
1. In the Partition disks screen, choose Manual.
2. Select the hard disk. Then, choose Yes to confirm the Create a new empty
partition table on this device order.
[ 14 ]
Chapter 1
3. Next, create standard swap and / partitions with the file system that
you want.
4. For our /srv LVM partition, create a new logical partition and change the
Use as field to physical volume for LVM. Then, select Done setting up
the partition.
5. Now, choose Configure the Logical Volume Manager and select Yes.
6. On the next screen and for LVM configuration action, select Create volume
group. Name the VG (for example, vg01). Then, select the partition prepared
for LVM and choose Continue.
7. Return to the LVM configuration action page and select Create logical
volume. Choose the newly created VG and name the new LV. Then, choose
a size and at the end, select Finish. You will be taken to the main Partition
Disks page again.
8. Now, let's add a file system to our new LVM. To do this, select the partition
under the LVM that you created and set up the file system that you want and
choose /srv as the mount point. Next, select Done setting up the partition.
9. Finally, apply the Finish partitioning and write changes to disk order.
Then, confirm the changes and continue your installation.
Now, we will continue with the second part that started after the Ubuntu Server
installation and which covers adding a second hard disk, creating a PV, adding it to
the existing VG, extending LV with the srv command, and finally extending the file
system. In this part, we will use a second hard disk named /dev/sdb, and we will
use it entirely as a PV. You can configure and use as much of PV as you want:
1. First of all, create the PV using the following command:
sudo pvcreate /dev/sdb
3. Use the vgdisplay command to find out the size that you can allocate
(for free physical extents, see the Free PE / size line). We will assume in our
example a free size of 511 PE (which is equivalent to 2 GB with a size of
4 MB PE), and we will use the entire available free space.
4. We can now use the PE to extend the LV via the following command
(there are other methods, but they are beyond the scope of this book):
sudo lvextend /dev/vg01/srv -l +511
[ 15 ]
5. We used the -l option here to extend the LV using PE. If you want to extend
using MB, GB, and TB, you can use the -l option.
6. Before expanding an ext3 or ext4 file system, it is recommended that you
unmount it before hand (as best practice). In case you want to reduce an LV,
it will be mandatory to unmount it. The following commands unmount the
partition and then check it:
sudo umount /srv
sudo e2fsck -f /dev/vg01/srv
7. Finally, you can resize the file system by using the following command:
sudo resize2fs /dev/vg01/srv
8. Now, you can mount the partition and check its new size using the
following command:
mount /dev/vg01/srv /srv && df -h /srv
Chapter 1
2. After this, install the following packages that are necessary if you wish to set
up the PXE environment:
sudo apt-get install apache2 tftpd-hpa inetutils-inetd
Now, it is time to configure the TFTP service. To do this, add the following
two lines to the /etc/default/tftpd-hpa file:
RUN_DAEMON="yes"
OPTIONS="-l -s /var/lib/tftpboot"
Also, add the following line at the end of the /etc/inetd.conf file:
tftp
dgram
udp
wait
root
/usr/sbin/in.tftpd
/usr/sbin/in.tftpd -s /var/lib/tftpboot
Then, copy the required files to the server by using the following commands:
cd /mnt
sudo cp -fr install/netboot/* /var/lib/tftpboot/
sudo mkdir /var/www/Ubuntu
sudo cp -fr /mnt/* /var/www/ubuntu/
--
4. The last step required to set up the PXE server is to add the following lines at
the end of the /etc/dhcp/dhcpd.conf file:
allow booting;
allow bootp;
option option-128 code 128 = string;
option option-129 code 129 = text;
next-server 192.168.1.1;
filename "pxelinux.0";
Let's move on to the client configuration. In our case, I used a virtualbox instance
to test this kind of installation:
1. Create the virtual machine with the characteristics that you want via the
virtualbox manager.
2. Then, go to the Settings of the machine and select the System tab. In the
Boot Order part, deselect all options and select Network, as shown in the
following screenshot:
[ 18 ]
Chapter 1
3. Select the Network tab and configure the network adaptor to act as a bridge.
4. Finally, start your VM. You will see the following interface:
Enjoy watching the server installation if you were doing it locally from a CD.
[ 19 ]
Additional resources
Since this book consists of the essentials for the Ubuntu Server, we can't cover topics
in depth. Therefore, here are some useful links that will help you go as far as you
want in this subject:
For details regarding the installation of the Ubuntu desktop from a PXE
server, visit https://help.ubuntu.com/community/Installation/
LocalNet. You can use the same procedure to install Ubuntu Server.
To learn how to prepare a PXE server that allows you to boot multiple
distributions (Ubuntu, Debian, Fedora, CentOS, and openSUSE), visit
https://help.ubuntu.com/community/PXEInstallMultiDistro.
For those of you searching for how to set up a MAAS server that will
deploy a Ubuntu system through netboot, a very good guide is available
at http://maas.ubuntu.com/docs/install.html.
Summary
In this chapter, we had a look at how to install Ubuntu Server in different
modesmanually and automatedwith the help of a simple or an
advanced installation.
Now, we can start managing our server, which is the subject that we will cover
in the next chapter.
[ 20 ]
www.PacktPub.com
Stay Connected: