我已经build立了apache-tomcat集群(Ubuntu服务器),并且我在链接之后使用了tomcat支持的mod_jk集群技术。 我已经设置了一个负载平衡器和两个Web服务器。
主要的问题是部署WAR文件和哪个Web服务器? 我已经了解了将战争文件部署到群集中的其他tomcat服务器的Farmed Deployment,但是我还没有完成它。 我在两个Web服务器的元素中以下面的方式使用了农场部署者。
Web服务器1(192.168.1.101)
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" tempDir="/usr/share/tomcat/temp/" deployDir="/usr/share/tomcat/webapps/" watchDir="/usr/share/tomcat/watch/" watchEnabled="true"/>
Web服务器2(192.168.1.102)
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" tempDir="/usr/share/tomcat/temp/" deployDir="/usr/share/tomcat/webapps/" watchDir="/usr/share/tomcat/webapps/" watchEnabled="false"/>
我将WAR放在Web服务器1的监视目录中,但不会部署到其他服务器。 任何人得到这个工作,我做错了什么?请让我知道!
谢谢!
更新:1
我可以在catalina.out日志中的任一台计算机上看到以下信息,
14 Aug, 2011 9:12:11 PM org.apache.catalina.ha.deploy.FarmWarDeployer start SEVERE: FarmWarDeployer can only work as host cluster subelement!
它甚至不部署到webserver1,也不部署到webserver2。 访问网站时出现404错误。 还有什么帮助? 还有一件事,我没有从apt库安装tomcat,但是我从源码中构build了它,这对我们的java应用程序来说是完美的。
你应该看第一个位置是catalina.out
,它会告诉你什么可能是错的。
如果你不能使用多播,只要尝试静态成员资格 (我认为它会更简单) 。
以下是我的configuration:
将<Cluster
节点放在<Host
元素中:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1"> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"> <Channel className="org.apache.catalina.tribes.group.GroupChannel"> <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="192.168.5.149" port="4000" selectorTimeout="100" maxThreads="6"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor"> <Member className="org.apache.catalina.tribes.membership.StaticMember" port="4001" securePort="-1" host="192.168.5.199" domain="staging-cluster" uniqueId="{0,1,2,3,4,5,6,7,8,9}"/> </Interceptor> </Channel> <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" tempDir="/usr/share/tomcat6/tempdir/" deployDir="/usr/share/tomcat6/webapps/" watchDir="/usr/share/tomcat6/watchdir/" watchEnabled="true"/> </Cluster> </Host> </Engine>
<Receiver
元素中的address
属性是node1的IP地址。 (你的情况是.101) port
正在监听节点1上的复制消息(4000-4100) <Interceptor
的Member's port
正在侦听节点2上的群集消息 Member's host
是节点2的IP地址(.102) 节点2上的server.xml
:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"> <Channel className="org.apache.catalina.tribes.group.GroupChannel"> <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="192.168.5.199" port="4001" selectorTimeout="100" maxThreads="6"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor"> <Member className="org.apache.catalina.tribes.membership.StaticMember" port="4000" securePort="-1" host="192.168.5.149" domain="staging-cluster" uniqueId="{0,1,2,3,4,5,6,7,8,9}"/> </Interceptor> </Channel> <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" tempDir="/usr/share/tomcat6/tempdir/" deployDir="/usr/share/tomcat6/webapps/" watchDir="/usr/share/tomcat6/watchdir/" watchEnabled="false"/> </Cluster>
确保Tomcat可以写入tempDir
和watchDir
文件夹:
chmod g+w tempDir watchDir chgrp tomcat tempDir watchDir
如果你不这样做,你会得到下面的错误:
Aug 13, 2011 10:28:33 PM org.apache.catalina.ha.deploy.FarmWarDeployer messageReceived SEVERE: Unable to read farm deploy file message. java.io.IOException: Permission denied
请记住将<distributable/>
添加到webapps/ROOT/WEB-INF/web.xml
:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" ... <display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <distributable/> </web-app>
每当将一个.war
文件复制到节点1上的watchdir
文件夹中时,您将在catalina.out
看到如下内容:
Aug 14, 2011 1:40:58 AM org.apache.catalina.ha.deploy.WarWatcher check INFO: check cluster wars at /usr/share/tomcat6/watchdir Aug 14, 2011 1:40:59 AM org.apache.catalina.ha.deploy.FarmWarDeployer fileModified INFO: Installing webapp[/cas] from /usr/share/tomcat6/webapps/cas.war Aug 14, 2011 1:40:59 AM org.apache.catalina.ha.deploy.FarmWarDeployer remove INFO: Cluster wide remove of web app /cas Aug 14, 2011 1:40:59 AM org.apache.catalina.startup.HostConfig deployWAR INFO: Deploying web application archive cas.war
并在节点2上:
Aug 14, 2011 1:40:59 AM org.apache.catalina.startup.HostConfig deployWAR INFO: Deploying web application archive cas.war
祝你好运!
如果/ etc / hosts文件包含实际的NIC IP地址,而不是回送地址127.0.0.1,则多播地址将起作用。 Tomcat拿起由以下内容确定的Receiver.address属性:
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto"
多播服务将广播与服务器主机名关联的IP地址。 Catalina.out应该显示它在启动过程中获得的ip地址。 如果检测到环回地址,则群集节点将不能相互通信。 catalina.out日志文件中导致节点之间无法通信的错误地址拾取示例:
INFO: Cluster is about to start 09/08/2013 7:38:14 PM org.apache.catalina.tribes.transport.ReceiverBase bind INFO: Receiver Server Socket bound to:/127.0.1.1:5000