Beginning Ubuntu Server administration - Pdf 31

this print for content only—size & color not accurate spine = 0.875" 376 page count
Books for professionals By professionals
®
Beginning Ubuntu Server Administration:
From Novice to Professional
Dear Reader,
For the past few years, many have hailed Ubuntu Linux as the best chance to
finally sway the computing masses toward the Linux desktop. And it’s easy to
see why: it offers an amazingly user-friendly interface, intuitive installation
and configuration process, and an enormous choice of applications. Indeed,
it’s become so popular that system administrators are rapidly adopting Ubuntu
Server Edition to configure, deploy, and manage network services more effective-
ly than ever before.
Whether you’re interested in using Ubuntu within a Fortune 500 environment
or just managing your home network, you hold in your hands the only book
you need. While writing it, I kept your daily administration tasks constantly
in mind, and I’ve included chapters on how to set up and run Ubuntu Server
as a file and print server, a virtualization server, and a web server. I also show
you how to perform many other tasks that you’ll frequently encounter as an
Ubuntu Server administrator, such as automating installation, configuration,
and deployment processes, and managing the kernel.
Along the way, this book will help you become a more proficient administra-
tor as you learn to take advantage of little-known shell-related features, tips,
and tricks. Efficiency is a major theme of this book, and you’ll also learn how to
optimize, troubleshoot, and remotely manage your server.
Reading this book will help you master every aspect of Ubuntu Server, from
both the command line and the graphical interface. Whether you’re about to
manage your first server or are interested in expanding your knowledge of
Ubuntu Server, this is the book for you!
Sander van Vugt
Author of

on $10 eBook version
ISBN-13: 978-1-59059-923-5
ISBN-10: 1-59059-923-3
9 781590 599235
5 3 9 9 9
Everything you need to know to manage Ubuntu Server
Beginning
THE APRESS ROADMAP
Beginning SUSE Linux,
Second Edition
Beginning Ubuntu,
Second Edition
The Definitive Guide to
Samba 4, Second Edition
The Definitive Guide to
SUSE Linux Enterprise Server
From Bash to Z-Shell:
Conquering the Command Line
Beginning Ubuntu
Server Administration
Practical MythTV: Building
a PVR and Media Center

Sander van Vugt
Beginning Ubuntu
Server Administration
From Novice to Professional
9233fm.qxd 11/13/07 2:51 PM Page i
Beginning Ubuntu Server Administration: From Novice to Professional
Copyright © 2008 by Sander van Vugt

Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail , or visit
.
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 .
9233fm.qxd 11/13/07 2:51 PM Page ii
f7670b088a34e6aa65a5685727db1ff4
This book is dedicated to Alex.
9233fm.qxd 11/13/07 2:51 PM Page iii
9233fm.qxd 11/13/07 2:51 PM Page iv
Contents at a Glance
About the Author
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewer
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

CHAPTER 1 Installing Ubuntu Server
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

CHAPTER 2 Getting the Most Out of the Command Line
. . . . . . . . . . . . . . . . . . . . . 25

CHAPTER 3 Performing Essential System Administration Tasks
. . . . . . . . . . . . . 47

CHAPTER 4 Performing File System Management Tasks

9233fm.qxd 11/13/07 2:51 PM Page vi
Contents
About the Author
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewer
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

CHAPTER 1
Installing Ubuntu Server
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Preparing for the Installation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Starting the Ubuntu Server Installation Process
. . . . . . . . . . . . . . . . . . . . . . . 2
Configuring the Server’s Hard Drive
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Completing the Installation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

CHAPTER 2
Getting the Most Out of the Command Line
. . . . . . . . . . . . . . . 25
Working As root?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Working with the Shell
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Cut, Copy, and Paste
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Deleting Text
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
vii
9233fm.qxd 11/13/07 2:51 PM Page vii
Getting Help
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Using man to Get Help
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Using the --help Option
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Getting Information on Installed Packages
. . . . . . . . . . . . . . . . . . . . . 46
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

CHAPTER 3
Performing Essential System Administration Tasks
. . . . . . 47
Software Management
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Software Repositories and Package Databases
. . . . . . . . . . . . . . . . . 48
Package Management Utilities
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Installing Software from Tarballs
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Configuring a Graphical User Interface
. . . . . . . . . . . . . . . . . . . . . . . . 58

Working with Links
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Why Use Links?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Working with Symbolic Links
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Working with Hard Links
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Configuring Storage
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Comparing File Systems
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Creating File Systems
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Working with Logical Volumes
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Doing Magic on Your File Systems with dd
. . . . . . . . . . . . . . . . . . . . . . . . . 102
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

