本文主要记录一些常用的命令,方便后面查阅

crontab

我在RedHat上使用Bash。 我需要安排一个cron工作在每个月的第一个星期日上午9点运行。 我怎样才能做到这一点?

00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script
0 9 1-7 * * [ $(date +\%u) = 7 ] && /path/to/your/script

corantab执行失败的原因-环境变量
新启用的定时任务,cron日志显示确实执行了,但是结果却并不如人意,大部分原因就是环境变量,索性就将环境变量直接加入脚本,或者使用source命令,调用环境变量,可以参考下面的文章
https://blog.csdn.net/iteye_15440/article/details/82277682

ctrl+z、bg、fg

执行一个时间较长的任务,比如scp传输文件

# scp *.dmp 192.168.1.11:/backup/
# 输入密码后开始数据传输,因为数据量较大,需要等待,又怕连接断开导致传输中断
# 输入ctrl+z,此时任务会进入后台并暂停
# 执行jobs,此时任务是暂停状态
# jobs
[1]+ Stopped scp *.dmp 192.168.1.11:/backup/ &
# 执行bg 1,此时任务会在后台继续执行,1表示对应的任务号
# bg 1
# 执行jobs,查看当前任务状态,此时任务是运行状态
# jobs
[1]+ Running scp *.dmp 192.168.1.11:/backup/ &
# 此时如果想将任务调到前台,执行fg 1即可,后台任务会调到前台
# fg 1
test20220506.dmp	19% 1011MB 112.9MB/s	00:37
# 此时关闭shell工具有时候还是会断开,使用disown,后台作业从shell的作业列表中移除
# disown %1
# 此时可以关闭shell工具,且可以保证任务不被断开了

diff

[root@localhost test3]# diff log2014.log log2013.log 
3c3
< 2014-03
---
> 2013-03
8c8
< 2013-07
---
> 2013-08
11,12d10
< 2013-11
< 2013-12

上面的"3c3"和"8c8"表示log2014.log和log20143log文件在3行和第8行内容有所不同;"11,12d10"表示第一个文件比第二个文件多了第11和12行。

[root@localhost test3]# diff log2014.log log2013.log  -y -W 50
2013-01                 2013-01
2013-02                 2013-02
2014-03               | 2013-03
2013-04                 2013-04
2013-05                 2013-05
2013-06                 2013-06
2013-07                 2013-07
2013-07               | 2013-08
2013-09                 2013-09
2013-10                 2013-10
2013-11               <
2013-12               <
[root@localhost test3]# diff log2013.log log2014.log  -y -W 50
2013-01                 2013-01
2013-02                 2013-02
2013-03               | 2014-03
2013-04                 2013-04
2013-05                 2013-05
2013-06                 2013-06
2013-07                 2013-07
2013-08               | 2013-07
2013-09                 2013-09
2013-10                 2013-10
                      > 2013-11
                      > 2013-12

"|"表示前后2个文件内容有不同
"<"表示后面文件比前面文件少了1行内容
">"表示后面文件比前面文件多了1行内容

dmidecode

dmidecode命令是同事告诉我的,确认当前机器是实体机还是虚拟机,之前看过很多办法,总是忘记,这一条真的是一个万金油,其他的用处还可以再发掘

# dmidecode -s system-product-name
VMware Virtual Platform

# dmidecode -t 1
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.7 present.

Handle 0x0001, DMI type 1, 27 bytes
System Information
        Manufacturer: VMware, Inc.
        Product Name: VMware Virtual Platform
        Version: None
        Serial Number: VMware-56 4d 07 c6 7d b5 42 7b-6c cd 54 88 3a 49 a1 66
        UUID: c6074d56-b57d-7b42-6ccd-54883a49a166
        Wake-up Type: Power Switch
        SKU Number: Not Specified
        Family: Not Specified

dstat

