>  기사  >  백엔드 개발  >  고통 없는 서비스 재시작 튜토리얼을 달성하기 위한 nginx tomcat 클러스터 구성

고통 없는 서비스 재시작 튜토리얼을 달성하기 위한 nginx tomcat 클러스터 구성

WBOY
WBOY원래의
2016-08-08 09:22:20854검색

코드 사용자 수가 증가함에 따라 고가용성 서비스에 대한 의존도가 날로 증가하고 있습니다. 단일 지점 서비스는 재시작이 사용자에게 미치는 영향을 피할 수 없으므로 이를 달성하기 위해 다음 솔루션을 채택합니다. 무통 재시작.

nginx+2tomcat(8080,8081)

아이디어: 정상적인 서비스를 제공하는 Tomcat이 하나만 있으면 서비스가 정상화된 후 다른 Tomcat을 시작하십시오. , 마지막으로 이전 서비스의 tomcat을 닫습니다.

셸 코드는 다음과 같습니다.

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 파일만 로드하는 것입니다. <code>关键点在利用了nginx的include指令实现只加载需要的conf文件:<br>

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

위 내용은 관련 내용을 포함하여 손쉬운 서비스 재시작 튜토리얼을 달성하기 위한 nginx tomcat 클러스터 구성을 소개합니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.