First, system monitoring 1. Real-time monitoring of CPU, memory and hard disk status with the top command
The effect is Windows-like Task Manager, which refreshes the display on the screen every 5 seconds by default.
[[email protected]/]#TopTop-17:39:47 up-min, 2 users, load average:0.07, 0.05, 0.05Tasks:175 total, 3 running, 172sleeping, 0 stopped, 0 zombie%CPU (s): 14.0 us, 2.7 sy, 0.0 ni, 82.9 ID, 0.0 wa, 0.0 hi, 0.3 si, 0.0Stkib Mem:1875716 Total, 883260 free, 511916 used, 480540 buff/Cachekib Swap:2097148 Total, 2097148 free, 0 used. 1160536avail Mem PID USER PR NI VIRT RES SHR S%CPU%MEM time+COMMAND2930 Root 0 1491516 179012 49708 S 9.6 9.5 0:38.08 gnome-Shell1308 Root 0 221852 29924 10696 R 5.0 1.6 0:12.65Xorg3442 Root 0 573828 24200 15116 R 2.0 1.3 0:06.38 gnome-termi+ 670 root 20 0 4368 592 496 S 0.3 0.0 0:00.94Rngd710 Root 0 302644 6180 4804 S 0.3 0.3 0:04.39VMTOOLSD2888 Root 0 201268 3408 2756 S 0.3 0.2 0:00.29 at-spi2-reg+ 2900 root 20 0 1159540 23944 15760 S 0.3 1.3 0:00.95 gnome-setti+ 3044 root 0 377916 18660 14776 S 0.3 1.0 0:04.27VMTOOLSD4276 Root 0 157708 2256 1556 R 0.3 0.1 0:00.26Top1 root 0 128092 6692 3944 S 0.0 0.4 0:02.37systemd2 Root 0 0 0 0 S 0.0 0.0 0:00.00Kthreadd3 Root 0 0 0 0 S 0.0 0.0 0:00.16 ksoftirqd/06 Root 0 0 0 0 S 0.0 0.0 0:00.18 kworker/u12+ 7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/08 Root 0 0 0 0 S 0.0 0.0 0:00.00RCU_BH9 Root 0 0 0 0 S 0.0 0.0 0:00.77rcu_schedRoot RT 0 0 0 0 S 0.0 0.0 0:00.03 watchdog/0
1) The first line is the task queue information
Current time, system run time, number of users currently logged in, System load (three values are average in 1min.5min.15min)
2) second to third behavior process and CPU information
The total number of processes, number of processes running, number of processes to sleep, number of processes stopped, number of zombie processes, percentage of CPU per user control, percentage of CPU in kernel space, percentage of CPU that changed priority within user process space, percentage of idle CPU, The percentage of CPU time waiting for input and output, the percentage of CPU time that the hardware interrupt consumes, and the percentage of CPU time that the software outage consumes
Zombie Process: If a process ends, if his parent process does not wait or call him, then he becomes a zombie process, still consumes CPU
3) Fourth to fifth behavior memory information
4) The following is the process information
PID: Process ID
User: Username for process Owner
PR: Priority
Ni:nice, negative indicates high priority, positive value indicates low priority
Virt: Total amount of virtual memory used by the process, Unit kb,virt=swap+res
Res: the size of the physical memory that the process used, not swapped out, unit Kb,res=code+data
SHR: Shared memory size, in kilobytes
S: Process state. (d= non-disruptive sleep status, r= run, s= sleep, t= track/Stop, z= zombie process)
Command: Name/command line
CPU utilization vs. Load average
CPU is used to work, according to this level to understand, each yard is a CPU
CPU Utilization : The last day of the class time is 8 hours, while the code of the number of farmers to tap the time of 2 hours, 2/8=0.25, 25% is the yard in a day's time utilization (normal situation, CPU utilization <70%)
CPU Load : The company in a minute for a number of farmers to arrange 3 tasks, and 1 minutes in the yard to do 6 tasks, then the yard load of one minute is 0.5
If the company in 5 minutes for a number of farmers to arrange 100 tasks, and 5 minutes in the yard can only do 50 tasks, then the code farm 5 minutes of load of 2.0, that is, overloaded operation
CPU load <=1: can handle normally
CPU Load >1: overload operation
If there are 4 cores, equivalent to 100 tasks to 4 yards to dry, if each yard load is 100%, then the overall CPU load of 4.0 is very normal phenomenon
Multi-core CPU, load average should <= CPU cores * 0.7
There is a 1-minute, 5-minute, 15-minute, three-cpu-load reason to describe the CPU's usage in a more accurate way, if only 1 minutes of CPU load is high, 5 minutes or 15 minutes after the drop, then do not worry, if the CPU usage has been very high, Then you need to improve the hardware configuration.
In both cases, a process cannot logically run
1) process hangs is its own cause, encountering I/O blocking, it will let the CPU to allow other processes to execute, so that the CPU has been working
2) Regardless of the process, it is the operating system level, it may be because a process takes too much time, or priority, and so on, and call other processes to use the CPU.
2.free Command: Detects the total amount of memory space used and unused by the system
[[email protected]/] # Free Total used free shared buff/cache availablemem: 1875716 505684 890048 10752 479984 1166956Swap: 2097148 0 2097148
Use Free-w to disassemble the Buffer/cache
The use of free-h will be displayed in a human-readable way
[[email protected]/] # free-h Total used free shared buff/cache availablemem: 1.8G 517M 843M 10M 470M 1. 1GSwap: 2.0G 0B 2.0G
Explanation of buffer and cache:
A buffer is something that have yet to being "written" to disk.
A cache is something that have been "read" from the disk and stored for later use.
That is, buffer is used to store the data to be output to disk (block device), and the cache is to store the data read from disk. Both are designed to improve IO performance and are managed by the OS.
A mature system like windows that allocates more space to the cache to improve I/O performance
Available indicates that the cache can release memory + can be used as suffer/cache memory, directly represents the amount of memory remaining
command while:; Sleep 1; Clear;d one enables dynamic monitoring
Command echo 3 >/proc/sys/vm/drop_caches to release the cache
3. Monitoring of processes
Viewing processes with the PS aux command
View Top n rows with PS aux |head-n
[[email protected]/] # PS aux |head-5 USER PID%cpu%MEM VSZ RSS TTY STAT START time commandroot 1 0.0 0.3 128092 6692? Ss 16:54 0:02/usr/lib/systemd/systemd--switched-root--system--deserializeroot 2 0.0 0.0 0 0? S 16:54 0:00 [kthreadd]root 3 0.0 0.0 0 0? S 16:54 0:00 [ksoftirqd/0]root 7 0.0 0.0 0 0? S 16:54 0:00 [migration/0]
with PS aux | grep ' top ' can filter content that contains ' top ' characters
[[email protected]/] # PS aux |grep ' top 'root 3035 0.0 1.5 1020224 29872? Sl 16:55 0:01 nautilus--no-default-window--force-desktoproot 7548 0.0 0.0 112664 968 PTS/1 r+ 18:54 0:00 grep--color=auto Top
Kill a process with kill-9 PID command
We demo open a Firefox program and then kill it with a command,
[[email protected]/] # ps aux | grep ' firefox 'root 8384 7.6 10.1 2098636 190952 pts/1 sl+ 18:59 0:05/usr/ lib64/firefox/firefoxroot 8762 0.0 0.0 112664 972 pts/2 r+ 19:00 0:00 grep--color=/]# kill-9 8384
We can also view the process as a tree, using the command Pstree PID
[email protected]/]#Pstree 2kthreadd─┬─ata_sff├─* *[bioset]├─crypto├─deferwq├─fsnotify_mark├─*[hci0]├─ipv6_addrconf├─kauditd├─kblockd├─kdevtmpfs├─*[kdmflush]├─khugepaged├─khungtaskd├─kintegrityd├─kmpath_rdacd├─kpsmoused ├─KRFCOMMD├─KSMD├─KSOFTIRQD/0├─kswapd0├─kthrotld├─kworker/0:0├─kworker/0:0h├─kworker/0:1├─kworker/0:1h├─kworker/0:2├─kworker/u128:1├─kworker/u128:2├─kworker/u129:0 ├─kworker/u129:1├─md├─migration/0├─mpt/0├─mpt_poll_0├─netns├─nfit├─rcu_bh├─rcu_sched├─rpciod├─ Scsi_eh_0├─scsi_eh_1├─scsi_eh_2├─scsi_tmf_0├─scsi_tmf_1├─scsi_tmf_2├ ─ttm_swap├─watchdog/0├─WRITEBACK├─XFS-buf/dm-0├─XFS-buf/SDA1├─XFS-buf/SDB1├─XFS-cil/dm-0├─XFS-cil/SDA1├─XFS-cil/SDB1├─XFS-conv/dm-0├─XFS-conv/SDA1├─XFS-conv/SDB1├─XFS-data/dm-0├─XFS-data/SDA1├─XFS-data/SDB1├─XFS-eofblocks/d├─2*[xfs-eofblocks/S]├─XFS-log/dm-0├─XFS-log/SDA1├─XFS-log/SDB1├─XFS-reclaim/dm-├─XFS-reclaim/SDA├─XFS-reclaim/Sdb├─xfs_mru_cache├─xfsaild/dm-0├─xfsaild/Sda1├─xfsaild/Sdb1└─xfsalloc
View Code
Note that CENTOS7 does not have pstree by default and needs to be installed yum-y the install PSMISC command
second, hard disk format
When we add a new drive to a virtual machine, we need to partition it and then format it to write to the filesystem before we can use it.
We demonstrate the operation after joining a hard drive, add a 15G hard disk to the configuration information, reboot the system
In the Linux system, all files, hard disk corresponding files in the/dev directory, the default first hard drive is SDA, the second is SDB,.....
View information for the second hard drive with Fdisk-l/dev/sdb
Then start partitioning, using the command fdisk/dev/sdb
N: New Partition
P: View Partitions
W: Save
The code is as follows
[[Email protected] ~]#fdisk-l/dev/sdbDisk/dev/sdb:16.1 GB, 16106127360 bytes, 31457280a Sector units= Sector of 1 * 512 = 512bytes Sector size (logical/physical): 512 Bytes/512byte i/o Size (min/best): 512 Bytes/512bytes [[Email protected]~]#Fdisk/dev/sdbWelcome to FDISK (Util-linux 2.23.2). The changes will remain in memory until you decide to write the changes to disk. Think twice before you use the Write command. Device does notcontain a recognized partition table uses disk identifiers0xc23c658dCreate a new DOS disk label. Command (enter M for help): Npartition Type:p Primary (0 primary, 0 extended,4Free ) e extendedselect (default p): P-Partition Area code (1-4, default 1): Start Sector (2048-31457279, default is 2048): Default value will be used2048Last sector,+ Sectoror+size{k,m,g} (2048-31457279, default = 31457279): +5G Partitioning1 set to Linux type, size set to 5Gib command (enter M for help): Npartition Type:p Primary (1 primary, 0 extended, 3Free ) e extendedselect (default p): E partition number (2-4, default 2): Start Sector (10487808-31457279, default is 10487808): Default value will be used10487808Last sector,+ Sectoror+size{k,m,g} (10487808-31457279, default = 31457279): Default value will be used31457279Partitioning2 set to Extended type, size set to 10Gib command (enter M for help): Npartition Type:p Primary (1 primary, 1 extended, 2Free ) l logical (numbered from5) Select (default P): L Add logical Partition5Start Sector (10489856-31457279, default is 10489856): Default value will be used10489856Last sector,+ Sectoror+size{k,m,g} (10489856-31457279, default = 31457279): +5G Partitioning5 set to Linux type, size set to 5GIB command (input m for help): P Disk/dev/sdb:16.1 GB, 16106127360 bytes, 31457280a Sector units= Sector of 1 * 512 = 512bytes Sector size (logical/physical): 512 Bytes/512byte i/o Size (min/best): 512 Bytes/512byte disk label type: DOS disk identifier:0xc23c658ddevice Boot Start End Blocks Id System/DEV/SDB1 2048 10487807 5242880 83Linux/DEV/SDB2 10487808 31457279 10484736 5Extended/DEV/SDB5 10489856 20975615 5242880 83Linux Command (input m for help): Wthe partition table has been altered! Calling IOCTL () to re-read partition table. Synchronizing disks.
Then we format the filesystem and write the file system to the first partition, which is SDB1, and the command is mkfs.xfs/dev/sdb1/
The code is as follows
[[Email protected] ~] # mkfs.xfs/dev/sdb1meta-data=/dev/sdb1 isize=512 agcount=4, agsize=327680 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0data = bsize=4096 blocks=1310720, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1=none extsz=4096 blocks=0 , Rtextents=0
Mount:
Create a new Part1 folder under the root directory, mount the/DEV/SDB1 to/part1, and use the command Mount/dev/sdb1/part1
[[email protected]/]#Mkdir/part1[[email protected]/]#Mount/dev/sdb1/part1[[email protected]/]#DFFile system 1k-block used available%mount point/dev/mapper/cl-root 17811456 4613280 13198176 26%/Devtmpfs921036 0 921036 0%/Devtmpfs937856 144 937712 1%/dev/Shmtmpfs937856 9156 928700 1%/Runtmpfs937856 0 937856 0%/sys/fs/Cgroup/DEV/SDA1 1038336 178584 859752 18%/Boottmpfs187572 8 187564 1%/run/user/0/dev/sr0 4236604 4236604 0 100%/run/media/root/centos 7x86_64/DEV/SDB1 5232640 32944 5199696 1%/part1
Using the DF command to see the use of your hard disk, you can see that/DEV/SDB1 has been mounted in/part1.
With the XFS filesystem in CentOS 7, the performance of processing large files has improved significantly compared to ETC4
It is necessary to understand that files and folders are the logical units provided by the file system, and the only hard disk that can actually hold the data.
Unloading:
Umount/File name
Linux Basics (iv)