1.Nginx配置
/app/nginx/sbin/nginx-V
Tengineversion:Tengine/1.4.6(nginx/1.2.9)
builtbygcc4.4.720120313(RedHat4.4.7-3)(GCC)
TLSSNIsupportenabled
configurearguments:--user=nginx--group=app--prefix=/app/nginx--with-http_stub_status_module--with-http_ssl_module--with-http_concat_module--with-http_upstream_check_module--with-http_sub_module--with-http_realip_module
vim/app/nginx/conf/nginx.conf
upstreamapp_tomcat{
consistent_hash$remote_addr;
session_sticky;
server172.16.80.1:8000id=1001weight=1;
server172.16.80.2:8000id=1002weight=1;
checkinterval=1000rise=2fall=3timeout=1000type=httpport=8000;
check_http_send"GET/HTTP/1.0\r\n\r\n";
check_http_expect_alivehttp_2xxhttp_3xx;
}
vim/app/nginx/conf.d/app.test.com
server{
listen80;
server_nameapp.test.com;
#影藏.svn代碼文件
location~^(.*)\/\.svn\/{
denyall;
}
location/{
concaton;
root/app/web/app.test.com/ROOT;
indexindex.htmlindex.htmindex.jsp;
}
location/status{
stub_statuson;
access_logoff;
allow172.16.80.0/24;
}
location~(\.jsp)|(\.do)|(/url/)|(/membercard/)|(\.action)${
session_sticky_hide_cookieupstream=app_tomcat;
proxy_passhttp://app_tomcat;
proxy_set_headerHostapp.test.com;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
}
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
}
2.Tomcat配置
2.1第一臺Tomcat
vim/app/tomcat/conf/server.xml
<Enginename="Catalina"defaultHost="localhost"jvmRoute="jvm1">
<ClusterclassName="org.apache.catalina.ha.tcp.SimpleTcpCluster"channelSendOptions="8">
<ManagerclassName="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"notifyListenersOnReplication="true"/>
<ChannelclassName="org.apache.catalina.tribes.group.GroupChannel">
<MembershipclassName="org.apache.catalina.tribes.membership.McastService"
address="224.0.0.4"
port="45365"
frequency="500"
dropTime="3000"/>
<ReceiverclassName="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="172.16.80.1"
port="4002"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<SenderclassName="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<TransportclassName="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<InterceptorclassName="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<InterceptorclassName="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
<InterceptorclassName="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<ValveclassName="org.apache.catalina.ha.tcp.ReplicationValve"filter=""/>
<ValveclassName="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<DeployerclassName="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListenerclassName="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListenerclassName="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
<Hostname="app.test.com"appBase="webapps">
<Contextpath=""docBase="/app/web/app.test.com/ROOT"debug="0"reloadable="true"distributable="true"useHttpOnly="true"sessionCookiePath="/"sessionCookieDomain=".test.com"crossContext="true"/>主域名和二級域名之間的session複製
</Host>
第二臺Tomcat
vim/app/tomcat/conf/server.xml
<Enginename="Catalina"defaultHost="localhost"jvmRoute="jvm2">
<ClusterclassName="org.apache.catalina.ha.tcp.SimpleTcpCluster"channelSendOptions="8">
<ManagerclassName="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"notifyListenersOnReplication="true"/>
<ChannelclassName="org.apache.catalina.tribes.group.GroupChannel">
<MembershipclassName="org.apache.catalina.tribes.membership.McastService"
address="224.0.0.4"
port="45365"
frequency="500"
dropTime="3000"/>
<ReceiverclassName="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="172.16.80.2"
port="4002"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<SenderclassName="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<TransportclassName="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<InterceptorclassName="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<InterceptorclassName="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
<InterceptorclassName="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<ValveclassName="org.apache.catalina.ha.tcp.ReplicationValve"filter=""/>
<ValveclassName="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<DeployerclassName="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListenerclassName="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListenerclassName="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
<Hostname="app.test.com"appBase="webapps">
<Contextpath=""docBase="/app/web/app.test.com/ROOT"debug="0"reloadable="true"distributable="true"useHttpOnly="true"sessionCookiePath="/"sessionCookieDomain=".test.com"crossContext="true"/>
</Host>