分享
 
 
 

tomcat中的开发应用系统常见的配置

王朝system·作者佚名  2006-02-01
窄屏简体版  字體: |||超大  

tomcat中的开发应用系统常见的配置1.设置环境变量

Linux系统,修改catalina.sh和catalina.50.sh

JAVA_HOME=/usr/local/j2sdk1.4.2_06

JAVA_OPTS='-Xms512m -Xmx512m'

CATALINA_HOME=/usr/local/jakarta-tomcat-5.0.28

Windows系统,修改catalina.bat和catalina.50.bat

set JAVA_HOME=D:\j2sdk1.4.2_06

set CATALINA_HOME=D:\jakarta-tomcat-5.0.28

2. 如何加大tomcat连接数

在tomcat配置文件server.xml中的<Connector />配置中,和连接数相关的参数有:

minProcessors:最小空闲连接线程数,用于提高系统处理性能,默认值为10

maxProcessors:最大连接线程数,即:并发处理的最大请求数,默认值为75

acceptCount:允许的最大连接数,应大于等于maxProcessors,默认值为100

enableLookups:是否反查域名,取值为:true或false。为了提高处理能力,应设置为false

connectionTimeout:网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。

其中和最大连接数相关的参数为maxProcessors和acceptCount。如果要加大并发连接数,应同时加大这两个参数。

web server允许的最大连接数还受制于操作系统的内核参数设置,通常Windows是2000个左右,Linux是1000个左右。tomcat5中的配置示例:

<Connector port="8080"

maxThreads="150" minSpareThreads="25" maxSpareThreads="75"

enableLookups="false" redirectPort="8443" acceptCount="100"

debug="0" connectionTimeout="20000"

disableUploadTimeout="true" />

对于其他端口的侦听配置,以此类推。

3. tomcat中如何禁止列目录下的文件

在{tomcat_home}/conf/web.xml中,把listings参数设置成false即可,如下:

<init-param>

<param-name>listings</param-name>

<param-value>false</param-value>

</init-param>

4.如何加大tomcat可以使用的内存

tomcat默认可以使用的内存为128MB,在较大型的应用项目中,这点内存是不够的,需要调大。

Unix下,在文件{tomcat_home}/bin/catalina.sh的前面,增加如下设置:

JAVA_OPTS='-Xms【初始化内存大小】 -Xmx【可以使用的最大内存】'

需要把这个两个参数值调大。例如:

JAVA_OPTS='-Xms256m -Xmx512m'

表示初始化内存为256MB,可以使用的最大内存为512MB

5. 如何添加默认访问页面

修改文件web.xml,在welcome-file里面加入需要的页面即可。

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

6. 如何添加出错页面修改文件web.xml,在location里面加入出错页面

<error-page>

<error-code>404</error-code>

<location>/error.jsp</location>

</error-page>

<error-page>

<error-code>500</error-code>

<location>/error.jsp</location>

</error-page>

7.如何配置虚拟主机

为了实现基于域名(IP地址)的虚拟主机,修改文件server.xml,加入以下内容:

<Host appBase="C:/webapp1" name="www.test1.com" unpackWARs="true" autoDeploy="true"

xmlValidation="false" xmlNamespaceAware="false">

<Alias>www.test1.com</Alias>

<Alias>192.168.1.110</Alias>

</Host>

<Host appBase="C:/webapp2" name="www.test2.com" unpackWARs="true" autoDeploy="true"

xmlValidation="false" xmlNamespaceAware="false">

<Alias>www.test2.com</Alias>

<Alias>192.168.1.120</Alias>

</Host>

在conf\Catalina\目录下建立文件夹,文件夹的名称为”www.test1.com”和“www.test2.com”,然后在这两个目录下建立文件ROOT.xml,其“www.test1.com“目录下ROOT.xml内容为:

<?xml version='1.0' encoding='utf-8'?>

<!--

Context configuration file for the test1 App

-->

<Context displayName=www.test1.com path="/" docBase="" useNaming="false">

debug="0" privileged="true" reloadable="true">

<Logger className="org.apache.catalina.logger.FileLogger"

directory="C:/webapp1/WEB-INF/logs" prefix="test1_log."

