Code: http://www.zuidaima.com/share/1860227690056704.htm
Original article: nginx tomcat cluster configuration to achieve painless Restart service tutorial
As the number of users with the most Code increases, the dependence on high-availability services is increasing. Single-point services cannot avoid the impact of restart on users. Therefore, the following solution is adopted to achieve painless restart of services.
Nginx + 2 tomcat (8080,8081)
Idea: there is only one tomcat for normal services. If another one is started during restart, after the service is normal, run nginx-s reload and close tomcat for the previous service.
The shell code is as follows:
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
The script is somewhat redundant, but the implementation function is okay. You can optimize the code on your own.
Related:
The key point is to use the nginx include command to load only the required conf file:
include /usr/local/nginx/conf/vhost/*.conf;