??xml version="1.0" encoding="utf-8" standalone="yes"?>
在下面中Q将通过例子来了(jin)解TreeCache的功能及(qing)光|,使用JBossCache1.4和JDK5.0。首先是一个最基本使用TreeCache
的程序例子ƈ配置一个TreeCache的配|骨Ӟ各种常用的配|可参见jboss-cache-dist-1.4.0.CR1版本的etc目录Q如?
各种配置参考也可见该目录下的范例配|,以下不再Q,见下Q?
treecache.xmlQ?
<server>
<mbean code="org.jboss.cache.TreeCache"
name="jboss.cache:service=TreeCache">
<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>
<attribute
name="ClusterName">TreeCache-Cluster</attribute>
<attribute name="ClusterConfig">
<config>
<UDP mcast_addr="228.1.2.3" mcast_port="48866"
ip_ttl="64" ip_mcast="true"
mcast_send_buf_size="150000"
mcast_recv_buf_size="80000"
ucast_send_buf_size="150000"
ucast_recv_buf_size="80000"
loopback="false"/>
<PING timeout="2000" num_initial_members="3"
up_thread="false" down_thread="false"/>
<MERGE2 min_interval="10000"
max_interval="20000"/>
<FD_SOCK/>
<VERIFY_SUSPECT timeout="1500"
up_thread="false" down_thread="false"/>
<pbcast.NAKACK gc_lag="50"
retransmit_timeout="600,1200,2400,4800"
max_xmit_size="8192" up_thread="false"
down_thread="false"/>
<UNICAST timeout="600,1200,2400"
window_size="100" min_threshold="10"
down_thread="false"/>
<pbcast.STABLE desired_avg_gossip="20000"
up_thread="false" down_thread="false"/>
<FRAG frag_size="8192"
down_thread="false" up_thread="false"/>
<pbcast.GMS join_timeout="5000"
join_retry_timeout="2000"
shun="true" print_local_addr="true"/>
<pbcast.STATE_TRANSFER up_thread="true"
down_thread="true"/>
</config>
</attribute>
</mbean>
</server>
其中ClusterConfig配置在前面JavaGroups的介l详l介l,其它配置比较单,需要进一步了(jin)解请参见TreeCache文档?
一、Cache分类
TreeCache按功能分Zc:(x)本地(Local)Cache、复?Replication)Cache和失?
(Invalidation)Cache。本地Cache只应用于本地环境Q后两个Cache可应用于分布式环境,其中Q在分布式环境中Q复制Cache
当一个Cache实例的一个节点值发生变化时?x)将变化复制到其它实例中Q而失效Cache是当一个Cache实例的一个节点值发生变化时?x)将其它实例的?
应节点的D为空Q让光新去获得该|可通过q种方式~存大对象以减少在实例中复制对象的代仗分布式CacheQ复制和失效CacheQ又分ؓ(f)两种Q?
同步QREPL_ASYNCQ和异步QREPL_SYNCQ,同步Cache是在一个Cache实例做修Ҏ(gu)Q等待变化应用到其它实例后才q回Q而异?
Cache是在一个Cache实例做修Ҏ(gu)Q即刻返回。其配置见下Q?
!--
Valid modes are LOCAL
REPL_ASYNC
REPL_SYNC
INVALIDATION_ASYNC
INVALIDATION_SYNC
->
attribute name="CacheMode">REPL_SYNC</attribute>
二、事务和q行(Transaction And Concurrent)
TreeCache是一U事务CacheQ与JDBC一P其包括两斚w内容Q锁和隔ȝ别。锁分ؓ(f)(zhn)观锁和乐观锁,当用?zhn)观锁Ӟ分?f)五个隔离U别Q?
分别是SERIALIZABLE、REPEATABLE_READ
(default)、READ_COMMITTED、READ_UNCOMMITTED和NONEQ隔ȝ别逐步减弱。乐观锁也叫版本锁,其对数据q行?
作时Q将其复制到临时区,操作之后版本与原有数据比较Q如果一致则递增版本q写回,如果不一致则回滚Q由于乐观锁仅在复制出数据和提交数据时对数据?
锁,所以ƈ行度更高Q但如果写操作比较频J地话则Ҏ(gu)出现冲突D回滚。TreeCache默认使用(zhn)观锁。用TreeCacheӞ需要用容器提?
的事务管理器Q一般JBossTransactionManagerLookup和GenericTransactionManagerLookupQ?
前者应用于JBOSS服务器,后者应用于其他服务器,也可使用DummyTransactionManagerLookup用于试。如上介l的配置?
下:(x)
attribute name="NodeLockingScheme">OPTIMISTIC</attribute>
<attribute
name="IsolationLevel">REPEATABLE_READ</attribute>
<attribute
name="TransactionManagerLookupClass">org.jboss.cache.DummyTransactionManagerLookup</attribute>
三、逐出{略(Eviction Policy)
׃内存数量的局限,不可能将所有的Cache数据存放在内存中Q但使用内存辑ֈ一定极限时Q会(x)部分数据清除出内存Q保存到其它持久媒质中,定义的什?
时候清除、如何清除的{略是逐出{略。自定义一个逐出{略需要实现org.jboss.cache.eviction.EvictionPolicy?
org.jboss.cache.eviction.EvictionAlgorithm?
g.jboss.cache.eviction.EvictionQueue
和org.jboss.cache.eviction.EvictionConfiguration四个接口Q系l提供了(jin)LRU(Least
recently usedQ最q最?、LFU(Least Frequently Used最不经怋?、FIFO(First In
First Out先进先出)、MRU(Most Recently
Used最q最l常使用)四种实现Q详l参见org.jboss.cache.eviction包的源代码。配|如下:(x)
<attribute name="EvictionPolicyConfig">
<config>
<attribute
name="wakeUpIntervalSeconds">5</attribute>
<region name="/_default_">
<attribute name="maxNodes">5000</attribute>
<attribute
name="timeToLiveSeconds">1000</attribute>
</region>
<region name="/org/jboss/data"
policyClass="org.jboss.cache.eviction.FIFOPolicy">
<attribute name="maxNodes">5000</attribute>
</region>
<region name="/test/"
policyClass="org.jboss.cache.eviction.MRUPolicy">
<attribute name="maxNodes">10000</attribute>
</region>
<region name="/maxAgeTest/">
<attribute name="maxNodes">10000</attribute>
<attribute
name="timeToLiveSeconds">8</attribute>
<attribute name="maxAgeSeconds">10</attribute>
</region>
</config>
</attribute>
四、Cache加蝲
׃逐出{略的存在,那么当我们重新需要获得一个原来在~存中但由内存原因被逐出的数据时Q就需要定义一U加载策略,使地可以重新扑֛数据Q同
ӞCache加蝲也肩负在数据逐出时将数据保存到持久媒质的责Q?
Ҏ(gu)数据保存媒质的不同QCache加蝲包括F(xin)ileCacheLoader、JDBCCacheLoader{等Q可以同时用多U加载器来灵zd?
加蝲{略。例见下Q?
<attribute name="CacheLoaderConfiguration">
<config>
<passivation>false</passivation>
<preload>/</preload>
<shared>true</shared>
<cacheloader>
<class>org.jboss.cache.loader.ClusteredCacheLoader</class>
<properties>
timeout=1000
</properties>
<async>true</async>
<fetchPersistentState>false</fetchPersistentState>
ignoreModifications>false</ignoreModifications>
<purgeOnStartup>false</purgeOnStartup>
</cacheloader>
<cacheloader>
<class>org.jboss.cache.loader.JDBCCacheLoader</class>
<properties>
cache.jdbc.table.name=jbosscache
cache.jdbc.table.create=true
cache.jdbc.table.drop=true
cache.jdbc.table.primarykey=jbosscache_pk
cache.jdbc.fqn.column=fqn
cache.jdbc.fqn.type=varchar(255)
cache.jdbc.node.column=node
cache.jdbc.node.type=longblob
cache.jdbc.parent.column=parent
cache.jdbc.driver=com.mysql.jdbc.Driver
cache.jdbc.url=jdbc:mysql://localhost:3306/jbossdb
cache.jdbc.user=root
cache.jdbc.password=
</properties>
<async>true</async>
<fetchPersistentState>false</fetchPersistentState>
<purgeOnStartup>false</purgeOnStartup>
</cacheloader>
</config>
</attribute>
我们通过定制如上的配|信息以更有效地使用JBossCache。详l情况可参考JBoss TreeCache参考文档和范例?
TreeCache tree = new TreeCache();
tree.setClusterProperties("treecache.xml";
tree.createService();
tree.startService();
tree.put("/a/b/c", "name", "Ben";
tree.put("/a/b/c/d", "uid", new Integer(322649));
Integer tmp = (Integer) tree.get("/a/b/c/d", "uid";
tree.remove("/a/b";
tree.stopService();
tree.destroyService();
]]>
|络讉K消息: 无法昄此页
技术信?供支持h员?
错误代码: 502 Proxy Error。The specified Secure Sockets Layer (SSL) port is not allowed. ISA Server is not configured to allow SSL requests from this port. Most Web browsers use port 443 for SSL requests. (12204)
IP 地址: xxx.xx.xxx.xx
日期: 2010-1-13 4:35:17 [GMT]
服务? isa-srv.xxxx.com
其中的IP地址是我们公总理的地址Q服务器是公总理服务器?br />
在网上没有找到解x法,l过分析错误信息Q发现很多实?43端口而不是tomcat?443端口来访问SSL|址Q修改了(jin)tomcat下的server.xml文gQ果焉题解冟?br />
]]>
]]>
2). 安装tomcat 6 ;
二、配|过E?br />
1.生成 server key Q?br />
以命令行方式切换到目?tomcat_HOME%Q在command命o(h)行输入如下命令(jdk1.4以上带的工具Q:(x)
keytool -genkey -alias tomcat -keyalg RSA -keypass changit -storepass changit -keystore server.keystore -validity 3600
用户名输入域名,如localhostQ开发或试用)(j)或hostname.domainname(用户拥有的域?Q其它全部以 enter 跌Q最后确认,
此时?x)?JAVA_HOME%/bin下生成server.keystore 文g?br />
注:(x)参数 -validity 指证书的有效??Q缺省有效期很短Q只?0天?br />
2.证书导入的JDK的证书信d?
q步对于tomcat的SSL配置不是必须Q但对于CAS
SSO是必ȝQ否则会(x)出现如下错误Qedu.yale.its.tp.cas.client.CASAuthenticationException:
Unable to validate ProxyTicketValidator。。?br />
导入q程?步,W一步是导出证书Q第二步是导入到证书信Q库,命o(h)如下Q?br />
keytool -export -trustcacerts -alias tomcat -file server.cer -keystore server.keystore -storepass changit
keytool -import -trustcacerts -alias tomcat -file server.cer -keystore
%JAVA_HOME%/jre/lib/security/cacerts -storepass changeit
如果有提C,输入Y可以了(jin)?br />
其他有用keytool命o(h)Q列Z任证书库中所有已有证书,删除库中某个证书Q:(x)
keytool -list -v -keystore %JAVA_HOME%/jre/lib/security/cacerts
keytool -delete -trustcacerts -alias tomcat -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changit
3.配置tomcat :
修改%TOMCAT_HOME%"conf"server.xmlQ以文字~辑器打开Q查找这一行:(x)
xml 代码
之后的那段的注释去掉,q加?keystorePass?qing)keystoreFile属性?br />
注意Qtomcat不同版本配置是不同的:
tomcat4.1.34配置Q?br />
xml
代码 <Connector
className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8443" enableLookups="true" scheme="https"
secure="true" acceptCount="100"
useURIValidationHack="false" disableUploadTimeout="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="server.keystore"
keystorePass="changit"/> tomcat5.5.9配置Q?br />
xml 代码
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="server.keystore"
keystorePass="changit"/>
tomcat5.5.20配置(此配|同样可用于tomcat6.0)Q?br />
xml 代码
<Connector protocol="org.apache.coyote.http11.Http11Protocol"
port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="server.keystore"
keystorePass="changit"/>
tomcat6.0.10配置Q?br />
xml 代码
<Connector protocol="org.apache.coyote.http11.Http11NioProtocol"
port="8443" minSpareThreads="5" maxSpareThreads="75"
enableLookups="true" disableUploadTimeout="true"
acceptCount="100" maxThreads="200"
scheme="https" secure="true" SSLEnabled="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="server.keystore"
keystorePass="changit"/>
tomcat6支持3U,请参考以下文档:(x)
http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html
4.验证配置
讉K https://localhost:8443/
<connector protocol="org.apache.coyote.http11.Http11NioProtocol"></connector>
5. 如果默认想用HTTPS 方式q行|站, 可以作如下配|?
一般Tomcat默认的SSL端口h8443Q但是对于SSL标准端口h443Q?br />
q样在访问网늚时候,直接使用https而不需要输入端口号可以访问,?a href="https://localhost/">https://localhost
1).non-SSL HTTP/1.1 Connector定义的地方,一般如下:(x)
<Connector port="80" maxHttpHeaderSize="8192" scheme="https"
maxThreads="500" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
其中的redirectPort端口h为:(x)443
2).SSL HTTP/1.1 Connector定义的地方,修改端口号ؓ(f)Q?43Q如下:(x)
<Connector
port="443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
disableUploadTimeout="true"
acceptCount="100" scheme="https"
secure="true"
clientAuth="false" sslProtocol="TLS"
SSLEnabled="true"
keystoreFile="e:/server.keystore"
keystorePass="changit" />
3).AJP 1.3 Connector定义的地方,修改redirectPort?43Q如下:(x)
<Connector port="8009"
enableLookups="false" redirectPort="443" protocol="AJP/1.3" />
如上配置好后便可以用 Https://localhost 方式直接讉K,无需输入端口?
三、参考资?br />
1. Keytool使用指南Q?br />
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/keytool.html
2. tomcat-ssl配置指南Q?br />
http://tomcat.apache.org/tomcat-5.5-doc/ssl-howto.html
http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html
2.然后修改ejb3.deployer中jboss-service.xml文gQ主要是d域名?873的调用中
<mbean code="org.jboss.remoting.transport.Connector"
xmbean-dd="org/jboss/remoting/transport/Connector.xml"
name="jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3">
<depends>jboss.aop:service=AspectDeployer</depends>
<attribute name="Configuration">
<config>
<invoker transport="socket">
<attribute name="numAcceptThreads">1</attribute>
<attribute name="maxPoolSize">300</attribute>
<attribute name="clientMaxPoolSize" isParam="true">50</attribute>
<attribute name="timeout" isParam="true">60000</attribute>
<attribute name="serverBindAddress">${jboss.bind.address}</attribute>
<attribute name="serverBindPort">3873</attribute>
<!-- that's the important setting -->
<attribute name="clientConnectAddress">10.104.46.119</attribute>
<attribute name="clientConnectPort">3873</attribute>
<attribute name="backlog">200</attribute>
</invoker>
<handlers>
<handler subsystem="AOP">org.jboss.aspects.remoting.AOPRemotingInvocationHandler</handler>
</handlers>
</config>
</attribute>
</mbean>
3.讄java启动选项Q添加rmi-server的外部地址和禁用本地域名解析到启动脚本
Windows脚本例:(x)set JAVA_OPTS=-Djava.rmi.server.hostname= external IP -Djava.rmi.server.useLocalHostname=false
Unix脚本例:(x)d到jboss启动配置文grun.conf中即可?/p>
4.用run.sh --host=192.168.1.25启动服务或添?-host=192.168.1.25到启动脚本?/p>
1.在?span style="background-color: #ffff00;">Jboss 4.2GA 遇到的问? 以下是以default 模式启动?span style="background-color: #ffff00;">Jboss .启动参数 -c default /all
(1). localhost可以讉K与本机IP不能讉K
解决方式Q?
修改JBOSS_HOME"server"default"deploy"jboss-web.deployer下的server.xml address改ؓ(f)0.0.0.0或者你的实际IP 重启 JBOSS 然后可以通过ip讉K?/p>
(3)在windows 客户端调?Linux 服务?遇到org.jboss.remoting.CannotConnectException: Can not get connection to server. Problem establishing socket connection for InvokerLocator [socket://127.0.0.1:3873/]
解决Ҏ(gu): 修改 JBOSS_HOME/server/default/deploy/ejb3.deployer/META-INF/jboss-services.xml 文g中的${jboss.bind.address}:3873 为linux_home_ip:3873
以上两个问题也可以通过以下讄解决Q?
For Windows, use
run.bat -b 0.0.0.0
for Linux use
run.sh -b 0.0.0.0
在启动JBOSS节点前,要正?/span>安装SUN JDK1.5
q设|环境变?JAVA_HOME
解压~JBOOS-TGZ?/font>
cd $JBOSS_HOME/bin
nohup ./run.sh -c vcom -b 0.0.0.0 –u 229.12.12.12&
参数说明Q?/span>
-c: 指定q行的配|,default配置不带集群支持,all 和自定义的vcom目录配置带有集群支持功能
-b: 指定服务l定的IP地址Q即对外服务的IP地址Q?.0.0.0表示Ҏ(gu)器上所有的IP提供服务
-u 指定服务使用的UDPl播地址
~写脚本内容如下Q?/font>
#!/bin/bash
for i in ` ps -ef | grep -w java |grep -v grep |awk '{print $2 ""t"$3}'`;do kill -9 $i
done
安装好j(lu)bossq启动jboss后,在浏览器H口的地址栏里键入 http://localhost:8080/jmx-consoleQjboss默认的端口号?080,可以自定义修改)(j)?/span>可以浏?jboss的部|管理的一些信息,默认情况下不键入M用户名和密码可以进入此面Q方便是方便Q但真正使用hq是有点安全隐?zhn)Q因ZQ何h只要知道server的ip 都可以进去访问。下面我们针Ҏ(gu)问题对jbossq行配置Q得访问jmx-console也必?要知道用户名和密码才可进去访?
2.1 讄jmx-console安全讄
1. q入jmx-console.warQ通常此目录在$JBOSS_HOME/server/vcom/deploy目录下?/span>
2. ~辑该目录下?WEB-INF/web.xmlQ把<security-constraint>部分注释L 3.~辑$jboss_home/server/vcom/conf/props目录下的jmx-console-roles.properties和jmx-console-users.propertiesQ?/span>
1) users.properties文g里定义用户名和密码,格式为username=password。可以依照此格式d多个用户?
2) roles.propertie文g里定义用户名和角Ԍ格式为username=role。这里的role必须和web.xml文g里的<role-name>相对应?
4. ~辑/WEB-INF/jboss-web.xml文gQ打开<security-domain>部分注释Q这?lt;security- domain>内容对应的security-domain对应$jboss_home"server"vcom"conf"login-config.xmlq个jaas配置文g里的某个application-policy?
?
<security-domain>java:/jaas/jmx-console</security-domain>
在login-config.xml里对应有Q?/span>
<application-policy name = "jmx-console">
<authentication>
<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag = "required" />
</authentication>
</application-policy>
5Q重启jbossQ在览器中键入控制台地址Q就?x)出现输入username和password的提C窗口?
使用http://localhost:8080/jmx-console,使用名ؓ(f)jboss.cache:service=TomcatClustering MBean Members可以查看当前机群节点成员信息Q用jboss.cache:service=TomcatClusteringQ可以看到当前集的节点ip,在member 一中Q可以观察到当前集群中节点ip,如图Q?/font>
在此面下找?/span>java.lang.String printDetails() Q?/span>
invoke the printDetails操作Q点击invokeQ可以对session复制q行监控?/span>
目前应用使用的数据库q接是应用程序自带的JDBC QAPIQ接口,配置如下Q?/span>
Cd /$JBOSS_HOME/server/vcom/deploy/*.war/WEB-INF/class/
Vi proxool.xml
<?xml version="1.0" encoding="UTF-8"?>
<datasource>
<proxool>
<alias>pool</alias>
<driver-url>jdbc:oracle:thin:@192.168.104.32:1521:cportal</driver-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<driver-properties>
<property name="user" value="cportal"/>
<property name="password" value="cportal"/>
</driver-properties>
<house-keeping-sleep-time>30000</house-keeping-sleep-time>
<minimum-connection-count>0</minimum-connection-count>
<maximum-connection-count>300</maximum-connection-count>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
</datasource>
(1) jdbc:oracle:thin:@192.168.104.32:1521:cportalQoracle服务端口?521Qcportal为数据库的实例名即sid?/span>
(2) <property name="user" value="cportal"/>
<property name="password" value="cportal"/> 为数据库的用户名和密?/span>
Q?Q?/span><maximum-connection-count>300</maximum-connection-count>为客L(fng) 最大的数据库连接数
使用JBOSS中间件时,默认的访问端口是8080Q可以修攚w你想使用的端口,修改步骤如下Q?/font>
打开JBOSS目录$JBOSS_HOME/server/vcom/deploy/jboss-web.deployer/下的server.xml文g,搜烦(ch)8080,?080改ؓ(f)新的端口?保存文g,重启应用服务器即?讉K时用新的端口号.
<Connector port="80" address="${jboss.bind.address}"
maxThreads="150" maxHttpHeaderSize="8192"
emptySessionPath="true" protocol="HTTP/1.1"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
其中150是JVM中启动的最大线E数Q?00 为JVM辑ֈ最大线E阀值时Q可以放在队列中的HTTPh?/font>
如果需要监控jboss的系l资源,如:(x)jboss的基本配|情况,jvm的利用率Q线E池的用情况,可以使用web-consoleq行监控?/span>
具体Ҏ(gu)同jmx-consoleQ就是位|不同,具体Ҏ(gu)参考jmx-console配置Q?/font>
· jboss-web.xml、web.xml?JBOSS_HOME/vcom/deploy/management/console-mgr.sar/web-console.war/WEB-INF下;
· login-config.xmlq是原来的那个,把application-policy名ؓ(f)$webConsoleDomain的部分改成你需要的web-consoleQ?/span>
· web-console-users.properties、web-console-roles.properties定义?jin)访?web-console的用戗用戯Ԍ具体位置自己LQ用find /jboss -name web-console-users.properties 扑ֈ以后可以修改用户名、密码?/span>
使用http://localhost:8080/web-console/ 中,获取当前JBOSS-WEB应用模块的负载分担情况,q可以查看到当前JAVA虚拟机的内存使用情况Q及(qing)U程池用情c(din)?/font>
使用http://localhost:8080/web-console/statusQ可以进一步监控到每个U程的状态?/font>
?/span>$JBOSS_HOME /server/vcom/log下,有关于jboss的日志记录, 其中server.log是用来记录JBOOSq行q程的日志记?boot.log用来记录JBOOS启动信息的,出现问题时可以通过sever.log对jbossq行分析?/span>
$JBOSS_HOME /server/vcom/conf下的jboss-log4j.xmlQ可以对日志的来源和U别q行定义Q也可以定义日志的记录方式?/span>
可以把jboss-log4j.xml中最后有关cluster.log的APPENDER注释掉,pȝq行时会(x)在log目录下生cluster.log文gQ可以通过此文件对集群故障q行分析。在试调试q程可以使用此日?/font>
Jboss日志记录方式?U:(x)
1Q?/font> 按日期进行记?/font>
2Q?/font> 按日志文件的大小q行记录
目前使用的是按照大小信息记录。如果要修改记录方式Q直接编辑jboss-log4j.xml文gQ将此段注释L?/font>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
…………………………………………………
……………………………………………………………………….
</layout>
</appender>
同时下D|释掉
<!-- A size based file rolling appender-->
<appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="1"/>
……………………………………………………………
…………………………………………………………
</layout>
</appender>
下?/span>一?span style="font-weight: normal; font-size: 10.5pt; font-family: '宋体';">修改数据库的q接方式
1、采用数据源的Ş?br />
?nbsp;tomcat 中配|数据源方式如下:
在生成的目同目录中找此文Ӟ(x) context.xml
Servers/Tomcat 。。?/font>/context.xml 作如下配|:(x)
在标{?nbsp;<Context> 中间加入:
<Resource
name="jdbc/demo" auth="Container" type="javax.sql.DataSource"
maxActive="30" maxIdle="5" maxWait="10000" username="root"
password="admin" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=UTF-8">
</Resource>
2?span style="font-weight: normal; font-size: 10.5pt; font-family: '宋体';">使用非数据源的Ş?br />
在文Ӟ(x)persistence.xml 中添?/font>hibernate 的连接数据库的方式,如下Q?br />
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="admin"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=UTF-8"/>
二?span style="font-weight: normal; font-size: 10.5pt; font-family: '宋体';">修改 JPA 配置文g persistence.xml
1?/span>如果数据的连接方式采用数据源的Ş式,则只需修改里面数据源的名称Q如Q?br /> <jta-data-source>java:comp/env/jdbc/demo</jta-data-source>
2、如果采?font face="Times New Roman">hibernate
的连接方式,则把此行删了(jin)?/font> 3?span style="font-weight: normal; font-size: 10.5pt; font-family: '宋体';">删除里面的此行配|:(x)
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
4、修改事务的{略方式?RESOURCE_LOCAL Q?nbsp;
<persistence-unit name="demo" transaction-type="RESOURCE_LOCAL">
三?span style="font-weight: normal; font-size: 10.5pt; font-family: '宋体';">配置 Seam 的事务管理器
?nbsp;component.xml 文g加入Q?br />
<transaction:entity-transaction entity-manager="#{entityManager}"/>
默认生成的此文g是不含有 transaction 的命名空_(d)需要手动在此文件加入它的命名空_(d)(x)
xmlns:transaction=http://jboss.com/products/seam/transaction
http://jboss.com/products/seam/transaction
http://jboss.com/products/seam/transaction-2.1.xsd
四?span style="font-weight: normal; font-size: 10.5pt; font-family: '宋体';">为此目加入必要的依赖包 。。。。。?/span>
Transaction timeout (unit is always seconds) can be configured in various ways:
This argument is the same no matter if you are using JBossTM(<=4.0.5) or JBossJTA-Arjuna(>=4.2).
Globally: You can change this behavior globally by modifying the TransactionManagerService in /conf/jboss-service.xml (or /deploy/jta-service.xml for 4.0.3)
Version <= 4.0.5
This part is the same for either JBossTM or JBossJTA and is the same for ejb2 and ejb3
Per-method basis: Modifying the <transaction-timeout> element inside the <method> element of a session or entity bean. This is located in the META-INF/jboss.xml deployment descriptor of a session bean. When the transaction timeout is specified at the method level, it overrides the default timeout. Further information about this element can be found in jboss-x.x.x/docs/dtd/jboss_4_0.dtd. Example taken from the testsuite:
Using BMT: Calling javax.transaction.UserTransaction.setTransactionTimeout(int seconds). Please, be aware that this only applies to transactions started after this invocation on the same thread. Example:
@TransactionTimeout(1500)
P1:Tomcat6启动的时候出C面这L(fng)提示Q?/p>
2007-12-31 9:51:51 org.apache.catalina.core.AprLifecycleListener init
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Sun\jre1.6.0_03\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;D:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;.;D:\Sun\jdk1.6.0_03\bin;D:\Sun\jdk1.6.0_03\jre\bin;D:\ApacheTomcat\lib;
S1:实际q是使用apache的apr;apr 是apache portable runtime 用上q个后可以有效的提高tomcat处理?rn)态页面的能力.如果想用apr的话Q?实际操作很简单,
下蝲 http://tomcat.heanet.ie/native/1.1.1/binaries/win32/tcnative-1.dll
这个文件复制到C:\WINDOWS\system32\下面,然后重新启动tomcatQ就?x)发现tomcat 的控制台信息为:(x)
2007-12-31 9:55:40 org.apache.catalina.core.AprLifecycleListener init
信息: An older version 1.1.8 of the Apache Tomcat Native library is installed, while Tomcat recommends version greater then 1.1.10
2007-12-31 9:55:40 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded Apache Tomcat Native library 1.1.8.
Available option in deploy/jbossweb-tomcat.sar/META-INF/jboss-service.xml
or deploy/jboss-web.deployer/META-INF/jboss-service.xml
This configuration options toggles usage of separate classloaders for web modules. The JBoss unified classloader holds all the classes from multiple web applications in one big classloader and may cause unwanted interference.
Example
Imagine web modules "sales.war" and "stock.war", both containing some version of "utility.jar". In case "sales.war" uses version 1.0 and "stock.war" requires version 2.0, turning off the unified web loader is the safest solution. If you don't, the first loaded library will have priority, and remains in the classloader till the reference count drops to zero.
The disadvantage of using isolated classloaders: either you need to duplicate the same library across multiple web modules, or add it to the classpath of your server instance (default: lib/). The instance libraries are defaults, they can be overridden when the web module contains it's own custom versions.
The configuration file contains a small comment about isolation of JSP files as well, to separate two JSP files with the same name from two different web modules. In JBoss 4.0.5, using non-precompiled JSP pages, this seems to work fine, even with the JBoss unified web loader.
mod_python is similar to (and inspired by) mod_perl : It embeds Python within Apache and loads Python code into memory when the server starts. Code stays in memory throughout the life of an Apache process, which leads to significant performance gains over other server arrangements.
Django requires Apache 2.x and mod_python 3.x, and you should use Apache’s prefork MPM, as opposed to the worker MPM.
You may also be interested in How to use Django with FastCGI, SCGI or AJP (which also covers SCGI and AJP).
To configure Django with mod_python, first make sure you have Apache installed, with the mod_python module activated.
Then edit your httpd.conf file and add the following:
<Location "/mysite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug On
</Location>
...and replace mysite.settings with the Python import path to your Django project's settings file.
This tells Apache: "Use mod_python for any URL at or under '/mysite/', using the Django mod_python handler." It passes the value of DJANGO_SETTINGS_MODULE so mod_python knows which settings to use.
Because mod_python does not know we are serving this site from underneath the /mysite/ prefix, this value needs to be passed through to the mod_python handler in Django, via the PythonOption django.root ... line. The value set on that line (the last item) should match the string given in the <Location ...> directive. The effect of this is that Django will automatically strip the /mysite string from the front of any URLs before matching them against your URLConf patterns. If you later move your site to live under /mysite2, you will not have to change anything except the django.root option in the config file.
When using django.root you should make sure that what's left, after the prefix has been removed, begins with a slash. Your URLConf patterns that are expecting an initial slash will then work correctly. In the above example, since we want to send things like /mysite/admin/ to /admin/, we need to remove the string /mysite from the beginning, so that is the django.root value. It would be an error to use /mysite/ (with a trailing slash) in this case.
Note that we're using the <Location> directive, not the <Directory> directive. The latter is used for pointing at places on your filesystem, whereas <Location> points at places in the URL structure of a Web site. <Directory> would be meaningless here.
Also, if your Django project is not on the default PYTHONPATH for your computer, you'll have to tell mod_python where your project can be found:
<Location "/mysite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug On
PythonPath "['/path/to/project'] + sys.path"
</Location>
The value you use for PythonPath should include the parent directories of all the modules you are going to import in your application. It should also include the parent directory of the DJANGO_SETTINGS_MODULE location. This is exactly the same situation as setting the Python path for interactive usage. Whenever you try to import something, Python will run through all the directories in sys.path in turn, from first to last, and try to import from each directory until one succeeds.
An example might make this clearer. Suppose you have some applications under /usr/local/django-apps/ (for example, /usr/local/django-apps/weblog/ and so forth), your settings file is at /var/www/mysite/settings.py and you have specified DJANGO_SETTINGS_MODULE as in the above example. In this case, you would need to write your PythonPath directive as:
PythonPath "['/usr/local/django-apps/', '/var/www'] + sys.path"
With this path, import weblog and import mysite.settings will both work. If you had import blogroll in your code somewhere and blogroll lived under the weblog/ directory, you would also need to add /usr/local/django-apps/weblog/ to your PythonPath. Remember: the parent directories of anything you import directly must be on the Python path.
Note
If you're using Windows, we still recommended that you use forward slashes in the pathnames, even though Windows normally uses the backslash character as its native separator. Apache knows how to convert from the forward slash format to the native format, so this approach is portable and easier to read. (It avoids tricky problems with having to double-escape backslashes.)
This is valid even on a Windows system:
PythonPath "['c:/path/to/project'] + sys.path"
You can also add directives such as PythonAutoReload Off for performance. See the mod_python documentation for a full list of options.
Note that you should set PythonDebug Off on a production server. If you leave PythonDebug On, your users would see ugly (and revealing) Python tracebacks if something goes wrong within mod_python.
Restart Apache, and any request to /mysite/ or below will be served by Django. Note that Django's URLconfs won't trim the "/mysite/" -- they get passed the full URL.
When deploying Django sites on mod_python, you'll need to restart Apache each time you make changes to your Python code.
It's entirely possible to run multiple Django installations on the same Apache instance. Just use VirtualHost for that, like so:
NameVirtualHost *
<VirtualHost *>
ServerName www.example.com
# ...
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
</VirtualHost>
<VirtualHost *>
ServerName www2.example.com
# ...
SetEnv DJANGO_SETTINGS_MODULE mysite.other_settings
</VirtualHost>
If you need to put two Django installations within the same VirtualHost (or in different VirtualHost blocks that share the same server name), you'll need to take a special precaution to ensure mod_python's cache doesn't mess things up. Use the PythonInterpreter directive to give different <Location> directives separate interpreters:
<VirtualHost *>
ServerName www.example.com
# ...
<Location "/something">
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonInterpreter mysite
</Location>
<Location "/otherthing">
SetEnv DJANGO_SETTINGS_MODULE mysite.other_settings
PythonInterpreter othersite
</Location>
</VirtualHost>
The values of PythonInterpreter don't really matter, as long as they're different between the two Location blocks.
If you use mod_python for your development server, you can avoid the hassle of having to restart the server each time you make code changes. Just set MaxRequestsPerChild 1 in your httpd.conf file to force Apache to reload everything for each request. But don't do that on a production server, or we'll revoke your Django privileges.
If you're the type of programmer who debugs using scattered print statements, note that print statements have no effect in mod_python; they don't appear in the Apache log, as one might expect. If you have the need to print debugging information in a mod_python setup, either do this:
assert False, the_value_i_want_to_see
Or add the debugging information to the template of your page.
Django doesn't serve media files itself; it leaves that job to whichever Web server you choose.
We recommend using a separate Web server -- i.e., one that's not also running Django -- for serving media. Here are some good choices:
If, however, you have no option but to serve media files on the same Apache VirtualHost as Django, here's how you can turn off mod_python for a particular part of the site:
<Location "/media">
SetHandler None
</Location>
Just change Location to the root URL of your media files. You can also use <LocationMatch> to match a regular expression.
This example sets up Django at the site root but explicitly disables Django for the media subdirectory and any URL that ends with .jpg, .gif or .png:
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
</Location>
<Location "/media">
SetHandler None
</Location>
<LocationMatch "".(jpg|gif|png)$">
SetHandler None
</LocationMatch>
Note that the Django development server automagically serves admin media files, but this is not the case when you use any other server arrangement. You're responsible for setting up Apache, or whichever media server you're using, to serve the admin files.
The admin files live in (django/contrib/admin/media) of the Django distribution.
Here are two recommended approaches:
If you installed Django from a Python egg or are using eggs in your Django project, some extra configuration is required. Create an extra file in your project (or somewhere else) that contains something like the following:
import os
os.environ['PYTHON_EGG_CACHE'] = '/some/directory'
Here, /some/directory is a directory that the Apache webserver process can write to. It will be used as the location for any unpacking of code the eggs need to do.
Then you have to tell mod_python to import this file before doing anything else. This is done using the PythonImport directive to mod_python. You need to ensure that you have specified the PythonInterpreter directive to mod_python as described above (you need to do this even if you aren't serving multiple installations in this case). Then add the PythonImport line in the main server configuration (i.e., outside the Location or VirtualHost sections). For example:
PythonInterpreter my_django
PythonImport /path/to/my/project/file.py my_django
Note that you can use an absolute path here (or a normal dotted import path), as described in the mod_python manual. We use an absolute path in the above example because if any Python path modifications are required to access your project, they will not have been done at the time the PythonImport line is processed.
When you use Apache/mod_python, errors will be caught by Django -- in other words, they won't propagate to the Apache level and won't appear in the Apache error_log.
The exception for this is if something is really wonky in your Django setup. In that case, you'll see an "Internal Server Error" page in your browser and the full Python traceback in your Apache error_log file. The error_log traceback is spread over multiple lines. (Yes, this is ugly and rather hard to read, but it's how mod_python does things.)
If Apache causes a segmentation fault, there are two probable causes, neither of which has to do with Django itself.
If you continue to have problems setting up mod_python, a good thing to do is get a barebones mod_python site working, without the Django framework. This is an easy way to isolate mod_python-specific problems. Getting mod_python Working details this procedure.
The next step should be to edit your test code and add an import of any Django-specific code you're using -- your views, your models, your URLconf, your RSS configuration, etc. Put these imports in your test handler function and access your test URL in a browser. If this causes a crash, you've confirmed it's the importing of Django code that causes the problem. Gradually reduce the set of imports until it stops crashing, so as to find the specific module that causes the problem. Drop down further into modules and look into their imports, as necessary.
使用 apache ?/span> tomcat 配置一个可以应用的 web |站Q要辑ֈ以下要求Q?/span>
1?nbsp;Apache 做ؓ(f) HttpServer Q后面连接多?/span> tomcat 应用实例Qƈq行负蝲均衡?/span>
2?nbsp;为系l设?/span> Session 时旉Q包?/span> Apache ?/span> tomcat
3?nbsp;为系l屏蔽文件列表,包括 Apache ?/span> tomcat
不要下蝲安装?/span> , 下蝲地址
我们需要在一台机器上?/span> 2 个不同的 tomcat Q需要修改不同的 tomcat 的关闭口Q避免出现端口被占用的情c(din)在 server.xml 中找?/span> server, :(x)
<Server port="8005" shutdown="SHUTDOWN">
改ؓ(f)
<Server port="XXXX" shutdown="SHUTDOWN">
XXXX 在这里表CZ同的端口Q我的两?/span> tomcat 分别使用 8035 Q?/span> 8045
注意Q这里之所以要配置不同?/span> tomcat 关闭口,只是因ؓ(f)我们使用?jin)多?/span> tomcat Q其实用一?/span> server 多个实例也可以?/span>
我们需要对不同?/span> tomcat ?/span> service 取不同的名字Q在 server.xml 中找刎ͼ(x)
<Service name="Catalina">
改ؓ(f)Q?/span>
<Service name="XXXX">
两个 service 分别?/span> tomcat6 ?/span> tomcat5
q个部分主要是要改两?/span> Connector Q当然前提是你的 tomcat 只有两个 Connector ?/span>
修改 ajp1.3 的端口:(x)
扑ֈQ?/span> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
改ؓ(f)Q?/span> <Connector port="XXXX" protocol="AJP/1.3" redirectPort="8443" />
两个 Service ?/span> ajp/1.3 的端口分别ؓ(f)Q?/span> 8019 Q?/span> 8029
修改 http 的端口:(x)
扑ֈQ?/span>
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" />
改ؓ(f)Q?/span>
<Connector port="XXXX" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" />
两个 Service ?/span> ajp/1.3 的端口分别ؓ(f)Q?/span> 8060 Q?/span> 8070
Engine 主要是配|?/span> jvmRoute 属性,扑ֈQ?/span>
<Engine name="Catalina" defaultHost="localhost">
改ؓ(f)Q?/span>
<Engine jvmRoute="XXXX" name="Catalina" defaultHost="localhost">
两个实例分别为:(x) tomcat6 ?/span> tomcat5.
如果?/span> Context 是多个系l公用的Q比如图片等的存攑֜Q可以做个配|:(x)
?/span> Host 中增加:(x)
<Context path="/image" docBase="D:"webRoot"image" debug="0" reloadable="false" crossContext="true">
</Context>
打开 tomcat 目录下的 conf/web.xml Q?/span>
扑ֈQ?/span>
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
?/span> listings 参数改ؓ(f) false;
对系l应用做些控制?/span>
配置 session q期旉Q大多数|站用户都只是做些浏览性的操作Qؓ(f)?jin)减L务器负蝲压力Q我们将 session 时旉从默认的 30 分钟变ؓ(f) 5 分钟?/span>
?/span> web 应用E序?/span> web.xml ?/span> servlet-mapping 之后增加如下一D:(x)
<session-config>
<session-timeout>5</session-timeout>
</session-config>
下蝲地址 http://httpd.apache.org/download.cgi
下蝲后点d?/span> msi 文g?/span>
安装的时候没有什么特别需要注意的地方Q按照默认就行了(jin)。是否安装ؓ(f) service 看具体情况而定?/span>
http://tomcat.apache.org/download-connectors.cgi
注意Q很多网站上都介l是 JK2 Q可能是觉得 JK2 ?/span> JK 要新吧,其实 JK2 已经停止研发?jin),使?/span> jk1.2 ?/span>
下蝲压羃包,之后?/span> module 目录中的 mod_jk-apache****.so 文g攑օ /module/ 目录下?/span>
扑ֈ
Listen 80
改ؓ(f)
Listen **
当然如果不需要改的话Q就不用改了(jin)。正常情冉|L攏V?/span>
扑ֈ DocumentRoot D,其改ؓ(f)Q?/span>
DocumentRoot "E:/MyWebsite"
q里?/span> "E:/MyWebsite" 指的是你?/span> web E序的根路径Q视具体应用而定?/span>
扑ֈ serverName q个D,其配置Z?/span> ServerName
如果没有配置为域名,配ؓ(f) IP 也可以,此处q不是很清楚Q多虚拟L的情늚配置?/span>
<VirtualHost *:80>
ServerAdmin flyffa@gmail.com
DocumentRoot E:/MyWebsite
ServerName localhost
DirectoryIndex index.html index.htm index.jsp
ErrorLog logs/error_log
CustomLog logs/access_log common
ErrorDocument 404 /sys/logon.jsp
</VirtualHost>
我们需要与 tomcat 做连接,所以要?/span> tomcat ?/span> connector 的模块配|进厅R?/span>
?/span> LoadModule 部分加入Q?/span>
LoadModule jk_module modules/mod_jk-apache-2.0.55.so Q加载模?/span>
q个 so 是我下蝲的版本,个h可以Ҏ(gu)自己下蝲的文件名加以配置
JkWorkersFile conf/workers.properties Q指?/span> connector 的配|文件名U?/span>
JkLogFile logs/mod_jk.log Q指?/span> connector 的日志文件名U?/span>
JkLogLevel info Q指?/span> connector 的日志等U?/span>
定义列表
worker.list=tomcat6,tomcat5,loadbalancer
定义一个名?/span> “loadbalancer” ?/span> worker
其作为对多个 Tomcat q程的负载^衡用:(x)
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat5, tomcat6
Q?/span> 负蝲qcd?/span> worker q不?/span> Tomcat worker 通讯Q它负责理q些 Tomcat worker ?/span> Q?/span>
定义多个 worker 列表
# Set properties for tomcat6 (ajp13)
worker.tomcat6.type=ajp13
worker.tomcat6.host=localhost
worker.tomcat6.port=8019
worker.tomcat6.lbfactor=50
worker.tomcat6.cachesize=10
worker.tomcat6.cache_timeout=600
worker.tomcat6.socket_keepalive=1
worker.tomcat6.reclycle_timeout=300
# Set properties for tomcat5 (ajp13)
worker.tomcat5.type=ajp13
worker.tomcat5.host=localhost
worker.tomcat5.port=8029
worker.tomcat5.lbfactor=50
worker.tomcat5.cachesize=10
worker.tomcat5.cache_timeout=600
worker.tomcat5.socket_keepalive=1
worker.tomcat5.reclycle_timeout=300
注意Q?/span> lbfactor= 50 Q?/span> 当此 Tomcat worker 被用于一个负载^?/span> worker 使用Ӟ此属性将被用。它定义?jin)?/span> worker 的负载^衡权倹{?/span> Q?/span>
cachesize= 10 Q?/span> 当在多线E的 web server Q例?/span> apache2.0 ?/span> IIS ?/span> Netscape Q中使用 JK Ӟ此属性是有效的。如果将 cachesize 的D|ؓ(f)较高的|q些支持多线E的 web server 获得很好的处理能力。如果此属性不被设|,则连?/span> cache Ҏ(gu)将失效?/span> Q?/span>
?/span> DocumnetRoot 片段下加?/span>
JkMount /*.jsp tomcat6
JkMount /*.do tomcat6
JkMount /*Servlet tomcat6
q里只是单的?/span> apache 的请求{到其中的一?/span> tomcat 中,形成桥接Q至于负载均衡的时候,无进行这步操作,直接启动负蝲均衡。启动负载均衡见下一节?/span>
?/span> DocumnetRoot 片段下加?/span>
JkMount /*.jsp loadbalancer
JkMount /*.do loadbalancer
JkMount /*Servlet loadbalancer
Q指定对所有的h启动负蝲均衡Q这里的 loadbalancer ?span style="color: #ff6600">定义?/span> worker 的名?/span>
q里我在配置的时候犯?jin)两个错误?x)
W一是没有配|?/span> JkWorkersFile conf/workers.properties Q以?/span> Apache ?x)自动认识(其?/span> apache 是自动生了(jin)一个叫?/span> ajp13 ?/span> worker Q指向本机的 8009 端口Q?/span>
W二是以?/span> JkMount 语句中出?/span> loadbalancer,ajp13 之类的是pȝ讑֮的东西,其实都是?/span> workers.properties 文g中定义的Q结果出现名字不匚w的情c(din)后来配|了(jin) JkLogFile logs/mod_jk.log 之后看到错误日志才明白?/span>
使用 Apache2.1 以上的版本,可以用 mod_proxy_ajp 来完成负载均衡的配置Q不q到目前为止Q没有看到如何让 Apache 负责?rn)态部分, tomcat 负责动态部分的配置方式Q只能用 path q行区分分发h。如Q在虚拟L的配|中增加Q?/span>
ProxyPass / ajp://localhost:8019/
ProxyPassReverse / ajp://localhost:8019/
而Ş如:(x)
ProxyPass /*.jsp ajp://localhost:8019/
ProxyPassReverse /*.jsp ajp://localhost:8019/
q样的配|是不能通过的?/span>
1?br />
PermGen space的全U是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决Ҏ(gu)也一定是加大内存。说说ؓ(f)什么会(x)内存益出Q这一部分用于存放Class和Meta的信?Class在被 Load的时候被攑օPermGen space区域Q它和和存放Instance的Heap区域不同,GC(Garbage Collection)不会(x)在主E序q行期对PermGen spaceq行清理Q所以如果你的APP?x)LOAD很多CLASS的话,很可能出现PermGen space错误。这U错误常见在web服务器对JSPq行pre compile的时候?/p> Ҏ(gu)Ҏ(gu)Q?Xms256m -Xmx256m -XX:MaxNewSize=256m -XX:MaxPermSize=256m
2?/p>
在tomcat中redeploy时出现outofmemory的错?
可以有以下几个方面的原因:
Q?使用?u>proxool,因ؓ(f)proxool内部包含?jin)一个老版本的cglib.
2, log4j,最好不?只用common-logging
3, 老版本的cglib,快点更新到最新版?/font>
Q,更新到最新的hibernate3.2
PermGen space的全U是Permanent Generation space,是指内存的永久保存区?
q块内存主要是被JVM存放Class和Meta信息?Class在被Loader时就?x)被攑ֈPermGen space?
它和存放cd?Instance)的Heap区域不同,GC(Garbage Collection)不会(x)在主E序q行期对
PermGen spaceq行清理Q所以如果你的应用中有很多CLASS的话,很可能出现PermGen space错误,
q种错误常见在web服务器对JSPq行pre compile的时候。如果你的WEB APP下都用了(jin)大量的第三方jar, 其大?br />
过?jin)jvm默认的大?4M)那么׃(x)产生此错误信息了(jin)?br />
解决Ҏ(gu)Q?手动讄MaxPermSize大小
修改TOMCAT_HOME/bin/catalina.sh
?#8220;echo "Using CATALINA_BASE: $CATALINA_BASE"”上面加入以下行:(x)
JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m
Q将相同的第三方jar文gUȝ到tomcat/shared/lib目录下,q样可以辑ֈ减少jar 文档重复占用内存的目的?/p>
二、java.lang.OutOfMemoryError: Java heap space
Heap size 讄
JVM堆的讄是指javaE序q行q程中JVM可以调配使用的内存空间的讄.JVM在启动的时候会(x)自动讄Heap size的|
其初始空??Xms)是物理内存的1/64Q最大空?-Xmx)是物理内存的1/4。可以利用JVM提供?Xmn -Xms -Xmx{选项?br />
q行讄。Heap size 的大是Young Generation 和Tenured Generaion 之和?br />
提示Q在JVM中如?8Q的旉是用于GC且可用的Heap size 不2Q的时候将抛出此异怿息?br />
提示QHeap Size 最大不要超q可用物理内存的80Q,一般的要将-Xms?Xmx选项讄为相同,?Xmn?/4?Xmx倹{?
解决Ҏ(gu)Q手动设|Heap size
修改TOMCAT_HOME/bin/catalina.sh
?#8220;echo "Using CATALINA_BASE: $CATALINA_BASE"”上面加入以下行:(x)
JAVA_OPTS="-server -Xms800m -Xmx800m -XX:MaxNewSize=256m"
三、实例,以下l出1G内存环境下java jvm 的参数设|参考:(x)
JAVA_OPTS="-server -Xms800m -Xmx800m -XX:PermSize=64M -XX:MaxNewSize=256m -XX:MaxPermSize=128m -Djava.awt.headless=true "
三、相兌?/p>
在整合Apache和Tomcat之后Q发现该服务器的两个|站一个是?rn)态的Q一个是动态jsp的,讄ȝ如下
主要讄httpd.conf
1、DirectoryIndex的设|?/p>
如果多个虚拟站点中包含多U文件格式和文g名的首页文gQ必dq里全部出现
2、多个站点的定义如下
#NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
NameVirtualHost 220.231.32.*:80
<VirtualHost 220.231.32.*:80>
ServerAdmin liubin@sina.com
DocumentRoot /usr/local/tomcat/webapps/ronglian
ServerName www.ronglian.com
ErrorLog logs/ronglian.com-error_log
CustomLog logs/ronglian.com-access_log common
</VirtualHost>
<VirtualHost 220.231.32.*:80>
ServerAdmin wellboby@tom.com
DocumentRoot /usr/local/wwwroot/chinaface
ServerName www.chinaface.net
ErrorLog logs/chinaface.net-error_log
CustomLog logs/chinaface.net-access_log common
</VirtualHost>
Q! 在这里,NameVirtualHost的字D不能省略,否则起apache时报错:(x)VirtualHost 220.231.32.*.80 overlaps with VirtualHost 220.231.32.*:80, the first has precedence, perhaps you need a NameVirtualHost directive——虽然apache能vQ同错误描述一PW二个站点的定义被第一个站点的定义所覆盖Q即讉KW二个站Ҏ(gu)向的其实是第一?/p>
Q!
NameVirtualHost字段的端口号不能忽略Q否则vapache时报错:(x)VirtualHost 220.231.32.*:80 --
mixing * ports and non-* ports with a NameVirtualHost address is not
supported, proceeding with undefined results
[Sun Jul 09 16:59:37
2006] [error] VirtualHost 220.231.32.*:80 -- mixing * ports and non-*
ports with a NameVirtualHost address is not supported, proceeding with
undefined results——apache不能?/p>
Q!如果VirtualHost 字段的端口号实Qvapache时报错:(x)VirtualHost 220.231.32.28:0 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results——但apache可以启动Q访问也正常
自动化配|的前提是只有一?Tomcat 实例?Apache 在同一台机器上q行。自动化配置是通过?Tomcat 的配|文?server.xml 中的 Engine 元素中添加相应的 ApacheConfig 监听?Listener)来实现的?/span>
下面是具体的配置Q?/span>
W一步:(x)下蝲q安?Apache httpd?Tomcat
下蝲q安?Apache 2.2.9 ?Tomcat 5.5.26Q假设他们的安装目录如下Q?/span>
D:/apps/Apache/Apache2.2
D:/apps/Apache/apache-tomcat-5.5.26
q两个服务器可以在以下地址下蝲Q?/span>
Tomcat:
http://apache.osuosl.org/tomcat/tomcat-5/v5.5.26/bin/apache-tomcat-5.5.26.zip
Apache:
http://apache.osuosl.org/httpd/binaries/win32/apache_2.2.9-win32-x86-openssl-0.9.8h-r2.msi
W二步:(x)下蝲q安?mod_jk.so
mod_jk 的下载地址如下Q?/span>
http://apache.osuosl.org/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.26/mod_jk-1.2.26-httpd-2.2.4.so
下蝲后将光命名q复制到?D:/apps/Apache/Apache2.2/modules ?/span>
W三步:(x)创徏 workers.properties 文g
workers.properties 定义?jin)每?worker 的类型、协议、端口等信息。如果手上没有现成的配置文gQ可以用以下最单的配置Q?/span>
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
这个文件放?Tomcat 下的 conf/jk 目录中,如果攑֜其他地方Q则需要在 server.xml 的配|中明确指定?/span>
W四步:(x)修改 Tomcat server.xml 文g
扑ֈ下面q行内容q在后面d配置信息Q?/span>
<Engine name="Catalina" defaultHost="localhost">
配置信息如下Q?/span>
<Listener className="org.apache.jk.config.ApacheConfig"
workersConfig="conf/workers.properties"
modJk="D:/apps/Apache/Apache2.2/modules/mod_jk.so"
jkLog="logs/mod_jk.log"
jkDebug="info"
jkWorker="worker1"
noRoot="true"
/>
其中Q?/span>
W五步:(x)修改 Apache httpd.conf 文g
扑ֈ httpd.conf 文gq在最后加上如下配|:(x)
#To be added at the end of your httpd.conf
Include $TOMCAT_HOME/conf/auto/mod_jk.conf
要注意的是,q里 Include 后面的\径必L,q里 $TOMCAT_HOME ?Tomcat 安装目录QD:/apps/Apache/apache-tomcat-5.5.26?/span>
W六步:(x)重启 Tomcat q自动生?mod_jk.conf
重启 TomcatQ重启成功后?x)在?conf 下面生成 mod_jk.conf 文gQ这个配|文件就是在 httpd.conf 中要用到的那个,q个文g的\径必d?httpd.conf 中的一致。下面是生成的一个mod_jk.confQ?/span>
########## Auto generated on Sun Jun 29 11:21:57 CST 2008##########
<IfModule !mod_jk.c>
LoadModule jk_module "D:/apps/Apache/Apache2.2/modules/mod_jk.so"
</IfModule>
JkWorkersFile "D:/apps/Apache/apache-tomcat-5.5.26/conf/workers.properties"
JkLogFile "D:/apps/Apache/apache-tomcat-5.5.26/logs/mod_jk.log"
JkLogLevel info
<VirtualHost localhost>
ServerName localhost
JkMount /webdav worker1
JkMount /webdav/* worker1
JkMount /servlets-examples worker1
JkMount /servlets-examples/* worker1
JkMount /tomcat-docs worker1
JkMount /tomcat-docs/* worker1
JkMount /jsp-examples worker1
JkMount /jsp-examples/* worker1
JkMount /balancer worker1
JkMount /balancer/* worker1
</VirtualHost>
W七步:(x)启动 Apache q测试配|?/span>
Apache 启动完成后,试如下地址Q?/span>
如果面能正常显C,说明配置成功Q如果出?/span> internal server error 之类的错误,说明上面的配|有误,需要检查ƈ试?/span>
mod_jk is a replacement to the elderly mod_jserv. It is a completely new Tomcat-Apache plug-in that handles the communication between Tomcat and Apache.
Several reasons:
You will need to get to know a new simplified configuration mechanism. The advantage is that learning this mechanism will give you a head start if you want to deploy Tomcat on Apache and other web servers, such as Microsoft's Internet Information Server (IIS) and the iPlanet Enterprise Web Server.
In this document I am going to use a few terms, so let's define them:
Term |
Meaning |
---|---|
Worker Process |
A worker is a tomcat instance that is running to serve servlet requests coming from the web server. In most cases there is only a single worker (the one and only tomcat process) but sometimes you will run multiple workers to achieve load balancing or site partitioning. Each worker is identified to the web server by the host were it is located, the port where it listens and the communication protocol used to exchange messages. |
In-Process Worker |
This is a special worker. Instead of working with a Tomcat process residing on another process, the web server opens a JVM and executes Tomcat inside the web server process address space. Our discussion in this document is not going to get into this special worker. |
Web Server Plug-in/Tomcat Redirector |
For Tomcat to cooperate with any web server it needs an "agent" to reside in the web server and send him servlet requests. This is the web server plug-in, and in our case the web server plug-in is mod_jk. The redirector usually comes in the shape of a DLL or shared object module that you plug into the web server. |
Plug-in Configuration |
We need to configure the web server plug-in so that it knows where the different Tomcat workers are and to which of them it should forward requests. This information, accompanied with some internal parameter, such as the log level, comprises the plug-in configuration. |
Web Server Configuration |
Each web server has some configuration that defines its behavior, e.g. on which port to listen, what files to serve, what web server plug-ins to load, etc. You will need to modify your web server configuration to instruct it to load the Tomcat redirector mod_jk. |
mod_jk can be obtained in two formats - binary and source. Depending on the platform you are running your web server on, a binary version of mod_jk may be available. It is recommended to use the binary version if one is available. If the binary is not available, follow the instructions for building mod_jk from source. Notes at the end of this section offer recommendations for specific platforms.
Binaries for mod_jk are available for several platforms in the same area as the Tomcat Binary Release. The binaries are located in subdirectories by platform. For some platforms, such as Windows, this is the typical way of obtaining mod_jk since most Windows systems do not have C compilers. For others, the binary distribution of mod_jk offers simpler installation.
For example, the Tomcat 3.3 M1 Release at http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.3-m1/bin/ contains the following:
linux/i386/ | Contains mod_jk.so for Apache 1.3 for the standard API as well as EAPI and mod_jk.so for Apache 2.0 |
netware/ | Contains the mod_jk.nlm and nsapi.nlm |
win32/ | Contains the mod_jk.dll for Windows as well as other useful binaries. |
Check the site for the latest binaries.
Note: The version of mod_jk is not dependent on the version of Tomcat. The Tomcat 3.3 distribution of mod_jk will function correctly with other 3.x versions of Tomcat, such as Tomcat 3.2.1.
mod_jk is available in source distribution for all Windows and most Unix platforms. The source for mod_jk is included in the Binary Distribution of Tomcat in the TOMCAT_HOME/native/mod_jk/ directory. This directory is organized by Web Server name and version. Each directory contains the source as well as the appropriate build scripts, make files, or project files.
The redirector was developed using Visual C++ version 6.0, so having this environment is a prerequisite if you want to perform a custom build.
The steps that you need to take are:
This will build both release and debug versions of the redirector plug-in (mod_jk).
An alternative will be to open mod_jk.dsp in msdev and build it using the build menu.
Build mod_jk.so. Following are three techniques you can try, in order of simplicity:
# JAVA_INCLUDE="-I ${JAVA_HOME}/include -I ${JAVA_HOME}/include/linux"
Finally, you can try to build it manually. Run the apxs command that came with your apache distribution (hint: look in /usr/local/apache/bin, /usr/sbin, or wherever you installed apache). Type the command all on one line.
For Linux:
apxs -o mod_jk.so -I../jk -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c *.c ../jk/*.c
Your build may fail because the object files from the ../jk directory have been compiled to the current directory, rather than their source directory. Running gcc -shared -o mod_jk.so *.o should finish the build.
For Solaris:
Use the build-solaris.sh script as follows:
# sh build-solaris.sh
This will build and install mod_jk.so in your apache/libexec directory. This script contains settings for your Java and Apache home locations. Make sure that these are set according to your installation. The default settings are JAVA_HOME=/usr/java and APACHE_HOME=/usr/local/apache. If your installation is different, you will need to edit the build-solaris.sh script and change these values appropriately.
See README.solaris located in TOMCAT_HOME/native/mod_jk/apache1.3 for more information.
If the build script does not work, you can also build mod_jk as follows:
$APACHE_HOME/bin/apxs -o mod_jk.so -DSOLARIS -I../jk -I/usr/java/include -I/usr/java/include/solaris -c *.c ../jk/*.c
On some systems, this will build the module correctly, but will fail at runtime with a "symbol "fdatasync" not found". To fix, add -lposix4 just before the -c in the above command.
For HP-UX 11.00:
Use the build-hpux.sh script as follows:
# sh build-hpux.sh
This will build and install mod_jk.so in your apache/libexec directory. This script contains settings for your Java and Apache home locations. Make sure that these are set according to your installation. The default settings are JAVA_HOME=/opt/java1.3 and APACHE_HOME=/usr/local/apache. If your installation is different, you will need to edit the build-hpux.sh script and change these values appropriately.
Also note that there are two HP-UX build scripts. One script was written to build mod_jk without JNI support using GNU GCC. The other script builds mod_jk with JNI support, however, this script requires the HP ANSI C Compiler (not the stripped down C compiler included with HP-UX to rebuild the kernel). The HP Compiler is required because the dlopen() and related shared libraries are only available for 64-bit applications and reliable 64-bit compilation is not available with the current version of GCC.
The build-hpux.sh script should also work for HP-UX 10.00.
See README.hpux located in TOMCAT_HOME/native/mod_jk/apache1.3 for more information.
For other Unixes (including FreeBSD):
You may need to replace fdatasync() with fsync() in jk_util.c.
The build-hpux-cc.sh script should be modifiable for IRIX and AIX. Edit the script and change the APACHE_HOME and JAVA_HOME locations as required.
If you are using EAPI, try adding -DEAPI to the apxs command after mod_jk.so.
If apxs fails with apxs:Break: Command failed
with rc=255
, it may have been damaged by
mod_ssl. Search for:
my $CFG_LD_SHLIB = q(); # substituted via Makefile.tmpl
my $CFG_LDFLAGS_SHLIB = q(); # substituted via Makefile.tmpl
and change to:
my $CFG_LD_SHLIB = q(ld); # substituted via Makefile.tmpl
my $CFG_LDFLAGS_SHLIB = q(-G); # substituted via Makefile.tmpl
If you've installed Java in another directory, adjust accordingly.
For other Unixes you should be able to work it out, but remember that the order of the arguments to apxs is important!.
There are several Makefiles in the other directories under the TOMCAT_HOME/native/mod_jk/ directory. You should also check the Tomcat documentation for specific information related to other web servers.
This section details the configuration that is required for the Apache Web Server to support mod_jk.
If you've previously configured Apache to use mod_jserv, remove any ApJServMount directives from your httpd.conf. If you're including tomcat-apache.conf or tomcat.conf, you'll want to remove them as well - they are specific to mod_jserv. The mod_jserv configuration directives are not compatible with mod_jk!
The simplest way to configure Apache to use mod_jk is to turn on the Apache auto-configure setting in Tomcat and put the following include directive at the end of your Apache httpd.conf file (make sure you replace TOMCAT_HOME with the correct path for your Tomcat installation:
Include TOMCAT_HOME/conf/jk/mod_jk.conf-auto
Example:
Include /usr/local/jakarta-tomcat/conf/jk/mod_jk.conf-auto
This will tell Apache to use directives in the mod_jk.conf-auto file in the Apache configuration. This file is created by enabling the Apache auto-configuration as described in the configuring Tomcat section below [Configuring Tomcat].
NOTE: If you plan to use the Tomcat-Apache auto-configuration, skip the rest of this section and continue with the Configuring Tomcat section.
Custom configurations can be created by enabling the auto-configuration and copying the TOMCAT_HOME/conf/jk/mod_jk.conf-auto file to your own configuration file, such as TOMCAT_HOME/conf/jk/mod_jk.conf-local.
The basic configuration is as follows:
LoadModule jk_module libexec/mod_jk.so
AddModule mod_jk.c
JkWorkersFile /usr/local/jakarta-tomcat/conf/workers.properties
JkLogFile /usr/local/apache/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
If you have created a custom or local version of mod_jk.conf-local as noted above, you can change settings such as the workers or URL prefix.
Use mod_jk's JkMount directive to assign specific URLs to Tomcat. In general the structure of a JkMount directive is:
JkMount <URL prefix> <Worker name>
For example the following directives will send all requests ending in .jsp or beginning with /servlet to the "ajp13" worker, but jsp requests to files located in /otherworker will go to "remoteworker".
You can use the JkMount directive at the top level or inside <VirtualHost> sections of your httpd.conf file.JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /otherworker/*.jsp remoteworker
In most simple cases Tomcat can generate the needed Apache configuration. You can configure Tomcat so that when it starts up it will automatically generate a configuration file for Apache to use mod_jk. Most of the time you don't need to do anything but include this file (appending "Include TOMCAT_HOME/conf/jk/mod_jk.conf-auto") in your httpd.conf, as shown in the previous section (Configuring Apache).
To configure Tomcat to generate the Apache auto-configuration add the following block to your TOMCAT_HOME/conf/server.xml file after <AutoWebApp ... />.
<ApacheConfig />
That's it, you can now start Tomcat and Apache and access Tomcat from the Apache server.
Note: Settings for mod_jk auto-configuration is new in Tomcat 3.3. Older versions of Tomcat create the auto-config file without a directive in server.xml. The new directive in Tomcat 3.3 allows for additional configuration options as detailed later in this section. For older versions of Tomcat, refere to the documentation that came with that version.
If you have special needs, for example mounting URL prefixes that are not the default, you can use this file as a base for your customized configuration and save the results in another file. If you manage the Apache configuration yourself you'll need to update it whenever you add a new context.
Note that you must restart tomcat and apache after adding a new context; Apache doesn't support configuration changes without a restart. Also the file TOMCAT_HOME/conf/jk/mod_jk.conf-auto is generated when tomcat starts, so you'll need to start Tomcat before Apache. Tomcat will overwrite TOMCAT_HOME/conf/jk/mod_jk.conf-auto each startup so customized configuration should be kept elsewhere. For example, copy TOMCAT_HOME/conf/jk/mod_jk.conf-auto to TOMCAT_HOME/conf/jk/mod_jk.conf-local before making changes. You'll need to startup Tomcat once to generate this file with your configuration for the first time.
It is also possible to specify the location of the auto generated files by setting options in the <ApacheConfig /> block. The following details the syntax:
< ContextManager ... >
...
<ApacheConfig options />
...
< /ContextManager >
where options can include any of the following attributes:
Example:
...
<AutoWebApp dir="webapps" host="DEFAULT" />
<ApacheConfig confighome="/home/mydir" />
...
<RequestInterceptor
className="org.apache.tomcat.modules.server.Ajp13Interceptor"
port="8009"/>
The server.xml file already has a block similar to this for Ajp12 connections on port 8007 (as delivered by mod_jserv). Even if you think you're only using Ajp13, you probably don't want to delete this connector -- it's required to shut down Tomcat.
Workers are configured using the file TOMCAT_HOME/conf/jk/workers.properties. There is a great deal of information in the workers.properties howto document, and you should really look at that first. If you're in a hurry however, you can probably get away with editing the file workers.properties and setting the workers.tomcat_home, workers.java_home and ps variables to the correct values for your system.
. |
# Setup for Solaris system |
# Load mod_jk |
For additional help, the best resource is the Tomcat Users Discussion list. You should start by searching the mail list archives located at http://mikal.org/interests/java/tomcat/index.html before you post questions to the list. If you are unable to locate the answer to your question in the archive, you can post questions about Tomcat or mod_jk to the user list for assistance. Make sure that you include the version of Apache and Tomcat that you are using as well as the platform you are running on. http://jakarta.apache.org/site/mail.html
# cd /usr/local/src
# gzip -dc apache_1.3.19.tar.gz|tar xvf -
# cd apache_1.3.19
# ./configure --prefix=/usr/local/apache "
--enable-module=most "
--enable-shared=max
# make
# make install
Note: The above steps assume that you downloaded the Apache source and placed it in your /usr/local/src directory.
This document was originally created by Gal Shachor
Revisions by (Alphabetical)
Mike Braden <mikeb@mwbinc.com>
Mike Bremford
Chris Pepper
With help from countless others on the tomcat-dev and tomcat-user lists!
Copyright ©1999-2001 The Apache Software Foundation
Legal Stuff They Make Us Say
Contact Information
首先我们先介l一下ؓ(f)什么要? Apache ?Tomcat 之间q行q接。事实上 Tomcat 本n已经提供?HTTP 服务Q该服务默认的端口是 8080Q装? tomcat 后通过 8080 端口可以直接使用 Tomcat 所q行的应用程序,你也可以该端口改ؓ(f) 80?/p>
既然 Tomcat 本n已经可以提供q样的服务,我们Z么还要引?Apache 或者其他的一些专门的 HTTP 服务器呢Q原因有下面几个Q?/p>
1. 提升寚w(rn)态文件的处理性能
2. 利用 Web 服务器来做负载均衡以?qing)容?/p>
3. 无缝的升U应用程?/p>
q? 三点对一?web |站来说是非怹重要的,我们希望我们的网站不仅是速度快,而且要稳定,不能因ؓ(f)某个 Tomcat 宕机或者是升E序D用户讉K不了(jin)Q而能完成q几个功能的、最好的 HTTP 服务器也只?apache ?http server ?jin),它? tomcat 的结合是最紧密和可靠的?/p>
接下来我们介l三U方法将 apache ?tomcat 整合在一赗?/p>
q是最常见的方式,你可以在|上扑ֈ很多关于配置JK的网,当然最全的q是其官Ҏ(gu)提供的文档。JK 本n有两个版本分别是 1 ?2Q目?1 最新的版本?1.2.19Q而版?2 早已l废弃了(jin)Q以后不再有新版本的推出?jin),所以徏议你采用版本 1?/p>
JK 是通过 AJP 协议?Tomcat 服务器进行通讯的,Tomcat 默认?AJP Connector 的端口是 8009。JK 本n提供?jin)一个监控以?qing)管理的?jkstatusQ通过 jkstatus 可以监控 JK 目前的工作状态以?qing)对?tomcat 的连接进行设|,如下图所C:(x)
? q个图中我们可以看到当前JK配了(jin)两个q接分别?8109 ?8209 端口上,目前 s2 q个q接是停止状态,?s1 q个q接自上ơ重启后已经处理?47 万多个请求,量辑ֈ 6.2 ?GQ最大的q发数有 13 {等。我们也可以利用 jkstatus 的管理功能来切换 JK C同的 Tomcat 上,例如?s2 启用Qƈ停用 s1Q这个在更新应用E序的时候非常有用,而且整个切换q程对用h说是透明的,也就辑ֈ?jin)无~升U的目的。关?JK 的配|文章网上已l非常多?jin),q里我们不再详细的介l整个配|过E,但我要讲一下配|的思\Q只要明白了(jin)配置的思\QJK 是一个非常灵zȝlg?/p>
JK 的配|最关键的有三个文gQ分别是
httpd.conf
Apache 服务器的配置文gQ用来加?JK 模块以及(qing)指定 JK 配置文g信息
workers.properties
?Tomcat 服务器的q接定义文g
uriworkermap.properties
URI 映射文gQ用来指定哪?URL ?Tomcat 处理Q你也可以直接在 httpd.conf 中配|这?URIQ但是独立这些配|的好处?JK 模块?x)定期更新该文g的内容,使得我们修改配置的时候无需重新启动 Apache 服务器?/p>
其中W二、三个配|文件名都可以自定义。下面是一个典型的 httpd.conf ?JK 的配|?/p>
# (httpd.conf) |
接下来我们在 Apache ?conf 目录下新Z个文件分别是 workers.properties、uriworkermap.properties。这两个文g的内容大概如?/p>
# |
以上?workers.properties 配置是我们前面那个屏幕抓图的页面所用的配置。首先我们配|了(jin)两个cd?ajp13 ?worker 分别?s1 ? s2Q它们指向同一台服务器上运行在两个不同端口 8109 ?8209 ?Tomcat 上。接下来我们配置?jin)一个类型ؓ(f) lbQ也是负蝲均衡的意思)(j)?workerQ它的名字是 DLOG4JQ这是一个逻辑?workerQ它用来理前面配置的两个物理连?s1 ?s2。最后还配置?jin)一个类型ؓ(f) status ?workerQ这是用来监?JK 本n的模块。有?jin)这三?worker q不够,我们q需要告?JKQ哪?worker 是可用的Q所以就?worker.list = DLOG4J, status q行配置?/p>
接下来便?URI 的映配|了(jin)Q我们需要指定哪些链接是?Tomcat 处理的,哪些是由 Apache 直接处理的,看看下面q个文g你就能明白其中配|的意义
/*=DLOG4J |
怿你已l明白了(jin)一大半?jin)?x)所有的h都由 DLOG4J q个 worker q行处理Q但是有几个例外Q?jkstatus h?status q个 worker 处理。另外这个配|中每一行数据前面的感叹h什么意思呢Q感叹号表示接下来的 URI 不要?JK q行处理Q也是 Apache 直接处理所有的囄、css 文g、js 文g以及(qing)?rn)?html 文本文g?/p>
通过?workers.properties ?uriworkermap.properties 的配|,可以有各U各L(fng)l合来满x们前面提出对一?web |站的要求。?zhn)不妨动手试试Q?/p>
![]() ![]() |
![]()
|
q是利用 Apache 自带?mod_proxy 模块使用代理技术来q接 Tomcat。在配置之前L(fng)保是否用的?2.2.x 版本?Apache 服务器。因?2.2.x 版本对这个模块进行了(jin)重写Q大大的增强?jin)其功能和稳定性?/p>
http_proxy 模式是基?HTTP 协议的代理,因此它要?Tomcat 必须提供 HTTP 服务Q也是说必d?Tomcat ?HTTP Connector。一个最单的配置如下
ProxyPass /images ! |
在这个配|中Q我们把所? http://localhost 的请求代理到 http://localhost:8080/ Q这也就?Tomcat 的访问地址Q除? images、css、js 几个目录除外。我们同样可以利?mod_proxy 来做负蝲均衡Q再看看下面q个配置
ProxyPass /images ! |
配置?JK 单多?jin),而且它也可以通过一个页面来监控集群q行的状态,q做一些简单的l护讄?/p>
?2Q监控集运行状?/strong>
![]() ![]() |
![]()
|
ajp_proxy
q接方式其实?http_proxy 方式一P都是?mod_proxy 所提供的功能。配|也是一P只需要把 http:// 换成
ajp:// Q同时连接的?Tomcat ?AJP Connector 所在的端口。上面例子的配置可以改ؓ(f)Q?/p>
ProxyPass /images ! |
采用 proxy 的连接方式,需要在 Apache
上加载所需的模块,mod_proxy 相关的模块有
mod_proxy.so、mod_proxy_connect.so、mod_proxy_http.so、mod_proxy_ftp.so?
mod_proxy_ajp.soQ?其中 mod_proxy_ajp.so 只在 Apache 2.2.x 中才有。如果是采用
http_proxy 方式则需要加?mod_proxy.so ?mod_proxy_http.soQ如果是 ajp_proxy 则需要加?
mod_proxy.so ?mod_proxy_ajp.soq两个模块?/p>
![]() ![]() |
![]()
|
?
对于 JK 的连接方式,后两U在配置上是比较单的Q灵zL方面也一炚w不逊色。但q定性而言׃?JK q样久经考验Q毕?Apache
2.2.3 推出的时间ƈ不长Q采用这U连接方式的|站q不多,因此Q如果是应用于关键的互联|网站,q是采用 JK 的连接方式?/p>
![]() |
||
![]() |
刘冬Q一直?J2EE/J2ME 从事Ud互联|方面的开发。?zhn)可以通过 Java 自由人网站来跟他联系Q网址是:(x)http://www.dlog.cn/javayou Q另外他的邮件地址?a href="mailto:javayou@gmail.com?cc=">javayou@gmail.com?/p> |
JBoss 4.0.4GA环境变量
JBOSS_HOME JBoss的位|?br />
JAVA Javaq行E序的位|?br />
JAVA_OPTS JVM启动参数
MAX_FD JBoss能够使用文g描述W的最大数量(仅用于Un*xQ?/p>