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 如果你 ...
随机推荐
- Oracle 物理和逻辑备库健康监測的一个根据
以以下keyword眼为例: 1 物理备库健康检查根据: Tue Apr 22 16:44:51 CST 2014Media Recovery Log /data/CMS/arch_log/1_583 ...
- Effective C++ 条款17 以独立语句将newed对象置入智能指针
对于函数: int priority(); void processWidget(std::tr1:: shared_ptr<Widget> pw,int priority); 调用 ...
- 查询mysql字段名和字段注释
select COLUMN_NAME,column_comment from INFORMATION_SCHEMA.Columns where table_name='表名' and table_sc ...
- 解决查询access数据库含日文出现“内存溢出”问题
ACCESS有个BUG,那就是在使用 like 搜索时如果遇到日文就会出现“内存溢出”的问题,提示“80040e14/内存溢出”. 会出问题的SQL: where title like '%" ...
- Windows下也能够使用osw追朔系统历史性能
1.Windows系统历史性能分析困难背景 在Linux/Unix上.要追朔历史性能,一般採用部署nmon进行性能监控採集与存储的方式实现.可是却没有在Windows上的版本号. Windows系统假 ...
- 浅谈xss原理
近日,论坛上面XSS满天飞,各处都能够见到XSS的痕迹,前段时间论坛上面也出现了XSS的迹象.然后我等小菜不是太懂啊,怎么办?没办法仅仅有求助度娘跟谷歌这对情侣了. 能够说小菜也算懂了一些.不敢藏私, ...
- JAVA BigDecimal 高精度运算
文章参考一位博友,由于时间太久忘了链接,见谅! public class BigDecimalUtils { private static final int DIV_SCALE = 10;// 除法 ...
- 使网页适应UIWebView的宽度
比較简单的做法是:在- (void)webViewDidFinishLoad:这种方法中,改动JavaScript的值: //UIWebViewDelegate - (void)webViewDidF ...
- Entity Framework 6 Code First 实践系列(1):实体类配置-根据依赖配置关系和关联
EF实体类的配置可以使用数据注释或Fluent API两种方式配置,Fluent API配置的关键在于搞清实体类的依赖关系,按此方法配置,快速高效合理.为了方便理解,我们使用简化的实体A和B以及A.B ...
- 常见mysql分布式数据中间件
一般分为三种: 1. proxy sharding,目前由cobar,mycat,drds,atlas修改,这几个产品的起源一般是mysqlproxy 或 ameoba,特点是mysql协议基本兼容, ...