首頁  >  文章  >  後端開發  >  nginx tomcat叢集設定實作無痛重啟服務教學課程

nginx tomcat叢集設定實作無痛重啟服務教學課程

WBOY
WBOY原創
2016-08-08 09:22:20855瀏覽

隨著最代碼用戶量的增大,對高可用服務的依賴度日益增強,單點的服務無法避免重啟給用戶帶來的影響,所以採用瞭如下方案來實現無痛重啟服務。

nginx+2tomcat(8080,8081)

思路:其中正常服務的tomcat只有1個,如果重啟時,啟動另外一個,服務正常後,執行nginx -s reload,最後在關閉上一個服務的tomcat。

shell程式碼如下:

nginx_root_path="/usr/local/nginx/"
nginx_c/vhost/"
tomcat_running_8080_port="8080"
tomcat_running_808181> tomcat_shutdown_path= "bin/shutdown.sh"
cnt=`ps -ef|grep "apache-tomcat-6.0.39_${tomcat_running_8080_port}"|wc -l`
if [ "${cnt}" == "0" ] ; then
        stop_tomcat_port="${tomcat_running_8081_port}"
        start_tomcat_port="${tomcat_running_8080008080   mv_stop_c>        url="http://www.zuidaima.com:8080/share.htm"
else
    stop_tomcat_port="$ {tomcat_running_8080_port}"
    start_tomcat_port="${tomcat_running_8081_port}"
    mv_start_c>    mv_stop_c>    mv_start_c>    mv_stop_c>    mv_start_c>    mv_stop_c>  tomcat ${start_tomcat_port}"
mv ${mv_start_conf_path}.bak ${mv_start_conf_path}
mv ${mv_stop_conf_path} ${mv_stop_conf_path}.bak
/usr/local/apache-tomcat-6.0.39_$fid_39_%/hcat_catft- share.htm -v
curl -v "${url}" -o "share.htm"
sleep 10
echo "nginx reload"
${nginx_root_path}sbin/nginx -s reload
sleep 2
e 2
e "stop cattom ${stop_tomcat_port}"
/usr/local/apache-tomcat-6.0.39_${stop_tomcat_port}/${tomcat_shutdown_path}
sleep 10
ps -ef|grep tomcat-6.0.0.39_$ $2}'|xargs kill

腳本有些冗餘,但實作功能沒問題了,大家可以自行發揮優化下程式碼。

相關截圖如下:

關鍵點在利用了nginx的include指令實作只載入需要的conf檔:

include /usr/local/nginx/confcal/hostm <br> 以上就介紹了nginx tomcat叢集配置實現無痛重啟服務教程,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn