2017.3.24作业

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

#/bin/bash
ystemctl status nginx
if[ $? -ne 0 ]
    then
    yum install -y nginx
    if[ $? -nq 0 ]
        then
        #echo 'Is that ok!'
        systemctl start nginx
        if[ $? -nq 0 ]
            then
            echo "nginx hsve start!"
        else
            echo "nginx have stop!"   
        fi
    else
    echo"install is fail!"
    fi
fi
echo "writing.............."
grep 'upstream' /etc/nginx/nginx.conf
if[ $? -ne 0]
    then
    sed -ri '/^http/a oldboy {' /etc/nginx/nginx.conf
    sed -ri '/^upst/a server oldboy weight=3\;' /etc/nginx/nginx.conf
    sed -ri '/^server web1/123321 web2\;' /etc/nginx/nginx.conf
    sed -ri '/^server web2/123321 \}' /etc/nginx/nginx.conf
    sed -ri '/^(\ +)(location)(\ )(\/)/a proxy_pass http:\/\/oldboy\;' /etc/nginx/nginx.conf
fi
echo "config have already!"
systemctl reload nginx
if[ $? -nq 0 ]
    then
    echo "OK!!!!"
else
    echo "NO!!!!"
fi
systemctl status nfs
if[ $? -ne 0 ]
    then
    yum install rpcbind nfs-utils -y
    if[ $? -nq 0 ]
        then
        #echo 'OK !'
        systemctl start nfs
        if[ $? -nq 0 ]
            then
            echo "nfs have start!"
        else
            echo "nfs have stop!"   
        fi
    else
        echo"install is fail!"
       
    fi  
fi
echo "writing............"
echo "/webindex 192.168.16.0/24(rw,sync,fsid=0)" > /etc/exports
echo "config write have OK!"
systemctl reload nfs
if[ $? -nq 0 ]
    then
    echo "nfs have OK!"
else
    echo "nfs is fail!"
fi

posted @ 2017-03-26 11:31  im777  阅读(174)  评论(0编辑  收藏  举报