Home >Backend Development >PHP Tutorial >nginx tomcat cluster configuration to achieve painless service restart tutorial

nginx tomcat cluster configuration to achieve painless service restart tutorial

WBOY
WBOYOriginal
2016-08-08 09:22:20922browse

With the increase in the number of code users, the reliance on high-availability services is increasing day by day. Single-point services cannot avoid the impact of restarts on users, so the following solution is adopted to achieve painless service restarts.

nginx+2tomcat(8080,8081)

Idea: There is only one tomcat for normal service. If it is restarted, start the other one. After the service is normal, execute nginx -s reload, and finally close the tomcat of the previous service.

The shell code is as follows:

nginx_root_path="/usr/local/nginx/"<br>nginx_c/vhost/"<br>tomcat_running_8080_port="8080"<br>tomcat_running_8081_port="8081"<br>tomcat_startup_path="bin/startup.sh"<br>tomcat_ shutdown_path= "bin/shutdown.sh"<br>cnt=`ps -ef|grep "apache-tomcat-6.0.39_${tomcat_running_8080_port}"|wc -l`<br>if [ "${cnt}" == "0" ] ; then<br>stop_tomcat_port = "$ {tomcat_running_8081_port}" <br> start_tomcat_port = "$ {tomcat_running_8080_Port} //www.zuidaima.com:8080/share.htm"<br>else<br>lse_tomcat_port = "$ {tomcat_running_8080_port}"<br> start_tomcat_port="${tomcat_running_8081_port}"<br> mv_start_c> mv_stop_c> url="http://www.zuidaima.com:8081/share.htm"<br>fi<br>echo "start tomcat ${start_tomcat_port}" <br> mv ${mv_start_conf_path}.bak ${mv_start_conf_path}<br>mv ${mv_stop_conf_path} ${mv_stop_conf_path}.bak<br>/usr/local/apache-tomcat-6.0.39_${start_tomcat_port}/${tomcat_startup_path}<br>sleep 40<br>rm share.htm -v<br>curl -v "${url}" -o "share.htm"<br>sleep 10<br>echo "nginx reload"<br>${nginx_root_path}sbin/nginx -s reload<br>sleep 2<br>echo "stop tomcat ${stop_tomcat_port}"<br>/usr/local/apache-tomcat-6.0.39_${stop_tomcat_port}/${tomcat_shutdown_path}<br>sleep 10<br>ps -ef|grep tomcat-6.0.39_${stop_tomcat_port}|awk '{print $2}'|xargs kill<br>

The script is a bit redundant, but there is no problem in realizing the function. You can optimize the code by yourself.

The relevant screenshots are as follows:

The key point is to use nginx’s include directive to load only the required conf files: <br>

include /usr/local/nginx/conf/vhost/*.conf; <br>

The above introduces the nginx tomcat cluster configuration to achieve painless service restart tutorial, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn