CentOS下配置Tomcat

[linux@linux ~]$ rpm -qa|grep tomcat
tomcat5-servlet-2.4-api-5.5.23-0jpp.7.el5
tomcat5-jsp-2.0-api-5.5.23-0jpp.7.el5
tomcat5-server-lib-5.5.23-0jpp.7.el5
tomcat5-5.5.23-0jpp.7.el5
tomcat5-webapps-5.5.23-0jpp.7.el5
tomcat5-jasper-5.5.23-0jpp.7.el5
tomcat5-common-lib-5.5.23-0jpp.7.el5
tomcat5-admin-webapps-5.5.23-0jpp.7.el5
[linux@linux ~]$ sudo /etc/rc.d/init.d/tomcat5 start
Starting tomcat5:                                                                [ OK ]
[linux@linux ~]$ sudo vim /usr/share/tomcat5/conf/tomcat-users.xml 
<tomcat-users>
  <role rolename="admin"/>
  <role rolename="manager"/>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="admin" password="admin" fullName="" roles="admin,manager"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
</tomcat-users>
[linux@linux ~]$ sudo /etc/rc.d/init.d/tomcat5    restart
现在就可以用用户名admin和密码admin来登录 /manager/html或者/admin了。

但发现tomcat的状态还是用的jdk1.4下的JVM:
 Tomcat Version |JVM Version |JVM Vendor |OS Name |OS Version
Apache Tomcat/5.5.23 |1.4.2 |Free Software Foundation, Inc. |Linux |2.6.18-92.el5 i386
而刚刚装的JDK1.5却没有用到,
 [linux@linux ~]$ which java
/usr/java/jdk1.5.0_11/bin/java

于是观察sudo vim /etc/rc.d/init.d/tomcat5,发现
# Path to the tomcat launch script

TOMCAT_SCRIPT="/usr/bin/dtomcat5"

接着修改那里的JAVA_HOME, 然后

[linux@linux ~]$ sudo /etc/rc.d/init.d/tomcat5    restart

不过经过测试,发现还是用的jdk1.4,可能需要修改的地方比较多,比较麻烦。

相比较而言,如果是必须要用jdk1.5的虚拟机下的tomcat,可以不用centos5.2自带的服务脚本(/etc/rc.d/init.d/tomcat5),可以这样:

1、创建一个用户群组tomcat,再创建它的一个用户tomcat,并添加密码:

[linux@linux ~]$ sudo /usr/sbin/groupadd tomcat
[linux@linux ~]$ sudo /usr/sbin/useradd tomcat -G tomcat -g tomcat -d /home/tomcat
[linux@linux ~]$ sudo passwd tomcat
Changing password for user tomcat.
New UNIX password: 
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
[linux@linux ~]$

2、下载tomcat的安装文件(apache-tomcat-5.5.27.zip ),并解压到一个地方,用户tomcat需要对他有权限,推荐放在tomcat帐户下,如:/home/tomcat/svrside/,并修改该文件夹的权限,确保tomcat用户能访问到:

[linux@linux ~]$ sudo chown tomcat.tomcat /home/tomcat/svrside -R

[linux@linux ~]$ sudo chmod ug+rwx /home/tomcat/svrside -R 

3、然后进入tomcat 安装文件里的bin目录,解压文件jsvc.tar.gz,安照它里面的INSTALL.txt的介绍编译安装jsvc:

[linux@linux /]$ su tomcat

口令:

[tomcat@linux /]$cd ~/svrside/bin

[tomcat@linux bin]$tar zxvf jsvc.tar.gz

[tomcat@linux bin]$chmod -R ug+rwx ./jsvc-src/

[tomcat@linux bin]$cd ./jsvc-src/

[tomcat@linux jsvc-src]$./configure --with-java=/usr/java/jdk1.5.0_15

[tomcat@linux jsvc-src]$make

4、最后新建服务脚本(http://shellfish.iteye.com/blog/563614 ),放到/etc/rc.d/init.d/下,启动tomcat,并将其添加到系统启动项目里:

[linux@linux /]$ sudo chmod ug+rwx /etc/rc.d/init.d/tomcat

[linux@linux /]$ cd /etc/rc.d/init.d

[linux@linux init.d]$ sudo /etc/rc.d/init.d/tomcat start

Starting tomcat:                                  [OK]

[linux@linux init.d]$ sudo /sbin/chkconfig --add tomcat

[linux@linux init.d]$ sudo /sbin/chkconfig --level 345 tomcat on

这样就能保证tomcat用的是jdk1.5的虚拟机了,

Server Information
Tomcat Version JVM Version JVM Vendor OS Name OS Version OS Architecture
Apache Tomcat/5.5.27 1.5.0_15-b04 Sun Microsystems Inc. Linux 2.6.18-8.el5 amd64

当然和前面一样,需要在/conf/tomcat-users.xml里添加

<role rolename="admin"/>

<role rolename="manager"/>

<user username="admin" password="admin" fullName="" roles="admin,manager"/>

才能登录/manage/html,

另:

有时我们我们需要部署非英文的项目到tomcat,为了防止传递中文参数时乱码,须要添加URL编码类型(如UTF-8,GBK等)到/conf/server.xml:

 <Connector URIEncoding="UTF-8" port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />

  <Connector URIEncoding="UTF-8" port="8009" 
               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

猜你喜欢

转载自xiangxingchina.iteye.com/blog/939155