1.编写脚本自动部署反向代理、web、nfs;

要求: 

I、部署nginx反向代理三个web服务,调度算法使用加权轮询;

#!/bin/shngxStatus=`ps aux | grep -v grep |grep -c nginx`function ngxProxyInstall() {
if [ -e /usr/sbin/nginx ];thenecho "nginx already installed"exit 110
elseyum install epel-release -y -qyum install gcc-* glibc-* openssl openssl-devel pcre pcre-devel zlib zlib-devel -y -qyum install nginx -y -qecho "install nginx successful"
fi
if [ -f /etc/nginx/nginx.conf ];then/bin/cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.baksed -ri '/^http/a\\t upstream luchuangao { \n\t server 192.168.152.135 weight=3;\n\t server 192.168.152.136;\n\t server 192.168.152.137;\n\t }' /etc/nginx/nginx.confsed -ri '/^ *location \/ \{/a\\t\t proxy_pass http://luchuangao;' /etc/nginx/nginx.confecho "Configuration successful"
fi
if [ $ngxStatus -lt 2 ];thensystemctl start nginxecho "Start nginx successful"
fi
}function nfsInstall() {
if [ -e /usr/sbin/rpcinfo ];thenecho "nfs already installed"exit 111
elseyum install rpcbind nfs-utils -y -qecho "install NFS successful"
fiif [ ! -d /share ];thenmkdir -p /sharechmod -R o+w /share
fi
echo '/share 192.168.152.0/24(rw,sync,fsid=0)' > /etc/exports
systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl start rpcbind.service
systemctl start nfs-server.service
echo "Start NFS successful"
}ngxProxyInstall
nfsInstall

II、所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性;

#!/bin/shngxStatus=`ps aux | grep -v grep |grep -c nginx`
ipAddress="192.168.152.134"function ngxWebInstall(){
if [ -e /usr/sbin/nginx ];thenecho "nginx already installed"exit 110
else#yum install gcc-* glibc-* openssl openssl-devel pcre pcre-devel zlib zlib-devel -y -qyum install nginx -y -qecho "install nginx successful"
fi
if [ -f /etc/nginx/nginx.conf ];then/bin/cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.baksed  -ri '/^ *location \/ \{/a\\t\t root /data/www/html;\n\t\t index index.html;' /etc/nginx/nginx.confmkdir -p /data/www/htmlecho `hostname` > /data/www/html/index.htmlecho "Configuration successful"
fi
if [ $ngxStatus -lt 2 ];thensystemctl start nginxecho "Start nginx successful"
fi
}function nfsInstall(){
if [ ! -e /usr/sbin/rpcinfo ];thenyum install rpcbind nfs-utils -y -qecho "install NFS successful"
fi
systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl start rpcbind.service
systemctl start nfs-server.service
mount -t nfs $ipAddress:/share /data/www/html/
echo "welcome luchuangao" > /data/www/html/test.html
}ngxWebInstall
nfsInstall

2.编写监控脚本,监控集群内 Nginx、NFS 服务存活状态,内存、磁盘剩余率检测,异常则发送报警邮件

步骤一:准备发送邮件的工具

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import smtplib
import email.mime.multipart
import email.mime.textserver = 'smtp.163.com'
port = '25'def sendmail(server,port,user,pwd,msg):smtp = smtplib.SMTP()smtp.connect(server,port)smtp.login(user, pwd)smtp.sendmail(msg['from'], msg['to'], msg.as_string())smtp.quit()print('邮件发送成功email has send out !')if __name__ == '__main__':msg = email.mime.multipart.MIMEMultipart()msg['Subject'] = '你是风儿我是沙,缠缠绵绵回我家'msg['From'] = 'python4_mail@163.com'msg['To'] = 'python4_recvmail@163.com'user = 'python4_mail'pwd = 'sbalex3714'content='%s\n%s' %('\n'.join(sys.argv[1:4]),' '.join(sys.argv[4:])) #格式处理,专门针对我们的邮件格式txt = email.mime.text.MIMEText(content, _charset='utf-8')msg.attach(txt)

步骤二:将上述文件内容拷贝到/usr/bin/my_mail并chmod+x /usr/bin/my_mail

步骤三:然后新建监控脚本sysCheck.sh

#!/bin/shfunction ngxMonitor(){  #监控nginx服务
ps aux | grep nginx| grep -v grep &>/dev/null
if [ $? -ne 0 ];thenmsg="TIME:$(date +%F_%T)HOSTNAME:$(hostname)IPADDR:$(/usr/sbin/ifconfig |awk 'NR==2{print $2}')MSG:Nginx program is crash, Waiting to restart"echo $msg/usr/bin/my_mail $msgsystemctl restart nginx
fi
}function nfsMonitor(){ #监控nfs服务
ps aux | grep nfs| grep -v grep &>/dev/null
if [ $? -ne 0 ];thenmsg="TIME:$(date +%F_%T)HOSTNAME:$(hostname)IPADDR:$(/usr/sbin/ifconfig |awk 'NR==2{print $2}')MSG:NFS program is crash, Waiting to restart"echo $msg/usr/bin/my_mail $msgsystemctl restart nginx
fi
}function memMonitor(){  #监控内存
mem_use=`free | awk 'NR==2{print $3}'`
mem_total=`free | awk 'NR==2{print $2}'`
mem_per=`echo "scale=2;$mem_use/$mem_total"|bc -l |cut -d . -f2`if [ ! -e /usr/bin/bc ];thenyum install bc -y -qecho "bc install successful"
fi
if (( $mem_per > 10 )); thenmsg="TIME:$(date +%F_%T)HOSTNAME:$(hostname)IPADDR:$(/usr/sbin/ifconfig |awk 'NR==2{print $2}')MSG:Memory usage exceeds the limit,current value is ${mem_per}%"echo $msg/usr/bin/my_mail $msg
fi
}function diskMonitor(){  #监控磁盘
space_use=`df $disk |awk 'NR==2{print $5}'|cut -d% -f1`if [ $space_use -gt 80 ];thenmsg="TIME:$(date +%F_%T)HOSTNAME:$(hostname)IPADDR:$(/usr/sbin/ifconfig |awk 'NR==2{print $2}')MSG:Disk space usage exceeds the limit,current value is ${space_use}%"echo $msg/usr/bin/my_mail $msg
fi
}ngxMonitor  &>>/tmp/monitor.log
nfsMonitor  &>>/tmp/monitor.log
memMonitor  &>>/tmp/monitor.log
diskMonitor &>>/tmp/monitor.log

