开发脚本自动部署及监控

1.编写脚本自动部署反向代理、web、nfs;

(1)、部署nginx反向代理三个web服务,调度算法使用加权轮询;

 (2)、所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性;

脚本如下
#!/bin/sh
Nginx_WebInstall(){
systemctl stop firewalld
setenforce
ps -aux | grep nginx |grep -v "grep"
if [ $? -ne ]
then
yum install epel-release -y &>/dev/null;
yum install nginx -y &>/dev/null;
systemctl start nginx;
echo "nginx is successful!!"
else
systemctl restart nginx fi
} Conf_Nginx(){
if [ -f "/etc/nginx/nginx.conf" ]
then
sed -ri '/^http/a upstream xyyweb { ' /etc/nginx/nginx.conf
sed -ri '/^upstream/a server 192.168.31.101 weight=3; \n }' /etc/nginx/nginx.conf
sed -ri '/^upstream/a server 192.168.31.164 weight=3;' /etc/nginx/nginx.conf
sed -ri '/^upstream/a server 192.168.31.131 weight=3;' /etc/nginx/nginx.conf
sed -ri '47a \\n\t location \/ {\n\t\t proxy_pass http://xyyweb;\n\t}' /etc/nginx/nginx.conf
elif [ $? -eq ]
then
systemctl restart nginx
else
echo "input file false."
fi
} Nginx_WebInstall ##这个命令只安装web服务器
Conf_Nginx ##这个是进行修改配置文件(两者同时运行时是安装代理服务器) Nfs_install(){
if [ -s "/etc/exports" ]
then
systemctl stop firewalld
setenforce
yum -y install rpcbind nfs-utils &>/dev/null;
echo "rpcbind and nfs is successful!!"
elif [ $? -eq ]
then
systemctl enable nfs-server.service;
systemctl enable rpcbind.service;
systemctl start rpcbind;
systemctl start nfs;
Rpc=`rpcinfo -p localhost|wc -l;`
ps -ef|grep nfsd
elif [ $Rpc -eq -o $? -eq ]
then
echo "rpcbind and nfs is start success!!"
fi
mkdir /share; echo "/share 192.168.31.0/24 (rw,sync,fsid=0)" >/etc/exports chmod /share }
Nfs_install ##安装nfs的命令;

 

web节点服务器挂载nfs是 只需在上面执行mount -t nfs ipaddress:/share  /web-serverdir

 

 

安装nginx:

 

修改配置文件:

 

 

安装nfs:

 

 

2、编写监控脚本,监控集群内所有服务存活状态,内存、磁盘剩余率检测,异常则发送报警邮件

#!/bin/sh
NgxMonitor(){
ps -ef | grep nginx| grep -v grep
if [ $? -ne ]
then
msg="TIME:$(date +%F_%T)
HOSTNAME:$(hostname)
IPADDR:$(ifconfig |awk 'NR==2{print $2}')
MSG:Nginx program is crash, Waiting to restart"
echo $msg
/usr/bin/my_mail $msg
systemctl restart nginx
fi
} NfsMonitor(){
ps -ef | grep nfs| grep -v grep
if [ $? -ne ]
then
msg="TIME:$(date +%F_%T)
HOSTNAME:$(hostname)
IPADDR:$(ifconfig |awk 'NR==2{print $2}')
MSG:NFS program is crash, Waiting to restart"
echo $msg
/usr/bin/my_mail $msg
systemctl restart nginx
fi
} MemMonitor(){
mem_use=`free | awk 'NR==2{print $3}'`
mem_total=`free | awk 'NR==2{print $2}'`
mem_per=`echo "scale=2;$mem_use/$mem_total"|bc -l |cut -d . -f2` if (( $mem_per > ))
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_per}%"
echo $msg
/usr/bin/my_mail $msg
fi
} DiskMonitor(){
space_use=`df $disk |awk 'NR==2{print $5}'|cut -d% -f1` if [ $space_use -gt ]
then
msg="TIME:$(date +%F_%T)
HOSTNAME:$(hostname)
IPADDR:$(/usr/sbin/ifconfig |awk 'NR==2{print $2}')
MSG:Disk space usage exceeds the limit,current value is ${space_use}%"
echo $msg
/usr/bin/my_mail $msg
fi
} NgxMonitor
NfsMonitor
MemMonitor
DiskMonitor

 

 

 3.编写计划任务,定时运行监控脚本,完成监控操作

 

