CentOS 7 Linux Server Cookbook - Second Edition - Oliver Pelz - E-Book

CentOS 7 Linux Server Cookbook - Second Edition E-Book

Oliver Pelz

0,0
43,19 €

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

Mehr erfahren.
Beschreibung

Over 80 recipes to get up and running with CentOS 7 Linux server

About This Book

  • A practical guide to install, configure, administer and maintain CentOS 7 servers
  • An in-depth guide to the CentOS 7 operating system, exploring its various new features and changes in server administration
  • Presents tricks and solutions to tackle common server issues with the help of practical examples and real-life scenarios

Who This Book Is For

This book is targeted at beginner and more experienced system administrators alike who want to use CentOS as their server solution. Readers do not need much pre-knowledge or experience at all to work with this book.

What You Will Learn

  • Install and configure CentOS 7 Linux server system from scratch using normal and advanced methods
  • Maintain a performance-based and secure server solution by deploying expert configuration advice and managing software packages
  • Monitor, manage and develop your server's file system to maintain a stable performance
  • Gain best practice methods on sharing files and resources through a network
  • Install and configure common standard services such as web, mail, FTP, database and domain name server technologies
  • Introduce you to the world of operating-system-level virtualization using the Docker platform.
  • Understand the fundamentals of the Security-Enhanced Linux access control architecture
  • Monitor your IT infrastructure using Nagios

In Detail

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.

Style and approach

