[root@localhost ~]#groupadd ceshi
[root@localhost ~]#useradd -g ceshi -d /home/ceshi -s /bin/bash ceshi
[root@localhost ~]#passwd ceshi
[root@localhost ~]# vi /etc/init.d/tomcat
*************************输入以下脚本*************************************
#!/bin/bash
# chkconfig: 345 99 10
# description: Startup Script for tomcat
# /etc/rc.d/init.d/tomcat
#JDK Settings
export JAVA_HOME=/usr/java/jdk1.6.0_45
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/toos.jar
export PATH=$PATH:$JAVA_HOME/bin
case "$1" in
start)
echo "Starting tomcat: "
su -c /usr/local/tomcat/bin/./startup.sh etla
echo "OK......tomcat started"
;;
stop)
echo "Shutdown tomcat: "
/usr/local/tomcat/bin/./shutdown.sh
echo "OK.....tomcat stoped"
;;
*)
echo "Usage: 'basename $0' start|stop"
exit 1
esac
exit 0
*************************结束*************************************
[root@localhost ~]# chmod 777 /etc/init.d/tomcat
[root@localhost ~]# chown -R ceshi:ceshi /usr/local/tomcat //这步操作视情况而定,因为拷贝到这个目录的tomcat不一定属于tomcat用户
[root@localhost ~]# service tomcat stopomcat
[root@localhost ~]# service tomcat start
[root@localhost ~]# ps -ef |grep tomcat //查看当前运行tomcat的用户是不是etla
[root@localhost ~]# chkconfig --level 2345 tomcat on //增加自启动权限
[root@localhost ~]# reboot //重启测试,记得打开8080端口或关闭防火墙