CentOS 7 Server Deployment Cookbook - Timothy Boronczyk - E-Book

CentOS 7 Server Deployment Cookbook E-Book

Timothy Boronczyk

0,0
41,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Deploy and manage today's essential services on an enterprise-class, open operating system

About This Book

  • Configure and manage Linux servers in varying scenarios and for a range of business requirements
  • Explore the up-to-date features of CentOS using real-world scenarios
  • See practical and extensive recipes to deploy and manage CentOS

Who This Book Is For

This book is for Linux professionals with basic Unix/Linux functionality experience, perhaps even having set up a server before, who want to advance their knowledge in administering various services.

What You Will Learn

  • See how to deploy CentOS easily and painlessly, even in multi-server environments
  • Configure various methods of remote access to the server so you don't always have to be in the data center
  • Make changes to the default configuration of many services to harden them and increase the security of the system
  • Learn to manage DNS, emails and web servers
  • Protect yourself from threats by monitoring and logging network intrusion and system intrusion attempts, rootkits, and viruses
  • Take advantage of today's powerful hardware by running multiple systems using virtualization

In Detail

CentOS is derived from Red Hat Enterprise Linux (RHEL) sources and is widely used as a Linux server. This book will help you to better configure and manage Linux servers in varying scenarios and business requirements.

Starting with installing CentOS, this book will walk you through the networking aspects of CentOS. You will then learn how to manage users and their permissions, software installs, disks, filesystems, and so on. You'll then see how to secure connection to remotely access a desktop and work with databases. Toward the end, you will find out how to manage DNS, e-mails, web servers, and more. You will also learn to detect threats by monitoring network intrusion. Finally, the book will cover virtualization techniques that will help you make the most of CentOS.

Style and approach

This easy-to-read cookbook is filled with practical recipes. Hands-on, task-based exercises will present you with real-world solutions to deploy and manage CentOS in varying business scenarios.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 418

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

