芭比哇玩123 发表于 2017-6-12 17:15:28

linux 磁盘满了后的处理

昨天早上遇到的,之前因为几个类似井喷的事件才出现,本来也是打算做手动清除的。
硬盘问题会导致服务器dump. 一般会在本地备份一份,也会在服务器上备份,服务器的最好备份在单独1个服务器里,不占用产品的磁盘空间.本地的就没办法了.
当然磁盘空间不足有好几个原因,目前确定是塞满了.
使用df -hl可以查看到服务器硬盘的情况,当然现在是已经正常了。
https://testerhome.com/photo/2015/e5ecac0e2754402050d1ffb3e681eb2c.png
使用du –bs +路径 具体查看目录,看看恢复后的
我们是db s4区出了问题,然后du –bs /data/xxx/s4/logs
https://testerhome.com/photo/2015/132c016ca7de613cb81c9aabdb2c71ff.png
如果能用软件监控是最好的(一般运维用),如果身为测试想自己动手,可以用下面的那个脚本.供参考
#!/bin/bash
#Dsize=95 超过脚本的阀值
partition_list=(`df -h | awk 'NF>3&&NR>1{sub(/%/,"",$(NF-1));print $NF,$(NF-1)}'`)
Dsize=95
notification_email()
{
    emailuser='user@domain.com'
    emailpasswd='password'
    emailsmtp='smtp.domain.com'
    sendto='user1@domain.com'
    title='Disk Space Alarm'
    /opt/sendEmail-v1.56/sendEmail -f $emailuser -t $sendto -s $emailsmtp -u $title -
xu $emailuser -xp $emailpasswd
}
crit_info=""
for (( i=0;i<${#partition_list[@]};i+=2 ))
do
    if [ "${partition_list[((i+1))]}" -lt "$Dsize" ];then
      echo "OK! ${partition_list} used ${partition_list[((i+1))]}%"
    else      
            if [ "${partition_list[((i+1))]}" -gt "$Dsize" ];then
                crit_info=$crit_info"Warning!!! ${partition_list} used
${partition_list[((i+1))]}%\n"
            fi
    fi
done
if [ "$crit_info" != "" ];then
    echo -e $crit_info | notification_email
fi1)上传脚本xxx.sh到/opt目录下 需要用root用户的权限
2)赋予可执行权限chmod 777 xxx.sh
3)下载邮件程序 sendEmail-v1.56
4)解压文件到/opt下面 tar xvf /opt/sendEmail-v1.56.tar.gz
5)测试脚本 磁盘填充或者修改Dsize变小。
6)然后设置计划,设置1个时间定期查询1次。
希望大家可以在工作中和TesterHome一起努力,一起进步。

搜索

jingzizx 发表于 2017-6-12 17:40:23

赞一个

Miss_love 发表于 2017-6-13 09:01:28

动手能力强
页: [1]
查看完整版本: linux 磁盘满了后的处理