日期:2014-05-16 浏览次数:20875 次
本文主要内容:
(1)安装apr,这是 Apache 为了提升 Tomcat 的性能搞的一套本地化 Socket, Thread, IO 组件也就是说它有高级 IO 功能, 操作系统级别的功能调用, 以及本地进程处理等等。
(2)安装Tomcat Native,这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。
(3)安装tomcat为系统服务
(4)优化tomcat的jvm内存池
(5)修改tomcat的并发连接数
一、安装apr
(1)安装apr
# tar zxvf apr-1.4.2.tar.gz
# cd apr-1.4.2
# ./configure --prefix=/usr/local/www/apr
# make
# make install
(2)安装apr-iconv
# tar -zxvf apr-iconv-1.2.1.tar.gz
# cd apr-iconv-1.2.1
# ./configure --prefix=/usr/local/www/apr-iconv --with-apr=/usr/local/www/apr
# make
# make install
(3)安装apr-util
# tar zxvf apr-util-1.3.9.tar.gz
# cd apr-util-1.3.9
# ./configure
--prefix=/usr/local/www/apr-util??--with-apr=/usr/local/www/apr
--with-apr-iconv=/usr/local/www/apr-iconv/bin/apriconv
# make
# make install
二、安装tomcat和tomcat-native
(1)JDK安装
# chmod a+x jdk-6u18-linux-i586-rpm.bin
# ./jdk-6u7-linux-i586-rpm.bin
# ln -s /usr/java/jdk1.6.0_18 /usr/local/java
设置环境变量
# vi /etc/profile
末尾增加如下内容
JAVA_HOME=/usr/local/java
CLASSPATH=/usr/local/java/lib/dt.jar:/usr/local/java/lib/tools.jar
PATH=/usr/local/java/bin/PATH
export PATH JAVA_HOME CLASSPATH
# source /etc/profile
# java ?version??
查看java版本,如果是1.6的,就是说明安装成功了。
(2)安装Tomcat
# tar -zxvf apache-tomcat-6.0.26.tar.gz
# mv apache-tomcat-6.0.26 /usr/local/www/tomcat
# vi /usr/local/www/tomcat/bin/catalina.sh
加入一行:
JAVA_HOME=/usr/local/java
# /usr/local/www/tomcat/bin/startup.sh
(3)安装tomcat-native
# cp tomcat-native-1.1.20-src.tar.gz /usr/local/www/tomcat/bin/
# cd /usr/local/www/tomcat/bin? ?
# tar zxvf tomcat-native-1.1.20-src.tar.gz
# cd tomcat-native-1.1.20-src/jni/native? ?
# ./configure --with-apr=/usr/local/www/apr --with-java-home=/usr/local/java
# make??
# make install??
(4)设置 apr 的环境变量:
# vi /etc/profile? ?
后面添加以下内容? ?
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib? ?
# source /etc/profile??
启动 tomcat 后, 看日志:
# more /usr/local/www/tomcat/logs/catalina.out
Dec 5, 2009 3:25:39 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.20.
三、tomcat添加到系统服务
# cd /usr/local/www/tomcat/bin/
# tar -zxvf jsvc.tar.gz
# cd jsvc-src
# chmod a+x configure
# ./configure --with-java=/usr/local/java
# make
# cp /usr/local/www/tomcat/bin/jsvc-src/native/Tomcat5.sh /etc/rc.d/init.d/tomcat
# vi /etc/rc.d/init.d/tomcat
在#!bin/sh下添加
#chkconfig: 2345 85 15
#description: apache-tomcat.6
相应的内容修改为如下内容:
JAVA_HOME=/usr/local/java
CATALINA_HOME=/usr/local/www/tomcat
DAEMON_HOME=/usr/local/www/tomcat/bin
TOMCAT_USER=tomcat
CATALINA_BASE=/usr/local/www/tomcat
CATALINA_OPTS="-Djava.library.path=/usr/local/apr/lib"
$DAEMON_HOME/jsvc-src/jsvc? ?#有两处
添加执行用户tomcat
# groupadd tomcat
# useradd -g tomcat -s /sbin/nologin -M tomcat
加入系统服务,开机自启动
# chown -R tomcat.tomcat /usr/local/www/tomcat
# chmod a+x /etc/rc.d/init.d/tomcat
# chkconfig --add tomcat
# chkconfig tomcat on
四、修改Java虚拟机的虚拟内存
(1)添加tomcat管理员
# vi /usr/local/www/tomcat/conf/tomcat-users.xml
在<tomcat-users>??</tomcat-users>中间添加
<role rolename="manager"/>
<user username="tomcat" password="lin31415926"