Linux System Management
I. Process Management
1. Role of Process Management
1) Determine the health status of the server
2) View all processes in the system
3) Kill the process
2. View of the process
1) View All processes
PS aux view all processes in the system
Ps-le viewing all processes in the system
-A: Displays all processes of a terminal, except session leader
-U: Shows the user and memory usage of the process
-X: Show process without control terminal
-L: Long format display. Show more detailed information
-e: Show All Processes
PS aux output
User: This process is generated by which users
PID: Process ID Number
%CPU: The percentage of CPU resources that the process consumes
%MEM: The percentage of physical memory that the process occupies
VSZ: The size of the virtual memory that the process occupies
RSS: The process consumes the actual memory size
TTY: Which terminal the process is running on
Pstree Show Process Tree
Pstree-p View the PID process number for each process
Pstree-u display the user for the process
3.top command to determine the health status of the system
Note: (1) Maintenance server, if the server is a high-pressure server, it is best to restart one week, if the low-pressure server is best one months to restart.
(2) The difference between buffer and cache: buffer (buffer) accelerates the writing of the data, and the cache accelerates the reading of the data.
4. Kill the Process
1) Kill a single process
Kill signal Code Process number (cannot be followed by process name)
Note: If you modify the Apache configuration file needs to restart the service, so that if the people who are going to use the Web page will not be able to access, need a solution to reload the configuration file, the user can access the Web page, with Ps-le to view the Apache process number, and then use Kill-hup The Apache process number restarts Apache, but the logged-on user is not terminated.
2) Kill a certain type of process
Killall Signal Code Process name
Pkill Signal Code Process name
Note: If there are two users logged into the system, if one user wants to kill another user according to the user name, it can be found that the process names of all logged-in users are the same, in order to ensure that they do not kill themselves, you need to use the W command to view all logged in users, to view the user's running status. Then use pkill-9-t Tty1 (terminal number)
5. Modify Process Priority
Using Ps-le to view process priorities, both PRI and NI represent the priority, and the smaller the number, the higher the priority of the process. You cannot change the value of a PRI when modifying a process priority, and you can change the value of NI.
The value range of NI is-20-19
Normal user tuning NI is worth the range: 0-19, and can only adjust their own processes. Ordinary users can only increase the NI value, can not be reduced.
Root user can set the NI value to negative
PRI (final value) =pri+ni
=====================================
Nice "Options" command
#nice命令可以给新执行的命令直接赋予NI值, but you cannot modify the NI value of a process that already exists
Renice "Priority" PID
#renice只能修改某一个进程的优先级
Second, work management (background management)
1. Introduction
Work management refers to the behavior of managing multiple jobs at the same time in a single sign-on terminal.
Linux to see how many processes are running in the background: Jobs "-L"
Windows background management is to minimize the window
The role of Linux background management: In order to make long-running commands not stuck on the interface
Note: (1) Only the current terminal can manage the current background work, can not manage the background work of the other terminal.
(2) commands placed in the background must be able to run for a period of time so that we can catch and manipulate the work
(3) The command placed in the background cannot interact with the foreground user or need the foreground input, otherwise it can only be paused in the background and cannot be executed.
2. Methods
1) Put the process into the background
(1) Execute command +& (put into background execution)
(2) Ctrl + Z (pause in background) during command execution
2) View the work in the background
Jobs-l
3) Restore the background paused work to the foreground execution
FG% Work number (not process number)
4) Restore background paused work to background execution
BG% Work number (not process number)
3. Background command from the login terminal execution
Law one: Add commands that need to be executed in the background to the/etc/rc.loacl file
Method Two: Use the system timer task to let the system execute a background command at a specified time
Law III: Using the NOHUP command (standard)
Third, Linux system resources view
1.vmstat Command Monitoring system resources
Vmstat "Refresh delay Refresh Count"
Example: Vmstat 1 3
The 2.DMESG command displays the kernel information of the system
Example: DMESG | grep CPU
3.free Command View memory usage status
4. View CPU Information
Cat/proc/cpuinfo
5.uptime (first line of the top command)
6. View system and kernel-related information
Uname-a
7. Determine the current system's number of digits
File/bin/ls
8. Query the distribution of the current Linux series
Lsb_realse-a
9. The difference between buffering and caching
Caching (cache) is used to speed up the "reading" of data from the hard disk, and buffering (buffer) is used to speed up the data "writing" to the hard disk.
Iv. System Timing Tasks
1.at One time scheduled task
1) determine the at installation
Chkconfig--list | grep ATD #at服务是否安装
Service ATD Restart #at服务的启动
2) at Access control
3) at command
4) Other at management commands
(1) ATQ #查看当前服务器上的at工作
(2) ATRM #删除指定的at任务
2.crontab Recurring Timer task (no user name required)
1) Crond service Management and access control
(1) Service Crond restart
(2) Chkconfig Crond on
(3) Access control
2) User's crontab settings
(1) crontab-e (bind the current user, who executes this command, who the task belongs to)
#进入crontab编辑界面. will open vim to edit your work.
Tasks performed by #*****
Example: * * * * * * * * */root/sh/apache_check.sh This task will be at 1:10, 2:10 ..... 12:10
*/10 * * * */root/sh/apache_check.sh run every 10 minutes
(2) contrab-l
#查看root用户的crontab任务
(3) crontab-r
#删除root用户的所有定时任务
3) crontab Considerations
(1) Six options cannot be empty. If you are not sure to use "*" instead of any time.
(2) crontab Scheduled Tasks, the minimum effective time is minutes, the maximum range is the month
(3) when defining the time, the date and the week is best not to appear in a scheduled task, because they are all in the days of the
(4) In the scheduled task, whether the direct write command, or write commands in a script, preferably with an absolute path.
3. System Crontab settings (username required)
1) How to perform a system timing task
Law one: Copy the script that needs to be timed to/etc/cron.{ Datily,weekly,monthly} Any one of the directories that are called through the/etc/anacrontab file. But the disadvantage is that the execution time is uncertain.
Law II: Modify the/etc/crontab file
4.anacron configuration
1) Definition: Anacron is used to ensure that the system shuts down the time to miss the scheduled task, can be executed after the system boot.
2) Detection period:
(1) Anacron will be used one day, seven days, one months as the detection period
(2) in the system's/var/spool/anacron directory exists cron.{ daily,weekly,monthly} file, which records when the Cron was last executed.
(3) compared to the current time, if the difference of two times exceeds the specified time difference of Anacron, it proves that a cron task is executed.
3) Anacron configuration file
4) Anacron Execution process
Here follow the cron.daily work to illustrate the implementation process
(1) First read the time of the last Anacron execution in/var/spool/anacron/cron.daily.
(2) compared with the current time, if two times difference is more than one day, perform cron.daily work.
(3) Performing this work is only between 03:00-22:00.
(4) The forced delay time is 5 minutes when performing the work, and then a random delay of 0-45 minutes
(5) Use the Nice command to specify the default priority and use the Run-parts script to execute all executables in the/etc/cron.daily directory.
Note: Anacron will only perform scheduled tasks for/etc/crontab files
Linux System Management Learning