Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

The Definitive Guide to Centos
Nội dung xem thử
Mô tả chi tiết
this print for content only—size & color not accurate spine = 0.813" 352 page count
Books for professionals by professionals®
The Definitive Guide to CentOS
Dear Reader,
CentOS is an incredible operating system based on Red Hat Enterprise Linux.
It is the best of both worlds: truly open source and an enterprise-class server
operating system. People are beginning to see CentOS as a viable enterprise
platform in its own right, and we’re here to help you get started.
The Definitive Guide to CentOS starts from scratch with the sole aim of getting
you up and running in the shortest amount of time. We concentrate on services
that the majority of people will want to set up and make available, and we show
the easiest path to accomplishing these goals. We also discuss the potential
challenges a CentOS user might come across and how best to solve them. This
book is a hands-on guide to getting the job done.
I have had the privilege of working with some of the key members of the
CentOS Project on this book. Together we have created something that will help
speed you on your journey of discovery and, most important, help you get your
server up and running as quickly as possible.
We hope this book will just be the start of your exploration of CentOS and
that you will come to depend on and trust CentOS for your critical applications
as we do for ours.
Peter Membrey
US $39.99
Shelve in
Linux General
User level:
Beginner–Intermediate
Membrey,
Angenendt
Verhoeven, CentOS
The EXPERT’s VOIce® in Open Source
The Definitive Guide to
CentOS
CYAN
MAGENTA
YELLOW
BLACK
PANTONE 123 C
Peter Membrey, Tim Verhoeven,
and Ralph Angenendt
Foreword by Dag Wieers, CentOS Project
Companion
eBook
Available
www.apress.com
Companion eBook
See last page for details
on $10 eBook version
The complete guide to network administration
using CentOS, from members of the CentOS team.
ISBN 978-1-4302-1930-9
9 781430 219309
5 3 9 9 9
The Definitive
Guide to
THE APRESS ROADMAP
Beginning
Ubuntu Linux
Beginning the
Linux Command Line
Foundations of
CentOS Linux
Beginning SUSE Linux
Beginning Ubuntu LTS
Server Administration
Pro Linux
System Administration
The Definitive Guide
to CentOS
The Definitive Guide to
SUSE Linux Enterprise Server
Pro Ubuntu
Server Administration
The Definitive Guide
to CentOS
Peter Membrey, Tim Verhoeven,
Ralph Angenendt
The Definitive Guide to CentOS
Copyright © 2009 by Peter Membrey, Tim Verhoeven, Ralph Angenendt
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-4302-1930-9
ISBN-13 (electronic): 978-1-4302-1931-6
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Michelle Lowman
Technical Reviewers: Bert de Bruijn, Karanbir Singh
Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell,
Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper,
Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Project Manager: Beth Christmas
Copy Editor: Kim Wimpsett
Associate Production Director: Kari Brooks-Copony
Production Editor: Candace English
Compositor: Lynn L’Heureux
Proofreader: April Eddy
Indexer: BIM Indexing & Proofreading Services
Artist: April Milne
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or
visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600,
Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://
www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.
eBook versions and licenses are also available for most titles. For more information, reference our Special
Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com.
For my dear wife Sarah and xiaobao (little baby): without your unwavering support,
none of this would have been possible.
—Peter Membrey
v
Contents at a Glance
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
About the Technical Reviewer ...................................................... xix
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Part 1 ■ ■ ■ Getting Started with CentOS
Chapter 1 Introducing CentOS.............................................. 3
Chapter 2 Installing CentOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Chapter 3 Getting Started with CentOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Chapter 4 Using Yum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Part 2 ■ ■ ■ Going into Production
Chapter 5 Using Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Chapter 6 Setting Up Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
CHAPTER 7 Understanding DNS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Chapter 8 Setting Up DHCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Chapter 9 Sharing Files with Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Chapter 10 Setting Up Virtual Private Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Part 3 ■ ■ ■ Enterprise Features
Chapter 11 Using Core Builds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Chapter 12 Using High Availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Chapter 13 Monitoring Your Network Using Nagios . . . . . . . . . . . . . . . . . . . . . . . . 299
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
vii
Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
About the Technical Reviewer ...................................................... xix
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Part 1 ■ ■ ■ Getting Started with CentOS
Chapter 1 Introducing CentOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
What Is Enterprise Linux? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Extended Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Low-Risk Security Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
ABI/API Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Regular Updates and Bug Fixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Certification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Summary of Enterprise Linux’s Benefits . . . . . . . . . . . . . . . . . . . . . . . 7
What Is CentOS? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
How to Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Chapter 2 Installing CentOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Hardware Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Getting CentOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Checking the Checksums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Burning the ISOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Performing a Super-Quick CentOS Install . . . . . . . . . . . . . . . . . . . . . . . . . . 18
viii ■CONTENTS
Setting Other Installation Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Securely Erasing Your Disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Creating a Custom Partition Layout . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Using Software RAID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Setting IP Manually . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Chapter 3 Getting Started with CentOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
CentOS Filesystem Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Relative and Absolute Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Filesystem Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
/ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
/root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
/etc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
/proc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
/var . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
/boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
/bin and /sbin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
/dev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
/home . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
/lib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
/lost+found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
/media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
/mnt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
/usr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
/opt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
/srv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
/sys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
/tmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Getting Your Hands on a Command Prompt . . . . . . . . . . . . . . . . . . . 51
Getting an SSH Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Using SSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
■CONTENTS ix
You’re Logged In; Now What? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
First, the Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Important Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
pwd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
mkdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
cd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
rmdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
rm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
touch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
nano . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
cat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Chapter 4 Using Yum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
What Are RPMs? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
What Are Yum Repositories? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
CentOS Repositories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Official CentOS Repositories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Third-Party Repositories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Getting Started with Yum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Updating Your Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Installing a Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Installing a Group of Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Searching for Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Adding a Custom Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Setting It Up with RPM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
How to Do It Without an RPM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Yumex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
x ■CONTENTS
Part 2 ■ ■ ■ Going into Production
Chapter 5 Using Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
How Does the Server Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
A Brief Introduction to SSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Why Run Your Own Server? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
What It Involves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
When to Let Someone Else Do It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
What Is a Virtual Private Server (VPS)? . . . . . . . . . . . . . . . . . . . . . . . . 83
Picking a Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Installing Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Configuring the Firewall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Making Sure Apache Starts Each Time the Server Reboots . . . . . . 88
Starting Up and Testing Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Configuring Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Where Is Everything? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Configuring ServerAdmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Configuring ServerName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Saving the Configuration File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Testing Your New Configuration File . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Restarting Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
.htaccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Enabling .htaccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
How to Password Protect a Directory . . . . . . . . . . . . . . . . . . . . . . . . . 95
Configuring Password Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Creating User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Improving Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Compression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Enabling Compression in Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Why You Don’t Compress Everything . . . . . . . . . . . . . . . . . . . . . . . . . 98
Improving Server Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Things to Watch Out For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
■CONTENTS xi
Setting Up Virtual Hosts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Getting Started with Virtual Hosts . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Creating Your First Virtual Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Using vhosts.d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Using SSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Installing mod_ssl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Getting Your Shiny New Certificate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Signing Your Own Certificate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
What to Do with an Intermediary Certificate . . . . . . . . . . . . . . . . . . 109
Putting Your New Certificate to Work . . . . . . . . . . . . . . . . . . . . . . . . 109
Removing the Password Protection from the Key . . . . . . . . . . . . . 110
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Chapter 6 Setting Up Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
How Do Mail Servers Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Why Run Your Own Mail Server? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Caveats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
When Not to Run Your Own Mail Server....................... 117
Which Mail Server to Choose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Installing the Mail Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Configuring the Firewall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Making Sure Postfix Starts During Boot . . . . . . . . . . . . . . . . . . . . . . 121
Configuring Postfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Configuring Your System to Send Mail . . . . . . . . . . . . . . . . . . . . . . . 124
Configuring Your System to Receive Mail . . . . . . . . . . . . . . . . . . . . 132
Setting Up Users to Receive Mails . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Taking a Few Antispam Measures . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Receiving Mails for Several Domains . . . . . . . . . . . . . . . . . . . . . . . . 137
Authenticating Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Encrypted Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Usernames, Passwords, and Such . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Retrieving Mails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Configuring Your Firewall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Configuring Dovecot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Using Webmail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
xii ■CONTENTS
CHAPTER 7 Understanding DNS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
What Is DNS? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
DNS Was Born . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
The WHOIS System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
The Root DNS Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
The Resolver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
The Hosts File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
nsswitch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
NSCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
What Is BIND?.................................................. 164
Primary and Secondary Name Servers . . . . . . . . . . . . . . . . . . . . . . . 164
Installing BIND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Setting Up a Caching Name Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Making DNS Available to Other Machines . . . . . . . . . . . . . . . . . . . . 168
Configuring BIND to Host Domains . . . . . . . . . . . . . . . . . . . . . . . . . . 170
A Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
CNAME Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
MX Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
NS Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Quick Round-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Creating a Master Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Creating a Slave Zone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Allowing Zone Transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Gotchas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Forgetting to Increment the Serial Number . . . . . . . . . . . . . . . . . . . 179
Forgetting the Dot in the Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Chapter 8 Setting Up DHCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
How Does DHCP Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
DHCP and CentOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Installing DHCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Configuring the Firewall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
■CONTENTS xiii
Configuring DHCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
A Minimal Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Extended Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Defining Static IP Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Grouping Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Shared Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Relaying DHCP Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
PXE Booting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Configuring dhcpd for PXE Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
DHCP Integration with DNS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Chapter 9 Sharing Files with Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Windows Networking Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
The Basic Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Workgroups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Windows Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Active Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Samba and CentOS Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Preparing to Set Up Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Installing Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Configuring Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Example Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Minimal Stand-Alone Samba Setup . . . . . . . . . . . . . . . . . . . . . . . . . 209
Shares and Security........................................ 212
Extended Stand-Alone Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Samba As a Domain Member . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Chapter 10 Setting Up Virtual Private Networks . . . . . . . . . . . . . . . . . . . . . 219
What Is a Virtual Private Network? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Using SSH for Virtual Private Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Virtual Private Networks with IPSec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
IPSec Explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Using IPSec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
xiv ■CONTENTS
Configuring OpenVPN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Looking at an Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Configuring the Server Side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Configuring the Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Some Security Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Doing It the Even Easier Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Part 3 ■ ■ ■ Enterprise Features
Chapter 11 Using Core Builds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
What Are Core Builds? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
What Can’t Core Builds Do? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Why Create a Core Build? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
What Are Kickstart Files? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Anatomy of a Kickstart File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
The Command Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
%packages Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
The Scripts Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Using a Kickstart File on a Web Server . . . . . . . . . . . . . . . . . . . . . . 267
Dynamically Creating Kickstart Files . . . . . . . . . . . . . . . . . . . . . . . . 268
Installing CentOS over HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Updating Your Kickstart File to Install CentOS via HTTP . . . . . . . . . . . . . 271
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Chapter 12 Using High Availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Clustering and High Availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Theory of HA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Split Brain and Fencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Service or Virtual IP Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
HA Cluster Suite Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
HA Clustering with CentOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278