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

#!/bin/bash
#检测安装nginx
function detection_nginx(){
if [ -f /etc/nginx/nginx.conf ]
then
echo 'nginx has been installed'
exit
else
then
yum install epel-release -y
yum install nginx -y
echo 'nginx successfully installed'
fi
} #改写配置文件
function rewrite_nginx_conf(){
msg='upstream my_upstream{ server 192.168.19.129;server 192.168.19.130;server 192.168.19.131}'
sed -ri "/^http/a $msg" /etc/nginx/nginx.conf #增加upstream
sed -ri "/^ *location \/ \{$/a proxy_pass http://my_upstream\;" /etc/nginx/nginx.conf #修改localtion
#重新加载nginx
systemctl reload nginx
} #检测安装nfs和rpcbind
function detection_nfs(){
if [ -d /var/lib/nfs ]
then
echo 'nfs has been installed'
exit
else
then
yum install rpcbind nfs-utils -y
echo 'rpcbind nfs-utils successfully installed'
fi
} function start_service(){
#创建共享目录
mkdir /share
#给用户增加写的权限
chmod -R o+w /share/
#改写nfs的配置文件
echo '/share 192.168.19.0/24(rw,sync,fsid=0)' >> /etc/exports
#启动服务
systemctl start rpcbind.server
systemctl start nfs-utils.server
#设置开机启动
systemctl enable nfs-server.service
systemctl enable rpcbind.service
} detection_nginx #执行检测安装nginx函数
rewrite_nginx_conf #执行改写nginx.conf函数
detection_nfs #执行检测安装nfs函数
start_service #执行启动服务函数

服务端 Code

#!/bin/bash
#检测安装nginx
function detection_nginx(){
if [ -f /etc/nginx/nginx.conf ]
then
echo 'nginx has been installed'
exit
else
then
yum install epel-release -y
yum install nginx -y
echo 'nginx successfully installed'
fi
} #改写配置文件
function rewrite_nginx_conf(){
sed -ri "/^ *location \/ \{$/a root /var/www/html\;index index.html\;" /etc/nginx/nginx.conf
touch /var/www/html/index.html
echo 'web1 hello world' >> /var/www/html/index.html #写入文件内容
systemctl restart nginx
} #检测安装nfs和rpcbind
function detection_nfs(){
if [ -d /var/lib/nfs ]
then
echo 'nfs has been installed'
exit
else
then
yum install rpcbind nfs-utils -y
echo 'rpcbind nfs-utils successfully installed'
fi
} detection_nginx #执行检测安装nginx函数
rewrite_nginx_conf #执行改写nginx.conf函数
detection_nfs #执行检测安装nfs函数 #挂载共享目录
showmount -e 192.168.19.128
mount -t nfs 192.168.19.128:/share /var/www/html/

客户端 Code

2.编写监控脚本,监控集群内所有服务存活状态,内存,异常则发送报警邮件

#!/bin/bash
mem_limit=30 #内存使用超过30%则报警
#监控内存
mem_total=`free |awk 'NR==2{print $2}'`
mem_use=`free |awk 'NR==2{print $3}'`
memory_usage=`echo "scale=2;$mem_use/$mem_total" |bc -l|cut -d. -f2`
IP=`ifconfig |awk 'NR==2{print $2}'`
if [ $memory_usage -gt $mem_limit ]
then
msg="TIME:$(date +%F_%T)
HOSTNAME:$(hostname)
IPADDR:$IP
MSG:Memory usage exceeds the limit,current value is ${memory_usage}%"
echo $msg
/usr/bin/my_mail $msg fi

监控 Code

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import smtplib
import email.mime.multipart
import email.mime.text server = 'smtp.163.com'
port = '' 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) sendmail(server,port,user,pwd,msg)

my_mail Code

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

#!/user/bin/env python
#coding:utf-8
crontab -e -u root * * * * * /mem.sh restart #每分钟检测一次

crontab Code


python2.6.6升级2.7:生产环境

python升级导致yum无法使用方法:传送门

