nginx tomcat叢集配置實現無痛重啟服務教程

來源:互聯網
上載者:User

代碼:http://www.zuidaima.com/share/1860227690056704.htm

原文:nginx tomcat叢集配置實現無痛重啟服務教程

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

nginx+2tomcat(8080,8081)

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

shell代碼如下:

nginx_root_path="/usr/local/nginx/"nginx_conf_path="${nginx_root_path}conf/vhost/"tomcat_running_8080_port="8080"tomcat_running_8081_port="8081"tomcat_startup_path="bin/startup.sh"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_8080_port}"        mv_start_conf_path="${nginx_conf_path}www.zuidaima.com_8080.conf"        mv_stop_conf_path="${nginx_conf_path}www.zuidaima.com_8081.conf"        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_conf_path="${nginx_conf_path}www.zuidaima.com_8081.conf"    mv_stop_conf_path="${nginx_conf_path}www.zuidaima.com_8080.conf"    url="http://www.zuidaima.com:8081/share.htm"fiecho "start 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_${start_tomcat_port}/${tomcat_startup_path}sleep 40rm share.htm -vcurl -v "${url}" -o "share.htm"sleep 10echo "nginx reload"${nginx_root_path}sbin/nginx -s reloadsleep 2echo "stop tomcat ${stop_tomcat_port}"/usr/local/apache-tomcat-6.0.39_${stop_tomcat_port}/${tomcat_shutdown_path}sleep 10ps -ef|grep tomcat-6.0.39_${stop_tomcat_port}|awk '{print $2}'|xargs kill

指令碼有些冗餘,但實現功能沒問題了,大家可以自行發揮最佳化下代碼。

相關如下:

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

include /usr/local/nginx/conf/vhost/*.conf;

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.