首页 > 代码库 > shell脚本编写

shell脚本编写

自动部署、初始配置、并启动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脚本编写