默认情况下分五个区域:
1、 –total-cpu-usage—- CPU使用率
usr:用户空间的程序所占百分比;
sys:系统空间程序所占百分比;
idel:空闲百分比;
wai:等待磁盘I/O所消耗的百分比;
hiq:硬中断次数;
siq:软中断次数;
2、-dsk/total-磁盘统计
read:读总数
writ:写总数
3、-net/total- 网络统计
recv:网络收包总数
send:网络发包总数
4、—paging– 内存分页统计
in: pagein(换入)
out:page out(换出)

du

du用的时候习惯使用du -sh,后面又发现了新的方式,可以统计总大小,最后的面的total就是所有目录的大小

# du -ch *
4.0K    anaconda-ks.cfg
0       Desktop
0       Documents
0       Downloads
4.0K    initial-setup-ks.cfg
0       Music
0       Pictures
0       Public
0       Templates
0       Videos
8.0K    total

ethtool

机房建设,跳线时有时候找不准服务器网口,需要打灯,执行如下命令,之后服务器对应的网口就会不停闪烁

ethtool -p eth0

file

file 是 Linux 中一个非常实用的命令,用于检测文件的类型和编码信息。它通过分析文件的内容(而不是文件扩展名)来判断文件类型。


基本用法

file filename
  • 示例:
    file myfile.txt
    
    输出可能类似于:
    myfile.txt: ASCII text
    

查看文件编码

使用 -i--mime 选项可以查看文件的 MIME 类型和编码信息。

file -i filename
  • 示例:
    file -i myfile.txt
    
    输出可能类似于:
    myfile.txt: text/plain; charset=utf-8
    
    其中 charset=utf-8 表示文件的编码格式。

常用选项

选项 说明
-i--mime 显示文件的 MIME 类型和编码信息。
-b--brief 仅显示文件类型,不显示文件名。
-f--files-from 从指定文件中读取文件名列表并检测类型。
-F--separator 自定义输出中的分隔符(默认是冒号 :)。
-k--keep-going 即使文件类型已确定,仍继续检测其他可能的类型。

示例

  1. 检测单个文件类型

    file myfile.txt
    

    输出:

    myfile.txt: UTF-8 Unicode text
    
  2. 显示 MIME 类型和编码

    file -i myfile.txt
    

    输出:

    myfile.txt: text/plain; charset=utf-8
    
  3. 检测多个文件类型

    file file1.txt file2.jpg
    

    输出:

    file1.txt: ASCII text
    file2.jpg: JPEG image data, JFIF standard 1.01
    
  4. 从文件中读取文件名列表并检测类型
    创建一个文件 filelist.txt,内容如下:

    file1.txt
    file2.jpg
    

    运行命令:

    file -f filelist.txt
    

    输出:

    file1.txt: ASCII text
    file2.jpg: JPEG image data, JFIF standard 1.01
    
  5. 仅显示文件类型(不显示文件名)

    file -b myfile.txt
    

    输出:

    UTF-8 Unicode text
    
  6. 自定义输出分隔符

    file -F " -> " myfile.txt
    

    输出:

    myfile.txt -> UTF-8 Unicode text
    

检测二进制文件

file 命令也可以检测二进制文件(如可执行文件、图片、视频等)的类型。

  • 示例:
    file image.png
    
    输出:
    image.png: PNG image data, 800 x 600, 8-bit/color RGB, non-interlaced
    

总结

file 命令是一个非常强大的工具,适用于:

  • 检测文件类型(文本、二进制、图片、视频等)。
  • 查看文件的编码格式(结合 -i 选项)。
  • 批量检测文件类型(结合 -f 选项)。

在日常工作中,file 是排查文件类型和编码问题的利器!

find

通过正则删除指定目录

find ./ -name "*.tr[c|m]" -mtime +3 -delete
#下面方式文件太多删除可能会失败
find ./ -type d -name 'tt*[0-9]' -prune -exec rm -rf {} \;
## top

> 对于多线程的程序,top命令可以查看每个线程的运行情况,查看9883的每一个线程,运行情况