This book is a practical reference guide with hands-on examples and solutions to real-world administration problems. It covers in-depth and comprehensive information on CentOS 7 and its new features.

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

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 570

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 Linux Server Cookbook Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
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…
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Installing CentOS
Introduction
Downloading CentOS and confirming the checksum on Windows or OS X
Getting ready
How to do it...
How it works…
Creating USB installation media on Windows or OS X
Getting ready
How to do it...
How it works...
Performing an installation of CentOS using the graphical installer
Getting ready
How to do it...
How it works…
Running a netinstall over HTTP
Getting ready
How to do it...
How it works...
Installing CentOS 7 using a kickstart file
Getting ready
How to do it...
How it works...
Getting started and customising the boot loader
Getting ready
How to do it...
How it works...
Troubleshooting the system in rescue mode
Getting ready
How to do it...
Reaching rescue mode
Accessing the filesystem
Accessing the filesystem
Re-install the CentOS boot loader
How it works...
Updating the installation and enhancing the minimal install with additional administration and development tools
Getting ready
How to do it...
How it works...
2. Configuring the System
Introduction
Navigating text files with less
Getting ready
How to do it...
How it works...
Introduction to Vim
Getting ready
How to do it...
How it works...
Speaking the right language
Getting ready
How to do it...
How it works...
There's more…
Synchronizing the system clock with NTP and the chrony suite
Getting ready
How to do it...
How it works...
There's more...
Setting your hostname and resolving the network
Getting ready
How to do it...
How it works...
There's more...
Building a static network connection
Getting ready
How to do it...
How it works...
Becoming a superuser
Getting ready
How to do it...
How it works...
Customizing your system banners and messages
Getting ready
How to do it...
How it works...
There's more...
Priming the kernel
Getting ready
How to do it...
How it works...
There's more...
3. Managing the System
Introduction
Knowing and managing your background services
Getting ready
How to do it...
How it works...
There's more...
Troubleshooting background services
Getting ready
How to do it...
How it works...
Tracking system resources with journald
Getting ready
How to do it...
How it works...
Configuring journald to make it persistent
Getting ready
How to do it...
How it works...
Managing users and their groups
Getting ready
How to do it...
How it works...
Scheduling tasks with cron
Getting ready
How to do it...
How it works...
There's more...
Synchronizing files and doing more with rsync
Getting ready
How to do it...
How it works...
Maintaining backups and taking snapshots
Getting ready
How to do it...
How it works...
Monitoring important server infrastructure
Getting ready
How to do it...
How it works...
Taking control with GIT and Subversion
Getting ready
How to do it...
How it works
There's more...
4. Managing Packages with YUM
Introduction
Using YUM to update the system
Getting ready
How to do it...
How it works...
There's more...
Using YUM to search for packages
Getting ready
How to do it...
How it works...
There's more...
Using YUM to install packages
Getting ready
How to do it...
How it works...
There's more...
Using YUM to remove packages
Getting ready
How to do it...
How it works...
Keeping YUM clean and tidy
Getting ready
How to do it...
How it works...
There's more...
Knowing your priorities
Getting ready
How to do it...
How it works...
Using a third-party repository
Getting ready
How to do it...
How it works...
There's more...
Creating a YUM repository
Getting ready
How to do it...
How it works...
There's more...
Working with the RPM package manager
Getting ready
How to do it...
How it works...
There's more...
5. Administering the Filesystem
Introduction
Creating a virtual block device
Getting ready
How to do it...
How it works...
There's more...
Formatting and mounting a filesystem
Getting ready
How to do it...
How it works…
There's more...
Using disk quotas
Getting ready
How to do it...
Enabling user and group quotas
Enabling project (directory) quotas
How it works...
There's more...
Maintaining a filesystem
Getting ready
How to do it...
How it works...
There's more...
Extending the capacity of the filesystem
Getting ready
How to do it...
How it works...
6. Providing Security
Introduction
Locking down remote access and hardening SSH
Getting ready
How to do it...
How it works...
There's more...
Changing the SSH port number of your server
Limiting SSH access by user or group
Installing and configuring fail2ban
Getting ready
How to do it...
How it works...
Working with a firewall
Getting ready
How to do it...
How it works...
There's more...
Forging the firewall rules by example
Getting ready
How to do it...
To change an existing firewalld service (ssh)
To create your own new service
How it works...
There's more...
Generating self-signed certificates
Getting ready
How to do it...
How it works...
There's more...
Using secure alternatives to FTP
Getting ready
How to do it...
Securing your vsftpd server with SSL–FTPS
Securing your vsftpd server using SSH – SFTP
How it works...
There's more...
7. Building a Network
Introduction
Printing with CUPS
Getting ready
How to do it...
How it works...
There's more...
How to add a network printer to the CUPS server
How to share a local printer to the CUPS server
Running a DHCP server
Getting ready
How to do it...
How it works...
There's more...
Using WebDAV for file sharing
Getting ready
How to do it…
How it works…
Installing and configuring NFS
Getting ready
How to do it...
Installing and configuring the NFS server
Creating an export share
How it works...
Working with NFS
Getting ready
How to do it...
How it works...
Securely sharing resources with Samba
Getting ready
How to do it...
How it works...
There's more...
8. Working with FTP
Introduction
Installing and configuring the FTP service
Getting ready
How to do it...
How it works...
There's more...
Working with virtual FTP users
Getting ready
How to do it...
How it works...
Customizing the FTP service
Getting ready
How to do it...
How it works...
Troubleshooting users and file transfers
Getting ready
How to do it...
How it works...
9. Working with Domains
Introduction
Installing and configuring a caching-only nameserver
Getting ready
How to do it...
Configuring a caching-only Unbound DNS server
Configuring a forwarding only DNS server
How it works...
There's more...
Setting up an authoritative-only DNS server
Getting ready
How to do it...
How it works...
There's more...
Creating an integrated nameserver solution
Getting ready
How to do it...
How it works
There's more...
Populating the domain
Getting ready
How to do it...
How it works…
Building a secondary (slave) DNS server
Getting ready
How to do it...
Changes to the primary DNS server
Changes to the secondary DNS server(s)
How it works...
10. Working with Databases
Introduction
Installing a MariaDB database server
Getting ready
How to do it...
How it works...
Managing a MariaDB database
Getting ready
How to do it...
How it works...
There's more...
Reviewing and revoking permissions or dropping a user
Allowing remote access to a MariaDB server
Getting ready
How to do it...
How it works...
Installing a PostgreSQL server and managing a database
Getting ready
How to do it...
How it works...
There's more...
Configuring remote access to PostgreSQL
Getting ready
How to do it...
How it works...
Installing phpMyAdmin and phpPgAdmin
Getting ready
How to do it...
Installing and configuring phpMyAdmin
Installing and configuring phpPgAdmin
How it works...
11. Providing Mail Services
Introduction
Configuring a domain-wide mail service with Postfix
Getting ready
How to do it...
How it works...
There's more...
Changing an e-mail's appearing domain name
Using TLS- (SSL) encryption for SMTP communication
Configure BIND to use your new mailserver
Working with Postfix
How to do it...
Connecting mailx to a remote MTA
Reading your local mails from the mailbox
How it works...
Delivering the mail with Dovecot
Getting ready
How to do it...
How it works...
There's more...
Setting up e-mail software
Using Fetchmail
Getting ready
How to do it...
How it works...
There's more...
Configuring Fetchmail with gmail.com and outlook.com e-mail accounts
Automating Fetchmail
12. Providing Web Services
Introduction
Installing Apache and serving web pages
Getting ready
How to do it...
How it works...
Enabling system users and building publishing directories
Getting ready
How to do it...
How it works...
Implementing name-based hosting
Getting ready
How to do it...
How it works...
Implementing CGI with Perl and Ruby
Getting ready
How to do it...
Creating your first Perl CGI script
Creating your first Ruby CGI script
How it works...
There's more...
Installing, configuring, and testing PHP
Getting ready
How to do it...
How to do it...
Securing Apache
Getting ready
How to do it...
Configuring httpd.conf to provide better security
Removing unneeded httpd modules
Protecting your Apache files
How it works...
Setting up HTTPS with Secure Sockets Layer (SSL)
Getting ready
How to do it...
How it works...
There's more...
13. Operating System-Level Virtualization
Introduction
Installing and configuring Docker
Getting ready
How to do it...
How it works...
Downloading an image and running a container
Getting ready
How to do it...
How it works...
There's more...
Stopping and starting a container
Attaching and interacting with your container
Creating your own images from Dockerfiles and uploading to Docker Hub
Getting ready
How to do it...
Uploading your image to the Docker Hub
How it works...
Setting up and working with a private Docker registry
Getting ready
How to do it...
Steps to be done on our Docker registry server (192.168.1.100)
Steps to be done on every client needing access to our registry
How it works...
14. Working with SELinux
Introduction
Installing and configuring important SELinux tools
Getting ready
How to do it...
How it works...
There's more...
Working with SELinux security contexts
Getting ready
How to do it...
How it works...
Working with policies
Getting ready
How to do it...
How it works...
There's more...
Troubleshooting SELinux
Getting ready
How to do it...
How it works...
15. Monitoring IT Infrastructure
Introduction
Installing and configuring Nagios Core
Getting ready
How to do it...
How it works...
Setting up NRPE on remote client hosts
Getting ready
How to do it...
How it works...
Monitoring important remote system metrics
Getting ready
How to do it...
How it works...
Index

