In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The following brings you how to achieve nginx+tomcat-based load balancing on centos7, hoping to give you some help in practical application. Load balancing involves more things, there are not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.
Overview
In general, a Tomcat site may have a single point of failure and can not cope with the complex and diverse requests of too many customers, so it can not be used in the production environment alone, so a more reliable solution is needed to improve the web site architecture.
Nginx is an excellent http CVM software, which can support responses of up to 50000 concurrent connections, has strong static resource processing capacity, runs stably, and consumes very low system resources such as memory and CPU. At present, many large websites use nginx as the reverse proxy and load balancing of back-end website programs.
In this case, we use nginx as the load balancer, reverse proxy and tomcat as the node server.
Case environment host IP address nginx server 192.168.177.132tomcat server 1192.168.177.145tomcat server 2192.168.177.135tomcat server installation jdk (version 1.8) # tar xf apache-tomcat-8.5.23.tar.gz / opt# tar xf jdk-8u144-linux-x64.tar.gz / opt// extract installation package # mv apache-tomcat-8.5.23/ / usr/local/tomcat8# mv jdk1.8.0 _ 144 / / usr/local/java// is easy to manage # vim / etc/profile / / set the environment variable export JAVA_HOME=/usr/local/javaexport JRE_HOME=/usr/local/java/jreexport PATH=$PATH:/usr/local/java/binexport CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib# source / etc/profile# java-version / / View java version information java version "1.8.0x131" OpenJDK Runtime Environment (build 1.8.0_131-b12) OpenJDK 64-Bit Server VM (build 25.131-b12 Mixed mode)
Install tomcat# ln-s / usr/local/tomcat8/bin/startup.sh / usr/bin/tomcatup# ln-s / usr/local/tomcat8/bin/shutdown.sh / usr/bin/tomcatdown// under / usr/bin for easy identification command # tomcatup / / enable service # netstat-anpt | grep 8080 / / check whether the tomcat port is open # http://192.168.177.145:8080/ Test the default test page Whether the normal display (node) # vim / usr/local/tomcat8/webapps/ROOT/index.jsp / / modify the default web content (site) this is 145 website!
= Note: the configuration of the two tomcat servers is exactly the same
Nginx server manually compiles and installs # tar zxvf nginx-1.12.0.tar.gz-C / opt# yum install pcre-devel zlib-devel gcc gcc-c++-y / / installation environment package # useradd-M-s / sbin/nologin nginx / / user who creates and manages nginx # cd / opt/nginx-1.12.0/. / configure\-- prefix=/usr/local/nginx\-- user=nginx\ / / specify to run User-- group=nginx\ / / specify the running group-- with-http_stub_status_module / / enable statistical status # make & & make install# ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ Let the system recognize the command # nginx-t / / verify the syntax to write a script # cd / etc/init.d/ vim nginxAccording to service management. :-99 2 years description: Nginx Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" PIDF= "/ usr/local/nginx/logs/nginx.pid" case "$1" in start) $PROG ; stop) kill-s QUIT $(cat $PIDF);; restart) $0 stop $0 start;; reload) kill-s HUP $(cat $PIDF) *) echo "Usage: $0 {start | stop | restart | reload}" exit 1esacexit permission chmod + x / etc/init.d/nginx / / execute permission # chkconfig-- add nginx# chkconfig-- level 35 nginx on# service nginx stop# netstat-ntap | grep 8 modify service nginx start# netstat-ntap | grep 80 modify configuration file # vim / usr/local/nginx/conf/nginx.conf # keepalive_timeout 0; keepalive_timeout 65; # gzip on Add: upstream tomcat_server {# add server 192.168.177.145 weight=1; / / same weight, the page will repeatedly switch server 192.168.177.135 weight=1; 8080 weight=1;} server {listen 80th between the following two pages. Omit location / {# root html; # index index.html index.htm; proxy_pass http://tomcat_server; / / add a line, proxy the default site of nginx to the set tomcat_server load balancer server via proxy_pass method} # service nginx restart / / enable nginx service / /
After reading the above about how to achieve nginx+tomcat-based load balancing on centos7, if there is anything else you need to know, you can find what you are interested in in the industry information or find our professional and technical engineers to answer, technical engineers have more than ten years of experience in the industry. Official website link www.yisu.com
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.