320 likes | 688 Views
SUSE Linux Enterprise Desktop Administration. Objectives. Objective 1
E N D
1. SUSE Linux Enterprise Desktop Administration Chapter 10
Monitor the Linux System and Control Processes and Services
2. SUSE Linux Enterprise Desktop Administration 2
3. SUSE Linux Enterprise Desktop Administration Objective 1—Gather Information on a SUSE Linux Enterprise Desktop 10 System In this objective, you are introduced to tools that help you discover information on your hardware and Linux systems:
Boot Log Information
Hardware Information (/proc/)
Hardware Information (Command-Line Utilities)
System and Process Information (Command-Line Utilities)
Monitor Hard Drive Space 3
4. SUSE Linux Enterprise Desktop Administration Boot Log Information Boot messages are written to the /var/log/boot.msg file
The dmesg command is used to view the current content of the kernel ring buffer
dmesg |less allows you to scroll up and down in the output
The output of dmesg shows messages generated during the initialization of the hardware by the kernel or kernel modules
The /var/log/boot.msg file contains additional information beyond what you can display with dmesg
4
5. SUSE Linux Enterprise Desktop Administration Hardware Information (/proc/) The /proc/ directory contains a lot of information on the running system
Including hardware information stored in the kernel memory space
The following are some of the filenames commonly used to generate information:
/proc/devices
/proc/cpuinfo
/proc/ioports
/proc/interrupts 5
6. SUSE Linux Enterprise Desktop Administration Hardware Information (/proc/) (continued) The following are some of the filenames commonly used to generate information: (continued)
/proc/dma
/proc/bus/pci/devices
/proc/scsi/scsi 6
7. SUSE Linux Enterprise Desktop Administration Hardware Information (Command-Line Utilities) You can use the following utilities from the command line to view information about the hardware on your Linux system:
hwinfo
hdparm
fdisk
lspci
siga (System Information Gathering) 7
8. SUSE Linux Enterprise Desktop Administration System and Process Information (Command-Line Utilities) uptime
Displays the current time, the length of time the system has been running, the number of users on the system, and the average number of jobs in the run queue over the last 1, 5, and 15 minutes
netstat
Displays which network ports are offering services and what connections are established
netstat options are shown in Table 10-1 8
9. SUSE Linux Enterprise Desktop Administration 9 System and Process Information (Command-Line Utilities) (continued)
10. SUSE Linux Enterprise Desktop Administration System and Process Information (Command-Line Utilities) (continued) uname
Displays the current kernel version 10
11. SUSE Linux Enterprise Desktop Administration Monitor Hard Drive Space The df command
Provides information on where hard drives and their partitions or other drives are mounted in the file system and how much space they occupy
The du command
Provides information on the space occupied by files and directories
As a graphical tool equivalent to df, you can use the GNOME System Monitor (Computer > More Applications > System > Devices) 11
12. SUSE Linux Enterprise Desktop Administration 12
13. SUSE Linux Enterprise Desktop Administration Exercise 10-1: Gather Information on Your SUSE Linux Enterprise Desktop 10 In this exercise, you get information on the computer you are using
Use several of the administration tools covered to gather the following information on your SUSE Linux Enterprise Desktop 10 13
14. SUSE Linux Enterprise Desktop Administration Objective 2—Use System Logging Services A Linux system has many logs that track various aspects of system operation
System logs in /var/log/ track system-level events
To use system logging services, you need to understand the following:
The Syslog Daemon syslog-ng
Important Log Files
Archive Log Files (logrotate) 14
15. SUSE Linux Enterprise Desktop Administration The Syslog Daemon syslog-ng The syslog daemon syslog-ng is used by many services to log system events
syslog-ng is the new-generation syslogd
The main advantage of syslog-ng over syslogd
Capability to filter messages not only based on facilities and priorities, but also based on the content of each message
The syslog daemon accepts messages from system services and other hosts
Logs them based on settings in the configuration files 15
16. SUSE Linux Enterprise Desktop Administration The Syslog Daemon syslog-ng (continued) The /etc/syslog-ng/syslog-ng.conf file is generated by SuSEconfig from /etc/syslog-ng/syslog-ng.conf.in
/etc/sysconfig/syslog file
Contains general parameters applicable to syslog-ng as well as syslogd
/etc/syslog-ng/syslog-ng.conf.in
The template used to create /etc/syslog-ng/syslog-ng.conf 16
17. SUSE Linux Enterprise Desktop Administration The Syslog Daemon syslog-ng (continued) 17
18. SUSE Linux Enterprise Desktop Administration 18
19. SUSE Linux Enterprise Desktop Administration The Syslog Daemon syslog-ng (continued) Priorities
Give details about the urgency of the message 19
20. SUSE Linux Enterprise Desktop Administration The Syslog Daemon syslog-ng (continued) Sources
Collections of source drivers that collect messages using a given method
Used to gather log messages
The general syntax is as follows:
source identifier { src-driver{params}; src-driver{params};. . .}; 20
21. SUSE Linux Enterprise Desktop Administration The Syslog Daemon syslog-ng (continued) Filters
Boolean expressions that are applied to messages and are evaluated as either true or false
The general syntax is as follows:
filter identifier { expression; };
The identifier has to be unique within the configuration and is used later to configure the actual logging 21
22. SUSE Linux Enterprise Desktop Administration The Syslog Daemon syslog-ng (continued) Destinations
Define where messages can be logged
The general syntax is as follows:
destination <identifier> {
destination-driver(params);
destination-driver(params); ... }; 22
23. SUSE Linux Enterprise Desktop Administration The Syslog Daemon syslog-ng (continued) Log Paths
The point where it all comes together
Define which messages are logged where, depending on source, filter, and destination
The general syntax is as follows:
log { source(s1); source(s2); ...
filter(f1); filter(f2); ...
destination(d1); destination(d2); ...
flags(flag1[, flag2...]); }; 23
24. SUSE Linux Enterprise Desktop Administration Important Log Files Most messages are written to the /var/log/messages file
/var/log/audit/audit.log is the log file for AppArmor messages
Firewall messages are logged in /var/log/firewall
The best approach for reading the log files from the command line is to use the tail command
By using tail -n, you can specify the number of lines to display 24
25. SUSE Linux Enterprise Desktop Administration 25
26. SUSE Linux Enterprise Desktop Administration Archive Log Files (logrotate) It is important to ensure that log files do not get too large
The size and age of log files are monitored automatically by the logrotate program (/usr/sbin/logrotate)
Can configure the settings in the files to indicate whether files should be compressed or deleted in regular intervals or when a specified size is reached
Can configure how many compressed versions of a log file are kept over a specified period of time 26
27. SUSE Linux Enterprise Desktop Administration Archive Log Files (logrotate) (continued) The configuration file of logrotate is /etc/logrotate.conf 27
28. SUSE Linux Enterprise Desktop Administration Archive Log Files (logrotate) (continued) Many RPM packages contain preconfigured files for evaluation by logrotate
These files are stored in /etc/logrotate.d/
Any settings in the logrotate.d files supersede the general settings in logrotate.conf
Must list the files that you want to be monitored in entries in the /etc/logrotate.conf file
The syslog and syslog-ng files in /etc/logrotate.d/
Contain settings for configuring how the log files written by syslog (syslogd or syslog-ng) will be treated 28
29. SUSE Linux Enterprise Desktop Administration 29 Archive Log Files (logrotate) (continued)
30. SUSE Linux Enterprise Desktop Administration Exercise 10-2: Manage System Logging In this exercise, you practice configuring syslog-ng and logrotate 30
31. SUSE Linux Enterprise Desktop Administration Objective 3—Monitor Login Activity One of the most critical tasks you have as an administrator:
Make sure that you notice and act upon any suspicious activity on your system
To monitor login activity, use the following commands:
who
w
finger
last
lastlog
31
32. SUSE Linux Enterprise Desktop Administration Objective 4—View and Manage Processes To manage processes on your SUSE Linux Enterprise Desktop, you need to know the following:
Understand Process Definitions
Learn Jobs and Processes
Manage Foreground and Background Processes
View and Prioritize Processes
End a Process
Understand Services (Daemons)
Manage a Daemon Process 32
33. SUSE Linux Enterprise Desktop Administration Understand Process Definitions The following terms are used to describe Linux processes:
Program—A structured set of commands stored in an executable file on a Linux file system
Process—A program that is loaded into memory and executed by the CPU
User process—A process launched by a user that is started from a terminal or within the graphical environment
Daemon process—A system process that is not associated with a terminal or a graphical environment 33
34. SUSE Linux Enterprise Desktop Administration 34
35. SUSE Linux Enterprise Desktop Administration Understand Process Definitions (continued) Properties of a process:
Process ID (PID)
Child process
Parent process
Parent Process ID (PPID)
35
36. SUSE Linux Enterprise Desktop Administration Understand Process Definitions (continued) 36
37. SUSE Linux Enterprise Desktop Administration Learn Jobs and Processes Job identifier (job ID)
A numeric value that identifies the running program uniquely within that shell
Each process is identified using a process ID (PID) that is unique across the entire system
All jobs have a PID, but not all processes have a usable job ID
PID 1 always belongs to the init process
When performing tasks such as changing the priority level of a running program, use the PID 37
38. SUSE Linux Enterprise Desktop Administration Manage Foreground and Background Processes Processes executed in the foreground
Started in a terminal window and run until the process is completed
Background process execution
Occurs when a process is started and the terminal window returns to a prompt before the process finishes executing
Existing processes can be switched from foreground to background execution 38
39. SUSE Linux Enterprise Desktop Administration Manage Foreground and Background Processes (continued) Commands in a shell can be started in the foreground or in the background
Continue running a stopped process in the background by entering bg
Appending an ampersand to a command starts the process in the background
Each process started from the shell is assigned a job ID by the job control of the shell
Switch a process to the foreground by entering fg job_ID 39
40. SUSE Linux Enterprise Desktop Administration View and Prioritize Processes ps
View running processes with the ps (process status) command 40
41. SUSE Linux Enterprise Desktop Administration View and Prioritize Processes (continued) 41
42. SUSE Linux Enterprise Desktop Administration View and Prioritize Processes (continued) 42
43. SUSE Linux Enterprise Desktop Administration View and Prioritize Processes (continued) pstree
Displays a list of processes in the form of a tree structure
Gives you an overview of the hierarchy of a process
nice and renice
The nice command assigns a process a specific nice value that affects the calculation of the process priority
The lower the value of the nice level, the higher the priority of the process 43
44. SUSE Linux Enterprise Desktop Administration View and Prioritize Processes (continued) nice and renice (continued)
The nice level is used by the scheduler to determine how frequently to service a running process
Use the command renice to change the nice value of a running process
top
Allows you to watch processes continuously in a list that is updated in short intervals
Provides a real-time view of a running system
Can also be used to assign a new nice value to running processes or to end processes 44
45. SUSE Linux Enterprise Desktop Administration 45
46. SUSE Linux Enterprise Desktop Administration End a Process kill and killall
The killall command kills all processes with an indicated command name
The kill command kills only the indicated process
GNOME System Monitor
Start the GNOME System Monitor utility (Computer >More Applications > GNOME System Monitor) to view and kill processes
46
47. SUSE Linux Enterprise Desktop Administration 47 End a Process (continued)
48. SUSE Linux Enterprise Desktop Administration 48
49. SUSE Linux Enterprise Desktop Administration 49 End a Process (continued)
50. SUSE Linux Enterprise Desktop Administration Understand Services (Daemons) A service is also called a daemon
Process or collection of processes that wait for an event to trigger an action on the part of the program
Network-based services create a listener on a TCP or UDP port when they are started
Listener waits for network traffic to appear on the designated port
When traffic is detected, the program processes the traffic as input and generates output that is sent back to the requester 50
51. SUSE Linux Enterprise Desktop Administration Manage a Daemon Process Daemons run in the background and are usually started when the system is booted
Daemons make a number of services available
Daemons are terminal-independent processes, and are indicated in the ps x TTY column by a ?
Two types of daemons are available:
Signal-controlled daemons
Interval-controlled daemons
51
52. SUSE Linux Enterprise Desktop Administration Manage a Daemon Process (continued) Each daemon has a corresponding script in /etc/init.d/
Many scripts have a symbolic link in either the /usr/sbin/ directory or the /sbin/ directory
Find configuration files for daemons in the /etc/ directory or in its subdirectories 52
53. SUSE Linux Enterprise Desktop Administration Manage a Daemon Process (continued) Some important daemons:
cron—Starts other processes at specified times
cupsd—The printing daemon
sshd—Enables secure communication by way of insecure networks (secure shell)
syslog ng—Logs system messages in the directory /var/log/ 53
54. SUSE Linux Enterprise Desktop Administration Exercise 10-3: Manage Linux Processes In this exercise, start and stop processes and change their priorities
First, start and suspend xeyes, move it to the background and foreground, and stop it
Then, start xeyes and set the priority of the running program to a nice value of -5
Start a second xeyes with a nice value of 10 54
55. SUSE Linux Enterprise Desktop Administration Objective 5—Schedule Jobs Automate jobs in Linux by doing the following:
Schedule a Job (cron)
Run a Job One Time Only (at) 55
56. SUSE Linux Enterprise Desktop Administration Schedule a Job (cron) Schedule jobs to be carried out on a regular basis by using the cron service (/usr/sbin/cron)
The service runs as a daemon
Checks once a minute to see if jobs have been defined for the current time
A file that contains the list of jobs is called a crontab
A crontab exists for the entire system as well as for each user defined on the system
The /etc/sysconfig/cron file contains variables for the configuration of some scripts started by cron 56
57. SUSE Linux Enterprise Desktop Administration Schedule a Job (cron) (continued) System jobs
Control system jobs with the /etc/crontab file
Can add lines to /etc/crontab, but do not delete the lines added at installation
Information on the last time the jobs were run is kept in the /var/spool/cron/lastrun/ directory 57
58. SUSE Linux Enterprise Desktop Administration Schedule a Job (cron) (continued) User jobs
The jobs of individual users are stored in the /var/spool/cron/tabs/ directory
In files matching the usernames
Users create their own jobs using crontab
58
59. SUSE Linux Enterprise Desktop Administration Schedule a Job (cron) (continued) User jobs (continued)
Each line in a file defines a job
There are six fields in a line
59
60. SUSE Linux Enterprise Desktop Administration Run a Job One Time Only (at) If you want to run a job one time only, use the at command
To use at, make sure the atd service is started (rcatdstart)
Two files determine which users can run this command:
/etc/at.allow
/etc/at.deny
Can modify or create these text files 60
61. SUSE Linux Enterprise Desktop Administration Run a Job One Time Only (at) (continued) If the /etc/at.allow file exists, only this file is evaluated
If neither of these files exists, only the user root can define jobs with at
Example: 61
62. SUSE Linux Enterprise Desktop Administration Exercise 10-4: Schedule Jobs with at and cron In this exercise, schedule jobs with at and cron
First, redirect the output of finger to /var/log/messages three minutes from the current time
Then, schedule the same job for tomorrow at noon
Then, schedule a program to run tomorrow at 2:00 p.m., and afterwards remove the job
In the second part of the exercise, create a cron job as a normal user that logs the output of finger to ~/users.log every minute
62
63. SUSE Linux Enterprise Desktop Administration Summary To monitor the boot process, use YaST and view the output of the dmesg command
Most hardware information is available within text files under the /proc directory
General system information can be obtained using the uptime, netstat, and uname commands
The df command, du command, and GNOME System Monitor utility can be used to monitor disk usage
Most log files are stored in the /var/log directory and created by the Syslog daemon
63
64. SUSE Linux Enterprise Desktop Administration Summary (continued) The logrotate program is run daily to archive log files
Processes are programs that are executing on the system
Every process has a PID, a PPID, and can possibly start an unlimited number of child processes
Background processes have a job ID
View processes within a desktop environment using the GNOME System Monitor
kill, killall, and top commands can be used to stop processes 64
65. SUSE Linux Enterprise Desktop Administration Summary (continued) You can affect the priority of a process by changing its nice value
To change the nice value of a program, use the nice command
Daemon process names typically end with d and contain a ? in the TTY column of ps command output
Start daemons by running the appropriate script in the /etc/init.d directory
To schedule tasks to occur repetitively in the future, use the cron daemon and create a crontab 65