Implementation of nginx+ multiple Tomcat load balancing under Linux

Source: Internet
Author: User
Tags server port

As a result of the project, a total of 10 tomcat ports were created and the Nginx was responsible for forwarding. The 9 tomcat ports are 8080,11000,12000,13000,14000,15000,16000,17000,18000,19000 respectively.

Nginx configuration: Upstream Tomcat {

Server xxx.xxx.xx.xxx:8080

Server xxx.xxx.xx.xxx:11000

... And so on

}

Server configuration:

server{

if ($uri = '/') {
Rewrite. */break;
}
Location/{
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_pass Http://tomcat;
}

server{

if ($uri = '/') {
Rewrite. */break;
}
Location/{
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_pass Http://tomcat;
}

... In turn

}

Other similar. The main is tomcat here more cumbersome configuration.

1, download the JDK installation package, download the 1.8 version here.

2, unzip.

3, the installation path is in the/usr/java directory

4. Configuration of Environment variables:

Vim/etc/profile into edit:

Export java_home=/usr/java/jdk1.8.0_131
Export JRE_HOME=/USR/JAVA/JDK1.8.0_131/JRE
Export classpath= $JAVA _home/lib/tools.jar: $JAVA _home/lib/dt.jar: $JAVA _home/lib
Export path= $JAVA _home/bin:/usr/local/nginx/sbin:/usr/local/php/bin:/usr/local/mysql/bin: $PATH

After the add is complete source/etc/profile make it effective.

Detection: Enter java-version at the command line to see information such as JDK version, indicating that the installation was successful. Next is the Tomcat configuration.

Tomcat:

1, download the installation package, download here is apache-tomcat-8.5.15.tar.gz.

2. Unzip the installation script:

For I in CRM DZ JZ TB WM xyg YG YJ LCB GW
Do
Cd/usr/local
TAR-ZXF apache-tomcat-8.5.15.tar.gz
Mv-f apache-tomcat-8.5.15/usr/local/tomcat/"${i}" #生成10个Tomcat端
cd/usr/local/tomcat/"${i}"/bin/
Cat >> catalina.sh <<eof #这里的代码主要是配置每个Tomcat端的启动脚本的环境变量
Export catalina_base= ' $CATALINA ' _base_ "${i}"
Export catalina_home= ' $CATALINA ' _home_ "${i}"
Eof
Cat >>/etc/profile <<eof #这里的代码主要是配置这10个Tomcat端的环境变量

# "${i}"

Catalina_base_ "${i}" =/usr/local/tomcat/"${i}"
Catalina_home_ "${i}" =/usr/local/tomcat/"${i}"
Export Classpath=.:${catalina_home_ "${i}"}/bin/tomcat-juli.jar:${catalina_home_ "${i}"}/bin/bootstrap.jar
Export Catalina_base_ "${i}" Catalina_home_ "${i}"

Eof
Done

CRM dz JZ TB WM xyg YG YJ LCB GW These are the names in the project, you can also name them without having to worry about him.

Next, configure the ports for each tomcat. I'll upload the auto-replace script later.

Enter the Conf directory for each Tomcat side, cd/usr/local/tomcat/the project name/conf

Vim Server.xml

Modified 3:

1) <server port= "8005" shutdown= "shutdown" > Port port number

2) <connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443"/> Port Port number

3) <connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/> Port port number

After: CD. /bin/

Modify:

Vim catalina.sh

Find to: Setclasspath this name. Command:/setclasspath

Modify $catalina_home+ your project name (to correspond), note here to modify Setclasspath this name before all the $catalina_home

Esc,:wq Save and exit.

At this point, the configuration is basically complete.

Finally, go to the bin directory, first./shutdown.sh, and then./startup.sh, it's a successful launch.

If the page display is rejected, then most likely the firewall is rejected, to add a rule

Vim/etc/sysconfig/iptables

-A input-p tcp-m state--state new-m TCP--dport port number-j ACCEPT

Or

-A Input-s your IP address-j ACCEPT

Enter the http://localhost: port in the browser address bar to access it, the default should be Tomcat's own directory, a kitten.

Implementation of nginx+ multiple Tomcat load balancing under Linux

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.