一、shell脚本部署nginx反向代理和三个web服务

1 对反向代理服务器进行配置


#!/bin/bash #修改用户交互页面 用户输入参数执行相应的参数
#安装epel扩展包和nginx
function ng_yum_install(){ yum install epel-release -y
yum install nginx -y
yum install rpcbind nfs-utils -y }
#nginx init function
#nginx status
#nginx 开机enable
function ng_init(){ systemctl start nginx
systemctl enable nginx
} #脚本执行
ng_yum_install
sed -ri '/^http/a \ \ \ \ upstream pythonweb{\n server\ 192.168.43.21;weight=3;\n server\ 192.168.43.23;\nserver\ 192.168.43.24;\n}' /etc/nginx/nginx.conf #四个反斜杠是四个空格
sed -ri '/^ +location \/ /a proxy_pass http:\/\/pythonweb;' /etc/nginx/nginx.conf systemctl stop firewalld
systemctl enable firewalld echo 'share 192.168.43.0/24(rw,sync,fsid=0)' >/etc/exports
chmod -R o+w /share #修改share目录的权限
systemctl enable nfs-service.service
systemctl enable rpcbind.service
systemctl start rpcbind.service
systemctl start nfs_service.service

2 对三台web服务器分别进行配置

function ng_yum_install(){

    yum install epel-release -y
yum install nginx -y
yum install rpcbind nfs-utils -y #安装rpcbind和nfs
systemctl enable rpcbind.service && systemctl start rpcbind.service }
#nginx init function
#nginx status
#nginx 开机enable
function ng_init(){ systemctl start nginx
systemctl enable nginx
} ng_yum_install mkdir /html
touch /html/index.html
echo 'welcome nginx' >/html/index.html
sed -ri '/^ +location \/ /a root \/html;\nindex index.html; ' /etx/nginx/nginx.conf ng_init
systemctl stop firewalld
systemctl enable firewalld mount -t nfs 192.168.43.20:/share /var/www.html

二、编写监控脚本 服务 内存 磁盘使用率 异常报警##

ps aux |grep nginx |grep -v 'grep'
if[ $? -ne 0 ]
then
echo 'nginx is die'
systemctl start nginx
if[ $? -eq 0 ]
then
echo 'nginx now is activing'
fi
fi

1 Python 发送邮件工具

将此文件放到/bin下并给予可执行权限

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import smtplib
import email.mime.multipart
import email.mime.text server = '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'] = 'python'
msg['From'] = 'example@163.com' #发件人地址
msg['To'] = 'example@163.com' #收件人地址
user = '邮箱用户名'
pwd = 'stmp客户端密码'
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)

2 内存监控脚本


#!/bin/bash mem_limit=0 #测试的时候设置成0 后期根据实际需要设置
function memcheck(){
memtotal=`free |awk 'NR==2{print $2}'`
memuse1=`free |awk 'NR==2{print $3}'`
memuse2=`free |awk 'NR==2{print $6}'`
mempercent=`echo "scale=2;($memuse1+$memuse2)/$memtotal"|bc -l |cut -d. -f2`
#echo ${mempercent}% if [ $mempercent -gt $mem_limit ]
then
msg="TIME:$(date +%F_%T)
HOSTNAME:$(hostname)
IPADDR:$(ifconfig |awk 'NR==2{print $2}')
MSG:Memory usage exceeds the limit,current value is ${mem_percent}%"
echo $msg
/usr/bin/mail $msg
fi } memcheck #执行函数

下面是shell中执行成功的界面

这是邮箱收到的信息

3 计划任务crond

crond默认是开机启动的

crontab -e -u root  #  为root用户添加计划任务

* * * * *  

*代表分钟、小时、日、月、周
crontab -l  查看上次添加的计划任务


tail -f /var/log/cron # 查看日志

shell脚本自动部署及监控的更多相关文章

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

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

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

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

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

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

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

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

  5. shell脚本自动部署nignx反向代理及web服务器,共享存储

    #!/bin/bash systemctl status nginx var=$? ] then yum install epel-release -y ] then echo "epel库 ...

  6. shell脚本编写-自动部署及监控

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

  7. shell脚本安装部署反向代理 监控进程 计划任务

    1.编写脚本自动部署反向代理.web.nfs: 要求: I.部署nginx反向代理三个web服务,调度算法使用加权轮询: 反向代理服务器脚本配置脚本 #!/bin/bash #安装eple和nginx ...

  8. 010-- 开发脚本自动部署nginx_web和nfs及监控内存

    1.编写脚本自动部署反向代理.web.nfs: #!/bin/bash #检测安装nginx function detection_nginx(){ if [ -f /etc/nginx/nginx. ...

  9. Shell脚本一键部署——源码编译安装MySQL及自动补全工具

    Shell脚本一键部署--源码编译安装MySQL及自动补全工具 编译安装MySQL 1.软件包 Mysql安装包 将安装包拖至/opt目录下,编辑一个脚本文件,将以下内容复制进去,然后source或者 ...

随机推荐

  1. FLINK源代码调试方式

    此文已由作者岳猛授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 第一种,直接通过IDEA WINDOWS调试 前提是Flink所有依赖已经导入,直接在Test中打断点,然后直 ...

  2. Tomcat 容器的安全认证和鉴权

    大量的 Web 应用都有安全相关的需求,正因如此,Servlet 规范建议容器要有满足这些需求的机制和基础设施,所以容器要对以下安全特性予以支持: 身份验证:验证授权用户的用户名和密码 资源访问控制: ...

  3. MySQL备份与主备配置

    MySQL备份与主备配置 数据备份类型 全量备份:备份整个数据库 增量备份:备份自上一次备份以来(增量或完全)以来变化的数据 差异备份:备份自上一次完全备份以来变化的数据 全量备份 全量备份的方法有 ...

  4. 如何实现Vue已经弃用的$dispatch和$broadcast方法?

    对于父子(含跨级)传递数据的通信方式,Vue.js 并没有提供原生的 API 来支持,而是推荐使用大型数据状态管理工具 Vuex,但 Vuex 对于小型项目来说用起来真的很麻烦. 在 Vue.js 1 ...

  5. Unity3d 3d角色换装实现原理及步骤

    http://www.cnblogs.com/dosomething/archive/2012/04/15/2450526.html 1.角色模型制作 unity3d支持Skin动画  但是不支持Ph ...

  6. 后Selenium时代,网页自动化测试用Cypress

    本文技术难度★★★,初学自动化测试的朋友慎点!否则会引起焦虑等不适症状,严重者会怀疑自己技术人生! 来自Cypress官网首页! Web开发飞速换代! table控制页面OUT了! 原生态手写网页OU ...

  7. apringboot aop权限控制

    + 定义切面: ···@Aspect @Component public class LoginInterceptor { @Around("@annotation(lock)") ...

  8. LeetCode.905-按奇偶排序数组(Sort Array By Parity)

    这是悦乐书的第347次更新,第371篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第212题(顺位题号是905).给定一个非负整数数组A,返回一个由A的所有偶数元素组成的 ...

  9. nutzboot dubbo zookeeper简单使用

    提供方和消费方properties 配置基本差不多 nutz.application.name这个值不一样 提供方配置自动端口就行server.port=0 消费方一般需要对外提供web服务配置ip和 ...

  10. java操作redis实现和mysql数据库的交互

    连接地址http://blog.csdn.net/kingcat666/article/details/77936970