The shell finds the last data example of each line
$ echo abc:test:345:2020-05-06:8899 | awk -F ":" '{print $NF}'
8899
$ echo abc: 2020-05-06 8899 | awk -F " " '{print $NF}'
8899
1. View the Linux version number and centos version
Usually use uname -a to get the Linux version number, the detailed version can be viewed in /proc/version
$ uname -a
Linux localhost.localdomain 3.10.0-1160.66.1.el7.x86_64 #1 SMP Wed May 18 16:02:34 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/version
Linux version 3.10.0-1160.66.1.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Wed May 18 16:02:34 UTC 2022
$ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
2. Disk-related commands, df, lsblk, fdisk, iostat, etc.
View disk size and disk file type df -Th
$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 16G 0 16G 0% /dev
tmpfs tmpfs 16G 1.1M 16G 1% /dev/shm
tmpfs tmpfs 16G 1.7G 15G 11% /run
tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 50G 21G 30G 41% /
/dev/sdb1 ext4 504G 250G 229G 53% /512
/dev/sda1 xfs 1014M 238M 777M 24% /boot
/dev/mapper/centos-home xfs 70G 59G 12G 85% /home
tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1002
tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1004
tmpfs tmpfs 3.2G 56K 3.2G 1% /run/user/0
View disk partition lsblk
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 128G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 127G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 7.9G 0 lvm [SWAP]
└─centos-home 253:2 0 69.1G 0 lvm /home
sdb 8:16 0 512G 0 disk
└─sdb1 8:17 0 512G 0 part /512
sr0 11:0 1 4.4G 0 rom /run/media/root/CentOS 7 x86_64
View the hard disk information mounted on the machine fdisk -l (requires root privileges)
$ fdisk -l
Disk /dev/sdb: 549.8 GB, 549755813888 bytes, 1073741824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x90a525e8
Device Boot Start End Blocks Id System
/dev/sdb1 2048 1073741823 536869888 83 Linux
Disk /dev/sda: 137.4 GB, 137438953472 bytes, 268435456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b252e
View disk read and write performance iostat -xkt 1
# iostat -xkt 1
Linux 3.10.0-1160.66.1.el7.x86_64 04/20/2023 _x86_64_ (2 CPU)
04/20/2023 04:04:14 PM
avg-cpu: %user %nice %system %iowait %steal %idle
1.57 0.00 1.08 0.11 0.00 97.24
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sdb 0.00 0.25 0.05 0.75 5.22 25.28 76.72 0.01 6.53 2.64 6.77 0.22 0.02
sda 0.00 0.15 0.01 2.34 1.16 22.67 20.31 0.03 10.76 13.23 10.75 3.82 0.90
scd0 0.00 0.00 0.00 0.00 0.00 0.00 9.41 0.00 0.10 0.10 0.00 0.10 0.00
dm-0 0.00 0.00 0.01 1.86 0.38 15.45 16.96 0.02 10.38 11.95 10.38 4.10 0.76
dm-1 0.00 0.00 0.00 0.02 0.00 0.08 8.01 0.00 77.87 23.81 80.39 1.18 0.00
dm-2 0.00 0.00 0.01 0.60 0.78 7.14 26.14 0.01 12.15 12.70 12.14 3.03 0.18
04/20/2023 04:04:15 PM
avg-cpu: %user %nice %system %iowait %steal %idle
2.01 0.00 1.51 0.00 0.00 96.48
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda 0.00 0.00 1.00 0.00 8.00 0.00 16.00 0.00 2.00 2.00 0.00 2.00 0.20
scd0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
dm-0 0.00 0.00 1.00 0.00 8.00 0.00 16.00 0.00 2.00 2.00 0.00 2.00 0.20
dm-1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
dm-2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
3. Test disk read and write speed dd command
You must pay attention to the test disk writing. If the disk has been mounted and there is important data on it, of= cannot directly follow the hard disk. You need to specify the file name to be written on the hard disk, otherwise the disk information may be damaged, such as of=/512 /test.file, if the disk is new and has no data, you can directly use of=/dev/sda1. The following command gives the performance of writing 10G data, the disk write speed is 577MB/s
$ time dd if=/dev/zero of=/512/test.file bs=1M count=10000
10000+0 records in
10000+0 records out
10485760000 bytes (10 GB) copied, 18.1799 s, 577 MB/s
real 0m18.184s
user 0m0.019s
sys 0m13.717s
Test the disk read speed, that is, read from the file just written to the empty device, and the read speed is 563 MB/s
$ time dd if=/512/test.file of=/dev/null bs=1M count=10000
10000+0 records in
10000+0 records out
10485760000 bytes (10 GB) copied, 18.6303 s, 563 MB/s
real 0m18.635s
user 0m0.029s
sys 0m8.241s
Note that you need to clear the cache before testing the read.
4. Clear the cache command echo 3 > /proc/sys/vm/drop_caches
Clearing the cache requires root privileges
5. View free memory free -g
6. Add swap partition
Use the free command to view the current swap size, only 7GB
# free -g
total used free shared buff/cache available
Mem: 31 13 2 4 14 11
Swap: 7 1 6
1) Use the dd command to create a swap partition file, such as adding 8G swap space
# dd if=/dev/zero of=./swapfile bs=1G count=8
8+0 records in
8+0 records out
8589934592 bytes (8.6 GB) copied, 13.6308 s, 630 MB/s
2) Format the swap partition
# mkswap ./swapfile
Setting up swapspace version 1, size = 8388604 KiB
no label, UUID=d22eedad-fe74-4135-83b9-b6d74daf4af9
3) Set swap partition and modify permissions
# mkswap -f ./swapfile
mkswap: ./swapfile: warning: wiping old swap signature.
Setting up swapspace version 1, size = 8388604 KiB
no label, UUID=ba341cce-d097-4b7a-af52-54d27c4ddcb5
# chmod 600 ./swapfile
# ll -ltr ./swapfile
-rw------- 1 root root 8589934592 Apr 20 16:22 ./swapfile
4) Activate the swap partition. After activation, use the free command to see that the swap has increased by 8G, reaching 15G
# swapon ./swapfile
# free -g
total used free shared buff/cache available
Mem: 31 13 1 4 15 11
Swap: 15 1 14
5) Add to enable startup, add /512/swapfile none swap defaults 0 0 at the end of the /etc/fstab file
7. Swap partition Swappiness configuration
How to view the value of swappiness: You can use the following two methods: cat /proc/sys/vm/swappiness or sysctl -a |grep swappiness
# cat /proc/sys/vm/swappiness
20
# sysctl -a |grep swappiness
vm.swappiness = 20
Set the swappiness value: sysctl vm.swappiness=10
But this kind of temporary modification will fail after restarting
# sysctl vm.swappiness=10
vm.swappiness = 10
# cat /proc/sys/vm/swappiness
10
For permanent effect, add vm.swappiness=30 in the /etc/sysctl.conf file, and then execute sysctl -p
# vim /etc/sysctl.conf
# sysctl -p
vm.swappiness = 30
# cat /proc/sys/vm/swappiness
30
8. The watch command prints the executed command every second
For example, execute the ps -a command every 1 second, and ctrl+c to exit
# watch -p -n 1 ps -a
Every 1.0s: ps -a Thu Apr 20 16:29:47 2023
PID TTY TIME CMD
11627 pts/1 00:00:00 watch
11635 pts/1 00:00:00 watch
11636 pts/1 00:00:00 ps
9. Huge page
View large pages
# cat meminfo | grep HugePages
AnonHugePages: 573440 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Set huge pages: Modify /etc/sysctl.conf , for example, add 1G huge pages, each huge page is 2MB by default, then set vm.nr_hugepages=512 , 1GB=1024MB, 1024MB/2MB=512 huge pages
# vi /etc/sysctl.conf
vm.nr_hugepages=512
After saving, run sysctl -p to make the huge page effective