Book Image

CentOS 7 Linux Server Cookbook - Second Edition

By : Jonathan Hobson
Book Image

CentOS 7 Linux Server Cookbook - Second Edition

By: Jonathan Hobson

Overview of this book

This book will provide you with a comprehensive series of starting points that will give you direct access to the inner workings of the latest CentOS version 7 and help you trim the learning curve to master your server. You will begin with the installation and basic configuration of CentOS 7, followed by learning how to manage your system, services and software packages. You will then gain an understanding of how to administer the file system, secure access to your server and configure various resource sharing services such as file, printer and DHCP servers across your network. Further on, we cover advanced topics such as FTP services, building your own DNS server, running database servers, and providing mail and web services. Finally, you will get a deep understanding of SELinux and you will learn how to work with Docker operating-system virtualization and how to monitor your IT infrastructure with Nagios. By the end of this book, you will have a fair understanding of all the aspects of configuring, implementing and administering CentOS 7 Linux server and how to put it in control.
Table of Contents (22 chapters)
CentOS 7 Linux Server Cookbook Second Edition
About the Authors
About the Reviewer


This is the second edition of the highly rated CentOS Linux Server Cookbook. With the advent of CentOS 7 in mid 2014, there has been a long list of significant changes and new features to this famous operating system. To name a few, there is a new installer, suite of system management services, firewall daemon, enhanced Linux container support, and a new standard filesystem. With all these new advances in the operating system, a major part of the recipes from the CentOS 6 Linux Server Cookbook became obsolete or even non-functional, making an update of the book's original content essential. But this book is not just a refresher of the topics covered in the first edition: two brand new chapters have been included as well to keep up to date with the latest open source technologies as well as providing better security: operating system-level virtualization and SELinux. Finally, to make the book a more comprehensive server-administration book, another chapter about server monitoring has been included as well.

Building a server can present a challenge. It is often difficult at the best of times and frustrating at the worst of times. They can represent the biggest of problems or give you a great sense of pride and achievement. Where the word "server" can describe many things, it is the intention of this book to lift the lid and expose the inner workings of this enterprise-class computing system with the intention of enabling you to build your professional server solution of choice. CentOS is a community-based enterprise class operating system. It is available free of charge, and as a fully compatible derivative of Red Hat Enterprise Linux (RHEL), it represents the first choice operating system for organizations, companies, professionals, and home users all over the world who intend to run a server. It's widely respected as a very powerful and flexible Linux distribution and regardless of whether you intend to run a web server, file server, FTP server, domain server, or a multi-role solution, it is the purpose of this book to deliver a series of turnkey solutions that will show you how quickly you can build a fully capable and comprehensive server system using the CentOS operating system. So with this in mind, you could say that this book represents more than just another introduction to yet another server-based operating system. This is a cookbook about an enterprise-class operating system that provides a step-by-step approach to making it work. So, regardless of whether you are a new or an experienced user, there is something inside these pages for everyone, as this book will become your practical guide to getting things done and a starting point to all things CentOS.

What this book covers

Chapter 1, Installing CentOS, is a series of recipes that introduces you to the task of installing your server, updating, and enhancing the minimal install with additional tools. It is designed to get you started and to provide a reference that shows you a number of ways to achieve the desired installation.

Chapter 2, Configuring the System, is designed to follow on from a successful installation to offer a helping hand and provide you with a number of recipes that will enable you to achieve the desired starting server configuration. Beginning with showing you how to work with text files, then changing language and time and date settings, you will not only learn how configure your network settings but also how to resolve a fully qualified domain name and work with kernel modules.

Chapter 3, Managing the System, provides the building blocks that will enable you to champion your server and take control of your environment. It is here where you will kick start your role as a server administrator by disseminating a wealth of information that will walk you through a variety of steps that are required to develop a fully considered and professional server solution.

Chapter 4, Managing Packages with YUM, serves to introduce you to working with software packages on CentOS 7. From upgrading the system to finding, installing, removing, and enhancing your system with additional repositories, it is the purpose of this chapter to explain the open source command-line package management utility known as the Yellowdog Updater Modified (YUM) as well as the RPM package manager.

