Apache2.2和resin 3.1,windows平台单机做负载平衡

apache版本:2.2.6(Win32)
resin版本:3.1.3


1.安装apache.我下载的是apache的windows安装包,所以直接运行后,apache会自动被安装成windows服务,这里服务名我定为apache2.2

2.下载resin3.1.3 windows版,解压到硬盘上某个目录中

3.在resin目录下的win32\apache-2.2中有个文件:mod_caucho.dll,记住这个文件的全路径和文件名(e.g.:记在notepad中).比如,在我机器上,要记下的内容为:c:\resin-

3.1.3\win32\apache-2.2\mod_caucho.dll,然后,把路径中的反斜杠改为斜杠,所以,最后,要记录下的内容为:c:/resin-3.1.3/win32/apache-2.2/mod_caucho.dll

4.修改resin的配置文件resin.conf
    在resin2中,查看网上的一些资料,发现配置负载平衡是用<srun/>这个配置项,但在resin3中,配置文件已经全面变动,负载平衡改用<server/>
    这里以在一台机器上运行4个resin实例为例
    a.在resin.conf中找寻内容<!-- define the servers in the cluster -->,在这行的下面一行内容是<server id="" address="127.0.0.1" port="6800"/>,这行其实

就说明运行一个resin实例,所以这里我们要改成四个<server/>,如下:
            <server id='a' address='127.0.0.1' port='6801' watchdog-port="6601">
           <http port="8081"/>
        </server>
        <server id='b' address='127.0.0.1' port='6802' watchdog-port="6602">
           <http port="8082"/>
        </server>
        <server id='c' address='127.0.0.1' port='6803' watchdog-port="6603">
           <http port="8083"/>
        </server>
        <server id='d' address='127.0.0.1' port='6804' watchdog-port="6604">
           <http port="8084"/>
        </server>
        id标识了不同的server,这里的四个id可以随便改,只要不一样就行
        port标识了不同的监听端口,apache会把需要resin处理的http请求转发到此端口(不知道理解得对不对,如果有高人有别的看法,欢迎批评指正),这里的端口也可

以改为别的端口号
        watchdog-port是resin watchdog的监听端口,每启动一个resin实例,就会伴随启动一个resin的watchdog,watchdog也需要分配一个端口,watchdog好像是监视

resin服务的,它有自动启动和停止resin服务的功能,他的默认端口为6600,如果不指定这些端口,在日志文件中会看到JVM端口绑定错误,而且指明了是6600端口绑定错误
        <http port="端口号"/>,这个指定了每个resin的http侦听端口,也需要指定来进行区分,否则也会出现端口绑定错误
    b.查找行<http address="*" port="8080"/>,这里指定了默认的resin监听端口,这里需要把这行注释掉
    c.接下来,你可以用<web-app/>按一般方式来配置resin的web应用

5.修改apache的配置文件httpd.conf
    在httpd.conf的最后,加上如下的内容:
    LoadModule caucho_module C:/resin-3.1.3/win32/apache-2.2/mod_caucho.dll
    ResinConfigServer 127.0.0.1 6801
    ResinConfigServer 127.0.0.1 6802
    ResinConfigServer 127.0.0.1 6803
    ResinConfigServer 127.0.0.1 6804
    CauchoStatus yes
   
    可以看到,第3步中记录的内容就是放在这个地方的
   
   
    接下来,在httpd.conf加入你在resin.conf配置的web应用的目录的虚拟目录配置
    一般加在DocumentRoot这行下面
    Alias /web-app "D:/work/web-app"
    <Directory "D:/work/web-app">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    这里假设你在resin.conf中也配置了web-app目录的web应用
    这样,当你访问http://localhost/web-app时,一些不需要由resin处理的内容,如静态页面,jpg等,则由apache处理,而像jsp文件,则apache会交给resin处理.这里

主要是起到了一个resin应用目录和apache虚拟目录相对应的设置。当然,也可以通过配置虚拟主机来实现
   
    apache默认文档的配置:
        找到DirectoryIndex这个项,在后面写上你要设置的默认文档,比如
        DirectoryIndex index.jsp
   
   
   
6.把resin安装成windows服务
    这里把resin安装成四个服务
    进入windows的命令行,进行resin目录,执行如下命令:
    httpd -install-as resin-a -server a         //这里的-server后面的a就和resin.conf中的<server id="a"中的a对应
    httpd -install-as resin-b -server b
    httpd -install-as resin-c -server c
    httpd -install-as resin-d -server d
   
7.启动apache和四个resin
    进入windows的命令行,执行如下命令:
    net start apache2.2
    net start resin-a
    net start resin-b
    net start resin-c
    net start resin-d
   
8.在浏览器中输入http://localhost/caucho-status,如果看到host列的四个都为绿色,则表求配置成功,你可以输入你web应用的目录来进行测试了

原文地址:https://www.cnblogs.com/jamin/p/1381516.html