3.编写计划任务,定时运行监控脚本,完成监控操作

* * * * * /shell/sysCheck.sh

参考链接:http://www.cnblogs.com/linhaifeng/p/6602149.html

参考链接:http://www.cnblogs.com/linhaifeng/articles/6045600.html#_label21

转载于:https://www.cnblogs.com/luchuangao/p/6612304.html

开发脚本自动部署及监控相关推荐

  1. 刚设计的自动部署产品监控框架【图】

    刚设计的自动部署产品监控框架[图]

  2. 编写脚本自动部署反向代理、web、nfs

    服务器端 #!/bin/bashfunction nginx_install(){if [[ -f /usr/sbin/nginx ]]; thenecho 'Nginx has been insta ...

  3. java 实现自动生成部署文档_jenkins的部署、实现自动拉取gitlab仓库代码、实现项目中代码自动部署以及项目关联触发......

    jenkins主机内存和gitlab主机内存最好配置4G及以上,防止各自的web端打不开 1.配置JDK环境 1)jdk解压到此目录 [root@localhost src]# pwd /usr/lo ...

  4. 利用Git搭建自动部署的Laravel环境

    目标:服务器上搭建Laravel环境,本地使用IDE进行开发,使用Homestead做本地调试环境,代码提交后自动部署到服务器Root目录下. 下面是整个流程的示意图: 1. 准备工作,搭建LNMP环 ...

  5. zabbix_agent自动部署安装

    一.先编译个zabbix_zgent 1.下载安装zabbix wget "http://sourceforge.net/projects/zabbix/files/ZABBIX%20Lat ...

  6. github仓库项目自动部署到阿里云

    原文链接 前言 我的博客之前一直是手动更新的,需要自己打包,然后上传到网站.但是项目已经托管在github了,所以何不搞个自动部署呢? 想象一下,网站有修改之后,git push之后等几分钟,网站就自 ...

  7. 使用github提供的webhook服务完成自动部署网站

    Cover 前言 我的博客之前一直是手动更新的,需要自己打包,然后上传到网站.但是项目已经托管在github了,所以何不搞个自动部署呢? 想象一下,网站有修改之后,git push之后等几分钟,网站就 ...

  8. Lvs别样的自动部署监控shell脚本

    Lvs别样的自动部署监控shell脚本   l 脚本功能: l 实验环境图: l 具体脚本: l 结果验证: l 参考资料: 先申明,本文现在已经在我公司的测试环境和生产测试环境使用.正式环境请用ke ...

  9. java自动部署脚本

    java自动部署脚本 背景 每次开发了新功能和修复了bug上线前都需要打包上传到服务端运行 偶尔来几次还行 次次都这样就烦人了 今天终于忍无可忍 无需在忍 写了个脚本一键打包上传部署 实现思路 通过m ...

最新文章

  1. HDU 2080 夹角有多大II
  2. linux下mysql授权_linux下mysql命令(用户授权、数据导入导出)
  3. 利用三层交换机实现VLAN间路由
  4. 如何从字符串中删除最后一个字符?
  5. 关于Latex一个简单例子
  6. javascript (function(){})()
  7. console线驱动安装_文通证件识别SDK和驱动安装使用说明
  8. Java对二维数组排序
  9. algorithm头文件中的函数:remove()与remove_if() 函数,……
  10. 软件工程需求分析方法
  11. Json转换成excel 离线版
  12. iOS 9 真机调试
  13. PERT图之事件、活动、松弛时间、关键路径
  14. Spring Cloud Gateway 服务网关的部署与使用详细介绍
  15. 如何在google隐藏页面_如何在Google文档中隐藏或删除评论
  16. IE浏览器缓存第二次请求的解决方案
  17. Java计算机毕业设计水果购物商城源码+系统+数据库+lw文档
  18. html pdf支持css%写法吗,flying-saucer-pdf终于完美解决了(中文问题,换行问题,分页,页眉页脚,水印),html+css控制pdf样式...
  19. ios版本与xcode版本
  20. 学习型组织和自我优化型组织

热门文章

  1. 「学习笔记-Linux」学习Shell Script
  2. ios4.2文件夹及多任务
  3. 《资安人》:迈向成功SOC之路
  4. 简单的分级别写日志程序
  5. 如何连接本地mysql+设置无密码登录
  6. leetcode--删除排序数组中的重复项--python
  7. Servlet防止页面被客户端缓存
  8. 这些资源网站为什么能获得5万知乎大佬推荐,而我错失了什么吗?
  9. Java 学习(20)--异常 /  IO 流
  10. 学习Mybatis与mysql数据库的示例笔记