Chapter 5, Administering the Filesystem, focuses on working with your server's file system. From creating mocking disk devices to test-drive concepts expert level formatting and partitioning commands, you will learn how to work with the Logical Volume Manager, maintain your file system and work with disk quotas.

Chapter 6, Providing Security, discusses the need to implement a series of solutions that will deliver the level of protection you need to run a successful server solution. From protecting your ssh and FTP services, to understanding the new firewalld manager and creating certificates, you will see how easy it is to build a server that not only considers the need to reduce risk from external attack but one that will provide additional protection for your users.

Chapter 7, Building a Network, explains the steps required to implement various forms of resource sharing within your network's computers. From IP addresses and printing devices to various forms of file sharing protocols, this chapter plays an essential role of any server whether you are intending to support a home network or a full corporate environment.

Chapter 8, Working with FTP, concentrates on the role of VSFTP with a series of recipes that will provide the guidance you need to install, configure and manage the File Transfer Protocol (FTP) you want to provide on a CentOS 7 server.

Chapter 9, Working with Domains, considers the steps required to implement domain names, domain resolution, and DNS queries on a CentOS 7 server. The domain name system is an essential role of any server and whether you are intending to support a home network or a full corporate environment, it is the purpose of this chapter to provide a series of solutions that will deliver the beginning of a future-proof solution.

Chapter 10, Working with Databases, provides a series of recipes that deliver instant access to MySQL and PostgreSQL with the intention of explaining the necessary steps required to deploy them on a CentOS 7 server.

Chapter 11, Providing Mail Services, introduces you to the process of enabling a domain-wide Mail Transport Agent to your CentOS 7 server. From building a local POP3/SMTP server to configuring Fetchmail, the purpose of this chapter is to provide the groundwork for all your future e-mail-based needs.

Chapter 12, Providing Web Services, investigates the role of the well-known Apache server technology to full effect, and whether you are intending to run a development server or a live production server, this chapter provides you with the necessary steps to deliver the features you need to become the master of your web based publishing solution.

Chapter 13, Operating System-Level Virtualization, introduces you to the word of Linux containers using the state-of-the-art open source platform Docker, and guides you through building, running, and sharing your first Docker image.

Chapter 14, Working with SELinux, helps to understand and demystify Security Enhanced Linux, which is one of the most little-known topics of CentOS 7.

Chapter 15, Monitoring IT Infrastructure, introduces and shows how to set up Nagios Core, the de-facto industry standard for monitoring your complete IT infrastructure.

What you need for this book

The requirements of this book are relatively simple and begin with the need to download the CentOS operating system. The software is free, but you will need a computer that is capable of fulfilling the role of a server, some free installation media (blank CD-R/DVD-R or USB device), an Internet connection, some spare time, and a desire to have fun.

In saying that, many readers will be aware that you do not need a spare computer to take advantage of this book as the option of installing CentOS on virtualization software is always available. This approach is quite common and where the recipes contained within these pages remain applicable, you should be aware that the use of virtualization software is not considered by this book. For this reason, any requests for support regarding the use of this software should be directed towards the appropriate supplier.

Who this book is for

This is a practical guide for building a server solution, and rather than being about CentOS itself, this is a book that will show you how to get CentOS up and running. It is a book that has been written with the novice-to-intermediate Linux user in mind who is intending to use CentOS as the basis of their next server. However, if you are new to operating systems as a whole, then don't worry; this book will also serve to provide you with the step-by-step approach you need to build a complete server solution with plenty of tricks of the trade thrown in for good measure.


In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works and There's more).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "For the purpose of this recipe, it is assumed that all the downloads will be stored on Windows in your personal C:\Users\<username>\Downloads folder, or if using an OS X system, in the /Users/<username>/Downloads folder."

A block of code is set as follows:

<?xml version="1.0" encoding="utf-8"?>
  <description>enable FTPS ports</description>
  <port protocol="tcp" port="40000-40100"/>
  <port protocol="tcp" port="21"/>
  <module name="nf_conntrack_ftp"/>

Any command-line input or output is written as follows:

sudo diskutil unmountDisk /dev/disk3
sudo dd if=./CentOS-7-x86_64-Minimal-XXXX.iso of=/dev/disk3 bs=1M

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves you to the next screen."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.