Debian10 OOM(Out of Memory)异常以及 supervisor修改相关系统限制

1.查看当前系统文件描述符限制

默认情况

root@bzdtech:~# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 255186
max locked memory       (kbytes, -l) 65536
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 255186
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

2.编辑系统限制文件

nano /etc/security/limits.conf

3.在文件末尾添加

root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535

4.重新查看系统限制

 5.修改supervisor 的文件描述符与进程开启限制

nano /etc/supervisor/supervisord.conf

6.在下图位置添加minfds和minprocs

注:

minfds:最小打开的文件描述符数量

minprocs:supervisor管理的进程能开启的最小子进程数量

参考链接:https://supervisord.org/configuration.html#supervisord-section-settings

 7.重新启动

reboot

8.重新查看系统限制信息

root@bzdtech:~# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 255186
max locked memory       (kbytes, -l) 65536
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 255186
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

9.top查看运行程序PID

root@bzdtech:~# top

top - 16:14:12 up 20 min, 1 user, load average: 0.02, 0.02, 0.00
Tasks: 262 total, 1 running, 261 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.1 us, 0.1 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.2 si, 0.0 st
MiB Mem : 64002.2 total, 62594.6 free, 1161.9 used, 245.7 buff/cache
MiB Swap: 977.0 total, 977.0 free, 0.0 used. 62259.8 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
856 root 20 0 3165912 98848 32804 S 0.7 0.2 0:08.98 taosadapter
873 root 20 0 2077296 221780 7516 S 0.7 0.3 0:08.04 taosd
904 mysql 20 0 2342240 402344 36772 S 0.7 0.6 0:06.86 mysqld
11 root 20 0 0 0 0 I 0.3 0.0 0:03.15 rcu_sched
905 redis 20 0 64252 12036 3560 S 0.3 0.0 0:03.77 redis-server
1092 root 20 0 106444 29772 4124 S 0.3 0.0 0:03.07 opcuaserver
1093 root 20 0 6436 3920 3124 S 0.3 0.0 0:02.63 Server
8453 root 20 0 11612 3904 3148 R 0.3 0.0 0:00.04 top
1 root 20 0 19788 9944 7852 S 0.0 0.0 0:02.04 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-events_highpri
8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:1H-kblockd
9 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
12 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_bh
13 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
14 root 20 0 0 0 0 I 0.0 0.0 0:00.97 kworker/0:1-events
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0
16 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/1
17 root rt 0 0 0 0 S 0.0 0.0 0:00.75 migration/1
18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/1
19 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/1:0-mm_percpu_wq
20 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/1:0H-events_highpri
21 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/2
22 root rt 0 0 0 0 S 0.0 0.0 0:00.75 migration/2
23 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/2
24 root 20 0 0 0 0 I 0.0 0.0 0:00.02 kworker/2:0-mm_percpu_wq
25 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/2:0H-events_highpri
26 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/3
27 root rt 0 0 0 0 S 0.0 0.0 0:00.75 migration/3
28 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/3
29 root 20 0 0 0 0 I 0.0 0.0 0:00.01 kworker/3:0-events_power_efficient
30 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/3:0H-events_highpri
31 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/4
32 root rt 0 0 0 0 S 0.0 0.0 0:00.75 migration/4
33 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/4
34 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/4:0-events
35 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/4:0H-events_highpri
36 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/5
37 root rt 0 0 0 0 S 0.0 0.0 0:00.76 migration/5
38 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/5
39 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/5:0-mm_percpu_wq
40 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/5:0H-events_highpri
41 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/6
42 root rt 0 0 0 0 S 0.0 0.0 0:00.76 migration/6
43 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/6
44 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/6:0-mm_percpu_wq
45 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/6:0H-events_highpri
46 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/7

10.选择一个想要查看的进程PID 查看限制情况

比如要查看 PID:1092的进程

查看/proc/<PID>/limits 文件

root@bzdtech:~# cat /proc/1092/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             255186               255186               processes
Max open files            81920                524288               files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       255186               255186               signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

 

posted @ 2025-01-08 16:20  BlackSnow  阅读(54)  评论(0)    收藏  举报