Memcached Walkthrough (3) using memcached to build a tomcat cluster

Source: Internet
Author: User

In the previous article, the need for a tomcat cluster has been clarified, primarily from high availability and high concurrency considerations. In general, the Tomcat cluster is built using a pre-set nginx or Apache as a reverse proxy to forward the request to back-end tomcat. Using the Tomcat cluster will inevitably lead to session data sharing issues. How to solve this problem? Can be achieved with memcached.

Main content

    1. Test the throughput rate of a single tomcat

    2. Build a apache+mod_jk+2 Tomcat cluster environment

    3. Build a apache+mod_jk+2 tomcat+memcached cluster environment

    4. Compare throughput rates for 2 environments

Environment preparation

Confirm Apache service location and version number

[Email protected] httpd]# httpd-vserver version:apache/2.2.15 (Unix) Server Built:feb 11:17:44[[email Protect ED] httpd]# which httpd/usr/sbin/httpd#apache home directory:/ETC/HTTPD

Confirm JDK and Tomcat services

[[email protected] tomcat-sets]$ ls /u01/tomcat-setsapache-tomcat-node1[[email  protected] apache-tomcat-node1]$ cat /proc/meminfo memtotal:         1937148 KB ... [[email protected] /]$ /u01/tomcat-sets/apache-tomcat-node1/bin/version.sh using  catalina_base:   /u01/tomcat-sets/apache-tomcat-node1using catalina_home:    /u01/tomcat-sets/apache-tomcat-node1using catalina_tmpdir: /u01/tomcat-sets/ apache-tomcat-node1/tempusing jre_home:        /usr/local/java/ jdk1.6.0_45...server version: apache tomcat/7.0.33server built:   nov  18 2012 04:15:21server number:  7.0.33.0os name:         LinuxOS Version:     2.6.32-358.el6.i686Architecture:    i386jvm version:    1.6.0_45-b06jvm vendor:     sun  Microsystems inc.

1. Test the throughput rate of a single tomcat

1.1 Prepare a static test resource (staticprotocal.html, size 50K)

Resources can be accessed through http://192.168.163.146:8080/examples/staticProtocal.html

[Email protected] examples]$ ll/u01/tomcat-sets/apache-tomcat-node1/webapps/examplestotal 72-rw-r--r--. 1 Hadoop hadoop 1179 Nov index.htmldrwxr-xr-x.  Hadoop hadoop 4096 18:48 jspdrwxr-xr-x.  3 Hadoop hadoop 4096 18:48 servlets-rw-rw-r--.  1 Hadoop hadoop 50663 21:09 staticprotocal.htmldrwxr-xr-x.  7 Hadoop hadoop 4096 18:48 web-infdrwxr-xr-x. 2 Hadoop hadoop 4096 18:48 websocket

1.2 Start Apache-tomcat-node1, port is the default 8080

1.3 using Apache AB command test on another host

c:\apache24\bin>ab  -n 10000 -c 4  http://192.168.163.146:8080/examples/ staticprotocal.htmlthis is apachebench, version 2.3 < $Revision: 1604373  $>copyright 1996 adam twiss, zeus technology ltd, http:// www.zeustech.net/Licensed to The Apache Software Foundation, http:// www.apache.org/benchmarking 192.168.163.146  (be patient) completed 1000 requests ... completed 10000 requestsfinished 10000 requestsserver software:         Apache-Coyote/1.1Server Hostname:         192.168.163.146Server Port:             8080document path:          /examples/ Staticprotocal.htmldocument length:   &nbSp;    50663 bytesconcurrency level:      4time  taken for tests:   12.065 secondsComplete requests:       10000Failed requests:        0Total  transferred:      509120000 byteshtml transferred:        506630000 bytesRequests per second:    828.81  [#/sec]  (mean) time per request:       4.826 [ms]  ( Mean) time per request:       1.207 [ms]  (mean,  across all concurrent requests) transfer rate:           41207.63 [kbytes/sec] received ...

Tested, the result of a single Tomcat is:qps:828.81

There is a consensus that Apache's ability to handle static files is stronger than Tomcat. A mule is a horse, and a baby looks.

1.4 Simple Edit Apache config file httpd.conf. (It is best to modify the previous backup)

$ cat/etc/httpd/conf/httpd.conf ... ServerName localhost:80documentroot "/var/www/html" ...

1.5 Copy the staticprotocal.html file that you just made to the DocumentRoot "/var/www/html" directory.

$ ls/var/www/html/staticprotocal.html

1.6 Start httpd

$ service httpd startstarting httpd: [OK]

The resource can be accessed through a link at this time: http://192.168.163.146/staticProtocal.html

1.7 Testing Apache Throughput

c:\apache24\bin>ab  -n 10000 -c 4  http://192.168.163.146/ staticprotocal.htmlthis is apachebench, version 2.3 < $Revision: 1604373  $>copyright 1996 adam twiss, zeus technology ltd, http:// www.zeustech.net/Licensed to The Apache Software Foundation, http:// www.apache.org/benchmarking 192.168.163.146  (be patient) completed 1000 requests ... finished 10000 requestsserver software:        apache/ 2.2.15server hostname:        192.168.163.146server port:             80Document Path:           /staticProtocal.htmlDocument Length:         50663 bytesconcurrency level:      4time taken for tests:   11.902  secondscomplete requests:      10000failed requests:         0Total transferred:      509350000  Byteshtml transferred:       506630000 bytesrequests per  second:    840.17 [#/sec]  (mean) time per request:        4.761 [ms]  (mean) time per request:        1.190 [ms]  (mean, across all concurrent requests) Transfer  rate:          41790.94 [Kbytes/sec]  Received

