【Greenplum避坑指南 III 】如何在服务器上启用core generation?

在程序异常或者崩溃时,cores对于debugging非常有用。我们推荐大家在master和segment服务器上启用core generation。本文将详细描述如何在linux系统上开启这项设置。

在操作之前,我们首先确认一下服务器上和core文件相关的当前设置。你可以使用以下命令来确认core generation是否已经被禁用。以下内容表示有效禁用了core file generation。 (core文件的大小被限制为了0, 即禁用)

gpadmin$ ulimit -a
core file size (blocks, -c) 0

下面的两个步骤将启用core file generation:

1.允许系统生成任意大小的core文件

以root用户打开 /etc/security/limits.d/corefiles.conf 文件(你可能需要创建一个全新的文件)并输入以下命令

# Core file size set to unlimited
 gpadmin - core unlimited

保存文件并以gpadmin用户身份登录,并确认soft与hard limit均设置为无限制(unlimited):

 [root@hdp1 ~]# su - gpadmin
 [gpadmin@hdp1 ~]$ ulimit -S -c
 unlimited
 [gpadmin@hdp1 ~]$ ulimit -H -c
 unlimited

2. 定义core file的命名约定和位置

以root用户打开文件/etc/sysctl.d/cores_sysctl.conf并添加以下行(以下以RHEL操作系统举例)

kernel.core_uses_pid = 1
kernel.core_pattern = /<directory>/core-%e-%s-%u-%g-%p-%t {Choose the directory where you want to place the core files, their size may range in GB's, so choose it appropriately}

where:
kernel.core_uses_pid = 1 - Appends the coring processes PID to the core file name.
kernel.core_pattern = /<directory>/core-%e-%s-%u-%g-%p-%t - When the application terminates abnormally, a core file should appear in the /tmp. The kernel.core_pattern sysctl controls exact location of core file. You can define the core file name with the following template whih can contain % specifiers which are substituted by the following values when a core file is created:
 %% - A single % character
 %p - PID of dumped process
 %u - real UID of dumped process
 %g - real GID of dumped process
 %s - number of signal causing dump
 %t - time of dump (seconds since 0:00h, 1 Jan 1970)
 %h - hostname (same as ’nodename’ returned by uname(2))
 %e - executable filename

确保您选择的位置具有权限1777。否则,gpadmin将无法写入核心文件。

3. 加载上面添加的位置

使用以下命令加载配置文件:

[root@hdp1 ~]# sysctl -p /etc/sysctl.d/cores_sysctl.conf
 kernel.core_uses_pid = 1
 kernel.core_pattern = /var/crash/user/core-%e-%s-%u-%g-%p-%t
 [root@hdp1 ~]# 

4. 验证

使用以下命令验证配置是否已经生效:

[root@hdp1 ~]# sysctl kernel.core_pattern
kernel.core_pattern = /var/crash/user/core-%e-%s-%u-%g-%p-%t
[root@hdp1 ~]# sysctl kernel.core_uses_pid
kernel.core_uses_pid = 1

注意:Greenplum数据库需要重新启动,以确保这些更改有效。另外, 在操作系统上, 还需要重新登录一次以确保当前会话获取配置中的更改。

重新启动Greenplum后,此命令将有助于验证Greenplum 进程的运行限制:

cat /proc/$(pgrep -f silent)/limits

大家在使用过程中遇到问题,欢迎前往ask.greenplum.cn提问。

关注微信公众号

VMware 中国研发中心