CentOS6.5安装tomcat7并自动启动
1.下载apache-tomcat-7.0.56.tar.gz;
2.CentOS6.5默认安装了java-openjdk的环境,但是不带JDK,运行
yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel
其中,java-1.7.0-openjdk是JRE,java-1.7.0-openjdk-devel是JDK
3.配置tomcat环境并设置为服务,采用jsvc
tar vzvf apache-tomcat-7.0.56.tar.gz
mv apache-tomcat-7.0.56 /usr/local/apache-tomcat
cd /usr/local/apache-tomcat/bin
tar xvfz commons-daemon-native.tar.gz
cd commons-daemon-1.0.15-native-src/unix
./configure --with-java=/usr/lib/jvm/java/
make
cp jsvc ../..
cd ../..
拷贝/usr/local/apache-tomcat/bin目录下的daemon.sh到/etc/init.d,重命名为tomcat,用文本打开,第22行增加:
JAVA_HOME=/usr/lib/jvm/java
CATALINA_HOME=/usr/local/apache-tomcat
第91行TOMCAT_USER=tomcat改为TOMCAT_USER=root,保存。(备注:这种方法比较危险,建议新建一个tomcat的用户,设置此用户对/usr/local/apache-tomcat目录的读写权限)
命令行中service tomcat start
firefox地址栏http://local:8080/
4.设置tomcat服务自启动
打开/etc/init.dtomcat,在第2行添加:
#
# Startup script for the tomcat
#
# chkconfig: 2345 90 10
# description: The Tomcat Java Application Server
#
# Source function library.
./etc/init.d/functions
保存,再依次执行
chmod 755 /etc/init.d/functions ← 将启动脚本属性设置为755(使之可执行)
chkconfig --add tomcat ← 将Tomcat加入到chkconfig中
chkconfig tomcat on ← 将Tomcat设置为自启动
chkconfig --list tomcat ← 确认Tomcat服务状态
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 确认2~5为on的状态就OK
参考:
http://www.cnblogs.com/ilahsa/archive/2012/12/11/2813059.html
http://tomcat.apache.org/tomcat-7.0-doc/setup.html
http://my.oschina.net/yangphere/blog/73634
.......