CentOS 7 Linux Server Cookbook Second Edition

CentOS 7 Linux Server Cookbook Second Edition

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: April 2013

Second edition: January 2016

Production reference: 1250116

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78588-728-4

www.packtpub.com

Credits

Authors

Oliver Pelz

Jonathan Hobson

Reviewer

Mitja Resman

Commissioning Editor

Priya Singh

Acquisition Editor

Kevin Colaco

Content Development Editor

Pooja Mhapsekar

Technical Editor

Deepti Tuscano

Copy Editor

Angad Singh

Project Coordinator

Francina Pinto

Proofreader

Safis Editing

Indexer

Rekha Nair

Production Coordinator

Manu Joseph

Cover Work

Manu Joseph

About the Authors

Oliver Pelz has more than 10 years of experience as a software developer and system administrator. He graduated with a diploma degree in bioinformatics and is currently working at the German Cancer Research center in Heidelberg where he has authored and co-authored several scientific publications in the field of Bioinformatics. As well as developing web applications and biological databases for his department and scientists all over the world, he administers a division-wide Linux-based data center and has set up two high-performance CentOS clusters for the analysis of high-throughput microscope and genome sequencing data. He loves writing code, riding his mountain bike in the Black Forest of Germany and has been an absolute Linux and open source enthusiast for many years. He has contributed to several open-source projects in the past and also worked as a reviewer on the book CentOS High Performance, Packt Publishing. He maintains an IT tech blog at www.oliverpelz.de.

I would like to thank my family and especially my wonderful wife Beatrice and little son Jonah for their patience and understanding during all the long working hours while writing this book. Also I would like to thank the folks at Packt Publishing for all their support and the opportunity to to write this book, it was a great pleasure for me. Last but not least I would like to thank Jonathan Hobson for writing the first edition of this book: without him no second edition of this book would have been possible.

I would also like to thank all of the mentors that I've had over the years, especially Prof. Dr. Tobias Dykerhoff, who introduced me to the whole world of Linux a long time ago and infected me with his enthusiasm about open source and the free software movement.

Jonathan Hobson is a web developer, systems engineer, and applications programmer. For more than 20 years, he has been working behind the scenes to support companies, organizations, and individuals around the world to realize their digital ambitions. With an honors degree in both english and history and as a respected practitioner of many computer languages, Jonathan enjoys writing code, publishing articles, building computers, playing the video games, and getting 'out and about' in the big outdoors. He has been using CentOS since its inception, and over the years, it has not only earned his trust, but it has also become his first choice for a server solution. CentOS is a first class community-based enterprise class operating system. It is a pleasure to work with and because of this, Jonathan has written this book so that his knowledge and experience can be passed on to others.

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 an open source enthusiast, and also 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. Swiss Army knife syndrome makes Mitja an expert in the fields of VMware virtualization, Microsoft system administration, and 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. This website provides CentOS Linux guides and "how to" articles covering all sorts of topics appropriate for beginners and advanced users. Mitja wrote a book called CentOS High Availability, Packt Publishing, covering how to install, configure, and manage cluster on CentOS Linux.

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

