一、配置允许生成的 core 文件数量

vim /etc/security/limits.conf
添加 * soft core 1024
# 表示允许生成的最大 core 数量为 1024

二、配置 core 文件名

# format the name of core file.   
# %% – 符号%
# %p – 进程号
# %u – 进程用户id
# %g – 进程用户组id
# %s – 生成core文件时收到的信号
# %t – 生成core文件的时间戳(seconds since 0:00h, 1 Jan 1970)
# %h – 主机名
# %e – 程序文件名

echo -e "core-%p-%t" > /proc/sys/kernel/core_pattern

# or run the following command
# sysctl -w kernel.core_pattern=/corefile/core-%p-%t

# 注意: 这个配置重启机器后,会失效。需要重新设置或者采用永久配置生效方法

三、 配置 core 使用 pid (此步骤可不配置)

echo -e "1" > /proc/sys/kernel/core_uses_pid

# or run the following command
# sysctl -w kernel.core_uses_pid=1 kernel.core_uses_pid = 1

四、systemd 生成 core file

[Service]
# .................
# LimitCORE 表示允许生成 core 的最大数量
LimitCORE=infinity
LimitNOFILE=65535
LimitNPROC=65535

五、 references

https://linux-audit.com/understand-and-configure-core-dumps-work-on-linux/