• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

nginx tomcat集群配置实现无痛重启服务教程

php 搞代码 4年前 (2022-01-23) 18次浏览 已收录 0个评论

随着最代码用户量的增大,对高可用服务的依赖度日益增强,单点的服务无法避免重启给用户带来的影响,所以采用了如下方案来实现无痛重启服务。

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 sh@本文来源gaodaimacom搞#代%码@网-搞代gaodaima码are.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教程有兴趣的朋友有所帮助。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:nginx tomcat集群配置实现无痛重启服务教程

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址