www.PacktPub.com

Support files, eBooks, discount offers, and more

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://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why Subscribe?

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

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

This work is dedicated to my son Marlin Pelz who was tragically stillborn on 2.10.15, two weeks before his expected date of delivery while I was writing the last few chapters of this book. Marlin, words can not express how much I miss you!

Preface

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.

Sections

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.

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: "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"?> <service> <description>enable FTPS ports</description> <port protocol="tcp" port="40000-40100"/> <port protocol="tcp" port="21"/> <module name="nf_conntrack_ftp"/> </service>

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

sudo diskutil unmountDisk /dev/disk3sudo 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."

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. Installing CentOS

In this chapter, we will cover:

Downloading CentOS and confirming the checksum on Windows or OS XCreating USB installation media on Windows or OS XPerforming an installation of CentOS using the graphical installerRunning a netinstall over HTTPInstalling CentOS using a kickstart fileRe-installing the boot loaderTroubleshooting the system in rescue modeGetting started and customizing the boot loaderUpdating the installation and enhancing the minimal install with additional administration and development tools

Introduction

This chapter is a collection of recipes that covers the basic practice of installing the CentOS 7 operating system. The purpose of this chapter is to show you how quickly you can get CentOS up and running whilst enabling you to customize your installation with a few 'tricks of the trade' thrown in for good measure.

Downloading CentOS and confirming the checksum on Windows or OS X

In this recipe, we will learn how to download and confirm the checksum of one or more CentOS 7 disk images using a typical Windows or OS X desktop computer. CentOS is made available in various formats by HTTP, FTP, or the rsync protocol from a series of mirror sites located across the world or via the BitTorrent network. For downloading very important files from the Internet, such as operating system images, it is considered best practices to validate those files' checksum, in order to ensure that any resulting media would function and perform as expected when installing. This also makes certain that the files are genuine and come from the original source.

Getting ready

To complete this recipe, it is assumed that you are using a typical Windows-based (Windows 7, Windows Vista, or similar) or OS X computer with full administration rights. You will need an Internet connection to download the required installation files and also need access to a standard DVD/CD disk burner with the appropriate software, in order to create the relevant installation disks from the image files. 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.

How to do it...

Regardless of the type of installation files you download, the following techniques can be applied to all the image files supplied by the CentOS project:

Let's begin by visiting http://www.centos.org in a web browser and navigate to the button link Get CentOS Now. Then click the link list of the current mirrors in the text.The mirror sites are categorized, so from the resulting list of links, choose a mirror that is geographically near your current location. For example, if you are in London (UK), you can choose a mirror from EU and United Kingdom. Now choose a mirror site by selecting either the HTTP or the FTP link.Having made your selection, you will now see a list of directories of all the available CentOS versions. To proceed, simply click the appropriate folder that reads 7. Next, you will see an additional list of directories, such as atomic, centosplus, cloud, and so on. We proceed by choosing the isos directory.CentOS 7 currently only supports the 64-bit architecture, so browse to the only directory available labeled x86_64, which is a container for the 64-bit version.You will now be presented with a series of files available for download. Begin by downloading a copy of the valid checksum result identified as md5sum.txt.If you are new to CentOS or are intending to follow the recipes found throughout this book, then the minimal installation is ideal. This contains the least amount of packages to have a functional system, so choose the following (XXXX is the month stamp of this release):
CentOS-7-x86_64-Minimal-XXXX.iso
On a Windows-based system only (on Mac, this tool is already available in the system), visit http://mirror.centos.org/centos/dostools/ in your browser and download the program md5sum.exe.Now on Windows, open the command prompt (typically found at Start | All Programs | Accessories | Command Prompt) and type the following commands into the window that will open (press the Enter key at the end of all the lines):
cd downloadsdir
On OS X, open the program Finder | Applications | Utilities | Terminal, then type the following commands (press the Enter key at the end of all the lines):
cd ~/Downloadsls
You should now see all the files in your download folder (including all the downloaded CentOS installation image files, the md5sum.txt file and on Windows, the md5sum.exe program).Based on the file names shown, modify the following command in order to check the checksum of your downloaded ISO image file. On Windows, type the following command (change the XXXX month stamp accordingly):
md5sum.exe CentOS-7-x86_64-Minimal-XXXX.iso
On OS X, use instead:
md5 CentOS-7-x86_64-Minimal-XXXX.iso
Press the Return key to proceed and then wait for the command prompt to respond. The response is known as the MD5 sum and the result could look like the following:
d07ab3e615c66a8b2e9a50f4852e6a77 CentOS-7-x86_64-Minimal-1503-01.iso
Now look at the the sum and compare against the relevant listing for your particular image file in md5sum.txt (open in a text editor). If both the numbers match, then you can be confident that you have indeed downloaded a valid CentOS image file. If not, your downloaded file is probably corrupted, so please restart this procedure by downloading the image file again.When you have finished, simply burn your image file(s) to a blank CD-ROM or DVD-ROM using your preferred desktop software, or create a USB installation media from it, as we will show you in the next recipe in this chapter.

