[命令] Linux 命令 nestat (显示本地端口,以及其 PID 信息等)

案例一

$ netstat -ntulap
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:7001            0.0.0.0:*               LISTEN      1250/nxnode.bin     
tcp        0      0 127.0.0.1:25001         0.0.0.0:*               LISTEN      1345/nxrunner.bin   
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:3001          0.0.0.0:*               LISTEN      1316/pipewire
......


补充:
1) -n 不解析名称
2) -t 显示 tcp 端口
3) -u 显示 udp 端口
4) -l 显示服务器接口
5) -a 显示所有接口
6) -p 显示 PID 或者程序名称的接口

案例二

mingyuzhu@mingyuzhu:~$ netstat -W -neopa
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name     Timer
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      991        6431       -                    off (0.00/0/0)
tcp        0      0 0.0.0.0:7001            0.0.0.0:*               LISTEN      1001       11218      1250/nxnode.bin      off (0.00/0/0)
tcp        0      0 127.0.0.1:25001         0.0.0.0:*               LISTEN      1001       11498      1345/nxrunner.bin    off (0.00/0/0)
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      0          6018433    -                    off (0.00/0/0)
tcp        0      0 127.0.0.1:3001          0.0.0.0:*               LISTEN      1001       12293      1316/pipewire        off (0.00/0/0)
tcp        0      0 0.0.0.0:4000            0.0.0.0:*               LISTEN      121        11121      -                    off (0.00/0/0)
tcp        0      0 127.0.0.1:26001         0.0.0.0:*               LISTEN      1001       11426      1250/nxnode.bin      off (0.00/0/0)
tcp        0      0 127.0.0.1:26002         0.0.0.0:*               LISTEN      1001       6513629    1065010/nxnode.bin   off (0.00/0/0)
......


补充:
1) -W 不缩写 IP 地址
2) -n 不解析名称
3) -e 显示更多的信息
4) -o 显示计时器
5) -p 显示 PID 或者程序名称的接口
6) -a 显示所有接

[命令] Linux 命令 ss (显示本地端口,以及其 PID 信息等)

案例一

$ ss -ntulap
Netid  State      Recv-Q   Send-Q     Local Address:Port         Peer Address:Port   Process                                                                              
udp    UNCONN     188672   0          80.66.196.238:5353              0.0.0.0:*                                                                                           
udp    UNCONN     0        0                0.0.0.0:5353              0.0.0.0:*                                                                                           
udp    UNCONN     0        0                0.0.0.0:5353              0.0.0.0:*                                                                                           
udp    UNCONN     0        0                0.0.0.0:4000              0.0.0.0:*                                                                                           
udp    UNCONN     0        0                0.0.0.0:4011              0.0.0.0:*       users:(("nxnode.bin",pid=1065010,fd=27),("nxnode.bin",pid=1250,fd=70))              
......


补充:
1) -n 不解析名称
2) -t 显示 tcp 端口
3) -u 显示 udp 端口
4) -l 显示服务器接口
5) -a 显示所有接
6) -p 显示 PID 或者程序名称的接口

[步骤] Linux page_owner 排查工具的使用 (记录内存的使用情况)

正文:

步骤一:查看 page_owner 是否开启

1.1 通过 dmesg 命令查看 page_owner 是否开启

# dmesg | grep page_owner
[    1.149165] page_owner is disabled

(补充:当显示此类信息时则 page_owner 没有开启)

1.2 通过 /sys/kernel/debug/ 目录查看 page_ownerr 是否开启

# ls -l /sys/kernel/debug/page_owner
ls: cannot access /sys/kernel/debug/page_owner: No such file or directory.

(补充:当 /sys/kernel/debug/page_owner 文件不存在时则 page_owner 没有开启)

步骤二:开启 page_owner

2.1 开启 page_owner

# grubby --args="page_owner=on" --update-kernel=0

(注意:开启 page_owner 会额外占用一定量的内存)

2.2 重启系统

# reboot

2.3 确认 page_owner 已经开启

2.3.1 通过 dmesg 命令确认 page_owner 是否开启
# dmesg | grep page_owner
[    0.000000] Command line: BOOT_IMAGE=(hd0,gpt2)/vmlinuz-4.18.0-425.19.2.el8_7.x86_64 root=/dev/mapper/rootvg-rootlv ro ipv6.disable=1 audit=1 audit_backlog_limit=8192 crashkernel=auto resume=/dev/mapper/rootvg-swaplv rd.lvm.lv=rootvg/rootlv rd.lvm.lv=rootvg/swaplv rhgb quiet rd.shell=0 page_owner=on
[    0.000000] Kernel command line: BOOT_IMAGE=(hd0,gpt2)/vmlinuz-4.18.0-425.19.2.el8_7.x86_64 root=/dev/mapper/rootvg-rootlv ro ipv6.disable=1 audit=1 audit_backlog_limit=8192 crashkernel=auto resume=/dev/mapper/rootvg-swaplv rd.lvm.lv=rootvg/rootlv rd.lvm.lv=rootvg/swaplv rhgb quiet rd.shell=0 page_owner=o

(补充:当显示此类信息时则 page_owner 已经开启)

2.3.2 通过 /sys/kernel/debug/ 目录确认 page_ownerr 是否开启
# ls -l /sys/kernel/debug/page_owner
-r--------. 1 root root 0 Apr 13 14:36 /sys/kernel/debug/page_owner

(补充:当 /sys/kernel/debug/page_owner 文件存在时则 page_owner 已经开启)

步骤三:分析 page_owner 产生的记录

3.1 导出 page_owner 产生的记录

# cat /sys/kernel/debug/page_owner > page_owner_full.txt

(补充:这里以将 page_owner 产生的记录导出到名为 page_owner_full.txt 文件为例)


注意:
1) 此命令会产生体积很巨大的文件
2) 此命令会持续执行直到手动取消
3) 可以通过同时按下 “ctrl” 键和 “C” 键或者使用 kill 命令取消
4) 如果内存变化较快则可以让此命令多执行一会,反之则可以少执行一会

3.2 解析 page_owner 产生的记录

# page_owner_sort page_owner_full.txt sorted_page_owner.txt
loaded 42903
sorting ....
culling

(补充:这里以分析名为 page_owner_full.txt 的文件并将分析结果导入到 sorted_page_owner.txt 文件为例)

3.3 查看 page_owner 产生的记录

# less sorted_page_owner.txt
1 times:
Page allocated via order 0, mask 0x0(), pid 1, tgid 1 (swapper/0), ts 48952109 ns, free_ts 0 ns
PFN 4096 type Unmovable Block 8 type Unmovable Flags 0xfffffc0000100(slab|node=0|zone=1|lastcpupid=0x1fffff)
 register_early_stack+0x28/0x60
 init_page_owner+0x30/0x2d0
 kernel_init_freeable+0x13c/0x232
 kernel_init+0xa/0x108

1 times:
Page allocated via order 0, mask 0x0(), pid 1, tgid 1 (swapper/0), ts 48952566 ns, free_ts 0 ns
PFN 4097 type Unmovable Block 8 type Unmovable Flags 0xfffffc0000100(slab|node=0|zone=1|lastcpupid=0x1fffff)
 register_early_stack+0x28/0x60
 init_page_owner+0x30/0x2d0
 kernel_init_freeable+0x13c/0x232
 kernel_init+0xa/0x108
......

(补充:这里以查看名为 sorted_page_owner.txt 文件里的分析结果为例)

步骤四:关闭 page_owner

4.1 开启 page_owner

# grubby --remove-args="page_owner=on" --update-kernel=0

(注意:关闭 page_owner 会额外释放一定量的内存)

4.2 重启系统

# reboot

4.3 确认 page_owner 已关闭

4.3.1 通过 dmesg 命令确认 page_owner 是否关闭
# dmesg | grep page_owner
[    2.022585] page_owner is disabled

(补充:当显示此类信息时则 page_owner 没有开启)

4.3.2 通过 /sys/kernel/debug/ 目录确认 page_ownerr 是否关闭
# ls -l /sys/kernel/debug/page_owner
ls: cannot access '/sys/kernel/debug/page_owner': No such file or directory

(补充:当 /sys/kernel/debug/page_owner 文件不存在时则 page_owner 没有开启)

参考文献:

https://access.redhat.com/solutions/5609521

[CONTENT] Linux maximum number of processes setting

Case One: Set the maximum number of processes for all users

# vim /etc/security/limits.conf

Add the following

......
* soft nofile 10240
* hard nofile 10240

(Add: Take maximum number of processes is 10240 for everyone as an example here)

Case Two: Set the maximum number of processes for one group

# vim /etc/security/limits.conf

Add the following

......
@mingyuzhu soft nofile 10240
@mingyuzhu hard nofile 10240

(Add: Take maximum number of processes is 10240 for group mingyuzhu as an example here)

Case Two: Set the maximum number of processes for one user

# vim /etc/security/limits.conf

Add the following

......
mingyuzhu soft nofile 10240
mingyuzhu hard nofile 10240

(Add: Take maximum number of processes is 10240 for user mingyuzhu as an example here)