CentOS 7 Server Deployment Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Getting Started with CentOS
Introduction
Installing CentOS using Anaconda in graphics mode
Getting ready
How to do it...
How it works...
See also
Installing CentOS using Anaconda in text mode
Getting ready
How to do it...
How it works...
See also
Coordinating multiple installations using Kickstart
Getting ready
How to do it...
How it works...
See also
Running a cloud image with Amazon Web Services' EC2
Getting ready
How to do it...
How it works...
See also
Installing a container image from the Docker Registry
Getting ready
How to do it...
How it works...
See also
Installing the GNOME desktop
Getting ready
How to do it...
How it works...
See also
Installing the KDE Plasma desktop
Getting ready
How to do it...
How it works...
See also
2. Networking
Introduction
Setting a static IP address
Getting ready
How to do it...
How it works...
See also
Binding multiple addresses to a single Ethernet device
Getting ready
How to do it...
How it works...
See also
Bonding two Ethernet devices
Getting ready
How to do it...
How it works...
See also
Configuring the network firewall with FirewallD
Getting ready
How to do it...
How it works...
See also
Configuring the network firewall using iptables
Getting ready
How to do it...
How it works...
See also
Installing a DHCP server
Getting ready
How to do it...
How it works...
See also
Configuring an NFS server to share a filesystem
Getting ready
How to do it...
How it works...
See also
Configuring an NFS client to use a shared filesystem
Getting ready
How to do it...
How it works...
See also
Serving Windows shares with Samba
Getting ready
How to do it...
How it works...
See also
3. User and Permission Management
Introduction
Escalating privileges with sudo
Getting ready
How to do it...
How it works...
See also
Enforcing password restrictions
Getting ready
How to do it...
How it works...
See also
Setting default permissions for new files and directories
Getting ready
How to do it...
How it works...
See also
Running binaries as a different user
Getting ready
How to do it...
How it works...
See also
Working with SELinux for greater security
Getting ready
How to do it...
How it works...
See also
4. Software Installation Management
Introduction
Registering the EPEL and Remi repositories
Getting ready
How to do it...
How it works...
See also
Prioritizing repositories using the Priorities plugin
Getting ready
How to do it...
How it works...
See also
Automating software updates with yum-cron
Getting ready
How to do it...
How it works...
See also
Verifying installed RPM packages
Getting ready
How to do it...
How it works...
See also
Compiling a program from source
Getting ready
How to do it...
How it works...
See also
5. Managing Filesystems and Storage
Introduction
Viewing the size of files and available storage
Getting ready
How to do it...
How it works...
See also
Setting storage limits for users and groups
Getting ready
How to do it...
How it works...
See also
Creating a RAM disk
Getting ready
How to do it...
How it works...
See also
Creating a RAID
Getting ready
How to do it...
How it works...
See also
Replacing a device in a RAID
Getting ready
How to do it...
How it works...
See also
Creating a new LVM volume
Getting ready
How to do it...
How it works...
See also
Removing an existing LVM volume
Getting ready
How to do it...
How it works...
See also
Adding storage and growing an LVM volume
Getting ready
How to do it...
How it works...
See also
Working with LVM snapshots
Getting ready
How to do it...
How it works...
See also
6. Allowing Remote Access
Introduction
Running commands remotely through SSH
Getting ready
How to do it...
How it works...
See also
Configuring a more secure SSH login
Getting ready
How to do it...
How it works...
See also
Securely connecting to SSH without a password
Getting ready
How to do it...
How it works...
See also
Restricting SSH access by user or group
Getting ready
How to do it...
How it works...
See also
Protecting SSH with Fail2ban
Getting ready
How to do it...
How it works...
See also
Confining sessions to a chroot jail
Getting ready
How to do it...
How it works...
See also
Configuring TigerVNC
Getting ready
How to do it...
How it works...
See also
Tunneling VNC connections through SSH
Getting ready
How to do it...
How it works...
See also
7. Working with Databases
Introduction
Setting up a MySQL database
Getting ready
How to do it...
How it works...
See also
Backing up and restoring a MySQL database
Getting ready
How to do it...
How it works...
See also
Configuring MySQL replication
Getting ready
How to do it...
How it works...
See also
Standing up a MySQL cluster
Getting ready
How to do it...
How it works...
See also
Setting up a MongoDB database
Getting ready
How to do it…
How it works...
See also
Backing up and restoring a MongoDB database
Getting ready
How to do it...
How it works...
See also
Configuring a MongoDB replica set
Getting ready
How to do it...
How it works...
See also
Setting up an OpenLDAP directory
Getting ready
How to do it...
How it works...
See also
Backing up and restoring an OpenLDAP database
Getting ready
How to do it...
How it works...
See also
8. Managing Domains and DNS
Introduction
Setting up BIND as a resolving DNS server
Getting ready
How to do it...
How it works...
See also
Configuring BIND as an authoritative DNS server
Getting ready
How to do it...
How it works...
See also
Writing a reverse lookup zone file
Getting ready
How to do it...
How it works...
See also
Setting up a slave DNS server
Getting ready
How to do it...
How it works...
See also
Configuring rndc to control BIND
Getting ready
How to do it...
How it works...
See also
9. Managing E-mails
Introduction
Configuring Postfix to provide SMTP services
Getting ready
How to do it...
How it works...
See also
Adding SASL to Postfix with Dovecot
Getting ready
How to do it...
How it works...
See also
Configuring Postfix to use TLS
Getting ready
How to do it...
How it works...
See also
Configuring Dovecot for secure POP3 and IMAP access
Getting ready
How to do it...
How it works...
See also
Targeting spam with SpamAssassin
Getting ready
How to do it...
How it works...
See also
Routing messages with Procmail
Getting ready
How to do it...
How it works...
See also
10. Managing Web Servers
Introduction
Installing Apache HTTP Server and PHP
Getting ready
How to do it...
How it works...
See also
Configuring name-based virtual hosting
Getting ready
How to do it...
How it works...
See also
Configuring Apache to serve pages over HTTPS
Getting ready
How to do it...
How it works...
See also
Enabling overrides and performing URL rewriting
Getting ready
How to do it...
How it works...
See also
Installing NGINX as a load balancer
Getting ready
How to do it...
How it works...
See also
11. Safeguarding Against Threats
Introduction
Sending messages to Syslog
Getting ready
How to do it...
How it works...
See also
Rotating log files with logrotate
Getting ready
How to do it...
How it works...
See also
Using Tripwire to detect modified files
Getting ready
How to do it...
How it works...
See also
Using ClamAV to fight viruses
Getting ready
How to do it...
How it works...
See also
Checking for rootkits with chkrootkit
Getting ready
How to do it...
How it works...
See also
Using Bacula for network backups
Getting ready
How to do it...
How it works
See also
12. Virtualization
Introduction
Creating a new virtual machine
Getting ready
How to do it...
How it works...
See also
Cloning a virtual machine
Getting ready
How to do it...
How it works...
See also
Adding storage to a virtual machine
Getting ready
How to do it...
How it works...
See also
Connecting USB peripherals to a guest system
Getting ready
How to do it...
How it works...
See also
Configuring a guest's network interface
Getting ready
How to do it...
How it works...
See also

CentOS 7 Server Deployment Cookbook

CentOS 7 Server Deployment Cookbook

Copyright © 2016 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, and its dealers and distributors will be held liable for any damages caused or alleged to be 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.

First published: September 2016

Production reference: 1270916

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham 

B3 2PB, UK.

ISBN 978-1-78328-888-5

www.packtpub.com

Credits

Author

Timothy Boronczyk

Copy Editor

Tom Jacob

Reviewer

Mitja Resman

Project Coordinator

 Kinjal Bari

Commissioning Editor

Kartikey Pandey

