在CentOS 6上安装Kdump

最近把扔在客厅的下载机从Ubuntu换成了centos,每天都会出现kernel panic,为了调试,我选择了Kdump来导出核心vmcore,在看了N多网上说的安装Kdump方法无果之后,果断GOOGLE搜索,终于找到一个可以用的方法。

一.安装kexec-tools

[root@CentOS ~]# yum install kexec-tools

二.添加 crashkernel=64M 在grub.conf中
vi /boot/grub/grub.conf

kernel /vmlinuz-2.6.32-279.14.1.el6.i686 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS rd_NO_MD rd_LVM_LV=VolGroup/lv_swap crashkernel=auto LANG=zh_CN.UTF-8 rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet crashkernel=64M

然后重启电脑,待重启后使用free -m会发现总内存比添加之前少了64M。

三.设置Kdump导出的vmcore保存位置。

[root@CentOS ~]# df
文件系统                 1K-块      已用      可用 已用% 挂载点
/dev/mapper/VolGroup-lv_root
                      51606140   1883516  47101184   4% /
tmpfs                   477572         0    477572   0% /dev/shm
/dev/sda1               495844     53469    416775  12% /boot
/dev/mapper/VolGroup-lv_home
                     1868714292 197403328 1576385756  12% /home

mkdir /var/crash
vi /etc/kdump.conf 添加

ext4 /dev/mapper/Volume00-var

四.启动Kdump服务。

[root@CentOS ~]# service kdump start
Starting kdump:                                            [确定]

五.测试Kdump运行

echo 1 > /proc/sys/kernel/sysrq
echo c > /proc/sysrq-trigger

这时系统会马上panic,重启后检查/var/crash 会发现目录中有类似于127.0.0.1-2012-12-17-21:53:58目录生成,则代表Kdump运行正常。

参考:http://linuxczar.net/archives/383

php从一组数字(字符)随机选择一个数字或者一串字符

转自:http://www.blogguy.cn/show-376-1.html

第一个函数: 随机选择一串数字或者字符中的一个。

function GetID(){         
 $characters = array("99","149","150","151","145","146","147","141","142","143","137","138","139","133","134","135","129","130","131","125","126","127","96","97","98","105","106","107","108","109","110","111","112","115","116","117","118","119","120","121","122","123","103","102","100","153","154","155");   
 shuffle($characters);   
 $ReqID = $characters[mt_rand(0, count($characters))];   
 return $ReqID;   
  }         
  
  $ReqID .= GetID();   
  
  echo $ReqID;    

第二个函数:指定字符,返回指定长度的随机串

function code($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {   
   $l=strlen($a)-1; $r='';   
   while($nc-->0) $r.=$a{mt_rand(0,$l)};   
   return $r;   
}   
echo(code(10));  

第三个函数:指定字符返回8位随机串

$acceptedChars = 'azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN0123456789';    
$max = strlen($acceptedChars)-1;   
$password = null;   
for($i=0; $i < 8; $i++) {    
 $password .= $acceptedChars{mt_rand(0, $max)};    
}   
echo $password."

";

第四个函数:指定字符,返回序列号格式的字符串

function GetID($x){         
  
    $characters = array("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "2", "3", "4", "5", "6", "7", "8", "9");   
    shuffle($characters);   
  
    for (; strlen($ReqID)<$x;){   
      $ReqID .= $characters[mt_rand(0, count($characters))];   
    }   
  
    return $ReqID;   
       
  }         
  
  
  $ReqID .= GetID(3);   
  $ReqID .= "-";   
  $ReqID .= GetID(4);   
  $ReqID .= "-";   
  $ReqID .= GetID(3);   
  
  echo $ReqID