CONTENTSviii
9233fm.qxd 11/13/07 2:51 PM Page viii

CHAPTER 5
Configuring Your Server for Security
. . . . . . . . . . . . . . . . . . . . . 107
Setting Up User Accounts
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Commands for User Management

. . . . . . . . . . . . . . . . . . . . . . . . . . 127
ACL Limitations
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Applying File Attributes
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Apply Quota to Allow a Maximum Amount of Files
. . . . . . . . . . . . . . . . . . 131
Installing the Quota Software
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Preparing the File System for Quota
. . . . . . . . . . . . . . . . . . . . . . . . . . 132
Initializing Quota
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Setting Quota for Users and Groups
. . . . . . . . . . . . . . . . . . . . . . . . . . 133
Understanding Pluggable Authentication Modules
. . . . . . . . . . . . . . . . . . 134
Creating a Default Policy for Security
. . . . . . . . . . . . . . . . . . . . . . . . . 136
Discovering PAM Modules
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Configuring Administrator Tasks with sudo
. . . . . . . . . . . . . . . . . . . . . . . . . 140
An Introduction to Setting Up the Netfilter Firewall with iptables
. . . . . . 141
Netfilter Building Blocks
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Using iptables to Create a Firewall
. . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Summary

The GRUB Configuration File
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Installing GRUB
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Working with the GRUB Boot Menu
. . . . . . . . . . . . . . . . . . . . . . . . . . 168
Upstart
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Runlevels
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Making Service Management Easier
. . . . . . . . . . . . . . . . . . . . . . . . . 173
Managing Hardware
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Kernel Management
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Installing Your Own Custom Kernel
. . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Hardware Management with udev
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

CHAPTER 7
Running It Anyway You Like
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Before You Even Start
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
To Script or Not to Script?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

Using until
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Using for
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Using a Stream Editor
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Working with Functions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
A Complex Scripting Example
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

CONTENTSx
9233fm.qxd 11/13/07 2:51 PM Page x

CHAPTER 8
Making Connection
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Configuring the Network Card
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Using ifup, ifdown, and Related Tools
. . . . . . . . . . . . . . . . . . . . . . . . . 219
Using ifconfig
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Using the ip Tool
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Managing IPv6
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Managing Routes

Using Public/Private Key–Based Authentication in an SSH
Environment
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Setting Up SSH for Key-Based Authentication
. . . . . . . . . . . . . . . . . 249
Caching Keys with ssh-agent
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Tunneling Traffic with SSH
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
X Forwarding
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Generic TCP Port Forwarding
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253

CHAPTER 9
Configuring Network Infrastructure Services
. . . . . . . . . . . . 255
Configuring DNS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Methods of Name Resolution
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Structure of the DNS Hierarchy
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Introducing Forward and Reverse DNS
. . . . . . . . . . . . . . . . . . . . . . . 260
Configuring DNS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Configuring Reversed Lookup

Checking NTP Synchronization Status
. . . . . . . . . . . . . . . . . . . . . . . . 279
Customizing Your NTP Server
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Applying NTP Security
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Starting Services with xinetd
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Setting up xinetd by Hand
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Tuning Access to Services with TCP Wrapper
. . . . . . . . . . . . . . . . . . 284
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286

CHAPTER 10
Using Ubuntu Server As a File and Print Server
. . . . . . . . . 287
Setting Up a CUPS Print Server
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Adding Printers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Sharing Printers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Managing Printers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Accessing CUPS Printers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Sharing Files with NFS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Setting Up Apache
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Apache Components
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Starting, Stopping, and Testing the Apache Web Server
. . . . . . . . . 314
Exploring the Configuration Files
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
The Structure of the Apache Configuration Files
. . . . . . . . . . . . . . . 317
Checking the Configuration
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Working with Virtual Hosts
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Configuring Virtual Hosts
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Managing Access to the Web Server
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Configuring Host-Based Access Restrictions
. . . . . . . . . . . . . . . . . . 320
Configuring User-Based Access Restrictions
. . . . . . . . . . . . . . . . . . 322
Some Words on Apache Performance Tuning
. . . . . . . . . . . . . . . . . . . . . . . 323
Using PHP
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Setting Up MySQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Setting the MySQL Root Password

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Setting Up Xen on Ubuntu Server
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Installing Windows As a Guest Operating System on Xen
. . . . . . . . 338
Installing Ubuntu Server As a Guest Operating System on Xen
. . . 340
Using Xen Management Commands
. . . . . . . . . . . . . . . . . . . . . . . . . 341
Ubuntu Server in a VMware Environment
. . . . . . . . . . . . . . . . . . . . . . . . . . 342
Summary
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342

