Linux 如何在centos中为守护进程生成核心转储?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3937434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to generate core dumps for daemon processes in centos?
提问by istudy0
I have some daemon processes that crashes every now and then and I want to know how I can enable core dump generations. I know that by default on linux ulimit for core dumps is zero so I need to set it to unlimited if I want to see core dumps for processes that I am running. But what I want to do is to generate core dumps for daemon processes that are running under root account. Can anyone advise me how to configure the system? Thank you in advance.
我有一些守护进程时不时崩溃,我想知道如何启用核心转储代。我知道默认情况下,Linux 上的核心转储 ulimit 为零,因此如果我想查看正在运行的进程的核心转储,我需要将其设置为无限制。但我想要做的是为在 root 帐户下运行的守护进程生成核心转储。谁能告诉我如何配置系统?先感谢您。
采纳答案by Michael Goldshteyn
I believe something like:
我相信这样的事情:
ulimit -c unlimited
... or some value will allow what you to create those dumps. Also, you may want to check out the following web pages for more details: how to enable coreand Linux FAQ
...或某些值将允许您创建这些转储。此外,您可能需要查看以下网页以获取更多详细信息:how to enable coreand Linux FAQ
回答by harmic
I know, it's a years-old question, but it came up for me on a google search and the accepted answer is incomplete (for Centos at least).
我知道,这是一个多年以前的问题,但我在谷歌搜索中找到了它,并且接受的答案不完整(至少对于 Centos)。
For RHEL derived systems, most daemons have an init script which sources a file called:
对于 RHEL 派生系统,大多数守护进程都有一个 init 脚本,该脚本提供一个名为:
/etc/sysconfig/{daemon_name}
For example, for apache it is:
例如,对于 apache,它是:
/etc/sysconfig/httpd
Environment variables within these files are read by the init script during daemon startup, and these variables are used to configure the environment in which the daemon is running.
这些文件中的环境变量在守护进程启动期间由init脚本读取,这些变量用于配置守护进程运行的环境。
To enable core dumps, add the following line:
要启用核心转储,请添加以下行:
export DAEMON_COREFILE_LIMIT='unlimited'
Restart the daemon after editing this file.
编辑此文件后重新启动守护程序。
The other thing you may need to do is change the kernel core dump filename template. By default, core dumps will be produced in the current working directory and have the name 'core'. This is not so useful since they will overwrite one another, and also in the case of a daemon it's working directory may be (a) unknown (b) not writable. To change it:
您可能需要做的另一件事是更改内核核心转储文件名模板。默认情况下,核心转储将在当前工作目录中生成并具有名称“核心”。这不是很有用,因为它们会相互覆盖,而且在守护进程的情况下,它的工作目录可能是 (a) 未知 (b) 不可写。要改变它:
sysctl -w kernel.core_pattern=/tmp/core_%e_%p
That setting is my recommendation, you can alter both the path to the directory being used and also the pattern. The above pattern will contain the executable name and pid.
该设置是我的建议,您可以更改正在使用的目录的路径以及模式。上面的模式将包含可执行文件名称和 pid。
To set it more permanently, edit the file /etc/sysctl.conf
and insert:
要更永久地设置它,请编辑文件/etc/sysctl.conf
并插入:
kernel.core_pattern=/tmp/core_%e_%p