Proofreader

Safis Editing

Acquisition Editor

Rahul Nair

Indexer

Pratik Shirodkar

Content Development Editor

Mehvash Fatima

Graphics

Kirk D'Penha

Technical Editors

Devesh Chugh

Siddhi Rane

Production Coordinator

Shantanu N. Zagade

About the Author

Timothy Boronczyk is a native of Syracuse, New York, where he works as a lead developer at Optanix, Inc. (formerly ShoreGroup, Inc.). He's been involved with web technologies since 1998, has a degree in Software Application Programming, and is a Zend Certified Engineer. In what little spare time he has left, Timothy enjoys hanging out with friends, studying Esperanto, and sleeping with his feet off the end of the bed. He's easily distracted by shiny objects.

About the Reviewer

Mitja Resman comes from a small, beautiful country called Slovenia, located in southern Central Europe. Mitja is a fan of Linux and is an open source enthusiast. Mitja is a Red Hat Certified Engineer and Linux Professional Institute professional. Working as a system administrator, Mitja got years of professional experience with open source software and Linux system administration on local and international projects worldwide. The swiss army knife syndrome makes Mitja an expert in the field of VMware virtualization, Microsoft system administration, and lately, also Android system administration.

Mitja has a strong desire to learn, develop, and share knowledge with others. This is the reason he started a blog called GeekPeek.Net (https://geekpeek.net/). GeekPeek.Net provides CentOS Linux guides and How to articles covering all sorts of topics appropriate for beginners and advanced users. He wrote a book, CentOS High Availability by Packt Publishing, covering the topic of how to install, configure, and manage clusters on CentOS Linux.

Mitja is also a devoted father and husband. His two daughters and wife are the ones who take his mind off the geek stuff and make him appreciate life, looking forward to things to come.

www.PacktPub.com

For support files and downloads related to your book, please visit www.PacktPub.com.

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.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

For over a decade, the CentOS project has provided the community with a free, enterprise-grade operating system through the rebranding and recompilation of the Red Hat Enterprise Linux source. Since CentOS users rely almost exclusively on the community for their support needs, I was keen to write this book when Packt approached me about the project's latest release, CentOS 7. The recipes we chose cover a wide range of topics, from getting started to managing many common web services, and hopefully administrators of any skill level will find something of interest.

However, writing a book is a huge undertaking. Because of this, I want to thank the staff at Packt, my family, and my friends, for their support. The dog needs to be taken for a walk, family engagements need attending, and emergencies arise at the workplace. Without the understanding and encouragement of those around me and the editorial staff, you wouldn't be reading this book.

What this book covers

The recipes presented in this book aim to make even the most difficult configuration tasks easy by providing step-by-step instructions and discussion. Here's a quick rundown of what you can expect from each of the 12 chapters.

Chapter 1, Getting Started with CentOS, contains recipes for installing CentOS using graphical, text-based, and kick-start approaches. How to set up a CentOS platform for projects running Docker and on Amazon Web Services is also discussed.

Chapter 2, Networking, contains recipes to help you complete common networking tasks, such as how to set up a static IP address, assign multiple addresses to a single network interface, bond multiple interfaces with the same address, and configure the system's firewall using FirewallD and iptables. It also presents recipes for configuring network services such as DHCP, NFS, and Samba.

Chapter 3, User and Permission Management, shows you how to increase the security of your system by enforcing password restrictions, adjusting the default permissions given to newly created files and directories, and the use of sudo to avoid circulating the root password. How to work with SELinux is also discussed.

Chapter 4, Software Installation Management, provides recipes focused on working with software repositories and installing software. You'll learn how to register the EPEL and Remi repositories, prioritize the repositories packages are installed from, and update your software automatically. You'll also learn how to compile and install software from source code.

Chapter 5, Managing Filesystems and Storage, presents recipes that show you how to set up and work with RAID and with LVM. These services leverage your system's storage to maintain availability, increase reliability, and to keep your data safe against inevitable disk failures.

Chapter 6, Allowing Remote Access, aims to help you provide remote access to your CentOS system in a secure manner. Its recipes cover using SSH, configuring a chroot jail, and tunneling VNC connections through an encrypted SSH tunnel.

Chapter 7, Working with Databases, collects recipes that provide you with the necessary steps to get started with various database services such as MySQL, MongoDB, and OpenLDAP. You'll also learn how to provide backup and redundancy for these services.

Chapter 8, Managing Domains and DNS, takes us into the world of DNS. The recipes show you how to set up a resolving DNS server to decrease latency caused by domain lookups and how to manage your own domain with an authoritative DNS server.

Chapter 9, Managing E-mails, will help you set up your own mail server. The recipes discuss configuring Postfix to provide SMTP services, configuring Dovecot to provide IMAP and POP3 services, and securing these services with TLS. You'll also find instructions on how to set up SpamAssassin to help reduce unsolicited bulk e-mails.

Chapter 10, Managing Web Servers, contains recipes about configuring Apache to server web content. You'll learn how to set up name-based virtual hosting, server pages over HTTPS, and perform URL rewriting. How to set up NGINX as a load balancer is also discussed.

Chapter 11, Safeguarding Against Threats, contains recipes to help protect the investment you've made in your CentOS server. They cover logging, threat monitoring, virus and rootkits, and network backups.

Chapter 12, Virtualization, shows you how CentOS can function as a host operating system to one or more virtualized guests. This allows you to take better advantage of your hardware resources by running multiple operating systems on the same physical system.

What you need for this book

To follow the recipes in this book, first and foremost you'll need a system capable of running CentOS 7. The minimum requirements (and maximum capabilities) are documented in the Red Hat Enterprise Linux knowledge base available online at https://access.redhat.com/articles/rhel-limits. In brief, you'll need a system that has the following:

x86_64 processor (RHEL/CentOS 7 does not support x86)1 GB RAM8 GB Disk capacity

Apart from a system to install CentOS on, you'll also need a copy of the CentOS installation media and a working network connection. You can download a copy directly from https://www.centos.org/download/ or using BitTorrent.

Who this book is for

This book is for Linux professionals with basic Unix/Linux functionality experience, perhaps even having set up a server before, who want to advance their knowledge in administering various services.

Sections

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

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.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

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: "The repositories' configuration files are found in the /etc/yum.repos.d directory."

A block of code is set as follows:

[sshd] enabled=true bantime=86400 maxretry=5

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

firewall-cmd --zone=public --permanent --add-service=dns

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: "Select your desired language and click on Continue."

Note

Warnings or important notes appear in a box like this.

Tip

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 [email protected], 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 www.packtpub.com/authors.

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.

Errata

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 http://www.packtpub.com/submit-errata, 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 https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

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 [email protected] with a link to the suspected pirated material.

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

Questions

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

Chapter 1. Getting Started with CentOS

This chapter contains the following recipes:

Installing CentOS using Anaconda in graphics modeInstalling CentOS using Anaconda in text modeCoordinating multiple installations using KickstartRunning a cloud image with Amazon Web Services' EC2Installing a container image from the Docker RegistryInstalling the GNOME desktopInstalling the KDE Plasma desktop

Introduction

This chapter's recipes focus on getting up and running with CentOS using a variety of installation methods. You'll learn how to perform interactive graphical and text-based installations using Anaconda and perform an unattended installation using Kickstart. You'll also see how to run CentOS in the cloud with Amazon Web Services and in a Docker container image. Most of the recipes in this book take place at the command prompt, but some require a graphical desktop, so we'll finish up with a look at installing the GNOME and KDE Plasma desktops.

Installing CentOS using Anaconda in graphics mode

In this recipe, you'll learn how to install CentOS using the graphical installer Anaconda. This is the most common way that CentOS is installed, although there are other ways too (some of which are discussed in later recipes). This approach is also the easiest installation method, especially for setting up single-server deployments.

Getting ready

This recipe assumes that you have a copy of the CentOS 7 installation medium. If you don't, visit https://www.centos.org and download a minimal ISO image. You'll also need to make a physical disc from the image. Instructions for burning the ISO image to disc can be found at https://www.centos.org/docs/5/html/CD_burning_howto.html.

Tip

If your system doesn't have an optical drive and its BIOS supports booting from a USB device, you can also write the ISO image to a USB stick.

How to do it...

Follow these steps to install CentOS using the graphical installer Anaconda:

Insert the installation disc into your system's optical drive (or USB stick into a USB port) and reboot. The system should boot to the CentOS 7 installation menu:

The installer is launched from the installation menu

Note

If your system doesn't boot to the installation menu then the drive may not be configured as a boot device. The exact steps to verify and adjust the configuration vary between BIOS vendors, but in general you'll press Esc, F1, F2, or Delete while the system is booting to gain access to the BIOS settings. Then you'll find the list of boot devices and change the order in which each is searched for a boot record.

Using the arrow keys, make sure that the Install CentOS 7 option is highlighted and press Enter.The WELCOME TO CENTOS 7 screen confirms which language to use during the installation process. Select your desired language and click on Continue:

You can change the language used during the installation process

The next screen is a menu that organizes the installation options by category. We'll configure networking first—click on NETWORK & HOST NAME under the SYSTEM category:

Note

If your system doesn't have a mouse, you can navigate using Tab to cycle through the input fields, use the arrow keys to select the entry, and press Enter to select or activate an input.

The installation summary screen organizes the installation options into categories

Enter the system's hostname in the Host name field. Then, select the system's primary network interface and toggle the switch at the right to ON to enable it. Click on the Done button when you're finished to return to the INSTALLATION SUMMARY menu:

The NETWORK & HOST NAME screen lets us configure the system's network interfaces

Click on DATE & TIME under the LOCALIZATION category.Set your time zone by either selecting your region and city or by clicking on your location on the map. Then, click on Done to return to the INSTALLATION SUMMARY menu:

The DATE & TIME screen lets us configure the system's time zone

If you know what purpose the system will serve on your network and require something more than a minimal installation, click on SOFTWARE SELECTION under the SOFTWARE category. Select the environment and any additional add-ons to install the desired packages. When you're finished, click on Done:

The SOFTWARE SELECTION screen lets us install purpose-based software

Note

Software can easily be installed using yum, so don't worry if you need to install additional software after you already have CentOS up and running. The SOFTWARE SELECTION section is purely for convenience.

Click on INSTALLATION DESTINATION under the SYSTEM category.Click on the appropriate drive in the Local Standard Disks area to set the installation target. If the drive is not bootable, or if multiple drives are selected, click on the Full disk summary and boot loader... link at the bottom of the screen to open the Selected Disks window. Then, select the drive you want to be the boot device, click on the Set as Boot Device button, and click on Close. When you're finished, click on Done:

The INSTALLATION DESTINATION screen lets us set the disk where CentOS will be installed

Click on the Begin Installation button to start the installation process.Click on Root Password. In the input fields, enter and confirm the password you want to use for the system's root account. Click on Done when you've finished entering these details:

Note

You'll need to press the Done button twice to return to the configuration screen if you specify a password that's too weak. If you need help to create a strong password, visit http://www.howtogeek.com/195430/how-to-create-a-strong-password-and-remember-it/.

The ROOT PASSWORD screen lets us set the root account's password

Click on User Creation. In the input fields, provide your name, username, and desired password. Again, press Done when you've finished entering these details:

The CREATE USER screen lets us create an unprivileged user account

When the installation is complete, click on the Finish Configuration button. Anaconda will finalize the system's configuration and the button's label will change to Reboot.Remove the CentOS installation media from the drive and reboot your system.

How it works...

After installing CentOS using Anaconda in graphical mode, you should now have a basic CentOS 7 system up and running. The process began when we booted the system from the installation disc and selected Install CentOS 7 from the installation menu. The installer's kernel loaded into memory and Anaconda launched in graphical mode.

The NETWORK & HOST NAME screen shows a list of the available network interfaces and basic information about them, for instance, the card's MAC address and transfer rate. By default, the interfaces are configured to use DHCP to obtain their IP address when they are enabled. (Configuring a static IP address is discussed in a later recipe.)

The system's time zone is set on the LOCALIZATION screen. The date and time fields are disabled when NTP is enabled because the values will be set by the NTP service. The system clock's time can drift for many reasons, especially if the system is running on a virtual machine, so allowing NTP to manage the system's time is a good idea to ensure it stays correct. If the date and time fields aren't set by NTP, make sure the Network Time toggle is set ON. You can specify an NTP server by clicking on the button with the gears icon.

The INSTALLATION DESTINATION screen lets us set the installation target for CentOS and specify how the system's drives are partitioned. You can choose to configure the partitions if you have special requirements, but in this recipe I let Anaconda partition the drives automatically.

While Anaconda is busy installing CentOS and any additional software packages you may have requested, it shows us the Configuration screen. This screen gives us the opportunity to set a password for the system's administrative account (root) and create an unprivileged user account. You should only sign in with root when necessary; for your normal day-to-day work you should use your unprivileged account. Anaconda finalizes the installation by configuring the system's boot record and creating the user account.

After the system reboots, the Grub boot loader prompt appears and the arrow keys can be used to select a boot configuration. There's also a timer, so pressing nothing will eventually boot the system using the default configuration.

See also

For more information on installing CentOS 7, refer to the RHEL 7 Installation Guide (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide).

Installing CentOS using Anaconda in text mode

Next, you'll learn how to install CentOS using Anaconda in text mode. It's recommended that you install CentOS graphically because graphics mode is easier to use and offers more functionality. However, it may not be available when the system lacks sufficient resources to run the installer in graphical mode, for example, if the display adaptor's capabilities are limited or if there is reduced RAM.

Getting ready

This recipe assumes that you have a copy of the CentOS 7 installation medium. If you don't, visit https://www.centos.org to download an ISO image and then burn the image to a disc.

How to do it...

Follow these steps to perform a text-based installation of CentOS:

Insert the installation disc into your system's optical drive (or USB stick into a USB port) and reboot. The system should boot to the CentOS 7 installation menu.Using the arrow keys, make sure the Install CentOS 7 option is highlighted and press Tab. The command to boot the installer kernel appears at the bottom of the screen.Add the word text to the end of the list of arguments and press Enter. Anaconda will launch in text mode: vmzlinuz initrd=initrd.img inst.stage2=hd:LABEL=CentOS \x207\x20x86_64 rd.live.check quiet text

Note

Anaconda will launch in text mode automatically if your system has less than 768 MB of RAM.

The Installation menu presents the installation options by category. Type 2 and press Enter to select Timezone settings:

The text-based installation menu categorizes the installation options

The Timezone settings menu presents a list of regions. Enter the number for the desired value.You will be given a list of available time zones in the selected region (paginate through the list by pressing Enter if the list is long). Enter the number for the desired time zone.If you know what purpose the system will serve and require something more than a minimal installation, enter 3 to select Software selection. Here you can select groups of software packages for that purpose. When finished, enter c to continue back to the Installation menu.Enter 5 to select Network settings.Enter 1 to set the system's hostname. Type the desired name and press Enter.Enter the number to configure the system's primary network interface. Then, enter 7 to mark Connect automatically after reboot and 8 to mark Apply configuration in installer. Enter c to go back to the Network settings menu and c again to return to the Installation menu:

The Network settings menu lets us configure the system's network interfaces

Enter 6 to select Install Destination.If the desired drive is not already marked, enter the number for the drive. Then, enter c to continue. The Autopartioning Options menu is shown in the following screenshot:

The Install Destination menu let us set the installation target and the Autopartioning Options menu lets us specify how the disk will be used

Enter the number for the desired partitioning (Use All Space is the default) and then c to continue.Select the desired partition scheme (LVM is the default) and then enter c to return to the Installation menu.Enter 8 to select Create user.Enter 1 to mark the Create user option. Provide your name and set a username for the account by entering 2 and 3 respectively. Enter 4 to mark the Use password option and then 5 to set your password. Then, enter c to return to the Installation menu:

Note

You must confirm you really want to use your password if you provide a password that is too weak.

The Create User menu let us create an unprivileged user account

Enter 9 to select Set root password. Enter and confirm the password you want to use for the system's root account.After all of the sections that required attention have been resolved, enter b to begin the installation process.When the installation is complete, remove the media from the drive and reboot the system.

How it works...

This recipe showed you how to install CentOS using Anaconda running in text mode. The process began when we booted the system from the installation disc, selected Install CentOS 7 from the installation menu, and added the text option to the boot parameters. The installer's kernel loaded into memory and Anaconda launched in text mode.

The text-based installation is similar to installing CentOS in graphical mode, answering prompts for time zone, software, and networking information. However, Anaconda presents the prompts in a different order when running in text mode and some functionality is missing. For example, we can't perform custom disk partitioning. Nevertheless, text mode enables us to quickly install a basic CentOS system.

See also

For more information on installing CentOS 7, refer to the RHEL 7 Installation Guide (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide).

Coordinating multiple installations using Kickstart

If you're planning on installing CentOS on multiple servers, it's more convenient to automate as much of the process as possible. In this recipe, you'll learn how to use Anaconda's kickstart.cfg file to perform an unattended network-based installation.

Getting ready

This recipe requires at least two systems on your network: an existing system running an HTTP server to host the installation files and Kickstart configuration (the recipe Installing Apache HTTP Server and PHP in Chapter 10, Managing Web Servers, shows you how to install Apache) and the target system on which we'll install CentOS. You'll also need the installation media and administrative privileges.

How to do it...

Follow these steps to perform unattended network installations using the Kickstart method:

Log in to the system running the HTTP server using the root account.Place the installation disc in the system's optical drive.Mount the disc using the mount command so that its contents are accessible:mount /dev/cdrom /mediaCreate a new directory under Apache's web root to host the installation files:mkdir -p /var/www/html/centos/7/x86_64Copy the contents of the installation disc to the new directory:cp -r /media/* /var/www/html/centos/7/x86_64Copy the kickstart.cfg file created by Anaconda when the system was installed to Apache's web root:cp /root/kickstart.cfg /var/www/html/kickstart.cfgUnmount and remove the installation disc:umount /mediaeject /dev/cdromInsert the disc into the target system's drive and reboot it. The system should boot to the CentOS 7 installation menu.Highlight the Install CentOS 7 option and press Tab.Update the arguments used to boot the installer kernel to read as follows. Change the IP address as necessary to point to the system hosting the Kickstart file: vmlinuz initrd=initrd.img ks=http://192.168.56.100/kickstart.cfg Press Enter to begin the installation process.Once the installation process begins, you can eject the disc and begin the next system's installation. Repeat steps 8-11 for each additional system.

How it works...

Anaconda writes the configuration values we provide when performing a graphical or text-based installation to kickstart.cfg. If you plan on installing CentOS on multiple servers, it's more convenient to use the file to provide the interface's answers. The remaining installations can be performed mostly unattended and the systems' configurations will be more consistent.

This recipe showed you how to make the kickstart.cfg file and the CentOS installation files available to other systems over the network, and update the boot command to tell Anaconda where to look for the installation files and prompt responses. Since the software packages are retrieved from the installation server instead of the disc, you can eject the disc as soon as the installation process is underway and use it to begin the next process on your next system.

Of course, kickstart.cfg can be used as a starting point, and you can edit the responses using a text editor to further customize the installations. If you like, you can create multiple kickstart files in the web root, each with a different configuration. Just specify the desired file when you set the installer's boot arguments.

Tip

Although you can edit your kickstart files with a basic text editor, dedicated programs exist for editing them as well. Check out Kickstart Configurator (http://landoflinux.com/linux_kickstart_configurator.html).

See also

For more information on coordinating multiple installations of CentOS 7, refer to the following resources:

RHEL 7 Installation Guide (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide)Anaconda documentation (http://rhinstaller.github.io/anaconda/index.html)Install PXE Server on CentOS 7 (http://www.unixmen.com/install-pxe-server-centos-7)

Running a cloud image with Amazon Web Services' EC2

Amazon Web Services (AWS) is a suite of services hosted within Amazon's network infrastructure which allows companies and individuals take advantage of their computing/storage capacity and world wide data centers. Elastic Cloud Compute (EC2) is a virtualization platform that lets us set up virtual systems on demand, usually to host websites and web apps. This recipe will walk you through the process of setting up a new virtual server running CentOS on the AWS platform.

Getting ready

This recipe assumes that you have an AWS account. You can sign up for one at http://aws.amazon.com. You will need to provide a valid credit card, although you will have access to Amazon's free tier for 12 months.

How to do it...

To set up a new Amazon Machine Instance (AMI) on AWS's EC2 platform, follow these steps:

Log in at https://aws.amazon.com and go to the AWS Management console. Under the Compute category, click on the EC2 link to access the EC2 management page. Then, click on the Launch Instance button:

The EC2 Management Console presents an overview and quick access to resources

On the Choose an Amazon Machine Image (AMI) page, select Community AMIs in the side menu and then check the CentOS filter. A list of instances created by the community will be shown. Select the one you desire:

Note

Review the list of available images carefully. Many are available, created using different versions of CentOS and with various configurations.

The image selection page presents a filterable list of machine images created by community users

On the Review Instance Launch page, review your instance's resources (the number of virtual CPUs, available memory, and so on) and click on the Launch button:

Note

Amazon guides you through selecting an AMI and configuring it in a wizard-like fashion, listing the steps at the top of the page. The Review and Launch buttons jump directly to the last step. You can use the links at the top of the page to go back to an earlier step and adjust the instance's configuration.

Review your instance's resources on the Review Instance Launch page

Using the drop-down list, select Create a new key pair, enter a suitable filename for the key, and click on the Download Key Pair button. After you save the downloaded private encryption key, click on the Launch Instances button:

You're prompted to create a pair of encryption keys the first time you launch the image

On the launch status page, click on the View Instances button at the bottom of the page. Then, right-click on the running instance and select Connect from the context menu. Select the preferred connection method and follow the instructions that appear on the screen.

How it works...

This recipe walked you through the steps necessary to spin up a new CentOS AMI on AWS's EC2 platform. To log in to the system, a password or set of encryption keys is needed, and since the primary user account's password is likely to be unknown, we opted to generate a new pair of keys. The private key is downloaded and then used with your SSH client to authenticate your login.

Once you have logged in to your running system, it's worth viewing the contents of the /etc/system-release file to verify the running version of CentOS. Also, you should use the passwd command to change the root account's password if the account isn't already locked down. This is an important security precaution because you don't know who knows the default password. You'll find recipes for managing user permissions in Chapter 3, User and Permission Management, and recipes for managing remote access in Chapter 6, Allowing Remote Access:

After you log in, verify the system's version number and update the root password

See also

Refer to the following resources for more information on working with AMIs on Amazon's EC2 platform:

What Is Amazon EC2? (http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html)Connect to Your Linux Instance (http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html)Remove SSH Host Key Pairs (http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/building-shared-amis.html#remove-ssh-host-key-pairs)

Installing a container image from the Docker Registry

This recipe shows you how to procure a CentOS base for your development needs using Docker, a virtualization strategy based on the concept of containers. Each container wraps the target software in its own filesystem so that it can run regardless of the operating system on which it's installed. Developers like Docker especially because it helps provide consistency between development and deployment environments.

Getting ready

The recipe assumes that you have a system with Docker installed. If you don't, you can obtain the Docker installer from http://www.docker.com.

How to do it...

Follow these steps to install a CentOS container image from the Docker Registry:

Open the Docker Toolbox terminal program.At the terminal's prompt, invoke the docker pull command to retrieve a CentOS 7 container:docker pull centos:7After the container has been downloaded, you can launch an interactive shell with docker run:docker run -i -t centos:7 /bin/bash

How it works...

This recipe retrieves the official CentOS container from the Docker Registry using the docker pull command. By providing the version tag (:7), we can make sure we retrieved CentOS 7 as opposed to an earlier (or perhaps newer) version.

Alternatively, Kitematic is the graphical program which lets us search for and retrieve containers from the registry. Simply launch Kitematic and enter CentOS as the search term in the search box. Then, look for the official CentOS repository in the results list.

The default version retrieved by Kitematic is the latest. To specifically select CentOS 7 or a maintenance release, click on the entry's ellipsis button. Set the desired tag and then click on the Create button:

Kitematic displays the results of searching for CentOS

See also

Refer to the following resources for more information about working with Docker:

Docker home page (http://www.docker.com)Understanding the Docker architecture (https://docs.docker.com/engine/understanding-docker)The official CentOS Docker hub (https://hub.docker.com/_/centos)

Installing the GNOME desktop

This recipe shows you how to install the GNOME desktop environment, which provides a graphical user interface (GUI) for working with your CentOS system. Usually, such environments aren't installed on server systems, but it can be convenient sometimes to have one available. For example, an administrator might feel more comfortable updating a system's configuration using graphical programs.

Note

GNOME isn't the only GUI environment available —other popular environments include KDE, XFCE, and Fluxbox. If GNOME isn't your cup of tea, the next recipe shows you how to install KDE.

Getting ready

This recipe requires a CentOS system with a working network connection. Administrative privileges are also required by logging in with the root account.

How to do it...

Follow these steps to install the GNOME desktop environment:

Install the GNOME Desktop package group with yum groupinstall:yum groupinstall "GNOME Desktop"Manually start the desktop environment using startx:startxIf more than one environment is installed, you'll need to specify the path to gnome-session:startx /usr/bin/gnome-sessionWhen you're done using GNOME and log out of the desktop, you'll be returned to the console.To configure the system to automatically start the graphical environment when it boots, set the default start up target to graphical.target:systemctl set-default graphical.target

How it works...

This recipe uses yum to install the GNOME desktop environment. All of the necessary components and dependencies are installed by the GNOME Desktop package group. Package groups saves us time and hassle because they let us install a collection of packages for a common task at the same time instead of individual packages one at a time.

yum groupinstall "GNOME Desktop"

Unlike Windows, where the graphical desktop is part of its operating system, Linux systems delegate basic graphics and input handling to a graphics server. This approach is one reason why there are several desktop environments to choose from —it abstracts many of the specifics and provides a common platform on top of which any number of environments can run, both locally and across a network. CentOS's default graphics server is X Window System.

If GNOME is the only desktop environment installed, it'll be run by default when we launch X with startx. However, if more than one desktop is installed, we need to tell X which one we want to run. For GNOME, we provide the path to gnome-session:

startx /usr/bin/gnome-session

The GNOME desktop provides a graphical interface for working with the system

The systemd service manager is responsible for starting various servers and processes when the system boots. The systemctl command is our interface to the service manager and can be used to set the default boot target. The default target dictates whether the system boots to a terminal or GUI-based login screen:

systemctl set-default graphical.target

When set to graphical, systemd starts X and the GNOME Display Manager when the system boots, which presents us with a graphical login to provide our account details. Once we're authenticated, the desktop session is initiated and we find ourselves at the GNOME desktop.

If you no longer want to boot to the graphical environment, you can set the default target back to multiuser and the system will boot to the terminal-based login screen again:

systemctl set-default multi-user.target

Tip

You can choose which desktop environment you want to use if more than one environment is installed by selecting it from the gear button on the login screen:

You can select your preferred desktop from the login screen

See also

The following resources will provide you with more information about installing graphical desktop environments and using the GNOME desktop:

GNOME Library (https://help.gnome.org)RHEL 7 Desktop Migration and Administration Guide (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Desktop_Migration_and_Administration_Guide)Guild to X11/Starting Sessions (https://en.wikibooks.org/wiki/Guide_to_X11/Starting_Sessions)How to install desktop environments on CentOS 7 (http://unix.stackexchange.com/questions/181503/how-to-install-desktop-environments-on-centos-7/181504#181504)

Installing the KDE Plasma desktop

Separating the graphical interface from the operating system gives users the power to choose the graphical environment they like best. Don't worry if you're not a GNOME fan because there are still many other desktops you can explore! This recipe shows you how to install another popular desktop environment, KDE Plasma Workspaces.

Getting ready

This recipe requires a CentOS system with a working network connection. Administrative privileges are also required by logging in with the root account.

How to do it...

Follow these steps to install the KDE Plasma Workspaces desktop environment:

Install the KDE Plasma Workspaces package group:yum groupinstall "KDE Plasma Workspaces"Manually start the desktop environment using startkde. When you're done using KDE and log out of the desktop, you'll be returned to the console:startkdeTo configure the system to automatically start the graphical environment when it boots, use systemctl to set the default start up target to graphical.target:systemctl set-default graphical.target

How it works...