How it works…

So what have we learned from this experience?

The act of downloading a CentOS installation image is just the first step towards building the perfect server. Although this process is very simple, many do forget the need to confirm the checksum. In this book, we will work with the minimal installation image, but you should be aware that there are other installation options available to you, such as NetInstall, DVD, Everything, and various LiveCDs.

Creating USB installation media on Windows or OS X

In this recipe, we will learn how to create a USB installation media on Windows or OS X. Nowadays, more and more server systems, desktop PCs, and laptops get shipped without any optical drive. Installing a new operating system, such as CentOS Linux using USB devices gets essential for them as no other installation option is available, as there is no other way to boot the installation media. Also, installing CentOS using USB media can be considerably faster than using the CD/DVD approach.

Getting ready

Before we begin, it is assumed that you have followed the previous recipe in which you were shown how to download a minimal CentOS image and confirm the checksum of the relevant image files. It is also assumed that all the downloads (including the downloaded ISO file) are stored on Windows in your C:\Users\<username>\Downloads folder or if using a OS X system, in the /Users/<username>/Downloads folder. Next, you will need a free USB device which can be discovered by your operating system, with enough total space, and which is empty or with data on it that can be discarded. The total space of the USB device needed for preparing as an installation media for CentOS 7 for the minimal version must be roughly 700 megabyte. If you are working on a Windows computer, you will need a working Internet connection to download additional software. On OS X, you need an administrator user account.

How to do it...

To begin this recipe, start up your Windows or OS X operating system, then connect a free USB device with enough capacity, and wait until it gets discovered by File Manager under Windows or Finder under OS X.

On a Windows based system, we need to download an additional software called dd. Visithttp://www.chrysocome.net/dd in your favorite browser. Now download the latest dd-XX.zip file you can find there, with XX being the latest stable version number. For example, dd-0.5.zip.On Windows, navigate to your Downloads folder using File Manager. Here you will find the dd-05.zip file. Right-click on it and click on Extract All, and extract the dd.exe file without creating any subdirectory.On Windows, open the command prompt (typically found at Start | All Programs | Accessories | Command Prompt) and type the following commands:
cd downloadsdd.exe --list
On OS X, open the program Finder | Applications | Utilities | Terminal, and then type the following commands:
cd ~/Downloadsdiskutil list
On Windows, to spot the name of the right USB device you want to use as installation media, look into the output of the command under the removable media section. Below that, you should find a line starting with Mounting on and then a drive letter, for example, \.\e:. This cryptic written drive letter is the most important part we need in the next step, so please write it down.On OS X, the device path can be found in the output of the former command and has the format of /dev/disk<number>, where number is a unique identifier of the disk. The disks are numbered, starting with zero (0). Disk 0 is likely to be the OS X recovery disk, and disk 1 is likely to be your main OS X installation. To identify your USB device, try to compare the NAME, TYPE, and SIZE columns to the specifications of your USB stick. If you have identified the device name, write it down, for example, /dev/disk3.On Windows, type the following command, assuming your USB device selected as a installation media has the Windows device name \\.\e: (change this as required and be careful what you type – this can create tremendous data loss). Also, substitute XXXX with the correct iso file version number in the next command:
dd.exe if=CentOS-7-x86_64-Minimal-XXXX.iso of=\\.\e: bs=1M
On OS X, you need two commands which will ask for the administrator password (replace XXXX and disk3 with the correct version number and the correct USB device path):
sudo diskutil unmountDisk /dev/disk3sudo dd if=./CentOS-7-x86_64-Minimal-XXXX.iso of=/dev/disk3 bs=1m
After thedd program finishes, there will be some output statistics on how long it took and how much data has been transferred during the copy process. On OS X, ignore any warning messages about the disk not being readable.Congratulations! You now have created your first CentOS 7 USB installation media. You now can safely remove the USB drive in Windows or OS X, and physically unplug the device and use it as a boot device for installing CentOS 7 on your target machine.

