20170915 Linux System Management training

Source: Internet
Author: User
Tags pkill

    1. Process Management

Programs: Usually binary programs in the storage medium (such as CD-ROM, hard disk, floppy disk, tape, etc.), in the form of physical files exist;

Process: The program is running, after the program is triggered, the performer's permissions and properties, program code and all the data will be loaded into memory, the operating system and give the memory unit an identifier (PID).

Then view the process using the command: PS aux

All programs will produce a process

To lock related commands:

PS aux | grep http

#相对的来说, that's grep + service name

    1. Child processes and Parent processes

That is, "derived process", when we log into the system, we will get a bash shell, and then use this bash provided by the interface to execute another command, such as/USR/BIN/PASSWD or touch, etc., those other commands will be triggered to become PID, The PID of the subsequent execution of the command is the "child process"

For example:

So how to do process management?

What is the role of process management first?

n Determine the health status of the server, understand the server CPU, memory usage, etc.

n View all processes in the system

N Kill Process

View PS and Pstree commands for processes

To view the commands for all processes:

n Ps aux or Ps–le

#查看系统中所有进程

N Man PS

#查看命令解释

N Logout

#正常退出用户登录

How to understand the output information of PS aux command

L User: The process is generated by that user.

L PID: The ID number of the process;

L%CPU: The process consumes a percentage of CPU resources, the higher the consumption, the more resources the process consumes

L%MEM: The process consumes a percentage of physical memory, and the higher the process consumes the more resources

L VSZ: The size of the virtual memory that the process occupies, in kilobytes

L RSS: The process consumes the actual physical memory size, in kilobytes

L TTY: Which terminal the process is running in, where Tty1-tty7 represents the local console terminal, Tty1-tty6 is the local character interface terminal, Tty7 is a graphical interface, pts/0-225 represents a virtual terminal

L STAT: Process state, the common State is:

R: Run

S: Sleep

T: Stop state

S: Contains child processes

+: In the background

L Start: The start time of the process

L Time: The process takes up the CPU's operating times, not the system time

L Command: Generates the name of this process

Attention:

The PID of the/sbin/init must be 1, which is the first process for the system to start running. (different from the Linux system you use, the file name and path will differ)

TTY for? Can be understood as a system process, because there is no terminal

So let's look at the simpler commands: Pstree

N Pstree is the display process tree structure

-P: View includes sub-process section, which is the PID number of each process

-U: Displays the user of the process

View-top command for a process

The top command is an important command to view system health

n default every 3 seconds, the process state is automatically refreshed

Options:

-D Number of seconds: Specifies that the top command updates every few seconds, by default, 3 seconds

-B: Use batch mode output, common with "-n" option

-N times: Specifies the number of times the top command executes, typically with the "-B" option

Commands that can be executed in the interactive mode of the top command:

? or h: Show Help for interactive mode

P: Sort by CPU usage, this is the default

M: Sort by Memory utilization

N: Sort by PID

Q: Exit Top

The use of these options, such as Shift + P, is effective because the command function is case-sensitive

Description of the first line under the TOP command:

The first line of information is the task queue information

12:26:46 is the current time of the system

Up Days,13:32 is the system run time, the machine has been running for 86 days, 13 hours, 32 minutes

2 users say they are logged in to two subscribers

The load average:0.00,0.00,0.00 represents the average load of the system in the previous 1 minutes, 5 minutes, and 15 minutes. Generally considered less than 1 o'clock, the load is small, if greater than 1, the system has exceeded the load. (It is important to note that this 1 is a single-core number, if the dual core is not greater than 2, and so on, when the kernel is 4, it cannot be greater than 4)

Second line

Tasks:95 total indicates the number of processes in the system

1 running indicates the number of processes that are running

94 sleeping represents a process in sleep

0 stopped indicates a process that is stopping

0 Zombie Indicates a zombie process, if not 0, requires manual check of the zombie process

Third line

CPU (s): 0.1%us indicates the percentage of CPU consumed by user mode

0.1%sy indicates the percentage of CPU consumed by the system mode

0.0%ni indicates the percentage of CPU consumed by user processes that have changed precedence

99.7%id indicates the CPU percentage of the Idle CPU

0.1%wa indicates the percentage of CPU consumed by the process waiting for input/output

0.0%hi indicates the percentage of CPU consumed by the hard interrupt request service

0.1%si indicates the percentage of CPU consumed by the soft interrupt request service

0.0%st represents the St (steal Time) virtual machine percentage, which is the VM CPU when there is a virtual machine

Percent of time to wait for the actual CPU

Line Four

mem:625344k total represents the amount of physical memory in kilobytes

571504K used indicates the amount of physical memory already in use

53840k free indicates the amount of idle physical memory, and note that if you are using a virtual machine, be aware of how much virtual machines are allocated

65800K buffers as buffered amount of memory

Line Five

Information for interactive partitioning

swap:524280k total indicates the overall size of the swap partition (virtual memory)

0k used indicates the size of an interactive partition that is already in use

524280k free indicates the size of an idle swap partition

409280k cached represents the size of the interactive partition as a cache

Top can only see part of the process content

To see all the process conditions, you can use the

Command: Top–b–n 1 >/root/top.log

Write the contents of top to Top.log

# top–b represents batch mode output, and-n indicates how many times it is refreshed with top.

Command: VI top.log

#查看文本内容

#输入点击insert, enter content

# ESC Exit Input command

#保存文本 Command: W

#退出文本编辑器使用 command:: Q

A Kill process

    1. Kill command

Kill–l

#查看所有信号

For example, use: Kill-1 2235

#重启进程

