shell脚本编写
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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脚本编写的主要内容,如果未能解决你的问题,请参考以下文章