Currently, there are many popular JavaEE containers: Tomcat, Resin, JBoss, and Glassfish. We usually use the first three containers. Who is more stable in terms of java container performance, what about higher concurrency? The current version of resin is 4.0.33, which is known to be more concurrent than apache. It not only supports jsp language, but also php.
We have used tomcat many times before. We know that if you want to configure multiple services on one machine, you only need to copy different configuration files and configure different ports. In comparison, resin is troublesome to configure multiple services on one machine. Let's take a look at it today.
I. System Environment
System Environment: CentOS6.0x86 _ 64
Nginx version: Nginx-1.2.6
Resin version: Resin-4.0.33
JDK: JDK-1.6.0_18
Ii. Install Nginx
# First download the software to be installed: [JDK can be downloaded and installed on the java website]
Wget http://nginx.org/download/nginx-1.2.6.tar.gz
Wget http://www.caucho.com/download/resin-4.0.33.tar.gz
Tar zxvf nginx-1.2.6.tar.gz
Cd nginx-1.2.6/
./Configure -- user = www -- group = www -- add-module = ../ngx_cache_purge-1.4
\ -- Prefix =/usr/local/nginx \ -- with-http_stub_status_module -- with-http_ssl_module
Make & make install
Iii. Resin Installation
tar –xzvf resin-4.0.33.tar.gz
cd resin-4.0.33 &&./configure --prefix=/usr/local/resin
\--with-resin-log=/data/logs/resin/ --with-java-home=/usr/java/jdk1.6.0_18/
make &&make install
Iv. Configure Resin
# Cd/usr/local/resin/conf/
# Add the following code to configure ports 8080 and 8081 for two instances on the local machine
<Clusterid = "app1">
<! -- Define the servers in the cluster -->
<Server-multiid-prefix = "app1" address-list = "$ {appdomainservers}" port = "6800"/>
<! -- The default host, matching any host name -->
<Hostid = "" root-directory = ".">
<Web-appid = "/" root-directory = "/var/www/html/app1"/>
</Host>
</Cluster>
<Clusterid = "app2">
<! -- Define the servers in the cluster -->
<Server-multiid-prefix = "app2" address-list = "$ {app2_servers}" port = "6801"/>
<! -- The default host, matching any host name -->
<Hostid = "" root-directory = ".">
<Web-appid = "/" root-directory = "/var/www/html/app2"/>
</Host>
</Cluster>
Modify the current directory vi resin. properties to modify the following content:
# app-tier Triad servers: app-0 app-1 app-2
app1_servers : 127.0.0.1:6800
app2_servers : 127.0.0.1:6801
# Use overrides for individual server control, for example: app-0.http : 8081
app1.http : 8080
app2.http : 8081
Configure different ports and then start the resin service:
/Usr/local/resin/bin/resinctl start
Check the resin port netstat-tnl. We will see ports 8080 and 8081.
5. Configure Nginx
With the extensive use of Nginx High-Performance Web servers, the latest stable version of Nginx is 1.2.6. Dr. Zhang uses Nginx extensively in practical applications and shares knowledge about Nginx High-Performance Web servers, nginx is also developing rapidly in China. Now let's take a look at the knowledge of Nginx dynamic/static separation, which is for reference only.
I. Practical environment:
System Version: CentOS6.0 X86_64
Nginx version: Nginx-1.2.6
Tomcat version: Tomcat-6.0.18
Ii. Nginx installation:
To install Nginx in the actual environment, first install the pcre Library and then install Nginx:
# Install pcre to support the rewrite library. You can also install the source code. Note * when installing the source code, specify the pcre path as the path to extract the source code, instead of the compiled path. Otherwise, an error is reported.
Yum install pcre-devel pcre-y
# Download the Nginx source code package
Http://nginx.org/download/nginx-1.2.6.tar.gz cd/usr/src; wget-c
# Decompress the Nginx source code package
Tar-xzf nginx-1.2.6.tar.gz
# Go To The extract directory, and then sed to change the Nginx version information to TDTWS
Cd nginx-1.2.6; sed-I-e's/1.2.6 // G'-e's/nginx \ // TDTWS/G'-e's/"NGINX"/"TDTWS"/g 'src/core/nginx. h
# Pre-compile Nginx
./Configure -- user = www -- group = www -- prefix =/usr/local/nginx -- with-http_stub_status_module -- with-http_ssl_module
#. After the configure pre-compilation is successful, run the make command to compile
Make
# After make is successfully executed, execute make install to officially install
Make install
# Nginx installation has been completed since now !!!
3. Configure Nginx:
In view of the fact that my 51CTO blog already has Tomcat installation and configuration, ignore this and only configure Nginx.
# Enter the Nginx application directory
Cd/usr/local/nginx/conf
# Back up the original nginx. conf file
Mv nginx. conf nginx. bak
Create vi nginx. conf and write the following content:
User www;
Worker_processes 8;
Worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
Pid/usr/local/nginx. pid;
Worker_rlimit_nofile 102400;
Events
{
Use epoll;
Worker_connections 102400;
}
Http
{
Include mime. types;
Default_type application/octet-stream;
Fastcgi_intercept_errors on;
Charset UTF-8;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 4 k;
Large_client_header_buffers 4 32 k;
Client_max_body_size 300 m;
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 60;
Tcp_nodelay on;
Client_body_buffer_size 512 k;
Proxy_connect_timeout 5;
Proxy_read_timeout 60;
Proxy_send_timeout 5;
Proxy_buffer_size 16 k;
Proxy_buffers 4 64 k;
Proxy_busy_buffers_size 128 k;
Proxy_temp_file_write_size 128 k;
Gzip on;
Gzip_min_length 1 k;
Gzip_buffers 4 16 k;
Gzip_http_version 1.1;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
### 2012-12-19 change nginx logs
Log_format main '$ http_x_forwarded_for-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ request_time $ remote_addr ';
# Here is the configuration of the backend server wugk application cluster, which can be modified according to the actual backend situation. tdt_wugk is the name of the Server Load balancer instance and can be specified arbitrarily.
# However, it must be consistent with the pass segment of the vhosts. conf VM. Otherwise, the backend requests cannot be forwarded.
Upstream tdt_wugk {
Server 10.10.141.30: 8080 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.30: 8081 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.31: 8080 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.31: 8081 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.32: 8080 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.32: 8081 weight = 1max_fails = 2fail_timeout = 30 s;
}
# Here is the backend APP Server Load balancer configuration, which can be modified based on the actual backend situation. Tdt_app is the Server Load balancer name, which can be specified at will
Upstream tdt_app {
Server 10.10.141.40: 8080 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.40: 8081 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.41: 8080 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.41: 8081 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.42: 8080 weight = 1max_fails = 2fail_timeout = 30 s;
Server 10.10.141.42: 8081 weight = 1max_fails = 2fail_timeout = 30 s;
}
# Include references vhosts. conf. This file is mainly used to configure the Nginx Virtual Host
Include vhosts. conf;
}
After nginx. conf is configured, configure the nginx virtual host and create vhosts. conf in the current directory.
Vi vhosts. conf:
#### Www.wuguangke.cn
Server
{
Listen 80;
Server_name www.wuguangke.cn;
Index index.html index.htm;
# Configure the publishing directory as/data/www/wugk
Root/data/www/wugk;
Location/
{
Proxy_next_upstream http_502 http_504 error timeout invalid_header;
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: // tdt_wugk;
Expires 3d;
}
# Send the dynamic page to http: // tdt_wugk, that is, the upstream tdt_wugk balance defined in nginx. conf.
Location ~ . * \. (Php | jsp | cgi )? $
{
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: // tdt_wugk;
}
# Configure Nginx static/dynamic separation. The defined static page is directly read from the Nginx release directory.
Location ~ . * \. (Html | htm | gif | jpg | jpeg | bmp | png | ico | txt | js | css) $
{
Root/data/www/wugk;
# Expires defines that the user's browser cache time is 3 days. If the static page is not updated frequently, you can set a longer period, which can save bandwidth and relieve server pressure.
Expires 3d;
}
# Define the path of Nginx output logs
Access_log/data/logs/nginx_wugk/access. log main;
Error_log/data/logs/nginx_wugk/error. log crit;
}
######### Chinaapp.sinaapp.com 2012-12-19
Server
{
Listen 80;
Server_name chinaapp.sinaapp.com;
Index index.html index.htm;
Root/data/www;
Location/
{
Proxy_next_upstream http_502 http_504 error timeout invalid_header;
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: // tdt_app;
Expires 3d;
}
Location ~ . * \. (Php | jsp | cgi )? $
{
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: // tdt_app;
}
Location ~ . * \. (Html | htm | gif | jpg | jpeg | bmp | png | ico | txt | js | css) $
{
Root/data/www/app;
Expires 3d;
}
Access_log/data/logs/nginx_app/access. log main;
Error_log/data/logs/nginx_app/error. log crit;
}
6. deployment test:
After the backend is configured with the Tomcat service and started, the released program needs to be synchronized to the/data/www directory of Nginx, because after the static and dynamic separation is configured, the user requests the static page you defined, by default, requests will be sent to the nginx publishing directory instead of to the backend. Therefore, you must ensure that the backend and front-end programs are consistent at this time. You can use Rsync for automatic synchronization on the server.
# Check whether the Nginx configuration file is correctly configured. The prompt "OK" and "successful" is displayed as follows:
[Root @ WEB-11-151 ~] #/Usr/local/nginx/sbin/nginx-t
Nginx: the configuration file/usr/local/nginx/conf/nginx. conf syntax is OK
Nginx: configuration file/usr/local/nginx/conf/nginx. conf test is successful
# Start the Nginx Service
/Usr/local/nginx/sbin/nginx
# Check whether the Nginx process is started
Ps-ef | grep nginx
This article is just a simple practical case. The configuration and parameters are not described too much here and will be updated later.
This article from the "Wu guangke-Focus on automated O & M" blog, please be sure to keep this source http://wgkgood.blog.51cto.com/1192594/1094236