码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本编写

时间:2017-03-23 21:47:15      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:restart   stop   脚本   expr   使用率   $?   监控脚本   gre   内存使用率   

自动部署、初始配置、并启动nginx反向代理服务;自动部署、初始配置、并启动两台web

#!/bin/bash
yum install epel-release -y
yum install nginx -y
ps aux |grep nginx |grep -v grep
if [ $? -ne 0 ]
    then
        systemctl start nginx
fi
sed -ri /^http/a upstream xzhweb\{ /etc/nginx/nginx.conf
sed -ri /^upstream/a server 192.168.16.99 /etc/nginx/nginx.conf
sed -ri /^server/a } /etc/nginx/nginx.conf
sed -ri /^server/a server 192.168.16.175 /etc/nginx/nginx.conf
sed -ri /^\ +location \/ /a proxy_pass http://xzhweb; /etc/nginx/nginx.conf
systemctl stop firewalld
setenforce 0
systemctl restart nginx
if [ $? -ne 0 ]
    then
       echo wellcome to congratulation
fi

技术分享

192.168.16.27 为反向代理

监控脚本:监控每台机器的内存使用率>70%,则输出报警信息

#!/bin/bash
mem_used=`free | awk NR==2{print $3}`
mem_total=`free | awk NR==2{print $2}`
x=`expr "scale=2; $mem_used/$mem_total" |bc -l |cut -d. -f2`
if ((x>70)); then
        echo "Your memory is using $x\%, please handle as soon as possible."
    else
        echo "Your memory usage is $x%, can be at ease use!"
fi    

shell脚本编写

标签:restart   stop   脚本   expr   使用率   $?   监控脚本   gre   内存使用率   

原文地址:http://www.cnblogs.com/xuzheng940806/p/6607149.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!