suffix=".txt" timestamp="true"/>

<Valve className="org.apache.catalina.valves.AccessLogValve"

directory="logs" prefix="test1_access_log." suffix=".txt"

pattern="combined" resolveHosts="false"/>

</Context>

8. 如何配置mysql数据源

在本机建立数据库test,将mysql的JDBC驱动mysql-connector-java-3.0.9-stable-bin.jar拷贝到目录common\lib下,

修改文件web.xml,加入以下内容:

<resource-ref>

<description>MySQL Datasource example</description>

<res-ref-name>jdbc/test</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

在WEB应用的配置文件里加入以下内容:

<Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/test">

<parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>

</parameter>

<!-- Class name for mm.mysql JDBC driver -->

<parameter>

<name>driverClassName</name>

<value>org.gjt.mm.mysql.Driver</value>

</parameter>

<!-- The JDBC connection url for connecting to your MySQL dB.

The autoReconnect=true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. -->

<parameter>

<name>url</name>

<value>jdbc:mysql://localhost:3306/test?autoReconnect=true</value>

</parameter>

<!-- MySQL dB username and password for dB connections -->

<parameter>

<name>username</name>

<value>root</value>

</parameter>

<parameter>

<name>password</name>

<value></value>

</parameter>

<!-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit. -->

<parameter>

<name>maxActive</name>

<value>100</value>

</parameter>

<!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. -->

<parameter>

<name>maxIdle</name>

<value>30</value>

</parameter>

<!-- Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. -->

<parameter>

<name>maxWait</name>

<value>10000</value>

</parameter>

</ResourceParams>

<resource-ref>

<description>MySQL Datasource example</description>

<res-ref-name>jdbc/test</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

在WEB应用的配置文件里加入以下内容:

<Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/test">

<parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>

</parameter>

<!-- Class name for mm.mysql JDBC driver -->

<parameter>

<name>driverClassName</name>

<value>org.gjt.mm.mysql.Driver</value>

</parameter>

<!-- The JDBC connection url for connecting to your MySQL dB.

The autoReconnect=true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. -->

<parameter>

<name>url</name>

<value>jdbc:mysql://localhost:3306/test?autoReconnect=true</value>

</parameter>

<!-- MySQL dB username and password for dB connections -->

<parameter>

<name>username</name>

<value>root</value>

</parameter>

<parameter>

<name>password</name>

<value></value>

</parameter>

<!-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit. -->

<parameter>

<name>maxActive</name>

<value>100</value>

</parameter>

<!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. -->

<parameter>

<name>maxIdle</name>

<value>30</value>

</parameter>

<!-- Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. -->

<parameter>

<name>maxWait</name>

<value>10000</value>

</parameter>

</ResourceParams>9. tomcat连接池的配置

修改文件web.xml,在location里面加入出错页面

<error-page>

<error-code>404</error-code>

<location>/error.jsp</location>

</error-page>

<error-page>

<error-code>500</error-code>

<location>/error.jsp</location>

</error-page>

7.如何配置虚拟主机

为了实现基于域名(IP地址)的虚拟主机,修改文件server.xml,加入以下内容:

<Host appBase="C:/webapp1" name="www.test1.com" unpackWARs="true" autoDeploy="true"

xmlValidation="false" xmlNamespaceAware="false">

<Alias>www.test1.com</Alias>

<Alias>192.168.1.110</Alias>

</Host>

<Host appBase="C:/webapp2" name="www.test2.com" unpackWARs="true" autoDeploy="true"

xmlValidation="false" xmlNamespaceAware="false">

<Alias>www.test2.com</Alias>

<Alias>192.168.1.120</Alias>

</Host>

在conf\Catalina\目录下建立文件夹,文件夹的名称为”www.test1.com”和“www.test2.com”,然后在这两个目录下建立文件ROOT.xml,其“www.test1.com“目录下ROOT.xml内容为:

<?xml version='1.0' encoding='utf-8'?>

<!--

Context configuration file for the test1 App

-->

<Context displayName=www.test1.com path="/" docBase="" useNaming="false">

debug="0" privileged="true" reloadable="true">

<Logger className="org.apache.catalina.logger.FileLogger"

