环境背景
项目 | 值 |
---|---|
操作系统 | CentOS 7.9 |
KVM | Libvirt 4.5.0 |
问题现象
[root]# sudo -i
-bash: fork: Cannot allocate memory
-bash: fork: Cannot allocate memory
[root]# sysctl -p
-bash: fork: Cannot allocate memory
-bash: fork: Cannot allocate memory
[root]# hostname
-bash: fork: Cannot allocate memory
/usr/libexec/grepconf.sh: fork: Cannot allocate memory
-bash: fork: Cannot allocate memory
导致出现此问题的原因:
- 系统内存不足
- 内核总进程数(pid_max)达到上限
登录虚拟机宿主机查看,发现不是内存的问题,那么就是内核进程数(pid_max)的问题
[root]# virsh dominfo 7
Id: 7
Name: KVM_CONTAINER
UUID: KVM_UUID
OS Type: hvm
State: running
CPU(s): 8
CPU time: 22142591.8s
Max memory: 33554432 KiB
Used memory: 33554432 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0
[root]# virsh dommemstat 7
actual 33554432
swap_in 0
swap_out 0
major_fault 193
minor_fault 162918
unused 31765736
available 32779716
last_update 1626920535
rss 26484216
重启虚拟机
[root]# virsh reboot KVM_CONTAINER
系统重启后查看message日志
[root]# cat /var/log/message
Nov 23 10:21:41 192-168-5-68 systemd: Failed to fork: Cannot allocate memory
Nov 23 10:21:41 192-168-5-68 systemd: PROC_NAME.service failed to run 'start' task: Cannot allocate memory
Nov 23 10:21:41 192-168-5-68 systemd: Failed to start titanagent check exception.
Nov 23 10:21:41 192-168-5-68 systemd: Unit PROC_NAME.service entered failed state.
Nov 23 10:21:41 192-168-5-68 systemd: PROC_NAME.service failed.
Nov 23 10:24:41 192-168-5-68 systemd: Failed to fork: Cannot allocate memory
Nov 23 10:24:41 192-168-5-68 systemd: PROC_NAME.service failed to run 'start' task: Cannot allocate memory
Nov 23 10:24:41 192-168-5-68 systemd: Failed to start titanagent check exception.
Nov 23 10:24:41 192-168-5-68 systemd: PROC_NAME.service failed.
Nov 23 10:27:41 192-168-5-68 systemd: Failed to fork: Cannot allocate memory
Nov 23 10:27:41 192-168-5-68 systemd: PROC_NAME.service failed to run 'start' task: Cannot allocate memory
Nov 23 10:27:41 192-168-5-68 systemd: Failed to start titanagent check exception.
Nov 23 10:27:41 192-168-5-68 systemd: PROC_NAME.service failed.
Nov 23 10:30:41 192-168-5-68 systemd: Starting titanagent check exception...
Nov 23 10:30:41 192-168-5-68 bash: /bin/bash: fork: Cannot allocate memory
Nov 23 10:30:41 192-168-5-68 systemd: PROC_NAME.service: main process exited, code=exited, status=254/n/a
Nov 23 10:30:41 192-168-5-68 systemd: Failed to start titanagent check exception.
Nov 23 10:30:41 192-168-5-68 systemd: Unit PROC_NAME.service entered failed state.
Nov 23 10:30:41 192-168-5-68 systemd: PROC_NAME.service failed.
Nov 23 10:33:41 192-168-5-68 systemd: Starting titanagent check exception...
调整内核进程数(pid_max)
[root]# echo "kernel.pid_max = 65535" >> /etc/sysctl.conf
[root]# sysctl -p