开发脚本自动部署及监控
Posted 征丶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发脚本自动部署及监控相关的知识,希望对你有一定的参考价值。
1.编写脚本自动部署反向代理、web、nfs;
#!/bin/bash yum install epel-release -y yum install nginx -y ps aux |grep nginx |grep -v \'grep\' if [ $? -ne 0 ] then systemctl start nginx fi sed -ri \'/^http/a upstream xzhweb\\{\' /etc/nginx/nginx.conf sed -ri \'/^upstream/a server 192.168.16.99 weight=3;\' /etc/nginx/nginx.conf sed -ri \'/^upstream/a least_conn; \' /etc/nginx/nginx.conf sed -ri \'/^server/a }; \' /etc/nginx/nginx.conf sed -ri \'/^server/a server 192.168.16.175;\' /etc/nginx/nginx.conf sed -ri \'/^\\ +location \\/ /a proxy_pass http://xzhweb;\' /etc/nginx/nginx.conf systemctl stop firewalld setenforce 0 systemctl restart nginx if [ $? -ne 0 ] then echo wellcome to congratulation fi yum install rpcbind nfs-utils -y mkdir /share touch /share/share.txt echo xuzheng666 > /share/share.txt echo /share 192.168.16.0/24(rw,sync,fsid=0) > /etc/exports chmod -R o+w /share systemctl enable nfs-server.service systemctl enable rpcbind.service systemctl start rpcbind.service systemctl start nfs-server.service mount -t nfs 192.168.16.176:/share /var/www/html
2.编写监控脚本,监控集群内所有服务存活状态,内存、磁盘剩余率检测,异常则发送报警邮件
#!/bin/bash ps aux |grep nginx |grep -v \'grep\' if [ $? -ne 0 ] then wasai="TIME:$(date +%F_%T) HOSTNAME:$(hostname) IPADDR:$(ifconfig |awk \'NR==2{print $2}\') WASAI:Nginx application error!" echo $wasai /usr/bin/my_mail $wasai fi ps aux |grep nfs |grep -v \'grep\' if [ $? -ne 0 ] then wasai="TIME:$(date +%F_%T) HOSTNAME:$(hostname) IPADDR:$(ifconfig |awk \'NR==2{print $2}\') WASAI:Nfs application error!" echo $wasai /usr/bin/my_mail $wasai fi mem_used=`free | awk \'NR==2{print $3}\'` mem_total=`free | awk \'NR==2{print $2}\'` y=$(($mem_total - $mem_used)) x=`expr "scale=2; $y/$mem_total" |bc -l |cut -d. -f2` if ((x<100)) then wasai="TIME:$(date +%F_%T) HOSTNAME:$(hostname) IPADDR:$(ifconfig |awk \'NR==2{print $2}\') WASAI:Memory usage exceeds the limit,current value is $x%" echo $wasai /usr/bin/my_mail $wasai fi
3.编写计划任务,定时运行监控脚本,完成监控操作
每五分钟运行24-1.sh监控脚本,并且给邮箱发邮件!!!
以上是关于开发脚本自动部署及监控的主要内容,如果未能解决你的问题,请参考以下文章