欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > ce第六次作业

ce第六次作业

2025/9/25 22:26:56 来源:https://blog.csdn.net/2301_81928712/article/details/144700422  浏览:    关键词:ce第六次作业

1、判断当前磁盘剩余空间是否有20G,如果小于20G,则将报警邮件发送给管理员,每天检查一次磁盘剩余空间。

[root@Server ~]# yum install -y mailx
[root@Server ~]# yum -y install bind-utils
[root@Server ~]# vim /etc/mail.rc
set from=15339232034@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=15339232034@163.com
set smtp-auth-password=PVw7kZuYqpjYij3E
set smtp-auth-login[root@Server ~]# vim remaining_disks.sh
#/bin/bash
remaining_disks=$(df -h | grep "\/$" | cut -d" " -f4 | cut -d"G" -f1)
msg="当前磁盘空间小于20g,请及时处理"
if [ ${remaining_disks} -lt 20 ]
thenecho $msg | mail -s "内存报警" 15339232034@163.com
fi[root@Server ~]# crontab -l
0 0 * * * /usr/bin/sh /root/remaining_disks.sh


​ 2、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。

[root@Server ~]# vim nginx_process.sh
#/bin/bash
pro=$(netstat -lntup |grep -w 80 |wc -l)
if [ $pro -gt 0 ]
thenecho "the nginx services is running"
elseecho "the nginx services is not running"systemctl start nginxsystemctl start firewalldfirewall-cmd --permanent --zone=public --add-port=80/tcp &>/dev/nullfirewall-cmd --permanent --zone=public --add-service=http &> /dev/nullfirewall-cmd --reload &>/dev/nullecho "nginx is already running"
fi[root@Server ~]# vim nginx_process2.sh 
#!/bin/bash
pro=$(netstat -lntup | grep -w 80 | wc -l)
if [ $pro -gt 0 ]
thenecho "nginx is running"
elseecho"nginx is not running"systemctl start nginxsystemctl start firewalldfirewall-cmd --permanent --zone=public --add-service=http &>/dev/nullfirewall-cmd --permanent --zone=public --add-port=80/tcp &>/dev/null
fi[root@Server ~]# systemctl stop nginx

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词