Chinaunix首页 | 论坛 | 博客
  • 博客访问: 285642
  • 博文数量: 84
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -10
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-05 09:11
文章分类
文章存档

2015年(1)

2014年(6)

2013年(8)

2012年(1)

2011年(6)

2010年(2)

2009年(16)

2008年(44)

我的朋友

分类: LINUX

2008-04-17 13:27:19

                     Tomcat 负载均衡配置
1.安装包:
apache-tomcat-5.5.25.tar.gz
httpd-2.2.3.tar.tar
 
2.安装:
[root@localhost build]# pwd
/usr/local/apache/build
[root@localhost build]# more config.nice
#! /bin/sh
#
# Created by configure
"./configure" \
"--prefix=/usr/local/apache" \
"--enable-mods-shared=all" \
"--enable-so" \
"--enable-proxy" \
"--enable-proxy_http=shared" \
"--enable-module=so" \
"--enable-mods-shared=all" \
"--enable-proxy-ajp=shared" \
"$@"
 
 
 
 
 
3.配置:
[root@localhost bin]# cat /usr/local/apache/conf/httpd.conf|grep httpd-vhosts.conf
Include conf/extra/httpd-vhosts.conf
 
 
 
[root@localhost extra]# cat /usr/local/apache/conf/extra/httpd-vhosts.conf
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost 172.18.3.200:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any block.
#
#
#    ServerAdmin
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ServerAlias
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#
 

#ServerName 172.18.3.200
   
        Options FollowSymlinks
        Order allow,deny
        Allow from all
   
 
#DocumentRoot /usr/local/apache/htdocs/index.html
#    ServerAdmin
#    DocumentRoot /www/docs/dummy-host2.example.com
#    ServerName dummy-host2.example.com
#    ErrorLog logs/dummy-host2.example.com-error_log
#    CustomLog logs/dummy-host2.example.com-access_log common
ProxyPass / balancer://aaa/ stickysession=JSESSIONID lbmethod=byrequests maxattempts=1 nofailover=Off
ProxyPassReverse / balancer://aaa/
ProxyRequests Off

   BalancerMember ajp://172.18.3.200:8009 smax=2048 timeout=200 ttl=200 route=work1
   BalancerMember ajp://172.18.3.200:8010 smax=2048 timeout=200 ttl=200 route=work2
#ProxyPass / ajp://172.18.3.200:8009/ smax=1024 timeout=200 ttl=200
 
 
说明:本机器设置一个ip172.18.3.200. tomcat 分别对应两个端口8009,8010
 
还需要更该的端口号有: 
1.
 

 

 
2.                 maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
 
3.                enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
 
 
       
4.                     className="org.apache.catalina.cluster.mcast.McastService"
                mcastAddr="228.0.0.4"
                mcastPort="45564"
                mcastFrequency="500"
                mcastDropTime="3000"/>
                            className="org.apache.catalina.cluster.tcp.ReplicationListener"
                tcpListenAddress="172.18.3.200"
                tcpListenPort="4001"
                tcpSelectorTimeout="100"
                tcpThreadCount="6"/>
 
 
启动tomcat查看端口号(4001 8005 8009 8080),另一台(4002,8006,8010,8088)
[root@localhost conf]# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State     
tcp        0      0 0.0.0.0:32769               0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN     
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN     
tcp        0      0 127.0.0.1:5335              0.0.0.0:*                   LISTEN     
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN     
tcp        0      0 ::ffff:172.18.3.200:4001    :::*                        LISTEN     
tcp        0      0 ::ffff:127.0.0.1:8005       :::*                        LISTEN     
tcp        0      0 :::8009                     :::*                        LISTEN     
tcp        0      0 :::80                       :::*                        LISTEN     
tcp        0      0 :::8080                     :::*                        LISTEN     
tcp        0      0 :::22                       :::*                        LISTEN     
tcp        0     36 ::ffff:172.18.3.200:22      ::ffff:172.18.3.194:3323    ESTABLISHED
tcp        0      0 ::1:35620                   ::1:32770                   TIME_WAIT
 
 
 
 
启动另一台tomcat出错
Tomcat启动出错     2008-04-07 18:42:05
LifecycleException: java.net.SocketException: No such device
    at org.apache.catalina.cluster.tcp.SimpleTcpCluster.start(SimpleTcpCluster.java:790)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1004)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
以上原因为:组播路由丢失.
 

route add -net 228.0.0.4 netmask 255.255.255.255 dev eth0

 

启动正常

 

验证方法,停掉其中一台tomcat,查看另一台的tomcat日志是否滚动.如果滚动代表session复制成功.

 

 

 

 
如下日志:
[root@localhost bin]# tail -f /opt/tomcat_1/logs/catalina.out
Apr 3, 2007 12:10:55 PM org.apache.catalina.cluster.tcp.SimpleTcpCluster memberDisappeared
INFO: Received member disappeared:org.apache.catalina.cluster.mcast.McastMember[tcp://172.18.3.200:4001,catalina,172.18.3.200,4001, alive=1573558]

 

 

补充:

tomcat集群和负载均衡的实现(session同步)补充

因为tomcat的session同步功能需要用到组播,windows默认情况下是开通组播服务的,但是linux默认情况下并没有开通,可以通过指令打开route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0,如果需要服务器启动时即开通组播需在/etc/sysconfig/static-routes文件内加入eht0 net 224.0.0.0 netmask 240.0.0.0。具体组播概念请查阅CCNP相关内容。

 

 

 

 
 
 
阅读(1335) | 评论(0) | 转发(0) |
0

上一篇:ntpd时间同步

下一篇:SSH无密码验证登陆

给主人留下些什么吧!~~