How it works...

So what have we learned from this experience?

The purpose of this recipe was to introduce you to the concept of creating an exact copy of a CentOS installation ISO file on a USB device, using the dd command-line program. The dd program is a Unix based tool which can be used to copy bits from a source to a destination file. This means that the source gets read bit by bit and written to a destination without considering the content or file allocation; it just involves reading and writing pure raw data. It expects two file name based arguments: input file (if) and output file (of). We will use the CentOS image file as our input filename to clone it exactly 1:1 to the USB device, which is accessible through its device file as our output file parameter. The bs parameter defines the block size, which is the amount of data to be copied at once. Be careful, it is an absolute expert tool and overwrites any existing data on your target while copying data on it without further confirmation or any safety checks. So at least double-check the device drive letters of your target USB device and never confuse them! For example, if you have a second hard disk installed at D: and your USB device at E: (on OS X, at /dev/disk2 and /dev/disk3 respectively) and you confuse the drive letter E: with D: (or /dev/disk3 with /dev/disk2), your second hard disk would be erased with little to no chances of recovering any lost data. So handle with care! If you're in doubt of the correct output file device, never start the dd program!

In conclusion, it is fair to say that there are other far more convenient solutions available for creating a USB installation media for CentOS 7 than the dd command, such as the Fedora Live USB Creator. But the purpose of this recipe was not only to create a ready-to-use CentOS USB installer but also to get you used to the dd command. It's a common Linux command that every CentOS system administrator should know how to use. It can be used for a broad variety of daily tasks. For example, for securely erasing hard disks, benchmarking network speed, or creating random binary files.

Performing an installation of CentOS using the graphical installer

In this recipe, we will learn how to perform a typical installation of CentOS using a new graphical installer interface introduced in CentOS 7. In many respects, this is considered to be the recommended approach to installing your system, as it not only provides you with the ability to create the desired hard disk partitions but also to customize your installation in lots of ways (for example, keyboard layout, package selection, installation type, and so on). Your installation will then form the basis of a server on which you can build, develop, and run any type of service you may want to provide in the future.

Getting ready

Before we begin, it is assumed that you have followed the previous recipe in which you were shown how to download a CentOS image, confirm the checksum of the relevant image files, and create the relevant installation optical disks or USB media. Your system must be a 64 bit (x64_86) architecture, must have at least 406 MB RAM to load the graphical installer 1 GB or more is recommended if installing a graphical window manager such as Gnome), and have at least 10 GB free hard disk space.

How to do it...

