shell脚本自动部署及监控
一、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脚本自动部署及监控的更多相关文章
- linux开发脚本自动部署及监控
linux开发脚本自动部署及监控 开发脚本自动部署及监控一.编写脚本自动部署反向代理.web.nfs:要求:1.部署nginx反向代理三个web服务,调度算法使用加权轮询: #!/bin/sh ngx ...
- linux基础 -nginx和nfs代理 开发脚本自动部署及监控
开发脚本自动部署及监控 1.编写脚本自动部署反向代理.web.nfs: (1).部署nginx反向代理三个web服务,调度算法使用加权轮询: (2).所有web服务使用共享存储nfs,保证所有web ...
- 脚本自动部署及监控 web
1.编写脚本自动部署反向代理.web.nfs: I.部署nginx反向代理两个web服务,调度算法使用加权轮询 II.所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性: ...
- Shell脚本 自动部署 SpringBoot 应用
公司项目使用了SpringBoot.开发的应用需要自动上传到服务器.虽然目前对热部署还没完全掌握.先使用shell简化一下部署吧. # 上传密钥 sshLoginKey=/f/MyFile/root. ...
- shell脚本自动部署nignx反向代理及web服务器,共享存储
#!/bin/bash systemctl status nginx var=$? ] then yum install epel-release -y ] then echo "epel库 ...
- shell脚本编写-自动部署及监控
1.编写脚本自动部署反向代理.web.nfs: I.部署nginx反向代理两个web服务,调度算法使用加权轮询 II.所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性: ...
- shell脚本安装部署反向代理 监控进程 计划任务
1.编写脚本自动部署反向代理.web.nfs: 要求: I.部署nginx反向代理三个web服务,调度算法使用加权轮询: 反向代理服务器脚本配置脚本 #!/bin/bash #安装eple和nginx ...
- 010-- 开发脚本自动部署nginx_web和nfs及监控内存
1.编写脚本自动部署反向代理.web.nfs: #!/bin/bash #检测安装nginx function detection_nginx(){ if [ -f /etc/nginx/nginx. ...
- Shell脚本一键部署——源码编译安装MySQL及自动补全工具
Shell脚本一键部署--源码编译安装MySQL及自动补全工具 编译安装MySQL 1.软件包 Mysql安装包 将安装包拖至/opt目录下,编辑一个脚本文件,将以下内容复制进去,然后source或者 ...
随机推荐
- CSS3 制作魔方 - 玩转魔方
在上一篇<CSS3 制作魔方 - 形成魔方>中介绍了一个完整魔方的绘制实现,本文将介绍魔方的玩转,支持上下左右每一层独立地旋转.先来一睹玩转的风采. 1.一个问题 由于魔方格的位置与转动的 ...
- [Xcode 实际操作]八、网络与多线程-(21)延时启动画面:使用Thread线程对象的延时方法
目录:[Swift]Xcode实际操作 本文将演示如何使用线程对象的延时方法,让线程休眠一段时间,暂停动作的执行. 在项目导航区,打开启动画面的故事板[LaunchScreen.storyboard] ...
- PUSH 和 远程推送
1. UIApplacation向 APNS 注册 push notification 服务 (1) 应用程序要支持推送服务, 在网页里面配置 http://developer.apple.com/ ...
- 要单独拿出来讲的a标签
a标签的属性 href属性赐予a标签力量:href属性指定要通过a标签借助浏览器请求的资源,可以是图片.视屏.网站.音频等.不加herf属性的a标签就是一个没有任何特殊样式和功能的文本容器. targ ...
- jsp内置对象分析
1.html表单的提交方式比较: 1.1.get方式:将表单内容经过编码之后 ,通过URL发送, 使用get方式发送时有255个字符的限制. 1.2.post方式:将表单的内容通过http发送,pos ...
- IOS正则表达式 (身份证、电话、汉字等常用条件筛选)
下面的正则列表 替换对应的正则规则 那个字符串就可以了 例如: //正则规则 NSString *regex = @"^((13[0-9])|(147)|(17[0-9])|(15[^ ...
- [題解]luogu_P1854 花店櫥窗佈置
來源:題解 一開始看不懂題目,一萬年了終於看懂 f [ i ] [ j ] 表示第i朵花放在第j個花瓶中最大美學值,(花是必須用完嗎?) 顯然放i-1朵花至少要放到前i-1個瓶子里,最多放到前j-1個 ...
- sql 规范
https://www.cnblogs.com/jacktang/archive/2012/09/25/2701301.html http://blog.csdn.net/ethan_fu/artic ...
- systemback-----做你折腾的后盾
http://imcn.me/html/y2015/24421.html ubuntu的系统还原工具,最近在学习grunt,要安装nodejs 等一些依赖,对于有轻微系统洁癖的我来说是个好的解决方案, ...
- 在switch中的case语句中声明变量会被提前
原文链接:http://my.oschina.net/u/2000201/blog/514384 本人今天在编写工具类时,无意之间发现,在Java的Swith语句的case语句中声明局部变量时出现了一 ...