INDEX
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343

CONTENTS xiii
9233fm.qxd 11/13/07 2:51 PM Page xiii
9233fm.qxd 11/13/07 2:51 PM Page xiv
About the Author

SANDER VAN VUGT is an independent trainer and consultant, living in
the Netherlands and working in the extended EMEA (Europe, Middle
East, and Africa) area. He specializes in Linux High Availability and
Storage solutions and has successfully implemented Linux clusters
across the globe. Sander has written several books about Linux-related
subjects, including The Definitive Guide to SUSE Linux Enterprise Server
(Apress, 2006).
His articles can also be found on several international web sites and

that help you in doing your work in a more efficient manner.
Many books about Ubuntu are presently available, but you can’t do Ubuntu Server justice
by covering both the desktop and the server version in one book. The needs of a server admin-
istrator are incredibly different from the needs of a desktop administrator. So I’ve chosen an
approach that makes sense for the server administrator, and all topics are selected and organ-
ized to make sense for your day-to-day work as a server administrator.
The book starts by describing Ubuntu Server with a special focus on storage configura-
tion, which is an especially important concern when dealing with server environments. After
that, you’ll find a quick introduction to driving Ubuntu Server from the command line, in case
you haven’t done this before. The third chapter tackles some of the common generic tasks of a
server administrator, including managing software packages and configuring a graphical user
interface. Next are chapters about file system management, Ubuntu Server security, managing
processes, and the boot procedure. The last chapter dealing with stand-alone server function-
ality explains Bash shell scripting: in fewer than 30 pages, you’ll learn everything you ever
needed to know about this complex topic.
The second part of the book teaches you all about network services. First, you’ll learn
how to configure and troubleshoot a network interface. Next, you’ll read how to set up infra-
structure services such as time services, name services, and DHCP. Following that, you’ll find
chapters about managing file services, the Apache web server (including performance tuning
hints and a section on virtual hosts), and related packages such as MySQL. Finally, the last
chapter provides an overview of the approaches to running virtualization on Ubuntu Server.
Who This Book Is For
This book is written for Linux administrators, whether novice or experienced, who are looking
for a quick, thorough, and authoritative introduction to daily Ubuntu Server management.
Prerequisites
To get the most out of this book, you should have a computer that you can use to install
Ubuntu Server. Any Pentium-based system with 128 MB of RAM and a hard disk with at least
2 GB of free space will do fine. You of course also need the Ubuntu Server software, which you
xix
9233fm.qxd 11/13/07 2:52 PM Page xix

able, a standard PC is fine.
In this chapter you won’t learn how to install Ubuntu Server on a computer that already
has some Windows installation. The reason for this is simple: on a real server you want only
your server operating system and nothing else. Creating a dual-boot machine is cool for a
desktop operating system, but you just don’t want that for a real server. So at this point, make
sure that you have the hardware available to start the installation of a dedicated server.
Also make sure that you have the installation CD, which can be downloaded from
www.ubuntu.com. (Make sure that you select the server version of Ubuntu.) In this book, I’m
working with Ubuntu Server 7.04, simply because it’s the most recent version of Ubuntu
Server that is currently available. I’m sure that, by the time this book is in your hands, a more
recent version will be available, but most of the information presented here will still apply.
However, if you want to be sure that everything works in exactly the same way as it is
described here, I recommend that you download the 7.04 version of Ubuntu Server.
1
CHAPTER 1
9233ch01.qxd 10/31/07 3:29 PM Page 1
Starting the Ubuntu Server Installation Process
Have everything ready? Time to go! Insert the installation CD in your server’s optical drive and
boot your server. Make sure the server boots from the CD-ROM and follow these steps to com-
plete the installation.
1. In the installation menu that appears once the CD spins up, specify what you want
to do. Often, it will be enough to select Install to the hard disk, but in certain cases
other options are required as well. This is especially the case if you want to install in
a language other than English and you’re using a keyboard different from a US key-
board. If this is the case, use the F2 and the F3 keys to specify your language settings.
The other options are rarely used. Make sure that you have selected everything you
need, select Install to the hard disk as in Figure 1-1 and then press the Enter key to
start the installation.
Figure 1-1. In many situations, you just have to press the Enter key to start the installation.


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status