May 4th

10.1 Use w to view system load

1. Use w to view the system load (mainly view the CPU load)

blob.png


Explanation: The most common command used by Linux administrators is this w, which displays a wealth of information. The information displayed in the first row from left to right is: time, system running time, number of logged-in users, and average load.

All the lines starting from the second line tell us: the currently logged in user name and its login address, etc.

Note: The most important thing to pay attention to here is the load average: the last three values ​​in the first line.

The first value represents the average load value of the system in one minute.

The second value represents the average load value of the system over five minutes.

The third value represents the average load value of the system over fifteen minutes.

Remarks: We focus on the first value, which indicates the number of active processes using cpu in a unit time period (in this case, it is actually within one minute). The larger the value, the greater the pressure on the server. Under normal circumstances, this value does not matter as long as it does not exceed the number of CPUs of the server. If the number of CPUs of the server is 8, then the value is less than that means that the current server is not under pressure. Otherwise, pay attention.

1.1 Check how many CPU cores the server has (logical CPU)

The processor count here starts from 0, that is, the first one is displayed as 0, and the second is displayed as 1

Command: cat /proc/cpuinfo

blob.png

1.1.1 Check how many CPUs the current system has

: : Grep -c 'processor' / proc / cpuinfo

blob.png

10.2 The vmstat command

1. The meaning of the 1.vmstat command is to display the virtual memory status ("Viryual Memor Statics"), which can report the overall operating status of the system such as processes, memory, and I/O. Let us know where the usage bottleneck of the system is.

blob.png

Explain the role of related processes, focusing on the columns of information r, b, si, so, bi, and bo:

blob.png

  2. procs displays information about the process.

  2.1 r (run): Indicates the number of processes running or waiting for CPU time slices. Note: Do not mistakenly think that waiting for the CPU time slice means that the process is not in progress. In fact, at a certain time, there can only be one process on a CPU, and other processes can only wait in line. At this time, these processes waiting for CPU resources are still Operating status. If the value is greater than the number of server CPUs for a long time, it indicates that the CPU resources are insufficient.

  2.2 b (block): Indicates the number of processes waiting for resources, such as I/O, memory, etc. For example: when the disk reads and writes very frequently, writing data will be very slow. At this time, the CPU operation will end soon, but the process needs to write the result of the calculation to the disk, so that the task of the process is completed, then this When the process can only wait slowly, so the process is the b state. If the value is greater than 1 for a long time, you need to pay attention.

  3. memory Displays information about memory

swpd: Indicates the amount of memory switched to the swap partition, in KB.

free: Indicates the current amount of free memory, in KB.

buff: Indicates the buffer size (to be written to disk), in KB.

cache: Indicates the size of the cache (read from disk), in KB.

 4. swap shows the swap of memory.

si: Indicates the amount of data written into memory by the swap area, in KB.

so: Indicates the amount of data written into the swap area from memory, in KB.

5. io displays disk usage.

bi: Indicates the amount of data read from the block device (read disk), in KB.

bo: Indicates the amount of data written from the block device (write to disk), in KB.

6. The system displays the number of interrupts that occurred within the acquisition interval.

in: Indicates the number of device interruptions per second observed in a certain time interval.

cs: Indicates the number of context switches generated per second.

7. cpu shows the usage status of the CPU.

us: Displays the percentage of time spent on CPU under the user.

sy: Displays the percentage of time the system spends CPU time.

id: Indicates the percentage of time the CPU is idle.

wa: Indicates the percentage of CPU time occupied by I/O waiting.

st: Indicates the percentage of stolen CPU (usually 0, do not pay attention)

Second, pay attention to the r column, the b column, and the wa column 

In addition, when the values ​​of the two columns of si and so are relatively high and keep changing, it means that the memory is not enough.


10.3 top command

 

1.top command to view the resource usage of the process 

The top command is used to dynamically monitor the system resources occupied by processes , which changes every 3 seconds . Its characteristic is to put the processes that occupy the highest system resources ( cpu , memory, hard disk I/O , etc.) to the front .

blob.png 

There are just a few items of concern: %CPU, %MEM, COMMAND , load average , tasks

2. The top -c  command displays detailed process command information 

blob.png 

3. The top -bn1 command statically displays all processes 

blob.png 

Remark:

q exit top , the number 1 shows all core cpu 

Capital M to sort by memory usage 

Capital P to sort by cpu usage 

kill+pid kills the process

RES represents the amount of memory occupied by the process.

 

 10.4 The sar command

1. sar monitors system status ( mainly view historical network card traffic )

The ar command is very powerful and is nicknamed Swiss ×××. It can monitor the status of almost all resources of the system , such as average load, network traffic, disk status, memory usage, etc. Different from other system status monitoring tools, it can mainly print historical information , and can display the system status information from zero o'clock to the current moment of the day. 

2. Use yum to install sysstat to obtain, command: yum install -y sysstat   installation

 ( The first time you use the sar command, an error will be reported, because the sar tool has not yet generated the corresponding database file (data is generated every 10 minutes). Its database file is in the "/var/log/sa/" directory, which is saved for one month by default  )

blob.png 

3. View the network card traffic history  command: sar -n DEV

blob.png 

explain:

The IFACE column represents the device name .

rxpck/s这一列表示每秒进入收取的包的数量有多少。

txpck/s这一列表示每秒发送出去的包的数量有多少。

rxkB/s这一列表示每秒收取的数据量(单位为KB)。

txkB/S这一列表示每秒发送的数据量。

如果rxpck/s 那一列的数值大于4000,或者rxkB/s那一列的数值大于50000000,很有可能是被攻击了,正常的服务器网卡流量不会这么高,除非是你自己在复制数据

4.实时查看网卡流量命令:sar -n DEV 1 5

blob.png 

5 查看某一天网卡流量历史,.使用-f选项,后面跟文件名 (默认会存储30)

命令:sar -n DEV -f  /var/log/sa/sa30

blob.png 

(在Red Hat或者CentOS发行版中,sar的库文件一定在/var/log/sa/目录下)

6.查看历史负载 命令:sar -q

blob.png 

7.历史磁盘读写命令:  sar -b

blob.png 

 

10.5 nload命令

1. sar虽然可以查看网卡流量,但是不够直观,还有一个更好用的工具,

    那就是nload更直观的查看网卡进出流量

 1.1 安装nload命令:

先安装: yum install -y epel-release     安装扩展源

 再安装:yum install -y nload                因为nload依赖于epel-release

1.2 使用命令:nload    (q退出界面)

blob.png 

说明:

Incoming is the traffic entering the network card.

Outgoing is the outgoing traffic from the network card.

The main focus is on the data in the Curr row, and its units can also be dynamically adjusted automatically.

Press q to exit this interface.





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325269415&siteId=291194637
May