


Senior Acquisitions Editor: Jeff Kellum
Development Editor: Gary Schwartz
Technical Editors: Floris Meester, Erno de Korte
Production Editor: Rebecca Anderson
Copy Editor: Kim Wimpsett
Editorial Manager: Pete Gaughan
Production Manager: Tim Tate
Vice President and Executive Group Publisher: Richard Swadley
Vice President and Publisher: Neil Edde
Book Designer: Judy Fung and Bill Gibson
Proofreaders: Louise Watson and Jennifer Bennett, Word One New York
Indexer: J & J Indexing
Project Coordinator, Cover: Katherine Crocker
Cover Designer: Ryan Sneed
Cover Image: © Jacob Wackerhausen / iStockPhoto
Copyright © 2013 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-30129-6
ISBN: 978-1-118-62045-8 (ebk.)
ISBN: 978-1-118-42143-7 (ebk.)
ISBN: 978-1-118-57091-3 (ebk.)
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (877) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 9781118301296
TRADEMARKS: Wiley, the Wiley logo, and the Sybex logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Red Hat is a registered trademark of Red Hat, Inc. Linux is a registered trademark of Linus Torvalds. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
Dear Reader,
Thank you for choosing Red Hat Enterprise Linux 6 Administration: Real World Skills for Red Hat Administrators. This book is part of a family of premium-quality Sybex books, all of which are written by outstanding authors who combine practical experience with a gift for teaching.
Sybex was founded in 1976. More than 30 years later, we're still committed to producing consistently exceptional books. With each of our titles, we're working hard to set a new standard for the industry. From the paper we print on to the authors we work with, our goal is to bring you the best books available.
I hope you see all that reflected in these pages. I'd be very interested to hear your comments and get your feedback on how we're doing. Feel free to let me know what you think about this or any other Sybex book by sending me an email at nedde@wiley.com. If you think you've found a technical error in this book, please visit http://sybex.custhelp.com. Customer feedback is critical to our efforts at Sybex.