Kill-9 2236

#强制杀死单一进程

Kill-15 2234

#以正常的步骤结束一项工作

    1. killall [options] [signal] Process name

#按照进程名杀死进程

Options:

-I interactive, asking if you want to kill a process

-I ignores process name capitalization

    1. Pkill

Pkill-9–t PTS/1

#强制杀死从pts/1 Virtual machine terminal logon process

Kick the user according to the terminal number

Command W

#使用w命令查询本机已经登录的用户

Third, process-priority modification.

    1. Start Service is set priority
    2. To modify the priority of a process that already exists

But this part is not very relevant to the general system administrator.

Command: Ps–le

#查询所有进程优先级

The PRI represents Priority,ni on behalf of Nice, with two values representing the priority, and a smaller number representing the higher priority.

The range of NI values is 20 to 19

Normal user adjustment ni is worth 0 to 19

The root user can set the process NI value to negative, or adjust the progress of any user.

A Work Management

Command: Jobs

#把进程放入后台

Order TAR–ZCF Etc.tar.gz/etc &

#把命令放入后台, and executes in the background

Command Top

#按下ctrl +z shortcut key to pause in the background

For example, you can put commands that can last for a period of time into the background,

For example: I put the top command into the background to execute

Command Top &

Command Jobs–l

#显示工作的PID

But the state is stopped, thought the top command is for the user to see, there will be interactive action

Note: "+ "Number represents the most recent work that is put into the background, and is also the default recovery work when work resumes. The "-" sign represents the second-to-last job that is put into the background.

How to put the backstage work into the foreground

Command: FG% work number

Parameters:

-% work Number:% number can be omitted, but note the difference between work number and PID

Restore to run in the background

Command: BG% work number

The console cannot remember the path to its files, and can be found using command find

Command Find/-name Uwsgi

#查找, a file named Uwsgi under the root

For example:

What if you let the command run off the terminal?

For example, I opened a terminal A, the background executes a top command

Then I open another terminal B, can query to the previous command, if I close the terminal A, then the task of the top command will be ended

There are three ways to get the command out of the terminal.

    1. Write commands that need to be executed in the background to the/etc/rc.local file

    1. Use the System Timer task to have the system perform a background command at a specified time
    2. Using the Nohup command

To write a. sh executable command file with Add for loop content (here you can explain the shell script)

File category.

The output is divided into two categories: standard output and standard error output

A: Standard output: Code 1, using > or >>;

B: standard error Output: Code 2, using 2> or 2>>;

The difference between > and >>:

#如果重定向的文件不存在, then create;

#如果文件存在那么清空数据, write again;

# > output to an existing file, will overwrite the original content;

# >> means to accumulate on the basis of the original file data;

    1. 2>&1

# indicates that both correct and incorrect output are written to a file (this is a special way of writing the same file)

# write different files separately written as >/home/right.txt 2>/home/error.txt

    1. Then the background execution command becomes the following:

    1. Command LL/

#查看系统根目录下面文件名, Permissions and properties

Four How to do timed tasks, to monitor the script to run again if the exception and send mail--?

Routine use of work (crontab)

Routine work scheduling for cyclic execution

    1. The root account can restrict users who use Crontab

Restrict Data mode

/etc/cron.allow

#将可以使用crontab的账号写入其中, crontab cannot be used if the account is not within this file.

/etc/cron.deny

#将不使用crontab的账号写入其中, you can use crontab without logging into this file's account

The syntax of crontab

# crontab [u username] [-l|-e|-r]

Parameters:

-U: Only root can perform this task, that is, to help other users create/delete crontab work schedule;

-e: Edit Crontab's work;

-L: View the work of crontab;

-R: Delete all Crontab's work, if only one item is deleted, then use-e to delete.

To achieve this, send yourself mail via timed tasks

    1. To configure the mail server

First, confirm what version of your system it is.

Command: Cat/proc/version

Then confirm how to install mail

Check to see if you have mail installed

#直接输入mail命令, if no installation prompts for the Mail command is not recognized

#如果有安装那么就可以提示是否有收到mail

Install mail (just some packages)

Command

Yum Install Mutt

Yum Install Swaks

Yum Install Mailx

The test sends mail, but if you do not modify the configuration file, you can only send the individual users of the native environment.

To send to an external mailbox, configure the mail configuration file

For example:

Here you need a simple command.

Mail root–s "Hello"

#表示当前账号下面有接收到的邮件

Command Mail [email protected]

Will enter the subject input

Body input

To end the body input you need to break the line first. Exit after Enter

If you want to know the internal commands inside mail, use

Command?

If you want to see if there is an account under Account mail

Command: Mail

# can display mail received under the current account

& Commands for mail control can be entered later

& D Delete Mail

& Q quit Mail management

Configuring the mail file to provide a receiving messaging server

As follows:

Cat/etc/mail.rc

#查看文件配置内容

Vi/etc/mail.rc

#编辑配置信息

Command: Crontab–e

#此时会进入vi编辑页面, you can edit the work for each work line.

After editing is complete, you can enter: Wq to write and exit

Each work format has six fields and each field has the following meanings:

Minutes: 0~59

Hours: 0~23

Date: 1~31

Month: 1~12

Week: 0~7 which week is more interesting 0 and 7 all represent Sunday

There are other auxiliary characters

* (asterisk): means accepted at all times

, (comma): Represents the period of separation for example: 0 3,6 * * * command

#表示3点, 6-point execution once

-(minus sign): Represents a time frame

/n (Slash): N represents a number, meaning the interval n units. For example, */5 means every 5 minutes.

20170915 Linux System Management training

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.