June 2018
M T W T F S S
« May    
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

WordPress Quotes

Are you bored with life? Then throw yourself into some work you believe in with all your heart, live for it, die for it, and you will find happiness that you had thought could never be yours.
Dale Carnegie

Recent Comments

June 2018
M T W T F S S
« May    
 123
45678910
11121314151617
18192021222324
252627282930  

Short Cuts

2012 SERVER (64)
2016 windows (9)
AIX (13)
Amazon (26)
Ansibile (17)
Apache (124)
Asterisk (2)
cassandra (2)
Centos (207)
Centos RHEL 7 (250)
chef (3)
cloud (2)
cluster (3)
Coherence (1)
DB2 (5)
DISK (25)
DNS (9)
Docker (24)
Eassy (11)
EXCHANGE (3)
Fedora (6)
ftp (5)
GOD (2)
Grub (1)
Hacking (10)
Hadoop (6)
horoscope (23)
Hyper-V (10)
IIS (15)
IPTABLES (15)
JAVA (6)
JBOSS (32)
jenkins (1)
Kubernetes (1)
Ldap (4)
Linux (188)
Linux Commands (167)
Load balancer (5)
mariadb (14)
Mongodb (4)
MQ Server (21)
MYSQL (80)
Nagios (5)
NaturalOil (13)
Nginx (27)
Ngix (1)
openldap (1)
Openstack (6)
Oracle (33)
Perl (3)
Postfix (19)
Postgresql (1)
PowerShell (2)
Python (3)
qmail (36)
Redis (11)
RHCE (28)
SCALEIO (1)
Security on Centos (29)
SFTP (1)
Shell (64)
Solaris (58)
Sql Server 2012 (4)
squid (3)
SSH (10)
SSL (14)
Storage (1)
swap (3)
TIPS on Linux (28)
tomcat (59)
Uncategorized (29)
Veritas (2)
vfabric (1)
VMware (28)
Weblogic (38)
Websphere (71)
Windows (19)
Windows Software (2)
wordpress (1)
ZIMBRA (17)

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Who's Online

20 visitors online now
5 guests, 15 bots, 0 members

Hit Counter provided by dental implants orange county

Tomcat load balancing using Nginx reverse proxies.

This essay focuses on Tomcat clusters and Tomcat load balancing using Nginx reverse proxies.

First, we need to literacy some knowledge points (to literacy, embarrassment):
Cluster (Cluster)
Simply put, N servers form a loosely coupled multiprocessor system (external is a server), internal communication through the network. Let N servers cooperate with each other and jointly carry the request pressure of a website. In the words of the last author is “the same business, deployed on multiple servers,” This is the cluster. The more important task in the cluster is task scheduling.
Load Balance
simply means that the request is distributed to each server in the cluster according to a certain load policy, and the entire server group processes the website request so as to jointly complete the task.
2, the installation environment is as follows:
Tencent cloud host, the installation is CentOS 7.3 64bits
Nginx 1.7.4
JDK8 and Tomcat8

Configure Nginx web reverse proxy to implement two Tomcat load balancing:

–Install and configure Tomcat tar -zxvf apache-tomcat-8.5.28.tar.gz
cp -rf apache-tomcat-8.5.28 /usr/local/
tomcat1 mv apache-tomcat-8.5.28 /usr/local/tomcat2

– Modify the tomcat1 port number
$ cd /usr/local/tomcat1/conf/
$ cp server.xml server.xml.bak
$ cp web.xml web.xml.bak
$ vi server.xml

# # Modify the Tomcat2 port number
$ cd / usr / local / tomcat / conf /
$ cp server.xml server.xml.bak
$ cp web.xml web.xml.bak
$ vi server.xml

– Add Tomcat1 to boot automatically
– Copy the /usr/local/tomcat1/bin/catalina.sh file to the /etc/init.d directory and rename it to tomcat1
# cp /usr/local/tomcat1/bin/catalina. Sh /etc/init.d/tomcat1 –Modify the
/etc/init.d/tomcat1 file and add it in the file:
# vi /etc/init.d/tomcat1 –Enter the
following in the first line (otherwise Error: The tomcat service does not support chkconfig):

#!/bin/sh
# chkconfig: 2345 10 90
# description:Tomcat1 service

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
……………………. ……………………………………..
# $ Id: catalina. Sh 1498485 2013-07-01 14:37:43Z markt $
# ———————————– ——————————————

