秀脱linux笔记之tomcat6实战篇1
xiutuo
|
1#
xiutuo 发表于 2008-05-09 15:01
秀脱linux笔记之tomcat6实战篇1
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
秀脱linux笔记之tomcat6实战篇 Q Q : 6541657 E_MAIL: xiutuo@gmail.com 文章地址: http://hi.baidu.com/xiutuo/blog/item/4222e119ad9a914743a9adbc.html 环境: -------------------------------------------- 操作系统:centos 4.5_x86 数据库oracle 10.2.01_x86_32 jre:1.6:jdk-6u1-linux-i586-rpm.bin tomcat6.0:编译好的二进制软件包apache-tomcat-6.0.13.tar.gz tomcat6.0 安装路径:/usr/local/tomcat6 oracle jdbc:class12.jar 软件包存放的路径:/home/xiutuo/software/ java安装路径:/usr/java/jdk1.6.0_01 apr安装路径:/usr/local/apr/ apr的lib文件路径:/usr/local/apr/lib 使用普通用户:xiutuo来启动tomcat6 tomcat6开机自动启动脚本:/etc/init.d/tomcat 下载路径: http://java.sun.com/javase/downloads/index.jsp 下载apr提高执行效率 (其中tomcat-native-1.1.10-src.tar.gz在tomcat6软件的bin目录里,无需下载) http://apache.mirror.phpchina.com/apr/apr-1.2.12.tar.gz (Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies) 不安装apr会报错: INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/jdk1.6.0_01/jre/lib/i386/client: /usr/java/jdk1.6.0_01/jre/lib/i386: /usr/lib:/usr/local/lib 解决此问题需要加 LD_LIBRARY_PATH=/usr/local/apr/lib export LD_LIBRARY_PATH 这个环境变量 -------------------------------------------- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 一:安装jre 1.安装jre软件包, # cd /home/xiutuo/software 进入软件包存放目录 # chmod a+x jdk-6u1-linux-i586-rpm.bin 使它有执行权限 # ./jdk-6u1-linux-i586-rpm.bin 多敲几个空格,然后看到[yes]的时候输入yes,回车 然后在当前目录下就生成了jdk-6u1-linux-i586-rpm # rpm -ivh jdk-6u1-linux-i586-rpm 安装jdk 如果之前有其他老版本的jdk,卸载掉,如: rpm -e j2sdk-1.4.1-fcs 2.:设置环境变量 仅设置某个用户而不是所有用户可以修改~/.cshrc,~/.bash_profile文件, 追加下面一段,如果为所有用户以及以后添加的用户都加上环境变量的话, 追加/etc/profie文件. ***主意不要在profile和~/.cshrc或~/.bash_profile中重复追加** 这里: # vi /etc/profile //java //如果你安装的j2sdk的路径不一样,请自行修改 JAVA_HOME=/usr/java/jdk1.6.0_01 export JAVA_HOME CLASSPATH=/usr/java/jdk1.6.0_01/lib:/usr/java/jdk1.6.0_01/jre/lib export CLASSPATH PATH=$PATHJAVA_HOME/binJAVA_HOME/jre/bin export PATH JRE=/usr/java/jdk1.6.0_01/jre export JRE LD_LIBRARY_PATH=/usr/local/apr/lib export LD_LIBRARY_PATH 3:立即生效 //如果你修改的是/etc/profile # source /etc/profile //如果你修改的是~/.cshrc # source ~/.cshrc //如果你修改的是~/.bash_profile # source ~/.bash_profile 4:测试成功否 # java -version 出现 java version "1.4.2" //这里比较怪,本来是jre是1.6这里居然…… gcj (GCC) 3.4.6 20060404 (Red Hat 3.4.6-8) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ********************************************************** 解决这个问题的方法, # cd /usr/java/ # ls -l 看看default和latest这俩个文件夹是不是jdk1.6.0_01的软连接 如果是就不用修改了,否则删除default和latest, # rm -rf default # rm -ff latest 然后 # ln -s jdk1.6.0_01 default # ln -s jdk1.6.0_01 latest 删除/usr/bin/目录中的 java,javac,javaws # cd /usr/bin # rm -f java # rm -f javac # rm -f javaws 然后: ln -s /usr/java/default/bin/java /usr/bin/java ln -s /usr/java/default/bin/javac /usr/bin/javac ln -s /usr/java/default/bin/javaws /usr/bin/javaws 最好再 //如果你修改的是/etc/profile # source /etc/profile //如果你修改的是~/.cshrc # source ~/.cshrc //如果你修改的是~/.bash_profile # source ~/.bash_profile ********************************************************** 再执行 # java -version //这回正常了 java version "1.6.0_01" Java(TM) SE Runtime Environment (build 1.6.0_01-b06) Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing) 二:安装tomcat6 1.安装tomcat # cd /home/xiutuo/software //进入软件包存放目录 # tar -zvxf apache-tomcat-6.0.13.tar.gz //解压 # mv apache-tomcat-6.0.13 /usr/local/tomcat6 //安装 # cd /usr/local/tomcat6/bin/ //进入安装目录 # tar -zvxf jsvc.tar.gz //解压 # cd jsvc-src //进入jsvc-src目录 # autoconf # ./configure --with-java=/usr/java/jdk1.6.0_01 # configure时切记加java的jdk路径,否则无法使用普通用户开机自动启动tomcat # make //编译生成jsvc文件 # cp jsvc .. //拷贝jsvc到上级目录 # cd .. //回到上级目录 安装apr # cd /home/xiutuo/software # tar -zvxf apr-1.2.12.tar.gz # cd apr-1.2.12 # ./configure # make # make install 此时,apr安装在/usr/local/apr目录 # cd /usr/local/tomcat6/tomcat-native-1.1.10-src/jni/native/ # ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.6.0_01/ # make # make install 生成tomcat日志文件 # cd /usr/local/tomcat6/ //运行下面的命令可以使tomcat以daemon方式运行 # ./bin/jsvc -cp ./bin/bootstrap.jar \ -outfile ./logs/catalina.out \ -errfile ./logs/catalina.err \ org.apache.catalina.startup.Bootstrap 2.配置oralce的jdbc //拷贝oracle的jdbc到/usr/local/tomcat6/lib目录下 # cp /home/software/class12.jar ./lib/ 3.配置tomcat用户 # cd /usr/local/tomcat6/conf # vi tomcat-users.xml 内容如下: <?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="tomcat"/> <role rolename="role1"/> <role rolename="manager"/> <role rolename="admin"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="role1" password="tomcat" roles="role1"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="admin" password="admin" roles="admin,manager"/> </tomcat-users> 请修改tomcat里所有定义用户的密码:即修改password为自己想要的值。 4.启动停止tomcat服务 # cd /usr/local/tomcat6/bin # ./start.sh //启动tomcat # ./shutdown.sh //停止tomcat 查看tomcat的进程: # ps -e | grep java 出现了java这个进程的话,说明你的tomcat差不多了。 5.让tomcat开机运行: # cd /usr/local/tomcat6/bin/jsvc-src/native/ # cp Tomcat.sh /etc/init.d/tomcat # 这里以tomcat4的自动运行脚本来做修改 # vi tomcat 修改后内容如下: # # cd /usr/local/tomcat6/bin/jsvc-src/native/ # 4.自动启动脚本编辑、赋权 # cp tomcat5.sh /etc/init.d/tomcat # chown xiutuo:xiutuo tomcat # chmod 711 tomcat # # 建立软连接 # # ln -s /etc/init.d/tomcat /etc/rc.d/rc3.d/K01tomcat # ln -s /etc/init.d/tomcat /etc/rc.d/rc3.d/S99tomcat # ln -s /etc/init.d/tomcat /etc/rc.d/rc5.d/K01tomcat # ln -s /etc/init.d/tomcat /etc/rc.d/rc5.d/S99tomcat # #--------------------------------------------- # 5.如何查看该脚本已经工作了,方法如下: # 启动脚本:/etc/init.d/tomcat start # a.通过web浏览器查看能不能访问tomcat的管理页面 # b.通过查看有没有jsvc进程 ps -e | grep jsvc # 如果看到俩个jsvc进程,恭喜,你成功啦! # # 6.脚本无法正常工作的解决方法: # 启动脚本:/etc/init.d/tomcat start # 查看/usr/local/tomcat6/logs/目录下的俩个日志文件: # catalina.out,catalina.err, 使用cat查看。 # a.错误 # Cannot find daemon loader org/apache/commons/daemon/support/DaemonLoader # 解决:更改tomcat安装目录权限为所有用户可以读,并属于xiutuo用户和xiutuo组 # 命令:chmod -R 755 /usr/locat/tomcat6 # chown -R xiutuo:xiutuo /usr/locat/tomcat6 # b.错误 # Cannot open PID file /var/run/jsvc.pid # 解决:chown xiutuo:xiutuo /var/run/jsvc.pid # chown 744 /var/run/jsvc.pid JAVA_HOME=/usr/java/jdk1.6.0_01 #改成你java安装目录 CATALINA_HOME=/usr/local/tomcat6/ #改成你tomcat安装目录 DAEMON_HOME=/usr/local/tomcat6/bin/jsvc-src/ #改成jsvc程序所在目录 TOMCAT_USER=xiutuo #改成启动tomcat使用的普通用户 JAVA_HOME=/usr/java/jdk1.6.0_01 #改成你java安装目录 CATALINA_HOME=/usr/local/tomcat6 #改成你tomcat安装目录 DAEMON_HOME=/usr/local/tomcat6/bin #改成jsvc程序所在目录,记住该进程是开机tomcat自动启动进程 #测试该脚本时候,使用/etc/init.d/tomcat start #如果顺利启动的话,通过ps -e可以看到俩个jsvc进程 TOMCAT_USER=xiutuo #改成启动tomcat使用的普通用户 TMP_DIR=/var/tmp CATALINA_OPTS= #这个环境变量不管 CLASSPATH=\ $JAVA_HOME/lib/tools.jar:\ $DAEMON_HOME/commons-daemon.jar:\ $CATALINA_HOME/bin/bootstrap.jar # classpath这个很重要,一定要确保这三个 # tools.jar、commons-daemon.jar、bootstrap.jar # 的正确路径。 case "$1" in start) # # Start Tomcat # $DAEMON_HOME/jsvc \ -user $TOMCAT_USER \ -home $JAVA_HOME \ -Dcatalina.home=$CATALINA_HOME \ -Djava.io.tmpdir=$TMP_DIR \ -outfile $CATALINA_HOME/logs/catalina.out \ -errfile '&1' \ $CATALINA_OPTS \ -cp $CLASSPATH \ org.apache.catalina.startup.Bootstrap # # To get a verbose JVM #-verbose \ # To get a debug of jsvc. #-debug \ ;; stop) # # Stop Tomcat # PID=`cat /var/run/jsvc.pid` kill $PID ;; *) echo "Usage tomcat.sh start/stop" exit 1;; esac # # #××××××××××××××××××××××××××××× |