010-- 开发脚本自动部署nginx_web和nfs及监控内存的更多相关文章

  1. linux基础 -nginx和nfs代理 开发脚本自动部署及监控

    开发脚本自动部署及监控 1.编写脚本自动部署反向代理.web.nfs: (1).部署nginx反向代理三个web服务,调度算法使用加权轮询:  (2).所有web服务使用共享存储nfs,保证所有web ...

  2. linux开发脚本自动部署及监控

    linux开发脚本自动部署及监控 开发脚本自动部署及监控一.编写脚本自动部署反向代理.web.nfs:要求:1.部署nginx反向代理三个web服务,调度算法使用加权轮询: #!/bin/sh ngx ...

  3. 自动部署Nginx和nfs并架设Nginx集群脚本

    本人经过多次尝试,简单完成了自动部署Nginx和nfs脚本,并且能够自动部署web反向代理集群,下面详细的阐述一下本人的思路.(以下脚本本人处于初学阶段,写的并不是很完善,所以需要后期进行整理和修正, ...

  4. 脚本自动部署及监控 web

    1.编写脚本自动部署反向代理.web.nfs: I.部署nginx反向代理两个web服务,调度算法使用加权轮询 II.所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性: ...

  5. ceph脚本-自动部署计算机节点

    依然还在加班中,最近确实忙的脚打后脑勺! 又花了些时间丰富ceph脚本,可以连带着自动部署计算机节点了. 这一部分内容是后加的.可以关注我的公众号获取更多的项目代码和讲解!波神与你同行哦,加油!!!

  6. Tomcat通过脚本自动部署

    1:autodeploy_tomcat_app.sh now=`date +%Y%m%d%H%M%S` tomcatPath=/home/test/apache-tomcat- backupPath= ...

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

    服务器端 #!/bin/bash function nginx_install(){ if [[ -f /usr/sbin/nginx ]]; then echo 'Nginx has been in ...

  8. Shell脚本 自动部署 SpringBoot 应用

    公司项目使用了SpringBoot.开发的应用需要自动上传到服务器.虽然目前对热部署还没完全掌握.先使用shell简化一下部署吧. # 上传密钥 sshLoginKey=/f/MyFile/root. ...

  9. Azure vm 扩展脚本自动部署Elasticsearch集群

    一.完整过程比较长,我仅给出Azure vm extension script 一键部署Elasticsearch集群的安装脚本,有需要的同学,可以邮件我,我给你完整的ARM Template 如果你 ...

随机推荐

  1. SolidEdge 工程图中如何控制是否显示爆炸图组装线

    右击视图,点击性质,取消勾选"显示流线"   即可取消爆炸视图的装配线              

  2. 王立平--GUI与GUILayout的差别

    GUI.Button (new Rect(0,0,5,5,"哈哈"); GUILayout.Button ("heheh"); 1.以上代码都是现实一个butt ...

  3. Type cannot use 'try' with exceptions disabled

    cannot use ‘throw’ with exceptions disabled 在为 DragonBonesCPP/refactoring 的 cocos2d-x-3.2 demo 增加 An ...

  4. 浅析怎样学好C语言

    今天,我能够自称是一个混IT的人,并能以此谋生,将来大家能一次谋生.都要感谢两个人:克劳德.香农和约翰.冯.诺依曼,是他们发现了全部的数字化信息,不论是一段程序,一封email.一部电影都是用一连串的 ...

  5. Codeforces Round #258 (Div. 2/A)/Codeforces451A_Game With Sticks

    解题报告 http://blog.csdn.net/juncoder/article/details/38102263 n和m跟木棍相交,问一人取一交点(必须是交点.且取完后去掉交点的两根木棍),最后 ...

  6. [iOS]APP代码实践:建立一个辅助的APP类,降低对AppDelegate的改动

    郝萌主倾心贡献.尊重作者的劳动成果,请勿转载. [UIApplication sharedApplication].delegate 可是时间长了还是认为这样不太好,AppDelegate本身有其自己 ...

  7. Python 003- 小知识汇总(更新中)

    #查询key是否存在,可以在使用未知的字典的时候使用 #-*- coding:utf-8 -*- D={'a':1,'c':3,'b':2} for key in sorted(D): print(k ...

  8. jetty java文件无法删除 java文件占用 delete无效 运行时锁定静态资源的解决方法

    前几天jetty下发现java无法删除文件,文件操作后一直被jvm占用,无奈换了tomcat问题消失. 今天又想起来,尝试网上的解决方法,经本人试验,直接修改配置文件有时不能生效,具体原因不清楚,建议 ...

  9. Designing a RESTful API with Python and Flask 201

    rest服务器的搭建 - CSDN博客 http://blog.csdn.net/zhanghaotian2011/article/details/8760794 REST的架构设计 REST(Rep ...

  10. hadoop yarn namenode datanoe 启动异常问题解决 分析日志

    cat logs/hadoop-root-datanode-hadoop1.log ********************************************************** ...