1. Install tomcat:
(1), install jdk:
[root@localhost java]# mkdir -p /usr/java
[root@localhost java]# tar zxvf jdk-7u3-linux-x64.tar.gz -C
/usr/java/
[root@localhost java]# vi /etc/profile
JAVA_HOME=”/usr/java/jdk1.7.0_03″
JRE_HOME=”/usr/java/jdk1.7.0_03/jre”# Without this configuration, tomcat will report an error when it is closed.
CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export JAVA_HOME
export JRE_HOME
export CLASSPATH
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
[root@localhost java]# source /etc/profile
[root@localhost java]# java -version
java version “1.7.0_03”
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed
mode)
2. Install tomcat:
Tomcat download:
# tar zxvf apache-tomcat-7.0.26.tar.gz -C /usr/src/
# cd /usr/src/
# cp -rf apache-tomcat-7.0.26 /usr/local/tomcat
# cp -rf apache-tomcat-7.0.26 /usr/local/tomcat1
Install the first TOMCAT in /usr/local/tomcat
# cd /usr/local/tomcat
# vi /etc/profile
Add $TOMCAT_HOME/common/lib/servlet.jar after CLASSPATH
Add after PATH: $CATALINA_HOME/lib
export TOMCAT_HOME=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
export CATALINA_BASE=/usr/local/tomcat
export PATH=$PATH:$CATALINA_HOME/lib
export
CLASSPATH=$CLASSPATH:$CATALINA_HOME/common/lib/servlet.jar
Install the second TOMCAT in /usr/local/tomcat1
Setting environment variables
#vi /etc/profile
Add $TOMCAT_2_HOME/common/lib/servlet.jar after CLASSPATH
Add after PATH: $CATALINA_2_HOME/lib
export TOMCAT_1_HOME=/usr/local/tomcat1
export CATALINA_1_HOME=/usr/local/tomcat1
export CATALINA_1_BASE=/usr/local/tomcat1
export PATH=$PATH:$CATALINA_1_HOME/lib
export
CLASSPATH=$CLASSPATH:$CATALINA_1_HOME/common/lib/servlet.jar
Save and exit
:wq
Enabling environment variables to take effect
#source /etc/profile
Modify the TOMCAT configuration file vi
/usr/local/tomcat1/conf/server.xml (if the two tomcats are not on the same machine, you don’t need to modify the port)
Put the following
…
<Connector port="8080" protocol="HTTP/1.1"
…
<Host name="localhost"
appBase="webapps"
…/>
Change to
…
<Connector port="9080" protocol="HTTP/1.1"
…
<Host name="localhost"
appBase="/usr/local/www/web" (You don't need to change it here, you can jump directly to the tomcat home page during the test)
…/>
Modify the TOMCAT configuration startup file /usr/local/tomcat1/bin/startup.sh
Add the following on exec
export JAVA_HOME=/usr/java/jdk1.7.0_03
export JRE_HOME=/usr/java/jdk1.7.0_03/jre
export CLASSPATH=$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH
%Attention, many of the online ones are written as export PATH=$JAVA_HOME/bin, and an error will be reported at startup%
export CATALINA_HOME=$CATALINA_2_HOME
export CATALINA_BASE=$CATALINA_2_BASE
Modify the TOMCAT configuration startup file /usr/local/tomcat2/bin/shutdown.sh
Add the following on exec
export JAVA_HOME=/usr/local/java/jdk1.7.0_03
export JRE_HOME=/usr/java/jdk1.7.0_03/jre
export CLASSPATH=$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH
export CATALINA_HOME=$CATALINA_2_HOME
export CATALINA_BASE=$CATALINA_2_BASE
Start TOMCAT
/usr/local/tomcat1/bin/startup.sh
Close TOMCAT
/usr/local/tomcat1/bin/shutdown.sh
3. Install nginx:
(1), install pcre:
# tar zxvf pcre-8.30.tar.gz -C /usr/src/
# cd /usr/src/pcre-8.30/
# ./configure
# make && make install
(2), install the plug-in upstream,
# tar zxvf nginx-1.0.13.tar.gz -C /usr/src/
# tar zxvf nginx-upstream-jvm-route-0.1.tar.gz -C /usr/src/
Note that this is decompressed to the same folder, the default name here is nginx-1.0.13
# cd /usr/nginx-1.0.13/
# patch -p0 <
/usr/nginx-1.0.13/nginx_upstream_jvm_route/jvm_route.patch
(3), install nginx:
# ./configure –prefix=/usr/local/nginx
–with-http_stub_status_module –with-pcre=/usr/src/pcre-8.30
–add-module=/usr/src/nginx_upstream_jvm_route –with-openssl=/usr/
( –user= –group= )
# make && make install
(4), edit nginx.conf:
# vi /usr/local/nginx/conf/nginx.conf
user nobody;
worker_processes 8;
error_log logs/nginx_error.log crit;
pid
/usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be
opened by this process.
worker_rlimit_nofile 20480;
events
{
use epoll;
worker_connections 20480;
}
http {
upstream aa {
“
server 127.0.0.1:8080 max_fails=3 fail_timeout=50s;
}
upstream bb {
“
server 127.0.0.1:8081 max_fails=3 fail_timeout=50s;
}
include
mime.types;
default_type application/octet-stream;
#charset gb2312;
charset UTF-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_header_timeout 20;
client_max_body_size 20m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
proxy_connect_timeout 30;
proxy_read_timeout 60;
proxy_send_timeout 20;
proxy_buffer_size 96k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
# proxy_store on;
# proxy_store_access user:rw group:rw all:rw;
proxy_temp_path /usr/local/nginx/proxy_temp;
proxy_cache_path /usr/local/nginx/www levels=1:2
keys_zOne=cache_one:20m inactive=1d max_size=2g;
gzip on;
gzip_proxied any;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain
application/x-Javascript text/css application/xml;
gzip_vary on;
# limit_zone one $binary_remote_addr 10m;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
server {
“
listen 80;
“
server_name 192.168.3.30;
index index.html;
# rewrite ^/index.html
/ last;
#rewrite
^/(.*)_p([0-9]*)_(.*)_e(.*)/(.*)_(.*)_t(.*)_o(.*)_(l|s |k|[0-9]*)$
/searchclassbigkey?skey=$1&pno=$2&sw=$3&pe=$4&rk=$5&dekey=$6&tid=$7&ocs=$8&ocid=$9
last;
#rewrite
^/(.*)_p([0-9]*)_s(.*)/(.*)_(.*)_(.*)$ /searchkey?skey=$1&pno=$2&sw=$3&pe= $4&rk=$5&dekey=$6
last;
# rewrite ^/d-(.*)$
/detaillist?id=$1 last;
location /
{
# proxy_next_upstream http_502
http_504 error timeout invalid_header;
# proxy_headers_hash_max_size 1024;
# proxy_headers_hash_bucket_size
128;
# proxy_cache cache_one;
proxy_cache_valid 200 304 2h;
proxy_cache_valid any 30m;
proxy_cache_key
$host$uri$is_args$args;
# proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_pass http://aa;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
# proxy_cache cache_one;
proxy_cache_valid 200 304 5h;
proxy_cache_valid any 3m;
proxy_cache_key
$host$uri$is_args$args;
expires
8h;
proxy_pass http://aa;
}
location ~ .*\.(js|css|html)$
{
# proxy_cache cache_one;
proxy_cache_valid 200
304 3h;
proxy_cache_valid any 3m;
proxy_cache_key
$host$uri$is_args$args;
expires
5h;
proxy_pass http://aa;
}
log_format aa ‘$remote_addr – $remote_user
[$time_local] “$request”‘
‘$status $body_bytes_sent “$http_referer”‘
‘”$http_user_agent” $http_x_forwarded_for’;
access_log /usr/local/nginx/logs/aa.log aa;
}
server {
listen 80;
server_name 192.168.3.31;
index index.html;
location /
{
proxy_cache cache_one;
proxy_cache_valid 200 304 2h;
proxy_cache_valid any 3m;
proxy_cache_key
$host$uri$is_args$args;
proxy_pass http://bb;
}
the
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|html)$
{
proxy_cache cache_one;
proxy_cache_valid 200 304 5h;
proxy_cache_valid any 3m;
expires
8h;
proxy_cache_key
$host$uri$is_args$args;
proxy_pass http://bb;
}
log_format bb ‘$remote_addr – $remote_user
[$time_local] “$request”‘
‘$status $body_bytes_sent “$http_referer”‘
‘”$http_user_agent” $http_x_forwarded_for’;
access_log /usr/local/nginx/logs/bb.log bb;
}
}
# /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
# /usr/local/nginx/sbin/nginx
# netstat -anpt | grep
80
tcp
0 0
0.0.0.0:80
0.0.0.0:*
LISTEN 30169/nginx
# /usr/local/nginx/sbin/nginx ?s reload
; 80;
server_name 192.168.3.31;
index index.html;
location /
{
proxy_cache cache_one;
proxy_cache_valid 200 304 2h;
proxy_cache_valid any 3m;
proxy_cache_key
$host$uri$is_args$args;
proxy_pass http://bb;
}
the
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|html)$
{
proxy_cache cache_one;
proxy_cache_valid 200 304 5h;
proxy_cache_valid any 3m;
expires
8h;
proxy_cache_key
$host$uri$is_args$args;
proxy_pass http://bb;
}
log_format bb ‘$remote_addr – $remote_user
[$time_local] “$request”‘
‘$status $body_bytes_sent “$http_referer”‘
‘”$http_user_agent” $http_x_forwarded_for’;
access_log /usr/local/nginx/logs/bb.log bb;
}
}
# /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
# /usr/local/nginx/sbin/nginx
# netstat -anpt | grep
80
tcp
0 0
0.0.0.0:80
0.0.0.0:*
LISTEN 30169/nginx
# /usr/local/nginx/sbin/nginx ?s reload