Linux systems management and tuning (memory, CPU, disk IO, network)

System Management

Author: Rich Qi Ge

  • Check CPU load related tool, to find out the process using the most CPU system
  • View Memory running status tools to identify processes using the most memory system
  • View IO operation status tools to identify systems for disk reads and writes most of the process
  • View Network operating status tools to identify processes that use the most network systems
  • View the overall status of the system operation

Performance optimization is to find bottlenecks in system processing and removal of these processes. In fact, performance optimization is to define a balance of OS subsystems to achieve these subsystems including:

CPU Memory IO Network

The relationship between these subsystems are mutually dependent on each other, a high load will cause any problems with other subsystems such as:
a large number of page loading resulting in congestion memory request queue; high throughput network card may result in more CPU overhead ; a lot of CPU overhead will try to use more memory request;
a lot of memory from disk write requests may result in more CPU and IO problems; so to optimize the system for a look bottleneck from which side is the key, though do seems a subsystem of a problem, in fact, may be caused by other subsystems.
tuning is like a doctor, so you need to have a clear understanding of all local servers. When the system is a problem, run the card, how to quickly find out the following process:

  • 1, to find out the system using the most CPU process?
  • 2, identify processes using the most memory in the system?
  • 3, find the system disk read and write most of the process?
  • 4, to find out the process using the most network systems?

Check CPU load related tools

[root@localhost ~]# uptime
13:22:30 up 8 min, 1 users, load average: 0.14, 0.38, 0.25 其内容如下:

12:38:33
当前时间
up 8 min
系统运行时间 ,说明此服务器连续运行 8 分钟
1 user
当前登录用户数
load average: 0.06, 0.60,
0.48
系统负载,即任务队列的平均长度。 三个数值分别为  1 分 钟、5 分钟、15 分钟前到现在的平均值。

Identify system using the most CPU process?

Method 1: Use the top command to
run the top, find out the process using the most CPU, according to uppercase P, can be sorted by CPU usage display

The results are as follows

According to the actual use of CPU, sorted in descending order display a list of all processes

[root@harry63 ~]# ps -aux --sort -pcpu | more     #按 cpu 降序排序 查看
注: -pcpu 可以显示出进程绝对路径,方便找出木马程序运行的路径。

View Memory running status tools

Identify processes using the most memory system

free -h
total
used
free
shared
buff/cache
available
Mem:
976M
291M
156M
7.3M
527M
479M
Swap:
2.0G
0B
2.0G

total
used
free
shared
buff/cache
available
Mem:
976M
291M
156M
7.3M
527M
479M
Swap:
2.0G
0B
2.0G

The actual physical computing free memory: free + buffers / cache

According to the actual use of memory, sorted in descending order display a list of all processes

[root@harry63 ~]#   ps -aux   --sort -rss | more 内存降序排序(去掉减号就是升序) 或:
[root@harry63 ~]#   ps -aux   --sort -rss > a.log

Disk IO

  • I / O-related tuning viewer
[root@harry63 ~]# tune2fs -l /dev/sda1 | grep size
Filesystem features:         has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Block size:                       1024   #   为 1 个字节 。 一个扇区 512 字节。


RHEL 7
[root@harry63 ~]# xfs_growfs -l /dev/sda1 |grep bsize
data       =                                   bsize=4096     blocks=51200, imaxpct=25 naming                    =version 2                       bsize=4096     ascii-ci=0 ftype=1
log         =internal                      bsize=4096     blocks=855, version=2

Scene: server very slow to check the CPU usage is not high, the memory is good enough, but it is the card, especially when you open a new program or file, and more cards. Which is a problem at this time?

Where are the bottlenecks in the system at this time?
hard disk

See which process is using the most disk read and write?
iotop command to see which process to use disk read and write up to install:

[root@harry63 ~]# yum install -y iotop

例:
[root@harry63 ~]# iotop -o -d 1        #显示正在使用磁盘的进程 在另一个终端对磁盘进行大量读操作,执行:

选项:
-o:只显示有 io 操作的进程
-b:批量显示,无交互,主要用作记录到文件。
-n NUM:显示 NUM 次,主要用于非交互式模式。
-d SEC:间隔 SEC 秒显示一次。
-p PID:监控的进程 pid。
-u USER:监控的进程用户

iotop 常用快捷键:
<- / ->:左右箭头:改变排序方式,默认是按 IO 排序。
r:改变排序顺序。 o:只显示有 IO 输出的进程。 p:进程/线程的显示方式的切换。 a:显示累积使用量。
q:退出

Overall View

View memory and overall system operating status:
vmstat: command is the most common Linux / Unix monitoring tool that can be presented to the server given time intervals status values, including the server's CPU usage, MEM memory usage, VMSwap virtual memory swap case, IO read and write conditions.
Use vmstat can see the use of the entire machine CPU, memory, IO, rather than just see the CPU usage and memory usage of each process. Save resources than the top command.
Note: When the machine run more slowly, it is recommended that you use vmstat view indefinitely, without the use of top, top due to the use of resources more.

To be continued

Guess you like

Origin www.cnblogs.com/fusheng11711/p/11820742.html