After testing, the result of a single Apache is:qps:840.17

It is obvious that Apache handles static file capabilities slightly higher than Tomcat.

Next, use Apache to build a two-node Tomcat cluster, and in passing verify how much the QPS can achieve. This is the next section of the content.

2. Build a apache+mod_jk+2 Tomcat cluster environment

2.1 Download MOD_JK and install

To install Httpd-devel, you will configure:error:Cannot find the WebServer

# yum Install httpd-devel## after installing Httpd-devel, the newly added directory/usr/sbin/apxs# #下载 # wget # #解压 # tar zxvf tomcat-connectors-1.2.41-src. tar.gz # CD tomcat-connectors-1.2.41-src/native #./buildconf.sh--with-apxs=/usr/sbin/apxs # Make

Here mod_jk.so has been generated, and finally put mod_jk.so into the Apache modules directory

Cp/u01/software/tomcat-connectors-1.2.41-src/native/apache-2.0/mod_jk.so/etc/httpd/modules

2.2 Configuring MOD_JK

Please refer to: http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html

mod_jk: Support Platform Linux, FreeBSD, AIX, HP-UX, MacOS X, Solaris,Apache 1.3 and/or 2.x

MOD_JK: Support for Tomcat 3.2 to Tomcat 8.

Redirector Use protocol: AJP12 and AJP13

The AJP12 protocol is for Tomcat 3.2.x and 3.3.x.

AJP13 protocol supports Tomcat 4+

Mod_jk:2 a component.

the Apache HTTP Server module. Determined by the platform, is generally mod_jk.so, MOD_JK.NLM or MOD_JK. SRVPGM

workers.properties: Description tomcat related host (s) and port (s) files.

2.3 Enabling the Jk_module module

Add the following snippet to/etc/httpd/httpd.conf

# Load mod_jk moduleloadmodule jk_module modules/mod_jk.sojkworkersfile conf/workers.propertiesjklogfile logs/mod_jk. Logjkloglevel infoinclude "conf/mod_jk.conf"

2.4 Configuring back-end Tomcat host and port mappings, editing or creating new files,/etc/httpd/workers.properties

Configuration Instructions Reference: https://tomcat.apache.org/connectors-doc/reference/workers.html

worker.list=tomcat1worker.tomcat1.port=8009worker.tomcat1.host=127.0.0.1worker.tomcat1.type=ajp13# Worker.tomcat1.lbfactor=1

The effect now achieved is Apache anti-generational 1 tomcat. So there's no need to configure additional load balancing information.

2.5 editing conf/mod_jk.conf, adding resource mappings

#LoadModule jk_module modules/mod_jk.sojkmount/*.jsp tomcat1jkmount/examples/* tomcat1#jkworkersfile conf/ Workers.properties

The two lines of the comment, which are already configured in httpd.conf, do not require duplicate configuration.

2.6 booting Tomcat, and Apache

The author, in this step after testing, can not achieve the agent effect.

By viewing log information (/var/log/httpd/mod_jk.log)

[Fri 12 22:49:23.051 2016] [9739:3078039376] [ERROR] INIT_JK::MOD_JK.C (3574): Initializing shm:/etc/httpd/logs/jk-runtime-status.9739 errno= Load balancing workers would not function properly.


By referencing the on-line solution: Temporarily turn SELinux off

Confirm SELinux Status/usr/sbin/sestatus-v temporary shutdown Setenforce 0 Permanently turn off modify/etc/selinux/config set to Selinux=disabled

Access test, no problem

http://192.168.163.146/examples/servlets/

http://192.168.163.146:8080/examples/servlets/


Here, complete the apache+ single tomcat configuration.

c:\apache24\bin>ab  -n 10000 -c 4  http://192.168.163.146/examples/ staticprotocal.htmlthis is apachebench, version 2.3 < $Revision: 1604373  $>copyright 1996 adam twiss, zeus technology ltd, http:// www.zeustech.net/Licensed to The Apache Software Foundation, http:// www.apache.org/benchmarking 192.168.163.146  (be patient) completed 1000 requests ... completed 10000 requestsfinished 10000 requestsserver software:         Apache/2.2.15Server Hostname:         192.168.163.146Server Port:             80document path:          /examples/ Staticprotocal.htmldocument length:     &nBsp;  50663 bytesconcurrency level:      4time taken  for tests:   13.555 secondsComplete requests:       10000failed requests:        0total transferred:       509320000 bytesHTML transferred:      &NBSP;&NBSP;506630000&NBSP;BYTESREQUESTS&NBSP;PER&NBSP;SECOND:&NBSP;&NBSP;&NBSP;&NBSP;737.73&NBSP;[#/SEC]   (mean) time per request:       5.422 [ms]  (mean) time per request:       1.356 [ms]  (Mean, across  all concurrent requests) transfer rate:           36693.36 [kbytes/sec] received

Unfortunately, the apache+tomcat combination of the QPS:737.73

-------------

Not to be continued




This article is from a "simple" blog, so be sure to keep this source http://dba10g.blog.51cto.com/764602/1837468

Memcached Walkthrough (3) using memcached to build a tomcat cluster

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.