2017.3.24做業

開發腳本自動部署及監控
    1.編寫腳本自動部署反向代理、web、nfs;
     要求:
      I、部署nginx反向代理三個web服務,調度算法使用加權輪詢;
      II、全部web服務使用共享存儲nfs,保證全部web都對其有讀寫權限,保證數據一致性;nginx

#/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!"
fiweb

相關文章
相關標籤/搜索