010-- 开发脚本自动部署nginx_web和nfs及监控内存
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及监控内存的更多相关文章
- linux基础 -nginx和nfs代理 开发脚本自动部署及监控
开发脚本自动部署及监控 1.编写脚本自动部署反向代理.web.nfs: (1).部署nginx反向代理三个web服务,调度算法使用加权轮询: (2).所有web服务使用共享存储nfs,保证所有web ...
- linux开发脚本自动部署及监控
linux开发脚本自动部署及监控 开发脚本自动部署及监控一.编写脚本自动部署反向代理.web.nfs:要求:1.部署nginx反向代理三个web服务,调度算法使用加权轮询: #!/bin/sh ngx ...
- 自动部署Nginx和nfs并架设Nginx集群脚本
本人经过多次尝试,简单完成了自动部署Nginx和nfs脚本,并且能够自动部署web反向代理集群,下面详细的阐述一下本人的思路.(以下脚本本人处于初学阶段,写的并不是很完善,所以需要后期进行整理和修正, ...
- 脚本自动部署及监控 web
1.编写脚本自动部署反向代理.web.nfs: I.部署nginx反向代理两个web服务,调度算法使用加权轮询 II.所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性: ...
- ceph脚本-自动部署计算机节点
依然还在加班中,最近确实忙的脚打后脑勺! 又花了些时间丰富ceph脚本,可以连带着自动部署计算机节点了. 这一部分内容是后加的.可以关注我的公众号获取更多的项目代码和讲解!波神与你同行哦,加油!!!
- Tomcat通过脚本自动部署
1:autodeploy_tomcat_app.sh now=`date +%Y%m%d%H%M%S` tomcatPath=/home/test/apache-tomcat- backupPath= ...
- 编写脚本自动部署反向代理、web、nfs
服务器端 #!/bin/bash function nginx_install(){ if [[ -f /usr/sbin/nginx ]]; then echo 'Nginx has been in ...
- Shell脚本 自动部署 SpringBoot 应用
公司项目使用了SpringBoot.开发的应用需要自动上传到服务器.虽然目前对热部署还没完全掌握.先使用shell简化一下部署吧. # 上传密钥 sshLoginKey=/f/MyFile/root. ...
- Azure vm 扩展脚本自动部署Elasticsearch集群
一.完整过程比较长,我仅给出Azure vm extension script 一键部署Elasticsearch集群的安装脚本,有需要的同学,可以邮件我,我给你完整的ARM Template 如果你 ...
随机推荐
- 【IntelliJ Idea】启动参数JVM参数的配置 优先级高于 application.yaml/application.properties中的配置,前者可以覆盖后者的配置
- js时间戳和时间格式之间的转换
//时间戳转换成日期时间2014-8-8 下午11:40:20 function formatDate(ns){ return new Date(parseInt(ns) * 1000).toLoca ...
- BUPT复试专题—复数集合(?)
https://www.nowcoder.com/practice/abdd24fa839c414a9b83aa9c4ecd05cc?tpId=67&tqId=29643&rp=0&a ...
- WheelView实现省市区三级联动(数据库实现版本号附带完整SQL及数据)
近期在实现收货地址功能,用到了省市区三级联动效果,网上找到一般都是xml或json.数据源陈旧改动麻烦.改动了一下使用数据库方式实现了一下 数据源解决.因为数据量比較大通过初始化批量运行SQL的方式不 ...
- Cocos2d-x 精灵碰撞检測(方法一)
声明函数碰撞检測函数,两个精灵和重写update bool isCollision( CCPoint p1,CCPoint p2,int w1,int h1,int w2,int h2 ); CCSp ...
- python 字符串前缀
普通字符串 一般字符串都是已unicode编码,且和C类似,可以使用\来转义,比如 a = "test\ntest" print(a) 输出 test test 前面加r 在字符串 ...
- BIOS维修技术
BIOS是电脑中最基础且最重要的程序,为电脑提供最低级且最直接的硬件控制,电脑的原始操作都是依照固化在BIOS里的程序来完成的.因此如果BIOS出现故障将会导致影响电脑的正常工作.BIOS故障有很多, ...
- 基于bootstrap_登陆页面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Centos修改静态IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0代开配置文件 写入 DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为et ...
- UltraEdit中使用正则表达式-简单用法
UltraEdit中使用正则表达式 1.认识正则表达式语法: 正则表达式 (UltraEdit Syntax): % 匹配行首 - 表明要搜索的字符串一定在行首. $ 匹配行尾 - 表明要搜索的字符串 ...