nginx tomcat集群配置实现无痛重启服务教程
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_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_c> 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> url="http://www.zuidaima.com:8081/share.htm"
fi
echo "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 40
rm share.htm -v
curl -v "${url}" -o "share.htm"
sleep 10
echo "nginx reload"
${nginx_root_path}sbin/nginx -s reload
sleep 2
echo "stop tomcat ${stop_tomcat_port}"
/usr/local/apache-tomcat-6.0.39_${stop_tomcat_port}/${tomcat_shutdown_path}
sleep 10
ps -ef|grep tomcat-6.0.39_${stop_tomcat_port}|awk '{print $2}'|xargs kill
脚本有些冗余,但实现功能没问题了,大家可以自行发挥优化下代码。
相关截图如下:
关键点在利用了nginx的include指令实现只加载需要的conf文件:
include /usr/local/nginx/conf/vhost/*.conf;
以上就介绍了nginx tomcat集群配置实现无痛重启服务教程,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
下一篇: PHP中的可变参数函数和可选参数函数
推荐阅读