directory="C:/webapp1/WEB-INF/logs" prefix="test1_log."

suffix=".txt" timestamp="true"/>

<Valve className="org.apache.catalina.valves.AccessLogValve"

directory="logs" prefix="test1_access_log." suffix=".txt"

pattern="combined" resolveHosts="false"/>

</Context>

8. 如何配置mysql数据源

在本机建立数据库test,将mysql的JDBC驱动mysql-connector-java-3.0.9-stable-bin.jar拷贝到目录common\lib下,

修改文件web.xml,加入以下内容:

<resource-ref>

<description>MySQL Datasource example</description>

<res-ref-name>jdbc/test</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

在WEB应用的配置文件里加入以下内容:

<Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/test">

<parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>

</parameter>

<!-- Class name for mm.mysql JDBC driver -->

<parameter>

<name>driverClassName</name>

<value>org.gjt.mm.mysql.Driver</value>

</parameter>

<!-- The JDBC connection url for connecting to your MySQL dB.

The autoReconnect=true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. -->

<parameter>

<name>url</name>

<value>jdbc:mysql://localhost:3306/test?autoReconnect=true</value>

</parameter>

<!-- MySQL dB username and password for dB connections -->

<parameter>

<name>username</name>

<value>root</value>

</parameter>

<parameter>

<name>password</name>

<value></value>

</parameter>

<!-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit. -->

<parameter>

<name>maxActive</name>

<value>100</value>

</parameter>

<!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. -->

<parameter>

<name>maxIdle</name>

<value>30</value>

</parameter>

<!-- Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. -->

<parameter>

<name>maxWait</name>

<value>10000</value>

</parameter>

</ResourceParams>

<resource-ref>

<description>MySQL Datasource example</description>

<res-ref-name>jdbc/test</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

在WEB应用的配置文件里加入以下内容:

<Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/test">

<parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>

</parameter>

<!-- Class name for mm.mysql JDBC driver -->

<parameter>

<name>driverClassName</name>

<value>org.gjt.mm.mysql.Driver</value>

</parameter>

<!-- The JDBC connection url for connecting to your MySQL dB.

The autoReconnect=true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. -->

<parameter>

<name>url</name>

<value>jdbc:mysql://localhost:3306/test?autoReconnect=true</value>

</parameter>

<!-- MySQL dB username and password for dB connections -->

<parameter>

<name>username</name>

<value>root</value>

</parameter>

<parameter>

<name>password</name>

<value></value>

</parameter>

<!-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit. -->

<parameter>

<name>maxActive</name>

<value>100</value>

</parameter>

<!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. -->

<parameter>

<name>maxIdle</name>

<value>30</value>

</parameter>

<!-- Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. -->

<parameter>

<name>maxWait</name>

<value>10000</value>

</parameter>

</ResourceParams>9. tomcat连接池的配置

<Resource name="jdbc/testDB" auth="Container"

type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/testDB">

<parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>

</parameter>

<parameter>

<name>driverClassName</name>

<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>

</parameter>

<parameter>

<name>url</name>

<value>jdbc:microsoft:sqlserver://218.246.85.65:1433;DatabaseName=ZCMIS</v

alue>

</parameter>

<parameter>

<name>username</name>

<value>sa</value>

</parameter>

<parameter>

<name>password</name>

<value>sa</value>

</parameter>

<parameter>

<name>maxActive</name>

<value>30</value>

</parameter>

<parameter>

<name>maxIdle</name>

<value>10</value>

</parameter>

<parameter>

<name>maxWait</name>

<value>1000</value>

</parameter>

</ResourceParams>

把下面的东西加到web.xml中

<resource-ref>

<description>DB Connection</description>

<res-ref-name>jdbc/testDB</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

类的内部实现

try{

Context initCtx = new InitialContext();

Context ctx = (Context) initCtx.lookup("java:comp/env");

//获取连接池对象

Object obj = (Object) ctx.lookup("jdbc/testDB");

javax.sql.DataSource ds = (javax.sql.DataSource)obj;

Connection conn = ds.getConnection();

}

catch(Exception e)

{

System.out.print(e.toString());

}

[url=http://blog.csdn.net/wangyin5200/][/url]

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有