linux基础 -nginx和nfs代理 开发脚本自动部署及监控的更多相关文章

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

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

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

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

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

    一.shell脚本部署nginx反向代理和三个web服务 1 对反向代理服务器进行配置 #!/bin/bash #修改用户交互页面 用户输入参数执行相应的参数 #安装epel扩展包和nginx fun ...

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

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

  5. CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存

    CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存来自:互联网 时间:2020-03-22 阅读:114以下情况可能造成Linux内存占用过高服务配置存在直接分配错误,或隐性分 ...

  6. windows/Linux下设置ASP.Net Core开发环境并部署应用

    10分钟学会在windows/Linux下设置ASP.Net Core开发环境并部署应用 创建和开发ASP.NET Core应用可以有二种方式:最简单的方式是通过Visual Studio 2017 ...

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

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

  8. Linux安装Nginx使用反向代理

    nginx的反向代理功能(自带了反向代理的功能,天生的二道贩子)1.实验环境准备准备2个服务器,都安装好nginx软件nginx1 192.168.13.79 作为web服务器 (理解为火车票售票点) ...

  9. 10分钟学会在windows/Linux下设置ASP.Net Core开发环境并部署应用

    创建和开发ASP.NET Core应用可以有二种方式:最简单的方式是通过Visual Studio 2017 来创建,其优点是简单方便,但需要安装最新版本Visual Studio 2017 prev ...

随机推荐

  1. linux学习总结-----web前端①

    <html> <head> <title></title> <meta charset='utf-8'/> ... </head> ...

  2. LAXCUS对数据存储的优化

        LAXCUS兼容行存储(NSM)和列存储(DSM)两种数据模型,实现了混合存储.同时在分布环境里,做到将数据的分发和备份自动处理,这样就不再需要人工干预了.     行存储,为了兼容广大用户对 ...

  3. 问题 C: Goldbach's Conjecture

    题目描述 Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least ...

  4. 详谈P(查准率),R(查全率),F1值

    怎么来的? 我们平时用的精度accuracy,也就是整体的正确率 acc = predict_right_num / predict_num 这个虽然常用,但不能满足所有任务的需求.比如,因为香蕉太多 ...

  5. 【集训试题】SiriusRen的卡牌 set

    题意概述: 给出N张卡牌,每张有三个属性a,b,c,同时给出所有属性可能的最大值A,B,C.对于一张卡牌,当这张卡牌至少有两个属性大于另外一张卡牌的对应两个属性的时候,认为这张卡牌更加优秀.现在问有多 ...

  6. vue.js的特点-1

    1. Vue.js是数据驱动的,无需手动操作DOM. 它通过一些特殊的HTML语法,将DOM和数据绑定起来.一旦你创建了绑定,DOM将和数据保持同步,每当变更了数据,DOM也会相应的更新. 2. MV ...

  7. java线程(2)——模拟生产者与消费者

    前言: 我们都听说过生产者和消费者的例子吧,现在来模拟一下.生产者生产面包,消费者消费面包.假定生产者将生成出来的面包放入篮子中,消费者从篮子中取.这样,当篮子中没有面包时,消费者不能取.当篮子满了以 ...

  8. 【SSH】——梳理三大框架

    [前言] 去年软考,从System.out.println("Hello World!")开始,小编也算是进入java的世界了.转战java以后,虽然仍旧在学习.NET的知识,但越 ...

  9. 【bzoj1018】[SHOI2008]堵塞的交通traffic 线段树区间合并+STL-set

    题目描述 给出一张2*n的网格图,初始每条边都是不连通的.多次改变一条边的连通性或询问两个点是否连通. 输入 第一行只有一个整数C,表示网格的列数.接下来若干行,每行为一条交通信息,以单独的一行“Ex ...

  10. [洛谷P3195][HNOI2008]玩具装箱TOY

    题目大意:有n个物体,大小为$c_i$.把第i个到第j个放到一起,容器的长度为$x=j-i+\sum\limits_{k-i}^{j} c_k$,若长度为x,费用为$(x-L)^2$.费用最小. 题解 ...