chkconfig --list tomcat7
Linux环境为centos6.5
su到root权限在进行以下操作
一、
新机器,先安装编译需要用到的软件
yum -y install make gcc-c++ cmake bison-devel ncurses-devel gcc autoconf automake zlib* fiex* libxml* libmcrypt* libtool-ltdl-devel*
二、jdk rpm格式
2.1、
rpm -ivh jdk-7u71-linux-x64.rpm
安装目录:/usr/java/jdk1.7.0_71
需手动配置环境变量
export JAVA_HOME=/usr/java/jdk1.7.0_71 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
三、tomcat7
3.1 安装
解压:
tar -zxvf apache-tomcat-7.0.56.tar.gz
z : 表示 tar 包是被 gzip 压缩过的,所以解压时需要用 gunzip 解压
x : 从 tar 包中把文件提取出来
v : 显示详细信息
f xxx.tar.gz : 指定被处理的文件是 xxx.tar.gz
mv apache-tomcat-7.0.56 tomcat7056
启动tomcat:进入tomcat的bin目录,
bash startup.sh
停止:
bash shutdown.sh
3.2、设置开机自动启动tomcat7
建tomcat用户,建/home/tomcat文件夹赋权限:
chown -R tomcat.tomcat /home/tomcat
在/etc/init.d下vim tomcat7
输入:(注意,***start***和***end***不要输入,JDK和TOMCAT配好)
*********************** start **************************** #!/bin/bash # Startup script for the tomcat # chkconfig: 2345 95 15 # description: tomcat service script # Source function library. # . /etc/rc.d/init.d/functions CATALINA_BASE=/usr/local/tomcat7056; #export CATALINA_BASE CATALINA_HOME=/usr/local/tomcat7056; #export CATALINA_HOME CATALINA_TMPDIR=/usr/local/tomcat7056/temp; #export CATALINA_TMPDIR JRE_HOME=/usr/java/jdk1.7.0_71; #export JRE_HOME CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar; #export CLASSPATH TOMCAT_HOME=/usr/local/tomcat7056; #export TOMCAT_HOME RETVAL=0 checkjava(){ if [ -z "$JAVA_HOME" ]; then export JAVA_HOME=/usr/java/jdk1.7.0_71 fi } start(){ checkjava checkrun if [ $RETVAL -eq 0 ]; then echo "Starting tomcat" #su - tomcat -c $TOMCAT_HOME/bin/startup.sh su - tomcat -c $TOMCAT_HOME/bin/startup.sh #touch /var/lock/subsys/tomcat else echo "tomcat allready running" fi } stop(){ checkjava checkrun if [ $RETVAL -eq 1 ]; then echo "Shutting down tomcat" su - tomcat -c $TOMCAT_HOME/bin/shutdown.sh #while [ $RETVAL -eq 1 ]; do # sleep 5 # checkrun #done rm -f /var/lock/subsys/tomcat else echo "tomcat not running" fi checkrun } checkrun(){ ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' >/tmp/tomcat_process_count.txt read line < /tmp/tomcat_process_count.txt if [ $line -gt 0 ]; then RETVAL=1 return $RETVAL else RETVAL=0 return $RETVAL fi } status(){ checkrun if [ $RETVAL -eq 1 ]; then echo -n "Tomcat ( pid " ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' echo -n ") is running..." echo else echo "Tomcat is stopped" fi echo "---------------------------------------------" } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status # su - tomcat -c "$TOMCAT_HOME/bin/catalina.sh version" ;; *) echo "Usage: $0 {start|stop|restart|status}" esac *********************** end ****************************
然后使文件可执行
chmod +x tomcat7
将tomcat添加到启动服务中
chkconfig --add tomcat7
查看是否配置成功
使其自启动
chkconfig tomcat7 on
手动用service方式启动停止
service tomcat7 start service tomcat7 stop