注册
【与达梦同行】数据库coredump的配置方式与截断测试
技术分享/ 文章详情 /

【与达梦同行】数据库coredump的配置方式与截断测试

卖女孩的小废柴 2022/12/07 2508 6 1

一、简述

  1. Core的意思是内存, Dump的意思是扔出来, 堆出来.开发和使用Unix程序时, 有时程序莫名其妙的down了, 却没有任何的提示(有时候会提示core dumped). 这时候可以查看一下有没有形如core.进程号的文件生成。
  2. 在国产操作系统麒麟V10中运维的时候,经常遇见一个问题,那就是core文件生成不完整或者core文件不知道生成在哪里。

二、查看/配置core生成大小

1. 临时设置core文件

  1. 查看生成core文件的开关是否开启;
[root@VM-0-17-centos bin]# ulimit -a

说明:第一行core文件大小为0,没有开启。
image.png

2.使用#ulimit -c [kbytes]可以设置系统允许生成的core文件大小;

ulimit -c 0 不产生core文件 ulimit -c 100 设置core文件最大为100k ulimit -c unlimited 不限制core文件大小 [root@VM-0-17-centos bin]# ulimit -c unlimited ##查看配置 [root@VM-0-17-centos bin]# ulimit -a

image.png

2. 永久设置core文件

修改/etc/profile文件添加参数;

1. 在profile文件中加入ulimit -c unlimited [root@VM-0-17-centos bin]# vim /etc/profile ulimit -c unlimited [root@VM-0-17-centos bin]# source /etc/profile

三、查看/配置core生成路径

1. 查看core的文件扩展名以及生成目录

查看core的文件扩展名

  • 1:添加pid作为扩展名,生成的core文件名称为core.pid
  • 0:不添加pid作为扩展名,生成的core文件名称为core
[root@VM-0-17-centos bin]# cat /proc/sys/kernel/core_uses_pid 0 -- 修改 /proc/sys/kernel/core_uses_pid 文件内容为: 1 有下面的两种方式 随便选一种 [root@VM-0-17-centos bin]# echo "1" > /proc/sys/kernel/core_uses_pid [root@VM-0-17-centos bin]# sysctl -w kernel.core_uses_pid=1 kernel.core_uses_pid = 1

查看core的生成目录

-- 查看core文件的存在位置: [root@VM-0-17-centos bin]# cat /proc/sys/kernel/core_pattern core

基本两种情况

  • 值为core:则表示core文件默认的存储位置与对应的可执行程序在同一目录下,文件名是core开头的文件
  • 值为/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h,则coredump的目录在/var/lib/systemd/coredump/下,并且是以压缩的方式进行存储一般时lz4结尾的文件

2. 修改core的文件扩展名以及生成目录

-- core文件统一生成指定到/corefile目录下,产生的文件名为core-命令名-pid-时间戳 [root@VM-0-17-centos bin]# mkdir /corefile [root@VM-0-17-centos bin]# vi /etc/sysctl.conf kernel.core_uses_pid = 1 kernel.core_pattern=/corefile/core-%e-%p [root@VM-0-17-centos bin]# sysctl -p /etc/sysctl.conf 以下是参数列表: %p - insert pid into filename 添加pid(进程id) %u - insert current uid into filename 添加当前uid(用户id) %g - insert current gid into filename 添加当前gid(用户组id) %s - insert signal that caused the coredump into the filename 添加导致产生core的信号 %t - insert UNIX time that the coredump occurred into filename 添加core文件生成时的unix时间 %h - insert hostname where the coredump happened into filename 添加主机名 %e - insert coredumping executable name into filename 添加导致产生core的命令名

四、(防core截断)调整coredump.conf设置大小

## 1. 修改 /etc/systemd/coredump.conf 设置 ProcessSizeMax ExternalSizeMax 参数值 ## 2. 建议值比数据库使用总内存量大,即大于top命令下的dmserver的virt值 ##1.修改配置文件 [root@kylin ~]# vi /etc/systemd/coredump.conf [Coredump] #Storage=external #Compress=yes ProcessSizeMax=2G # 需大于top命令下的dmserver的virt值 ExternalSizeMax=2G # 需大于top命令下的dmserver的virt值 #JournalSizeMax=767M #MaxUse= #KeepFree= ##2.重启coredump进程 ##重新读取配置文件 [root@kylin ~]# systemctl daemon-reload ##重启进程 [root@kylin ~]# systemctl restart systemd-coredump.socket ##注意如曾经修改过/etc/sysctl.conf文件中core文件的生成路径的话,需要将core文件的路径还原为默认路径即做如下修改后,再修改coredump参数 [root@VM-0-17-centos bin]# echo "|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h">proc/sys/kernel/core_pattern [root@VM-0-17-centos bin]# echo "1">/proc/sys/kernel/core_uses_pid [root@VM-0-17-centos bin]# sysctl -p /etc/sysctl.conf

image.png

五、测试core生成

新建test.c文件

#include<stdio.h> void test(){ int *p = NULL; *p = 0; } int main() { test(); return 0; }
  1. 编译文件
[root@VM-24-17-centos bin]# vim test.c [root@VM-24-17-centos bin]# gcc -o test1 test.c [root@VM-24-17-centos bin]# ./test 1 段错误 (核心已转储) [root@VM-24-17-centos bin]# ll /corefile/* -rw------- 1 root root 249856 12月 7 19:20 /corefile/core-test1-2291735-1650281826

六、core截断测试(大于200G)

1. 编写core_main.c

#include <stdio.h> #include <stdlib.h> #include <string.h> int *fun() { int *p=(int*)malloc(1024 * 1024 * 500);//动态申请空间 memset(p, 0, 1024 * 1024 * 500); return p;//返回动态申请的空间是可以的. } int main(int argc, char *argv[]) { int create_num; if(argc == 2){ create_num=atoi(argv[1])*2; printf("coredump Generate Size is %dG \n",create_num/2); }else{ create_num=5; printf("coredump Generate Size is 2.5G by default\n"); } char *arr[create_num]; int i =0; for(i =0;i<create_num;i++){ arr[i]=(char *)malloc(1024 * 1024 * 512); memset(arr[i], 0, 1024 * 1024 * 512); // int *p_t = (int*)malloc(1024 * 1024 * 500); // memset(arr[i], 0, 1024 * 1024 * 500); // arr[i]= (char *)fun(); // printf("create_num is %d \n",create_num); // printf("num is %d \n",i); if(i>=create_num-1){ printf("Generating coredump, please wait\n"); int *core_p1 =NULL; *core_p1=0; } } printf("end end \n"); return 0; }

2. 编写make.sh

#!/bin/bash rm -rf coremain rm -rf ./core.* gcc -g -o ./coremain core_main.c #$1的值 =1,则表示生成1G的core文件,以此类推 if [ ! $1 ]; then ./coremain else ./coremain $1 fi

3.进行截断测试

##使用步骤: ##1. 将core_main.c与make.sh放到同级目录 ##2. 给make.sh脚本赋权限 [dmdba@localhost ~]$ chmod 755 make.sh ##3. 执行脚本生成core ## 3.1 不指定生成core的大小,则默认是2.5g [dmdba@localhost ~]$ ./make.sh ## 3.2 指定生成core的大小,后面跟参数即可, 210则表示生成的core文件为210G [dmdba@localhost ~]$ ./make.sh 210 ## 进行截断查看是否完整

生成core的时候会在操作系统的日志中有明显提示。需要注意查看操作系统有没有问题,如下图
image.png

评论
后发表回复

作者

文章

阅读量

获赞

扫一扫
联系客服