Cover Page

Red Hat® Enterprise Linux® 6 Administration

Real World Skills for Red Hat Administrators

Title Page

Sander van Vugt

Title Page

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.

sign

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.

About the Author

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.

Acknowledgments

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.

Table of Exercises

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

Introduction

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.

Who Should Read This Book?

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.

What You Need

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:

  • 64-bit CPU with support for virtualization.
  • At least 2GB of RAM is recommended. (It will probably work with 1GB, but this is not recommended.)
  • A DVD drive.
  • A hard disk that is completely available and at least 40GB in size.
  • A network card and connection to a network switch.

What Is Covered in This Book?

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:

  1. Part I: Getting Familiar with Red Hat Enterprise Linux
  2. Chapter 1, “Getting Started with Red Hat Enterprise Linux”  This chapter introduces Red Hat Enterprise Linux and explains its particulars. You'll also learn about the value added by this commercial Linux distribution as compared to free Linux distributions. In the second part of this chapter, you'll learn how to install Red Hat Enterprise Linux. You'll also get a quick introduction to the workings of the graphical user interface.
  3. Chapter 2, “Finding Your Way on the Command Line”  This chapter introduces you to working on the command line, the most important interface you'll use to manage your Red Hat Enterprise Linux server.
  4. Part II: Administering Red Hat Enterprise Linux
  5. Chapter 3, “Performing Daily System Administration Tasks”  In this chapter, you'll learn about some common system administration tasks. This includes mounting and unmounting file systems, setting up and managing a printing environment, and scheduling jobs with cron. You'll also learn how to do process administration and make backups.
  6. Chapter 4, “Managing Software”  In this chapter, you'll learn how to install software. You'll also read how to manage software, which includes querying software packages to find out everything you need to know about installed software. You'll also read how to set up the repositories that you'll need for an easy way to install and manage software.
  7. Chapter 5, “Configuring and Managing Storage”  This chapter teaches you how to set up storage. It includes information about managing partitions, logical volumes, and encrypted volumes. You'll also learn how to set up automatic mounting of volumes through fstab and how to create and manage swap space.
  8. Chapter 6, “Connecting to the Network”  Here you'll learn how to connect your server to the network. The chapter addresses setting up the network interface, both from the command line and from the configuration files. You'll set up normal network connections, and you will also learn how to create a bonded network interface. Finally, you'll learn how to test your network using common utilities such as ping and dig.
  9. Part III: Securing Red Hat Enterprise Linux
  10. Chapter 7, “Working with Users, Groups, and Permissions”  To manage who can do what on your system, you'll need to create users and put them in groups. In this chapter, you'll learn how to do that and how to add users to primary and secondary groups. You'll also learn how to work with basic and advanced permissions and set up access control lists.
  11. Chapter 8, “Understanding and Configuring SELinux”  This chapter teaches you how to make your Red Hat Enterprise Linux server really secure using SELinux. You'll learn about the different modes that are available and how to set file system context labels and Booleans to tune SELinux exactly to your needs.
  12. Chapter 9, “Working with KVM Virtualization”  Red Hat Enterprise Linux offers virtualization capabilities by default. In this chapter, you'll learn how to set these up using KVM virtualization. You'll learn what your server needs to be a KVM host, and you'll read how to create and manage virtual machines.
  13. Chapter 10, “Securing Your Server with iptables”  iptables is a kernel-provided firewall, which blocks or allows access to services configured to listen at specific ports. In this chapter, you'll learn how to set up the iptables firewall from the command line.
  14. Chapter 11, “Setting Up Cryptographic Services”  In this chapter, you'll learn how to set up cryptographic services on Red Hat Enterprise Linux. You'll learn how to configure SSL certificates and have them signed by a certificate authority. You'll also learn how to use GPG for file and email encryption and security.
  15. Part IV: Networking Red Hat Enterprise Linux
  16. Chapter 12, “Configuring OpenLDAP”  If you really need to manage more than just a few users, using a directory service such as OpenLDAP can be handy. In this chapter, you'll learn how to set up OpenLDAP on your server. You'll also learn how to add user objects to the OpenLDAP server and how to configure your server to authenticate on OpenLDAP.
  17. Chapter 13, “Configuring Your Server for File Sharing”  This chapter teaches you how to set up your server for file sharing. You'll learn about common file sharing solutions, such as FTP, NFS, and Samba. You'll also learn how to connect to servers offering these services from Red Hat Enterprise Linux.
  18. Chapter 14, “Configuring DNS and DHCP”  In this chapter, you'll read how to set up a Dynamic Host Configuration Protocol (DHCP) server to automate providing computers in your network with IP addresses and related information. You'll also learn how to set up Domain Name System (DNS) on your servers, configuring them as primary and secondary servers, as well as cache-only servers.
  19. Chapter 15, “Setting Up a Mail Server”  Postfix is the default mail server on Red Hat Enterprise Linux. In this chapter, you'll learn how to set up Postfix to send and receive email on your server. You'll also learn how to set up Dovecot to make email accessible for clients using POP or IMAP.
  20. Chapter 16, “Configuring Apache on Red Hat Enterprise Linux”  In this chapter, you'll learn how to set up Apache on your server. You'll learn how to configure basic hosts, virtual hosts, and SSL secured hosts. The chapter also teaches you how to set up file-based or LDAP-based user authentication.
  21. Part V: Advanced Red Hat Enterprise Linux Configuration
  22. Chapter 17, “Monitoring and Optimizing Performance”  For your server to function properly, it is important that it performs well. In this chapter, you'll learn how to analyze server performance and how to fix it if there are problems. You'll also read some hints about setting up the server in a way that minimizes the chance of having performance-related problems.
  23. Chapter 18, “Introducing Bash Shell Scripting”  Every Linux administrator should at least know the basics of shell scripting. This chapter teaches you how it works. You'll learn how to set up a shell script and how to use common shell scripting structures to handle jobs in the most ideal manner.
  24. Chapter 19, “Understanding and Troubleshooting the Boot Procedure”  Many tasks are executed sequentially when your server boots. In this chapter, you'll learn about everything that happens during server startup, including GRUB configuration and the way Upstart is used. You'll also learn how to troubleshoot common issues that you may encounter while booting your server.
  25. Chapter 20, “Introducing High-Availability Clustering”  In a mission-critical environment, the Red Hat High Availability add-on can be a valuable addition to your datacenter. In this chapter, you'll learn how to design and set up high availability on Red Hat Enterprise Linux.
  26. Chapter 21, “Setting Up an Installation Server”  In a datacenter environment, you don't want to set up every server manually. This is why it makes sense to set up an installation server. This chapter teaches you how to automate the installation of Red Hat Enterprise Linux completely. It includes setting up a network installation server and configuring a TFTP server that hands out boot images to clients that perform a PXE boot. You'll also learn how to create a kickstart configuration file, which passes all parameters that are to be used for the installation.
  27. Glossary   This contains definitions of the relevant vocabulary terms in this book.

How to Contact the Author

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.

Part I
Getting Familiar with Red Hat Enterprise Linux