1、nginx反向代理安装配置
#!/usr/bin/bash
if [ -e /etc/nginx/nginx.conf ]
then
echo 'Already installed'
exit
else
/usr/bin/yum -y install epel*
/usr/bin/yum -y install nginx*
fi if [ -f /etc/nginx/nginx.conf ];then
msg="upstream zhanggen { server 1.1.1.1 weight=8;server 2.2.2.2 weight=6;server 3.3.3.3;}"
/usr/bin/sed -ri "/^http/a $msg" /etc/nginx/nginx.conf
/usr/bin/sed -ri "/^ *location \/ \{$/a proxy_pass http://zhanggen\;" /etc/nginx/nginx.conf
fi /usr/sbin/nginx -t
return=`echo $?`
if [ $return -ne ]
then
echo "config error"
else
echo "config success "
fi
/usr/bin/systemctl start nginx
/usr/bin/ps -ef | /usr/bin/grep nginx |/usr/bin/grep -v 'grep' value=`echo $?`
if [ $value -eq ]
then
echo 'Start nginx successful'
else
echo 'Start nginx faild please check again'
fi
2、安装配置后端nginx
#!/usr/bin/bash
if [ -e /etc/nginx/nginx.conf ]
then
echo 'Already installed'
exit
else
yum -y install epel*;
yum -y install nginx*;
fi if [ -f /etc/nginx/nginx.conf ]
then
nginx -t
else
echo "Installation failed"
fi return=`echo $?`
if [ $return -ne ]
then
echo "config error"
else
echo "config success "
fi systemctl start nginx; ngxStatus=`ps aux | grep -v grep |grep -c nginx` if [ $ngxStatus -lt ]
then
echo "Start nginx successful"
fi
3、安装NFS服务端
#!/usr/bin/sh
while true
# -*- coding: UTF- -*-
do
test -s /etc/exports
return=`echo $?`
if [ $return -ne ]
then
yum install rpcbind nfs-utils –y
echo "/share * (rw,sync,fsid=0)" > /etc/exports
mkdir -p /share
chmod -R o+w /share
systemctl enable nfs-server.service && systemctl enable rpcbind.service
systemctl start rpcbind.service && systemctl start nfs-server.service
iptables -F && iptables -X
share=`showmount -e`
access_IP=`awk '{print $2}' /etc/exports`
echo "NFS安装成功,您共享给大家的目录为: $share $access_IP可访问到它"
exit else
echo "已经安装了 NFS 服务"
exit
fi
done
4、安装NFS客户端
#!/usr/bin/sh
while :
do
iptables -F && iptables -F
yum install rpcbind nfs-utils -y
service rpcbind start
service nfs start
showmount -e 192.168.182.141
re=`echo $?`
if [ $re -eq ]
then
mount -t nfs 192.168.182.141:/share /var/www/
else
mount fiald !
fi
exit
done
5、检查nginx和NFS可用性,并邮件报警。
#!/usr/bin/sh
ps -ef |grep nfsd |grep -v 'grep'
return6=`echo $?`
if [ $return6 -ne ]
then
msg="TIME:$(/usr/bin/date +%F_%T)
HOSTNAME:$(/usr/bin/hostname)
IPADDR:$(/usr/sbin/ifconfig |/usr/bin/awk 'NR==2{print $2}')
NFS is faild"
echo "$msg"
/usr/bin/mail $msg
systemctl start nfs-server.service
fi
ps -ef |grep nginx |grep -v 'grep'
return8=`echo $?`
if [ $return8 -ne ]
then
msg="TIME:$(/usr/bin/date +%F_%T)
HOSTNAME:$(/usr/bin/hostname)
IPADDR:$(/usr/sbin/ifconfig |/usr/bin/awk 'NR==2{print $2}')
nginx is faid"
echo "$msg"
/usr/bin/mail $msg
systemctl start nginx
fi
6、Python发邮件模块 mv /usr/bin/mail
#!/usr/bin/python
# -*- coding: UTF- -*-
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[:]),' '.join(sys.argv[:])) #格式处理,专门针对我们的邮件格式 txt = email.mime.text.MIMEText(content, _charset='utf-8')
msg.attach(txt) sendmail(server,port,user,pwd,msg)
7、设置crotable 每5分钟检查一次
crontab -e
*/5 * * * * /status_check.sh