CentOS deployment simple tomcat and load balancing

Source: Internet
Author: User

CentOS deployment simple tomcat and load balancing

Experimental topology:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/3C/wKioL1XfCwSQQVWJAADCOoTe3tI052.jpg "title=" Tomcat.png "alt=" Wkiol1xfcwsqqvwjaadcoote3ti052.jpg "/>



Experiment Preparation:

Prepare the Apache-tomcat and JDK and nginx packages, which I use

Jdk-7u65-linux-x64.gz

Apache-tomcat-7.0.54.tar.gz

Nginx-1.9.4.tar.gz

Stop Iptables and SELinux before the experiment

Sed-i '/selinux/s/enforcing/disabled/g '/etc/selinux/config/etc/init.d/iptables stop

I'm using it here.

Jdk-7u65-linux-x64.gz

Apache-tomcat-7.0.54.tar.gz

Nginx-1.9.4.tar.gz

Both Tomcat and JDK are free-to-install packages, just unzip the move and enable!

Tar zxf jdk-7u65-linux-x64.gz

MV Jdk1.7.0_65/usr/local/java

Add the PATH environment variable for Java

vim/etc/profile.d/java.sh

Export Java_home=/usr/local/java

Export path= $PATH: Java_home/bin

: Wq

. /etc/profile.d/java.sh

View Java version

Java-version

Deploying Tomcat

Tar zxf apache-tomcat-7.0.54.tar.gz

MV APACHE-TOMCAT-7.0.54/USR/LOCAL/TOMCAT7

Start Tomcat

/usr/local/tomcat7/bin/startup.sh

Access test

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/3C/wKioL1XfBbWA27HFAANvVy1BIKE235.jpg "title=" 2015-08-27_203312.png "alt=" Wkiol1xfbbwa27hfaanvvy1bike235.jpg "/>

The above page shows that Tomcat is complete!

To deploy a Tomcat directory-based virtual host:


Build a directory of virtual hosts and test Web pages

Mkdir-pv/web/webapp1

vim/web/webapp1/index.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>

: Wq

Edit the Tomcat configuration file Server.xml Add the following code:

Vim/usr/local/tomcat7/conf/server.xml
<context docbase= "/web/webapp" path= "" reloadable= "false" >
</Context>

The location is as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/3D/wKioL1XfDZfS5NvXAAI26fkP7dE355.jpg "title=" 2015-08-27_210526.png "alt=" Wkiol1xfdzfs5nvxaai26fkp7de355.jpg "/>

Restarting the service can be as follows:

/usr/local/tomcat7/bin/shutdown.sh

/usr/local/tomcat7/bin/startup.sh

The access page is as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/40/wKiom1XfDHTgS87nAACpIVjWwG4045.jpg "title=" 2015-08-27_211057.png "alt=" Wkiom1xfdhtgs87naacpivjwwg4045.jpg "/>

If the above page indicates that your directory-based virtual host has been completed!

If you have done it all, and have succeeded! Then I will congratulate you, according to the above configuration to build a tomcat to prepare for the back!

Build a Nginx+tomcat load Balancing cluster:

First we need two servers to build Tomcat, and a server to build Nginx!

For the system I recommend the best here!

Deploying Nginx Servers

To install a dependency package:

Yum-y Install pcre-devel zlib-devel openssl-devel OpenSSL


Create the required user www

Useradd-m-s/bin/false www


Unzip the Nginx and enter the directory

Tar zxf nginx-1.9.4.tar.gz

CD nginx-1.9.4


Compile and install Nginx

./configure--prefix=/usr/local/nginx \

--USER=WWW \

--GROUP=WWW \

--with-file-aio \

--with-http_stub_status_module

--with-http_gzip_static_module

--with-http_flv_module--with-http_ssl_module

Make &&make Install


Edit the Nginx configuration file by adding the following code:

Vim/usr/local/nginx/conf/nginx.conf

Upstream Tomcat_server {server 99.99.99.4:8080 weight=1;       Server 99.99.99.5:8080 weight=1; }proxy_pass Http://tomcat_server;

Add the following location:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/3D/wKioL1XfFESRO58IAAFfDpt5P4s253.jpg "title=" 2015-08-27_213334.png "alt=" Wkiol1xffesro58iaaffdpt5p4s253.jpg "/>

Check nginx configuration file for errors:

/usr/local/nginx/sbin/nginx-t


Start Nginx:

/usr/local/nginx/sbin/nginx


To see if the port is started:

NETSTAT-UTPLN |grep 80


Access test:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/41/wKiom1XfEt2wz8cdAACYeB4h3_A859.jpg "title=" 2015-08-27_213801.png "alt=" Wkiom1xfet2wz8cdaacyeb4h3_a859.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/3D/wKioL1XfFPeipWgwAACgrP3PG6c171.jpg "title=" 2015-08-27_213812.png "alt=" Wkiol1xffpeipwgwaacgrp3pg6c171.jpg "/>

Press F5 constantly refreshed, two pages constantly switching. Indicates that a simple Tomcat+nginx load Balancer cluster has been completed!

Error Summary:

All kinds of compilation did not succeed, remember to check whether the dependency package is complete!


After start-up access if it doesn't work, check the configuration file and Web page for errors.


If an error occurs with a word like CPU, you need to check the compatibility between the software and the system.


If there is a new error please leave a message, thank you!

This article is from the "XXX" blog, please be sure to keep this source http://moumou.blog.51cto.com/9995443/1689084

CentOS deployment simple tomcat and load balancing

Related Article

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.