CATALINA_HOME=/usr/local/tomcat1
JAVA_HOME=/usr/local/jdk8

# OS specific support. $var _must_ be set to either true or false.

– Add tomcat service:
# chkconfig –add tomcat1
– Set tomcat to boot from:
# chkconfig tomcat1 on – Tomcat2 will be set to boot from
– Copy /usr/local/tomcat2/bin/catalina.sh file To /etc/init.d directory and renamed tomcat2
# cp /usr/local/tomcat2/bin/catalina.sh /etc/init.d/tomcat2
– Modify / etc / init.d / tomcat2 file in the file :
# Vi /etc/init.d/tomcat2
– Enter the following in the first line (otherwise error: tomcat service does not support chkconfig):
#! / Bin / sh
# chkconfig: 2345 10 90
# description: Tomcat2 Service

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
……………………. ……………………………………..
# —– ————————————————– ———————-

CATALINA_HOME=/usr/local/tomcat2
JAVA_HOME=/usr/local/jdk8

# OS specific support. $var must be set to either true or false.

– Add tomcat service:
# chkconfig –add tomcat2
— Set tomcat to start from boot:
# chkconfig tomcat2 on

Here, tomcat has been installed, respectively, enable them, print out the referenced environment corresponds to two tomcat is right:

[root @ VM_177_101_centos src] # service tomcat1 start
Using CATALINA_BASE: / usr / local / tomcat1
Using CATALINA_HOME: / usr / local / tomcat1
Using CATALINA_TMPDIR: / usr / local / tomcat1 / temp
Using JRE_HOME: / usr / local / jdk8
Using CLASSPATH : /usr/local/tomcat1/bin/bootstrap.jar:/usr/local/tomcat1/bin/tomcat-juli.jar
Tomcat started.

[root @ VM_177_101_centos src] # service tomcat2 start
Using CATALINA_BASE: / usr / local / tomcat2
Using CATALINA_HOME: / usr / local / tomcat2
Using CATALINA_TMPDIR: / usr / local / tomcat2 / temp
Using JRE_HOME: / usr / local / jdk8
Using CLASSPATH: /usr/local/tomcat2/bin/bootstrap.jar:/usr/local/tomcat2/bin/tomcat-juli.jar
Tomcat started.

Last configuration configuration Nginx:

– Switch to the directory
cd /usr/local/nginx/conf
– Modify the configuration file
vi nginx.conf

– some common configuration –
worker_processes: the number of work processes can be configured more than one
–worker_connections: the maximum number of connections
per process –server: each server is equivalent to a proxy server
–lister: monitor port, the default 80
– server_name: The current service domain name, there can be more than one, separated by a space (we are local and therefore localhost) –
Location: said path matching, then configured / that all requests are matched here
–index: when If you do not specify a home page, the specified file will be selected by default, and can be separated by more than one space.
–proxy_pass: request to a custom server list
–upstream name {}: server cluster name

– Now want to access tomcat through nginx, you need to modify the server part of the configuration

server
{
listen 80 default;
charset utf-8;
server_name localhost;
access_log logs / host.access.log;

Location / {
proxy_pass http://localhost:8080;
proxy_redirect default;
}
}
– The proxy has been completed here, so that all requests need to go through the proxy server to access the official server.

Next, load balancing is implemented. During the installation process, the port configured by tomcat1 is 8080, and the port configured by tomcat2 is 8081. Then we need to define the upstream server in the configuration file (upstream server)

# The cluster
upstream testcomcat {
#weight is the greater the weight, the greater the probability of allocation
server 127.0.0.1:8080 weight=1;
server 127.0.0.1:8081 weight=2;
}

Server
{
listen 80 default;
charset utf-8;
access_log logs/host.access.log;

location / {
proxy_pass http: // testcomcat;
proxy_redirect default;
}
}

– In order to see is not the same, I will tomcat root the following index.jsp page slightly changed, respectively, joined TEST1, TEST2, to facilitate the distinction, restart nginx, the browser address bar enter the IP, visits, refresh several times Page, you will find that the switch between the two servers, as shown below:
service nginx reload

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Blue Captcha Image
Refresh

*

Protected by WP Anti Spam