nginx+tomcat集群+session仿制51CTO博客 - 娱乐之横扫全球

nginx+tomcat集群+session仿制51CTO博客

2019年04月04日10时13分20秒 | 作者: 吉星 | 标签: 装备,装置,修正 | 浏览: 1073

ulimit -SHn 65535  
echo "ulimit -SHn 65535" >>/etc/rc.local

环境:  
redhat5.4、pcre-8.12、nginx-upstream-jvm-route-0.1、nginx-1.0.5、apache-tomcat-6.0.33    
nginx服务器地址:192.168.0.40    
tomcat1:192.168.0.20    
tomcat2:192.168.0.30

拓扑如下:

 

 

1.装置nginx

tar zxf pcre-8.12.tar.gz  
cd pcre-8.12    
./configure    
make;make install

下载下面的插件装置,不然nginx无法辨认tomcat中jvmRoute,然后无法到达session仿制的作用。

wget http://friendly.sinaapp.com//LinuxSoft/nginx-upstream-jvm-route-0.1.tar.gz    
tar xzf nginx-upstream-jvm-route-0.1.tar.gz    
tar xzf nginx-1.0.5.tar.gz    
cd nginx-1.0.5    
patch -p0 <../nginx_upstream_jvm_route/jvm_route.patch    
/configure prefix=/usr/local/nginx with-http_stub_status_module  with-pcre=/root/pcre-8.12 add-module=../nginx_upstream_jvm_route/    
#with-pcre=指向的是pcre的源码包    
make;make install

2.装备nginx

vim /usr/local/nginx/conf/nginx.conf

#user  nobody;  
worker_processes  1;

#error_log  logs/error.log;  
#error_log  logs/error.log  notice;    
#error_log  logs/error.log  info;

pid        /usr/local/nginx/logs/nginx.pid;  
worker_rlimit_nofile 51200;

events {  
    worker_connections  5000;    
}

http {  
  upstream backend {    
    server 192.168.0.20:8080 srun_id=tomcat1; //在tomcat的装备里会装备jvmRoute为tomcat1
    server 192.168.0.30:8080 srun_id=tomcat2;    
    jvm_route $cookie_JSESSIONID|sessionid reverse;    
  }

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_max_body_size 20m;    
limit_rate  1024k;    
sendfile on;    
tcp_nopush     on;    
keepalive_timeout 60;    
tcp_nodelay on;    
fastcgi_connect_timeout 300;    
fastcgi_send_timeout 300;    
fastcgi_read_timeout 300;    
fastcgi_buffer_size 64k;    
fastcgi_buffers 4 64k;    
fastcgi_busy_buffers_size 128k;    
fastcgi_temp_file_write_size 128k;    
gzip on;    
#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;

server  
{    
   listen       80;    
   server_name  www.baiying.com;    
   index index.jsp index.htm index.html;    
   root  /usr/www;

   location /  {  
     proxy_pass  http://backend;    
     proxy_redirect    off;    
     proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;    
     proxy_set_header  X-Real-IP  $remote_addr;    
     proxy_set_header  Host $http_host;    
   }    
   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$    
   {    
     expires      30d;    
   }    
   location ~ .*\.(js|css)?$    
   {    
     expires      1h;    
   }    
   location /Nginxstatus {    
     stub_status on;    
     access_log   off;    
   }    
  log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '    
             '$status $body_bytes_sent "$http_referer" '    
             '"$http_user_agent" $http_x_forwarded_for';

}  
}    
                                                                                                          
[root@slave conf]# /usr/local/bin/nginx.sh stop    
[root@slave conf]# /usr/local/bin/nginx.sh start    
 

3.装置tomcat  
1)装置tomcat_1    
tar zxf apache-tomcat-6.0.33.tar.gz    
mv apache-tomcat-6.0.33/usr/local/tomcat    
cp tomcat-replication.jar /usr/local/tomcat/lib    
2)装置tomcat_2,过程同1)

4.分别在tomcat服务器装置jdk

chmod 755 jdk-6u26-linux-i586-rpm.bin  
./jdk-6u26-linux-i586-rpm.bin

cat >>/etc/profile <<EOF
export JAVA_HOME=/usr/java/jdk1.6.0_26    
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib    
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin

EOF;

source /etc/profile  //使环境变量当即收效

5.tomcat集群装备  
tomcat1装备:    
修正conf/server.xml装备文件

    &lt;Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">  
        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"    
                 channelSendOptions="8">    
          <Manager className="org.apache.catalina.ha.session.DeltaManager"    
                   expireSessionsOnShutdown="false"    
                   notifyListenersOnReplication="true"/>    
          <Channel className="org.apache.catalina.tribes.group.GroupChannel">    
            <Membership className="org.apache.catalina.tribes.membership.McastService"    
                        address="224.0.0.4"    
                        port="45564"    
                        frequency="500"    
                        dropTime="3000"/>    
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"    
                      address="192.168.0.20"    
                      port="4001"    
                      autoBind="100"    
                      selectorTimeout="5000"    
                      maxThreads="6"/>    
            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">    
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />    
            </Sender>    
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>    
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>    
         <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>    
          </Channel>    
          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"    
                 filter=""/>    
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>    
          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"    
                    tempDir="/tmp/war-temp/"    
                    deployDir="/tmp/war-deploy/"    
                    watchDir="/tmp/war-listen/"    
                    watchEnabled="false"/>    
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>    
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>    
        </Cluster> 

tomcat2装备:  
修正conf/server.xml装备文件

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">  
        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"    
                 channelSendOptions="8">    
          <Manager className="org.apache.catalina.ha.session.DeltaManager"    
                   expireSessionsOnShutdown="false"    
                   notifyListenersOnReplication="true"/>    
          <Channel className="org.apache.catalina.tribes.group.GroupChannel">    
            <Membership className="org.apache.catalina.tribes.membership.McastService"    
                        address="224.0.0.4"    
                        port="45564"    
                        frequency="500"    
                        dropTime="3000"/>    
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"    
                      address="192.168.0.30"    
                      port="4000"    
                      autoBind="100"    
                      selectorTimeout="5000"    
                      maxThreads="6"/>    
            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">    
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />    
            </Sender>    
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>    
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>    
         <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>    
          </Channel>    
          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"    
                 filter=""/>    
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"  
                    tempDir="/tmp/war-temp/"    
                    deployDir="/tmp/war-deploy/"    
                    watchDir="/tmp/war-listen/"    
                    watchEnabled="false"/>    
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>    
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>    
        </Cluster>

6.session装备

修正web使用里边WEB-INF目录下的web.xml文件,参加标签  
<distributable/>    
直接加在</web-app>之前    
敞开网卡组播功用:    
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

7.创立jsp测验页面  
在tomcat1装置途径下树立目录test    
mkdir /usr/local/tomcat/webapps/ROOT/test/    
vi index.jsp    
<html>    
<title>    
tomcat1 jsp    
</title>    
<%    
   String showMessage="Oh My God 192.168.0.20 华仔!";    
   out.print(showMessage);    
%>    
</html>    
   
在tomcat2装置途径下树立目录test    
mkdir /usr/local/tomcat/webapps/ROOT/test/    
vi index.jsp    
<html>    
<title>    
tomcat2 jsp    
</title>    
<%    
   String showMessage="Oh My God 192.168.0.30 华仔!";    
   out.print(showMessage);    
%>    
</html>

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表娱乐之横扫全球立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章