To Florence, my loving wife of 20 years who supports me and believes in everything I do. Chérie, I'm looking forward to spending the next 60 years of our lives together.
Sander van Vugt is an author of more than 50 technical books. Most of these books are in his native language of Dutch. Sander is also a technical instructor who works directly for major Linux vendors, such as Red Hat and SUSE. He specializes in high availability and performance issues in Linux. He has also built up a lot of experience in securing servers with SELinux, especially on platforms that don't support it natively. Sander has applied his skills in helping many companies all over the world who are using Linux. His work has taken him to amazing places like Greenland, Utah, Malaysia, and more.
When not working, Sander likes to spend time with his two sons, Franck and Alex, and his beautiful wife, Florence. He also likes outdoor sports, in particular running, hiking, kayaking, and ice-skating. During these long hours of participating in sports, he thinks through the ideas for his next book and the projects on which he is currently working, which makes the actual writing process a lot easier and the project go more smoothly.
Books of this size and depth succeed because of all the hard work put in by a team of professionals. I'm grateful for all the hard work put in by several people at Sybex on this project. Gary Schwartz was a great developmental editor. He helped keep things on track and provided excellent editorial guidance. The technical editors, Floris Meester and Erno de Korte, provided insightful input throughout the book. I appreciated the meticulous attention to detail provided by Rebecca Anderson, the production editor for this book. Last, but certainly not least, I want to thank Jeff Kellum, the acquisitions editor, for having the faith in me to write this book for Sybex.
| Exercise 1.1 | Installing Linux on Your Machine |
| Exercise 2.1 | Discovering the Use of Pipes |
| Exercise 2.2 | Using grep in Pipes |
| Exercise 2.3 | Redirecting Output to a File |
| Exercise 2.4 | Using Redirection of STDIN |
| Exercise 2.5 | Separating STDERR from STDOUT |
| Exercise 2.6 | Replacing Text with vi |
| Exercise 2.7 | Working with man -k |
| Exercise 3.1 | Managing Jobs |
| Exercise 3.2 | Managing Processes with ps and kill |
| Exercise 3.3 | Using nice to Change Process Priority |
| Exercise 3.4 | Running a Task from cron |
| Exercise 3.5 | Mounting a USB Flash Drive |
| Exercise 3.6 | Creating Links |
| Exercise 3.7 | Archiving and Extracting with tar |
| Exercise 3.8 | Configuring Logging |
| Exercise 4.1 | Setting Up Your Own Repository |
| Exercise 4.2 | Working with yum |
| Exercise 4.3 | Installing Software with yum |
| Exercise 4.4 | Finding More Information About Installed Software |
| Exercise 4.5 | Extracting Files from RPM Packages |
| Exercise 5.1 | Creating Partitions |
| Exercise 5.2 | Creating a File System |
| Exercise 5.3 | Setting a File System Label |
| Exercise 5.4 | Mounting Devices Through /etc/fstab |
| Exercise 5.5 | Fixing /etc/fstab Problems |
| Exercise 5.6 | Creating LVM Logical Volumes |
| Exercise 5.7 | Extending a Logical Volume |
| Exercise 5.8 | Extending a Volume Group |
| Exercise 5.9 | Reducing a Logical Volume |
| Exercise 5.10 | Managing Snapshots |
| Exercise 5.11 | Creating a Swap File |
| Exercise 5.12 | Creating an Encrypted Device |
| Exercise 5.13 | Mounting an Encrypted Device Automatically |
| Exercise 6.1 | Working with Services |
| Exercise 6.2 | Configuring a Network Interface with ip |
| Exercise 6.3 | Setting a Fixed IPv6 Address. |
| Exercise 6.4 | Enabling and Testing the SSH Server. |
| Exercise 6.5 | Securing the SSH Server |
| Exercise 6.6 | Setting Up Key-Based Authentication |
| Exercise 6.7 | Setting Up Key-Based SSH Authentication Protected with a Passphrase |
| Exercise 6.8 | Setting Up a VNC Server |
| Exercise 7.1 | Creating Users |
| Exercise 7.2 | Creating and Managing Groups |
| Exercise 7.3 | Logging in Using an LDAP Directory Server |
| Exercise 7.4 | Configuring PAM. |
| Exercise 7.5 | Setting Permissions for Users and Groups |
| Exercise 7.6 | Working with Special Permissions |
| Exercise 7.7 | Refining Permissions Using ACLs |
| Exercise 8.1 | Displaying SELinux Type Context |
| Exercise 8.2 | Switching Between SELinux Modes |
| Exercise 8.3 | Applying File Contexts |
| Exercise 8.4 | Working with SELinux Booleans |
| Exercise 8.5 | Enabling sealert Message Analysis |
| Exercise 9.1 | Determining Whether Your Server Meets KVM Virtualization Requirements |
| Exercise 9.2 | Preparing Your Server to Function as a KVM Hypervisor |
| Exercise 9.3 | Installing a KVM Virtual Machine |
| Exercise 9.4 | Working with Virtual Machine Manager |
| Exercise 9.5 | Changing a VM Hardware Configuration |
| Exercise 9.6 | Exploring virsh |
| Exercise 9.7 | Changing Virtual Machine Networking |
| Exercise 9.8 | Reconfiguring Networking in a Virtual Machine |
| Exercise 10.1 | Allowing Basic Services Through the Firewall |
| Exercise 10.2 | Configuring Port Forwarding |
| Exercise 10.3 | Building a Netfilter Firewall |
| Exercise 10.4 | Setting Up iptables Logging |
| Exercise 10.5 | Configuring NAT |
| Exercise 11.1 | Creating a Self-signed Certificate |
| Exercise 11.2 | Creating and Exchanging GPG Keys |
| Exercise 11.3 | Encrypting and Decrypting Files |
| Exercise 11.4 | Signing RPM Packages with GPG Keys |
| Exercise 12.1 | Changing the Base LDAP Configuration |
| Exercise 12.2 | Creating the Base LDAP Directory Structure |
| Exercise 12.3 | Installing the Schema File for DHCP |
| Exercise 12.4 | Creating an LDAP User |
| Exercise 12.5 | Adding an LDAP Group |
| Exercise 13.1 | Creating NFS Shares |
| Exercise 13.2 | Mounting an NFS Share |
| Exercise 13.3 | Using /net to Access an NFS Share |
| Exercise 13.4 | Creating an Automount Indirect Map |
| Exercise 13.5 | Creating an Automount Configuration for Home Directories |
| Exercise 13.6 | Setting Up a Samba Server |
| Exercise 13.7 | Setting SELinux Labels for Samba |
| Exercise 13.8 | Mounting a Samba Share Using /etc/fstab |
| Exercise 13.9 | Enabling an Anonymous FTP Server |
| Exercise 14.1 | Configuring a Cache-Only Name Server |
| Exercise 14.2 | Setting Up a Primary DNS Server |
| Exercise 14.3 | Setting Up a DHCP Server |
| Exercise 15.1 | Getting to Know Mutt |
| Exercise 15.2 | Sending a Message to an External User |
| Exercise 15.3 | Opening Your Mail Server for External Mail |
| Exercise 15.4 | Creating a Base Dovecot Configuration |
| Exercise 16.1 | Creating a Basic Website |
| Exercise 16.2 | Configuring SELinux for Apache |
| Exercise 16.3 | Installing and Using the Apache Documentation |
| Exercise 16.4 | Configuring Virtual Hosts |
| Exercise 16.5 | Setting Up an SSL-Based Virtual Host |
| Exercise 16.6 | Setting Up a Protected Web Server |
| Exercise 16.7 | Installing MySQL and Creating User Accounts |
| Exercise 17.1 | Monitoring Buffer and Cache Memory |
| Exercise 17.2 | Analyzing CPU Performance |
| Exercise 17.3 | Analyzing Kernel Memory |
| Exercise 17.4 | Exploring I/O Performance |
| Exercise 17.5 | Configuring Huge Pages |
| Exercise 17.6 | Changing Scheduler Parameters |
| Exercise 18.1 | Creating Your First Shell Script |
| Exercise 18.2 | Creating a Script That Works with Arguments |
| Exercise 18.3 | Referring to Command-Line Arguments in a Script |
| Exercise 18.4 | Counting Arguments |
| Exercise 18.5 | Asking for Input with read |
| Exercise 18.6 | Working with Pattern-Matching Operators |
| Exercise 18.7 | Applying Pattern Matching on a Date String |
| Exercise 18.8 | Example Script Using case |
| Exercise 18.9 | Checking Whether the IP Address Is Still There |
| Exercise 19.1 | Adding a GRUB Boot Password |
| Exercise 19.2 | Booting with Alternative Boot Options |
| Exercise 19.3 | Manually Starting GRUB |
| Exercise 19.4 | Applying Kernel Module Options |
| Exercise 19.5 | Starting Your Server in Minimal Mode |
| Exercise 19.6 | Resetting the Root Password |
| Exercise 19.7 | Starting a Rescue System |
| Exercise 20.1 | Creating a Bond Device |
| Exercise 20.2 | Creating an iSCSI Target Configuration |
| Exercise 20.3 | Connecting to an iSCSI Target |
| Exercise 20.4 | Creating an /etc/hosts File |
| Exercise 20.5 | Creating a Cluster with Conga |
| Exercise 20.6 | Creating a Quorum Disk |
| Exercise 20.7 | Creating an HA Service for Apache |
| Exercise 20.8 | Creating a GFS File System |
| Exercise 21.1 | Setting Up the Network Installation Server |
| Exercise 21.2 | Configuring the TFTP Server for PXE Boot |
| Exercise 21.3 | Performing a Virtual Machine Network Installation Using a Kickstart File |
Red Hat is the number-one Linux vendor on the planet. Even though official figures have never been released, as the first open source, one-billion dollar company, Red Hat is quite successful in enterprise Linux. More and more companies are installing Red Hat servers every day, and with that, there's an increasing need for Red Hat skills. That is why I wrote this book.
This book is a complete guide that contains real-world examples of how Red Hat Enterprise Linux should be administered. It targets a broad audience of both beginning and advanced Red Hat Enterprise Linux administrators who need a reference guide to learn how to perform complicated tasks.
This book was also written as a study guide, which is why there are many exercises included in the book. Within each chapter, you'll find step-by-step exercises that lead you through specific procedures. Also, in Appendix A at the end of the book, you'll find lab exercises that help you wrap up everything you've learned in the chapter.
Red Hat offers two certifications that are relevant for system administrators: Red Hat Certified System Administrator (RHCSA) and Red Hat Certified Engineer (RHCE). This book does not prepare for either the Red Hat RHCSA or RHCE exams, but it does cover most of the objectives of both exams. For those interested in taking RHCSA and RHCE exams, it is recommended that you also attend a Red Hat training course, where the learner risks meeting the author of this book who has been a Red Hat Certified Instructor for many years now.
This book was written for Red Hat administrators. The book is for beginning administrators as well as those who already have a couple of years of experience working with Red Hat systems. For the advanced administrators, it is written as a reference guide that helps them set up services such as web servers, DNS and DHCP, clustering, and more. It also contains advanced information, such as a long chapter on performance optimization.
To work with this book, you need a dedicated computer on which you can install Red Hat Enterprise Linux. If this is not feasible, a virtual machine can be used as an alternative, however this is absolutely not recommended, as you won't be able to do all the exercises on virtualization. To install Red Hat Enterprise Linux and use it as a host for KVM virtualization, make sure that your computer meets the following minimum criteria:
Red Hat Linux Enterprise 6 Administration is organized to provide the knowledge that you'll need to administer Red Hat Enterprise Linux 6. It includes the following chapters:
cron. You'll also learn how to do process administration and make backups.fstab and how to create and manage swap space.If you want to provide feedback about the contents of this book or if you're seeking a helping hand in setting up an environment or fixing problems, you can contact me directly. The easiest way to get in touch with me is by sending an email to mail@sandervanvugt.nl. You can also visit my website at www.sandervanvugt.com. If you're interested in the person behind the book, you're also more than welcome to visit my hobby site at www.sandervanvugt.org.
Sybex strives to keep you supplied with the latest tools and information you need for your work. Please check their website at www.sybex.com, where we'll post additional content and updates that supplement this book if the need arises. Enter search terms in the Search box (or type the book's ISBN: 978-1-118-30129-6), and click Go to get to the book's update page.