码迷,mamicode.com
首页 > 其他好文 > 详细

开发脚本自动部署及监控

时间:2017-03-24 23:22:32      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:exports   ror   image   mount   发邮件   port   asa   server   res   

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监控脚本,并且给邮箱发邮件!!!

 

开发脚本自动部署及监控

标签:exports   ror   image   mount   发邮件   port   asa   server   res   

原文地址:http://www.cnblogs.com/xuzheng940806/p/6613642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!