Linux Operations and Administration

advertisement
Linux Operations and
Administration
Chapter Twenty
Advanced Linux Administration
Objectives
• Manage kernel modules and load and configure the
kernel
• Explain how to monitor system resources and use
system-monitoring tools
• Use commands to fine-tune a file system
• Describe emergency recovery procedures
• Summarize common troubleshooting measures in
Linux
Linux Operations and Administration
2
Working with the Linux Kernel
• Linux kernel
– Innermost layer of Linux OS
– Also called the core
– Acts as an interface to hardware attached to the
computer
– Manages communication between processes
• Each Linux distribution includes a precompiled
kernel
Linux Operations and Administration
3
Basics of the Linux Kernel
• Linux kernel can function in one or more modes
– User mode and kernel mode
• Source code for the Linux kernel is stored in a
group of directories called kernel source tree
• Linux kernel is generally one of two types:
– Monolithic
– Modular
• Table 20-1 describes some of commands for
managing kernel modules
Linux Operations and Administration
4
Figure 20-1 Numbering of Linux kernel versions
© Cengage Learning 2013
Linux Operations and Administration
5
Basics of the Linux Kernel (cont’d.)
Table 20-1 Commands for managing kernel modules
Linux Operations and Administration
6
Kernel Configuration
• In openSUSE, you must install the Linux Kernel
Development pattern to have access to important
packages
• You must be in /usr/src/linux directory
• Configuration build file for kernel is .config file
• Configuration tools to edit .config file
– make oldconfig
– make menuconfig
– make config
Linux Operations and Administration
7
Compiling the Kernel
• Involves translating its contents into a binary format
• Compiling process automated by using make utility
• zcat command is used to view the gzipped kernel
configuration
– Running in real time in /proc/config.gz virtual
file
• Activity 20-1: Configuring and Building the Linux
Kernel
– Configure and build the Linux kernel
Linux Operations and Administration
8
System Monitoring
• Monitoring a server or a workstation for CPU and
memory use is an important task
– Helps identify possible performance problems
• OpenSUSE has several commands for monitoring
system performance, such as free and top
• Monitoring system performance helps determine
possible system errors or performance bottlenecks
• These errors can be diagnosed using system log
files
Linux Operations and Administration
9
Monitoring System Resources
• System monitoring
– Process of observing portions of a system for
problems or anomalies
– Includes monitoring:
•
•
•
•
CPU utilization
Network bandwidth
Storage space use
Memory use
Linux Operations and Administration
10
Monitoring CPU Utilization
• Context switching
– Specifies when CPU stops the currently running
process and starts a new process
• Interrupts
– An interrupt occurs when the CPU suspends its
current execution, saves the current work status, and
transfers control to an interrupt handler
• Load percentage
– Specifies the percentage of time a user-level or a
system-level process spends on a CPU
Linux Operations and Administration
11
Monitoring Network Bandwidth
• Number of bytes received or sent
– Specifies the number of bytes that can be sent or
received over a network connection
• Data transfer speed
– Specifies the maximum number of I/O operations
that a network connection can perform per second
Linux Operations and Administration
12
Monitoring Storage Space
•
•
•
•
•
Free space
Data transfer speed
File system–based information
Seek time
Latency
Linux Operations and Administration
13
Monitoring Memory Use
• Memory pages
– Gives detailed information about:
• Memory-resident pages, which can be active or
inactive
• How the system uses memory pages
• Swapping statistic
– Specifies a system’s swapping behavior
– Swapping
• Technique of moving data pages from memory to a
swap space on a hard drive
Linux Operations and Administration
14
Using Basic System-Monitoring
Commands
• top command
– Gives you an active view of a running system and
can display system summary information
• vmstat command
– Displays virtual memory statistics and information
about processes, CPU activity, and disk space use
– Syntax: vmstat -n delay cnt
Linux Operations and Administration
15
Using Basic System-Monitoring
Commands (cont’d.)
• free command
– Shows in column format the total amount of free,
physical, and swap memory in the system as well as
buffers used by the kernel
• df command
– Displays the amount of available disk space on the
file system
• Activity 20-2: Using System-Monitoring Commands
– Work with Linux system-monitoring commands
Linux Operations and Administration
16
Administering System Logs
• logrotate utility
– Included in OpenSUSE
– Can be used by administrators to manage large
numbers of log files
– Offers automatic rotation, compression, removal,
and mailing of log files
– Configuration file is called logrotate.conf
• Located in /etc directory
Linux Operations and Administration
17
Using GUI System-Monitoring Tools
• Linux offers sophisticated system-monitoring tools,
such as the sysstat package
• Graphical tools in GNOME and KDE desktop
environments are also included for monitoring
system resources and processes
Linux Operations and Administration
18
The GNOME System-Monitoring Tool
• GNOME System Monitor
– Displays information on CPU, memory, and swap
utilization in tabular form
– Started using gnome-system-monitor command
– Contains five tabs:
•
•
•
•
•
System
Processes
Resources
File Systems
Hardware
Linux Operations and Administration
19
Figure 20-4 The GNOME
System Monitor interface
© Cengage Learning 2013
Linux Operations and Administration
20
The KDE System-Monitoring Tool
• KDE System Monitor
– Used to monitor processes
– Started using ksysguard command
– Contains two tabs:
• Process Table
• System Load
Linux Operations and Administration
21
Figure 20-5 The KDE System Monitor interface
© Cengage Learning 2013
Linux Operations and Administration
22
Using the sysstat Package for
Resource Monitoring
• sysstat package
– Used to display detailed information on system
performance
– Consists of iostat and mpstat commands
• iostat command
– Used to report CPU utilization and I/O statistics for
devices, partitions, and network file systems
Linux Operations and Administration
23
Using the sysstat Package for
Resource Monitoring (cont’d.)
• mpstat command
– Used to display information for each processor,
starting with processor0
• Activity 20-3: Using Tools to Monitor System
Performance
– Display detailed information on system performance
with the sysstat package and GUI systemmonitoring tools
Linux Operations and Administration
24
Performance Tuning
• After you determine resource use with systemmonitoring tools, you should fine-tune system
resources to improve performance
• Two frequently used resources that require tuning
are the hard drive and file system
Linux Operations and Administration
25
Performance Tuning a Disk
• Disk I/O performance
– Has a large effect on a system’s benchmark
performance
– Can be improved by fine-tuning the hard drive
• For example:
– You can tune the hard drive to increase disk transfer
speed
– This improves system performance
Linux Operations and Administration
26
Using the hdparm Command
• Can be used to tune an IDE hard drive
• You must be logged in as root to use this command
• Syntax: hdparm option device
– option specifies flags that can be used to improve
drive performance
– device specifies the hard drive to be tuned
Linux Operations and Administration
27
Fine-Tuning a File System
• File system has a major effect on system
performance
• If file system size is very large, response time for
performing I/O operations increases
– Results in reduced system performance
• To improve system performance, you need to tune
the file system
Linux Operations and Administration
28
Using the mke2fs Command
• mke2fs command
– Used to create a Linux ext2, ext3, or ext4 file system
on a specified device, which is usually a hard drive
partition
– Format: mke2fs options device
• Best practice
– Large files: use a large block size
• If the file size isn’t a multiple of the block size, you
should specify the block size as a factor of the file size
– Small files: use small block sizes for optimized
performance
Linux Operations and Administration
29
Using the tune2fs Command
• tune2fs command
– Can be used to tune file system parameters on a
Linux ext2, ext3, or ext4 file system
– General format: tune2fs options device
• Example:
– Command to change the number of maximum
mounts on /dev/hda4 partition to 60:
tune2fs –c 60 –L mypartiton1 /dev/hda4
Linux Operations and Administration
30
Using the e2fsck Command
• e2fsck command
– Used to check an ext2, ext3, or ext4 file system for
bad data blocks
– Syntax: e2fsck options device
• Example:
– Command to force a file system check on
/dev/hda2 device:
e2fsck –f /dev/hda2
Linux Operations and Administration
31
Using the badblocks Command
• badblocks command
– Used to check a device for bad data blocks
– General syntax:
badblocks options device
• Example:
– Command to check /dev/hda1 device for bad data
blocks and write all bad blocks to the
badblockdata file:
badblocks –c 20 –o badblockdata /dev/hda1
Linux Operations and Administration
32
Using the noatime Option
• noatime option
– A special mount option for a file system
– Stored in /etc/fstab configuration file
• When the noatime option is used:
– Linux eliminates the need to update the access time
of an inode in the referenced file system
– Speeds up file access if files on the referenced file
system are accessed frequently
Linux Operations and Administration
33
Problem Solving in Linux
• A network’s security must be updated judiciously
from time to time
• Administrator should be equipped to face any
critical situation and have a thorough knowledge of
troubleshooting techniques
Linux Operations and Administration
34
Preventive Measures
• Having an overall view of a problem is important for
troubleshoot
• Applying preventive measures can minimize the
effect of critical situations that can cause losses
– Backups
– Configuration notes
– Rescue disks
Linux Operations and Administration
35
Backups
• YaST System Backup
– Started with yast2 backup command
– An easy-to-use backup program that searches files
on a Linux system to create a backup archive
• Pax
– A POSIX utility that can read and write a wide variety
of archive formats
– Command-line utility included with openSUSE Linux
• Ark
– KDE archiving tool
– A GUI tool
Linux Operations and Administration
36
Figure 20-7 The YaST System Backup tool
© Cengage Learning 2013
Linux Operations and Administration
37
Configuration Notes
• Keep notes on the system configuration
• Notes should contain data about partition table
entries and other important information, such as:
–
–
–
–
Partition number and size
Mount points
User details
Network card details
Linux Operations and Administration
38
Rescue Disks
• Rescue disks are emergency disks you create
ahead of time to save critical data
• To use openSUSE bootable CD as a rescue disk:
– Select Rescue System from the boot menu
Linux Operations and Administration
39
Recovering from a Disaster
• You should try to identify the root cause and find a
solution to recover from the problem
– Observe and read
– Monitor the system log file
– Refer to Linux user groups
• A disaster can also result from server downtime
caused by a system crash
Linux Operations and Administration
40
Single-User Mode
• Also known as maintenance mode
• An OS mode in which only the root partition is
active and mounted
• Linux runs in runlevel 1
Linux Operations and Administration
41
Rescue Mode
• You can boot a small Linux environment from some
type of medium, such as a CD-ROM
• This medium is called a rescue disk
• Helpful if you cannot recover from a system crash
or are having hardware or software problems
• Enables you to access files on the system’s hard
drive, even if you’re having trouble running Linux
from it
Linux Operations and Administration
42
Troubleshooting Linux
• Two widely used Linux boot loaders:
– LILO and GRUB
• Boot loader
– A small program stored on the Master Boot Record
(MBR) that can load one or more OSs by reading file
system information through a pointer from the disk
partition containing OS files
• Linux Loader (LILO)
– One of the original boot loaders
– No longer supported by openSUSE
Linux Operations and Administration
43
Using GRUB
• Grand Unified Boot Loader (GRUB)
– A more flexible boot loader than LILO
– Has become the boot loader of choice for current
Linux distributions
– Packaged with the latest version of openSUSE
• In openSUSE, the GRUB configuration file is
controlled by /boot/grub/menu.lst file
Linux Operations and Administration
44
Login Problems
• Login requires a username and password for
validation
• Sometimes root users forget their passwords
• You can change this password by editing the
kernel entry in the GRUB menu screen, which tells
the system to boot to a specific shell
• Activity 20-4: Changing a Root Password
– Change a root password
Linux Operations and Administration
45
File System Problems
• Problem
– System fails to unmount file system because it’s
been powered off by a hard reboot or power failure
• Solution
– System might run a file system check (by using
fsck command) to fix problems in file system
• Journaling file systems do not use fsck
– Use a log to recover from problems
• To use fsck command, you need to know partition
details
Linux Operations and Administration
46
Network Troubleshooting
• ping command
– Used to send Internet Control Message Protocol
(ICMP) packets to a remote host in an attempt to get
the remote host to send back an Echo packet
• traceroute command
– Tracks the route packets take through a network and
displays the routers used along the way
• Activity 20-5: Using the ping and traceroute
Commands
– Use ping and traceroute commands to check
network connectivity
Linux Operations and Administration
47
Summary
• Linux kernel performs two main tasks:
– Servicing low-level hardware programming
requirements
– Providing an environment for different processes in
the computer
• OS can function in user mode or kernel mode
• Linux kernel’s source code is stored under a group
of directories known as kernel source tree
• Kernel can be monolithic or modular
• You can use lsmod and insmod commands to
manage Linux kernel modules
Linux Operations and Administration
48
Summary (cont’d.)
• System monitoring is used to determine possible
performance bottlenecks and errors
– Monitoring CPU utilization, network connection’s
bandwidth, storage space, and memory use
• Basic system-monitoring commands in Linux: top,
vmstat, free, du, and df
• Logrotate utility enables administrators to manage
large numbers of log files
• Linux includes GUI tools in GNOME and KDE for
monitoring system resources and processes
Linux Operations and Administration
49
Summary (cont’d.)
• Two frequently used resources that require tuning
are hard drives and file systems
• Preventive measures can minimize the effect of
critical situations
• In single-user mode, also known as maintenance
mode, only root partition is active and mounted
• Grand Unified Boot Loader (GRUB): a small
program that can load one or more Oss
• Command for fixing file system problems: fsck
• Two useful commands for diagnosing networks:
ping and traceroute
Linux Operations and Administration
50
Download