```bash
# ps -ef | grep redis
redis      9883      1  0 17:39 ?        00:00:23 redis-server 0.0.0.0:6379
redis     12305      1  0 21:26 ?        00:00:00 redis-server 0.0.0.0:6380
redis     12344      1  0 21:26 ?        00:00:00 redis-server 0.0.0.0:6381
root      12921  12817  0 21:32 pts/0    00:00:00 grep --color=auto redis

# top -p 9883 -H
top - 21:32:41 up  7:46,  4 users,  load average: 0.00, 0.01, 0.05
Threads:   5 total,   0 running,   5 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1863012 total,   981796 free,   232296 used,   648920 buff/cache
KiB Swap:  2097148 total,  2073596 free,    23552 used.  1452172 avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
  9883 redis     20   0  164984   7776   1640 S  0.0  0.4   0:22.34 redis-server
  9884 redis     20   0  164984   7776   1640 S  0.0  0.4   0:00.00 bio_close_file
  9885 redis     20   0  164984   7776   1640 S  0.0  0.4   0:00.00 bio_aof_fsync
  9886 redis     20   0  164984   7776   1640 S  0.0  0.4   0:00.00 bio_lazy_free
  9887 redis     20   0  164984   7776   1640 S  0.0  0.4   0:01.32 jemalloc_bg_thd

history

今天想起这个命令,平常用的很多,之前反而忘掉了,这个命令可以查看历史操作

$ history
    1  vncserver :1
    2  ps -ef | grep vnc
    3  exit
    4  ps -ef | grep vnc
    5  vncserver -kill :1
    6  vncserver :1
    7  systemctl stop firewalld
    8  systemctl disable firewalld
    9  exit
   10  ls
   11  unzip LINUX.X64_193000_db_home.zip -d /u01/app/oracle/product/19.3/db/
   12  yum install unzip
   13  exit
   14  unzip LINUX.X64_193000_db_home.zip -d /u01/app/oracle/product/19.3/db/
   15  vim /etc/sysconfig/selinux
   56  history

这些数据其实是存存储在.bash_history里面的,黑客入侵一台计算机,最后的操作就是清空这个文件

$ more .bash_history
vncserver :1
ps -ef | grep vnc
exit
ps -ef | grep vnc
vncserver -kill :1
vncserver :1
systemctl stop firewalld
systemctl disable firewalld
exit
ls
unzip LINUX.X64_193000_db_home.zip -d /u01/app/oracle/product/19.3/db/
yum install unzip
exit
unzip LINUX.X64_193000_db_home.zip -d /u01/app/oracle/product/19.3/db/
vim /etc/sysconfig/selinux
exit
ls -lrt

hostnamectl

hostnamectl在红帽系统是7版本开始有的,可以不重启机器就可以修改主机名

hostnamectl set-hostname linuxprobe

如果主机名需要有大写,需要添加新的参数

hostnamectl set-hostname --static linuxProbe

iconv

在Linux中,可以使用iconv命令将GB2312编码的文件转换为UTF-8编码。以下是具体步骤:

1. 使用iconv命令

iconv是一个用于字符集转换的工具。

iconv -f GB2312 -t UTF-8 inputfile -o outputfile
  • -f GB2312:指定源文件编码为GB2312。
  • -t UTF-8:指定目标编码为UTF-8。
  • inputfile:要转换的文件。
  • -o outputfile:指定输出文件名。

2. 示例

假设有一个GB2312编码的文件gb2312.txt,将其转换为UTF-8编码并保存为utf8.txt

iconv -f GB2312 -t UTF-8 gb2312.txt -o utf8.txt

3. 直接覆盖原文件

如果想直接覆盖原文件,可以使用以下命令:

iconv -f GB2312 -t UTF-8 gb2312.txt -o gb2312.txt

4. 检查文件编码

可以使用file命令检查文件编码:

file -i filename

5. 批量转换

如果需要批量转换目录下的所有文件,可以使用find命令结合iconv

find . -type f -name "*.txt" -exec iconv -f GB2312 -t UTF-8 {} -o {}.utf8 \;

总结

iconv是Linux中转换文件编码的常用工具,支持多种编码格式的转换。

iostat

监控磁盘性能,trouble shooting时,需要时间戳,添加参数t

# iostat -xm 2 10 -t
Linux 3.10.0-1127.el7.x86_64 (dockerp)  01/09/2022      _x86_64_        (2 CPU)

01/09/2022 11:09:19 PM
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.22    0.00    0.52    0.02    0.00   99.23

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.16    0.12    1.92     0.01     0.04    44.20     0.01    3.09   18.05    2.16   0.58   0.12
dm-0              0.00     0.00    0.12    2.07     0.01     0.04    41.05     0.01    4.72   18.50    3.95   0.53   0.12
dm-1              0.00     0.00    0.00    0.01     0.00     0.00     9.34     0.00   13.41    6.32   14.42   1.85   0.00

01/09/2022 11:09:21 PM
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.25    0.00    0.50    0.00    0.00   99.24

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.00    0.50    0.50     0.00     0.01    24.00     0.00    1.00    2.00    0.00   1.00   0.10
dm-0              0.00     0.00    0.50    0.50     0.00     0.01    24.00     0.00    1.00    2.00    0.00   1.00   0.10
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

01/09/2022 11:09:23 PM
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00    0.51    0.00    0.00   99.49

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               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    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
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

# iostat -xk 1

ls

又想起来ls的一些技巧,平常使用这个命令要么就是ls -lrt,或者直接ll,想确认一个任务的执行时间,有时候就可以通过查看相关文件的最后修改时间就可以,比如日志文件,任务产生的临时文件

$ ls -lrt
total 87340
-rwxr-xr-x. 1 root root      2953 Oct 11  2008 zipgrep
-rwxr-xr-x. 1 root root        56 Jan 27  2011 modifyrepo
-rwxr-xr-x. 1 root root        55 Jan 27  2011 mergerepo
-rwxr-xr-x. 1 root root        60 Jan 27  2011 createrepo
-rwxr-xr-x. 1 root root      2086 Dec 28  2013 run-parts
-rwxr-xr-x. 1 root root        42 Dec 29  2013 pyinotify
-rwxr-xr-x. 1 root root       203 Dec 29  2013 perldoc
-rwxr-xr-x. 1 root root      3755 Dec 29  2013 pod2usage
-rwxr-xr-x. 1 root root     11004 Dec 29  2013 pod2text
-rwxr-xr-x. 1 root root     13581 Dec 29  2013 pod2man
-rwxr-xr-x. 1 root root     96760 Jan 25  2014 dbus-binding-tool

比较早的文件,没有具体时间,还需要再添加其他参数–full-time

$ ls -lrt --full-time
total 87340
-rwxr-xr-x. 1 root root      2953 2008-10-11 01:40:36.000000000 +0800 zipgrep
-rwxr-xr-x. 1 root root        56 2011-01-27 01:14:30.000000000 +0800 modifyrepo
-rwxr-xr-x. 1 root root        55 2011-01-27 01:14:30.000000000 +0800 mergerepo
-rwxr-xr-x. 1 root root        60 2011-01-27 01:14:30.000000000 +0800 createrepo
-rwxr-xr-x. 1 root root      2086 2013-12-28 03:08:27.000000000 +0800 run-parts
-rwxr-xr-x. 1 root root        42 2013-12-29 08:31:46.000000000 +0800 pyinotify
-rwxr-xr-x. 1 root root       203 2013-12-29 20:09:19.000000000 +0800 perldoc
-rwxr-xr-x. 1 root root      3755 2013-12-29 20:13:08.000000000 +0800 pod2usage
-rwxr-xr-x. 1 root root     11004 2013-12-29 21:42:41.000000000 +0800 pod2text
-rwxr-xr-x. 1 root root     13581 2013-12-29 21:42:41.000000000 +0800 pod2man

lvextend

扩展逻辑卷,有人是先扩然后resize文件系统,直接加-r参数就可以,下面表示扩展1GB

lvextend -r -L +1G /dev/mapper/vg-root-lvroot

ps

用如下方式查看Oracle会话是否活动,如下Rs表示活动会话

ps -aux|grep LOCAL=NO|grep -i " R"
oracle 102796 0.3 0.0 172709868 38720 ? Rs 09:43 0:13 oracleoadb (LOCAL=NO)

pwdx

查看当前pid进程启动时的工作目录

pwdx pid...
# 通过ps netstat jps等获取进行pid

# pwdx 2778				#查看进程号为2778是有哪个程序发起的
2778: /u01/app/oracle/product/12.1.0.2/db_1/dbs

# pwdx 1211	 #查看进程号为1211是有哪个程序发起的
1192: /	 #输出显示一个根目录,这说明了什么,说明这种进程是由systemctl、service启动管理的

mpstat

监控CPU状态

# mpstat -P ALL 1
Linux 3.10.0-1127.el7.x86_64 (My) 	08/03/2022 	_x86_64_	(2 CPU)

10:28:18 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
10:28:19 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
10:28:19 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
10:28:19 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

10:28:19 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
10:28:20 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
10:28:20 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
10:28:20 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

10:28:20 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
10:28:21 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
10:28:21 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
10:28:21 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

10:28:21 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
10:28:22 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
10:28:22 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
10:28:22 PM    1    0.00    0.00    0.99    0.00    0.00    0.00    0.00    0.00    0.00   99.01

rsync

快速删除大量文件

# 1、先建立一个空目录
mkdir /data/blank

# 2、用rsync删除目标目录
rsync --delete-before -d /data/blank/ /var/spool/clientmqueue/

快速删除大文件

# 1、创建空文件
touch /data/blank.txt

# 2、用rsync清空文件
rsync -a --delete-before --progress --stats /root/blank.txt /root/nohup.out

为什么rsync能够快速删除大文件
1、rm命令大量调用了lstat64和unlink,可以推测删除每个文件前都从文件系统中做过一次lstat操作。过程:正式删除工作的第一阶段,需要通过getdirentries64调用,分批读取目录(每次大约为4K),在内存中建立rm的文件列表;第二阶段,lstat64确定所有文件的状态;第三阶段,通过unlink执行实际删除。这三个阶段都有比较多的系统调用和文件系统操作。
2、rsync所做的系统调用很少:没有针对单个文件做lstat和unlink操作。命令执行前期,rsync开启了一片共享内存,通过mmap方式加载目录信息。只做目录同步,不需要针对单个文件做unlink。
另外,在其他人的评测里,rm的上下文切换比较多,会造成System
CPU占用较多——对于文件系统的操作,简单增加并发数并不总能提升操作速度。

tips:
当SRC和DEST文件性质不一致时将会报错 当SRC和DEST性质都为文件【f】时,意思是清空文件内容而不是删除文件
当SRC和DEST性质都为目录【d】时,意思是删除该目录下的所有文件,使其变为空目录
最重要的是,它的处理速度相当快,处理几个G的文件也就是秒级的事 最核心的内容是:rsync实际上用的就是替换原理

screen

可以虚拟一个终端,执行一些耗时较长的任务,异常中断不会导致这个虚拟终端中断,未执行的命令都会保留,如果要手动调到后台可以执行Ctrl+a+d

# screen
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 149185
Server version: 5.7.27-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bindb              |
| employees          |
| gtdb               |
| gtid_text          |
| mysql              |
| mysqlslap          |
| oldguo01           |
| performance_schema |
| sys                |
| test               |
+--------------------+
11 rows in set (0.00 sec)

mysql> use mysql;

通过screen -r命令返回虚拟终端,可以发现use mysql这个命令没有执行也还在

# screen -ls
There is a screen on:
        80680.pts-2.My  (Detached)
1 Socket in /var/run/screen/S-root.
# screen -r 80680
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 149185
Server version: 5.7.27-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bindb              |
| employees          |
| gtdb               |
| gtid_text          |
| mysql              |
| mysqlslap          |
| oldguo01           |
| performance_schema |
| sys                |
| test               |
+--------------------+
11 rows in set (0.00 sec)

mysql> use mysql;

任务完成后,直接通过exit可以退出screen
如下指令可以确认自己在虚拟终端,如果不显示信息,表示在真实终端

# echo $STY
93404.pts-0.mgr01

systemctl

图形界面、多用户界面

init 3多用户界面
init 5图形界面

systemctl get-default查看当前模式
systemctl set-default multi-user.target
systemctl set-default graphical.target

uuidgen

使用 uuidgen 生成通用唯一标识符 (UUID)

# uuidgen
6a5c3e16-57e3-420b-b3f5-72e36a2dcbc9
# for i in {1..10}; do echo `uuidgen`,`uuidgen`; done
7dd44050-9df4-43aa-b3b4-3b47eff8fc31@3052e93c-95d1-40f5-b468-3d4e06dd208b.com
cca71187-f666-46ff-81c6-eb3b72ff6972@30f4c9a8-712e-4f4c-ad3a-4b55ef85eee0.com
6ff086ad-493d-4b3a-8ed1-970239d7125b@8302d772-4deb-43d1-8901-0a3b4f747b55.com
f9813daa-6a8e-4543-8708-d42cefdda20a@d586854c-7df9-4046-89f8-51f960973afb.com
a7e9e43b-d2b1-4415-b73d-ff72b713e45f@a7c56c2c-df25-44bc-872d-a893f750b54d.com
0d1d13fe-777d-44d8-b1b2-302ca1e48aa1@7c2d8e6a-fa8b-4fa3-a0ef-8360aa42e730.com
f85d0772-22d2-43d0-8d71-4e6714c2bb20@fb4f74fe-f9f9-4e86-b31d-f148344a97e0.com
f46eb868-0a99-4291-98f2-19d95f1e9fbb@37ef072d-c515-4145-8b8a-edf32ec18bd2.com
eaa4a63e-2646-427a-a892-f8027c2791ed@33daf102-2b5b-4070-88c5-261fe5d96cfa.com
d75f6720-b249-4395-bcc7-9ffe2b67cabb@457b04b4-3c15-4b77-aae2-9afd6803bcfe.com

tcpdump

配合wireshark及科来网络分析系统使用

[root@Mon02 ~]# tcpdump -i ens33 port 27017 -C 300 -W 20 -w /tmp/mongo.pcap
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes

telnet

telnet测通后无法退出
使用Ctrl+],再输入q,按下回车键,即可退出

vmstat

监控系统性能,trouble shooting时,需要时间戳,添加参数t

# vmstat -t 2 10
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- -----timestamp-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st                 CST
 1  0   7208 164948      0 1736612    0    0     3    20   17   41  0  1 99  0  0 2022-01-09 23:08:54
 0  0   7208 164900      0 1736644    0    0     0     6  387  789  0  1 99  0  0 2022-01-09 23:08:56
 0  0   7208 165040      0 1736644    0    0     0     0  316  649  0  0 99  0  0 2022-01-09 23:08:58
 0  0   7208 164728      0 1736644    0    0     0     0  363  696  0  1 99  0  0 2022-01-09 23:09:00
 0  0   7208 164736      0 1736644    0    0     0     0  329  664  0  1 99  0  0 2022-01-09 23:09:02
 0  0   7208 164736      0 1736644    0    0     0     0  343  673  0  1 99  0  0 2022-01-09 23:09:04

watch

watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行。在Linux下,watch是周期性的执行下个程序,并全屏显示执行结果。
默认间隔2s,也可以设置间隔时长

watch df -h

Every 3.0s: df -h                                                                                                                                                                      Sat Apr  9 23:31:54 2022

Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               1.9G     0  1.9G   0% /dev
tmpfs                  1.9G     0  1.9G   0% /dev/shm
tmpfs                  1.9G   12M  1.9G   1% /run
tmpfs                  1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   50G   12G   39G  24% /
/dev/sda1             1014M  150M  864M  15% /boot
/dev/mapper/rhel-home   26G  2.9G   23G  12% /home
tmpfs                  378M     0  378M   0% /run/user/0

watch -n 3 df -h
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