To begin this recipe, insert your installation media (CD/DVD or USB device), restart the computer, and press the correct key for selecting the boot device during startup. Then choose the inserted device from the list (for many computers, this can be reached using F11 or F12 but can be different on your system. Please refer to your motherboard's manual).

On the welcome splash screen, the option Test this media & install CentOS 7 is preselected and we will use this option. When you are ready, press the Return key to proceed.After loading some initial files, the installer then starts to test the installation media. A single test should take between 30 seconds to five minutes and will report if there are any errors on your installation media. When this process is complete, the system will finally load the graphical installer.The CentOS installer will now present the graphical installation welcome screen. From this point onwards, you can use your keyboard and mouse (the latter is highly recommended), but remember to enable the number lock on your keyboard if you intend to use the keypad.On the left side you see the main language category and on the right side, the sub-languages for the installer. You can also search for a language using the textbox on the left bottom. All changes to your language settings will take effect immediately, so when you are ready, choose the Continue button to proceed.Now we reach the main installation menu, which is called Installation summary.Most options shown here already have some predefined values and can be used without changing, others which do not have any default value and which need your attention are labeled with a red exclamation mark like the Installation Destination under System category. So let's click on it using the mouse.After clicking the Installation Destination button, you will see a graphical list of all the hard disk devices currently connected to your computer, which you can use for installing the operating system on. You can select your target hard disk by clicking on the correct hard disk symbol. It will then put a check mark on it. If you are unsure about the right hard disk, try to identify it by comparing its brand and total size shown in the menu. Before the installation can proceed, you must select a hard disk. Be careful and choose your target hard disk wisely as it will erase any existing data on it during the installation. When you are ready, click the Done button.If your selected hard disk already contained data, then when clicking on Done, you may see what could be described as a warning/error message. The message may read: You don't have enough space available to install CentOS. Don't worry! This is to be expected and the message is simply asking you to re-initialize your hard disk because CentOS can only be installed on an empty disk. In most cases, especially if you have more than one partition on the hard disk, simply click on Reclaim space which will show a new window with a detailed list of all the partitions on this drive. Here just click on Delete All and then again on Reclaim space to discard any data on this disk, which will complete the task of disk initialization and enable you to proceed to the next step. When finished, click the Done button.Back at the Installation Summary screen, the exclamation mark on the Installation Destination item should be gone now.Optionally, we can click on Network & Hostname under System category. On the following page, on the left side, you can choose the primary network adapter you would like to connect to the Internet and select it by clicking on it. For the selected device, click on the switch on the right side to enable and connect it automatically using the On position of the switch. Finally, before closing this submenu, change the hostname in its text field to something appropriate. Click Done.Now back at the Installation Summary screen, all the important settings have been made or have got predefined values, and all the exclamation marks are gone. If you are happy with these settings, click on the Start installation button or change the settings appropriately.On the next screen, you will be required to create and confirm a root password for the root user while the new system gets installed in the background. Choose a secure password with not less than six characters.Here on this screen you can also create a standard user account which is highly recommended. If you create a new user do not check Make this user administrator. When you are ready, click Done (if you entered a weak password, you have to confirm this by clicking twice)CentOS will now partitionate and format your hard disk in the background and resolve any dependencies, and the installer will begin writing to the hard disk. This may take some time, but a progress bar will indicate the status of your installation. When finished, the installer will inform you that the entire process is complete and that the installation was successful. So when you are ready, click on the Reboot button. Now release your installation media from the drive.Congratulations! You have now installed CentOS 7 on your computer.

How it works…

In this recipe, you have discovered how to install the CentOS 7 operating system. Having covered the typical approach to the graphical installation process, you are now in a position to develop the server with additional configuration changes and packages that will suit the role you intend the server to fulfill. This graphical installer has been built with the aim to be very intuitive and flexible, and makes installation very easy as it will guide the user through some mandatory tasks that he has to fulfill before the installation of the main system can be started.

Running a netinstall over HTTP

In this recipe, we will learn how to initiate the process of running a netinstall over HTTP (using the URL method) in order to install CentOS 7. It is a process in which a small image file is used to boot the computer and let the user select and install only the software packages and services he wants and nothing more over a network connection thus providing great flexibility.

Getting ready

Before we begin, it is assumed that you already know how to download and checksum a CentOS 7 installation image and how to create the relevant installation media from it. For this recipe here, we will need to download and create installation media for the netinstall image (download the latest CentOS-7-x86_64-NetInstall-XXXX.iso file) instead of the minimal ISO shown in another recipe in this chapter. Also, it is assumed that you have at least gone through the graphical installation procedure once to exactly know how to boot from your installation media and work with the installer program.

How to do it...

To begin this recipe, insert your prepared netinstall media, boot your computer from it, and wait for the welcome screen to appear:

On the welcome splash screen, the option Test this media & install CentOS 7 is preselected and we will use this option. When you are ready, press the Return key to proceed.After the tests finish, the graphical installer will load and present the typical graphical installation summary screen.

Note

Here the installer should be configured exactly as in the normal graphical installation recipe, besides the following mandatory changes to the Network & Host name and Installation source menu items (which is shown by the red exclamation marks).

Before we can install CentOS over the network, we have to make sure that we have a working network connection. Therefore, you should first click on the Network & Host name menu entry and activate one of your network adapters to the connected state. Refer to the normal installation recipe for more details.Next, click on Installation source to enter the settings. As we will be installing over HTTP (also referred to as the URL method), you should leave the default On the network selected in the Which installation sourcewould you like to use? section.Now type in the following URL in the standard http:// textfield, which we will use to download all the required installation packages at http://mirror.centos.org/centos/7/os/x86_64/.Alternatively, you can also use a personal repository which you would have to create in advance (see Chapter 4, Managing Packages with YUM)When you are ready, click on Done to start the initialization process.On success, the installer will begin to retrieve the appropriate install.img file. This may take several minutes to complete, but once resolved, a progress bar will indicate all the download activity. When this process finishes successfully, the exclamation mark at the installation source will go away but another one will pop up which will tell the user that it is missing the software selection. Click on it and choose whatever fits your need. As for the purpose of this recipe, just select Minimal install under Base environment and then click on Done.If the Which installation source would you like to use stays greyed out and cannot be changed, then there are connection problems with your network adapter. If this is the case, go back to configure Network & Hostname and change the network settings until the connected state can be reached.CentOS 7 will now install the operating system the usual way and will congratulate you when this process finishes. It may be slower than installing from a physical installation media since all the packages have to be retrieved from the Internet.

How it works...

The purpose of this recipe was to introduce you to the concept of the CentOS network installation process, in order to show you just how simple this approach can be. By completing this recipe you have not only saved time by limiting your initial download to those files that are required by the installation process, but you have also been able to take advantage of the full graphical installation method without the need for a complete DVD suite.

Installing CentOS 7 using a kickstart file

While installing CentOS 7 manually using the graphical installer utility is fine on a single server, doing so on a multiple number of systems can be tedious. Kickstart files can automate the installation process of a server system and here we will show how this can be done. They are simple text based configuration files which provide detailed and exact instructions on how the target system should be set up and installed (for example, which keyboard layout or additional software packages to install).

Getting ready

To successfully complete this recipe, you will need access to an already installed CentOS 7 system to retrieve the kickstart configuration file we want to work with and use for automated installation. On this pre-installed CentOS server, you also need a working Internet connection to download additional software.

Next, we will need to download and create installation media for the DVD or the Everything image (download the latest CentOS-7-x86_64-DVD-XXXX.iso or CentOS-7-x86_64-Everything-XXXX.iso file), instead of the minimal iso file shown in another recipe in this chapter. Then you need another USB device which must be read and writable on Linux systems (formatted as FAT16, FAT32, EXT2, EXT3, EXT4, or XFS filesystem).

How to do it...

For this recipe to work, we first need physical access to an existing kickstart file from another finished CentOS 7 installation, which we will use as a template for a new CentOS 7 installation.

Log in as root on the existing CentOS 7 system and make sure the kickstart configuration file exists by typing the following command and pressing the Return key to execute (this will show you the details of the file):
ls -l /root/anaconda-ks.cfg
Next, physically plug in a USB device and then type the following command, which will give you a list of all the hard disk devices currently connected to the computer:
fdisk -l
Try to identify the device name by comparing its size, partitions, and identified filesystems with the specifications of your USB device. The device name will be of kind /dev/sdX, where X is an alphabetical character, such as b, c, d, e, … and so on. If you cannot find the right device name for your USB media using the fdisk command, try the following trick: run fdisk -l twice - first with plugged-out and then with plugged-in USB device and compare how the second output changed - it has one device name more than the first output: your device name of interest !If you have found the right device name in the list, create a directory to mount it to the current filesystem:
mkdir /mnt/kickstart-usb
Next, actually mount the stick to this folder, assuming that your USB partition of choice is at /dev/sdc1 (change this as required):
mount /dev/sdc1 /mnt/kickstart-usb
Now we will create our working copy of the kickstart file on the USB device for customizing:
cp /root/anaconda-ks.cfg /mnt/kickstart-usb
Next, open the copied kickstart file on the USB device with your favorite text editor (here we will use the editor nano, if you have not installed it yet type yum install nano):
nano /mnt/kickstart-usb/anaconda-ks.cfg
We will now modify the file for installing CentOS on a new target system. In nano, use the up and down arrow keys to go to the line which starts with (<your_hostname> will be the name of the hostname you gave during installation e.g. minimal.home):
network --hostname=<your_hostname>
Now edit the <your_hostname> string to give it a new unique hostname. For example, add a -2 to the end of any existing name, as shown next:
network --hostname=minimal-2.home
Next, move the cursor down using the up and down arrow keys until it stops at the line which says %packages. Append the following lines right below it (you can further customize this and provide additional packages that you want to install automatically):
mariadb-serverhttpdrsyncnet-tools
Now save and close the file, to do this in the nano editor use the key combination Ctrl+o (which means, hold down the Ctrl key on the keyboard and then the o key without releasing the Ctrl key) to write the changes. Then press Return to confirm the filename and Ctrl+x to exit the editor.Next, install the following CentOS package:
yum install system-config-kickstart
Now we validate the syntax of our kickstart file using the ksvalidator program, which is included in the package we just installed:
ksvalidator /mnt/kickstart-usb/anaconda-ks.cfg
If the config file is error-free, unmount the USB stick now by using the following commands:
cdumount /mnt/kickstart-usb