Nginx tomcat cluster configuration to achieve painless Restart service tutorial

Source: Internet
Author: User

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;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.