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. 第三讲_图像特征与描述Image Feature Descriptor

    第三讲_图像特征与描述Image Feature Descriptor 概要 特征提取方法 直方图 对图片数据/特征分布的一种统计:对不同量进行直方图统计:可以表示灰度,颜色,梯度,边缘,形状,纹理, ...

  2. 【Nutch基础教程之七】Nutch的2种执行模式:local及deploy

    在对nutch源码执行ant runtime后,会创建一个runtime的文件夹.在runtime文件夹下有deploy和local 2个文件夹. [jediael@jediael runtime]$ ...

  3. 怎样使用1M的内存排序100万个8位数

    今天看到这篇文章.颇为震撼.感叹算法之"神通". 借助于合适的算法能够完毕看似不可能的事情. 最早这个问题是在Stack Overflow站点上面给出的(Sorting numbe ...

  4. window服务器开站点(不通用)

    此文章为记录自己的配置流程,其他人不通用 网站服务器:Windows server 2008 R2 (IIS6.1) + Asp.net 数据库服务器:Windows server 2008 R2 + ...

  5. Qt:解析命令行

    Qt从5.2版開始提供了两个类QCommandLineOption和QCommandLineParser来解析应用的命令行參数. 一.命令行写法 命令行:"-abc" 在QComm ...

  6. 自己动手写CPU之第九阶段(4)——载入存储指令实现思路

    将陆续上传新书<自己动手写CPU>,今天是第40篇,我尽量每周四篇,可是近期已经非常久没有实现这个目标了,一直都有事,不好意思哈. 开展晒书评送书活动,在q=%E4%BA%9A%E9%A9 ...

  7. Maple入门使用教程

    http://anony3721.blog.163.com/blog/static/51197420105173915247/ 命令的运行:1.每条命令必须用":"(运行后不显示) ...

  8. uboot 对 FAT 分区的解析

    uboot 对 FAT 分区的解析 改写 UBOOT 从 U 盘读入固件,然后刷机.发现有的 U 盘无法正确读到分区,跟踪了一下发现自己写的代码有漏洞,只尝试解析分区表里的第一个分区.跟踪的过程中重温 ...

  9. 使用GitLab CI + Capistrano部署CakePHP应用程序

    使用GitLab CI + Capistrano部署CakePHP应用程序 摘要:本文描述了如使用GitLab CI + Capistrano部署CakePHP应用程序. 目录 1. 问题2. 解决方 ...

  10. [网页游戏开发]进一步了解Morn UI及工作流

    Morn UI工作流 Morn Builder不仅仅是对Flash IDE的改进,传统的开发协作是以fla为基础,由于fla是二进制文件,在以svn等版本控制软件协作下,合并过程中会出现各种各样的问题 ...