centos安装tomcat设置开机启动
时间:2016-05-30 00:08 来源:linux.it.net.cn 作者:IT
安装tomcat
tomcat解压就能用 安装包可以从官网上下载。
[root@template tmp]# wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.69/bin/apache-tomcat-7.0.69.tar.gz
解压
[root@template tmp]# tar -zxvf nginx-1.9.15.tar.gz -C /usr/local/
启动 注意这里我重命名了解压出来的文件夹名apache-tomcat-7.0.69为tomcat7
[root@template local]# mv apache-tomcat-7.0.69 tomcat7
[root@template bin]# cd /usr/local/tomcat7/bin/
[root@template bin]# ./startup.sh
关闭
[root@template bin]# ./shutdown.sh
设置开机启动
增加开机启动服务 从安装oracle开机启动学的 具体编辑脚本
vim /etc/init.d/tomcat7 #创建新文件
tomcat7是我自己取得名字
#!/bin/bash
# oracle: Start/Stop tomcat7
# chkconfig: 345 90 10
# description: tomcat .
JAVA_HOME=/usr/local/jdk1.7.0_79
JRE_HOME=$JAVA_HOME/jre
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/tomcat7flag
TOMCAT_HOME=/usr/local/tomcat7/
TOMCAT_USER=root
case "$1" in
'start')
if [ -f $LOCKFILE ]; then
echo $0 already running.
exit 1
fi
echo -n $"Starting tomcat! "
/usr/local/tomcat7/bin/startup.sh
touch $LOCKFILE
;;
'stop')
if [ ! -f $LOCKFILE ]; then
echo $0 already stopping.
exit 1
fi
echo -n $"Stopping tomcat! "
/usr/local/tomcat7/bin/shutdown.sh
rm -f $LOCKFILE
;;
'restart')
$0 stop
$0 start
;;
'status')
if [ -f $LOCKFILE ]; then
echo $0 started.
else
echo $0 stopped.
fi
;;
*)
echo "Usage: $0 [start|stop|status]"
exit 1
esac
exit 0
修改/etc/init.d/tomcat7服务文件权限 [root@CentOS init.d]# chmod 755 /etc/init.d/tomcat7
#chkconfig --add tomcat7
说明 如果脚本没写好 可能出现 service myservice does not support chkconfig 解决办法
添加下面两句到 #!/bin/bash 之后。
# chkconfig: 2345 10 90
# description: myservice ....
设置为开机启动
如果提示
[root@template sbin]# service tomcat7 stop
Stopping tomcat! Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
tomcat中需要做如下修改
vim /usr/local/tomcat7/bin/startup.sh
添加如下环境变量
export JAVA_HOME=/usr/local/jdk1.7.0_79
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export PATH=$PATH:$JAVA_HOME/bin
export CATALINA_HOME=/usr/local/tomcat7
[root@CentOS ~]# chkconfig tomcat7 on 进行service tomcat7 start/stop/restart测试
还有一种简单的办法 直接在启动文件中加启动命令 在/etc/rc.d/rc.local中加入: /usr/local/tomcat7/bin/startup.sh
(责任编辑:IT)
安装tomcat [root@template tmp]# wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.69/bin/apache-tomcat-7.0.69.tar.gz 解压 [root@template tmp]# tar -zxvf nginx-1.9.15.tar.gz -C /usr/local/ 启动 注意这里我重命名了解压出来的文件夹名apache-tomcat-7.0.69为tomcat7 [root@template local]# mv apache-tomcat-7.0.69 tomcat7 [root@template bin]# cd /usr/local/tomcat7/bin/ [root@template bin]# ./startup.sh 关闭 [root@template bin]# ./shutdown.sh 设置开机启动 增加开机启动服务 从安装oracle开机启动学的 具体编辑脚本 vim /etc/init.d/tomcat7 #创建新文件 tomcat7是我自己取得名字 #!/bin/bash # oracle: Start/Stop tomcat7 # chkconfig: 345 90 10 # description: tomcat . JAVA_HOME=/usr/local/jdk1.7.0_79 JRE_HOME=$JAVA_HOME/jre . /etc/rc.d/init.d/functions LOCKFILE=/var/lock/subsys/tomcat7flag TOMCAT_HOME=/usr/local/tomcat7/ TOMCAT_USER=root case "$1" in 'start') if [ -f $LOCKFILE ]; then echo $0 already running. exit 1 fi echo -n $"Starting tomcat! " /usr/local/tomcat7/bin/startup.sh touch $LOCKFILE ;; 'stop') if [ ! -f $LOCKFILE ]; then echo $0 already stopping. exit 1 fi echo -n $"Stopping tomcat! " /usr/local/tomcat7/bin/shutdown.sh rm -f $LOCKFILE ;; 'restart') $0 stop $0 start ;; 'status') if [ -f $LOCKFILE ]; then echo $0 started. else echo $0 stopped. fi ;; *) echo "Usage: $0 [start|stop|status]" exit 1 esac exit 0 修改/etc/init.d/tomcat7服务文件权限 [root@CentOS init.d]# chmod 755 /etc/init.d/tomcat7 #chkconfig --add tomcat7 说明 如果脚本没写好 可能出现 service myservice does not support chkconfig 解决办法 添加下面两句到 #!/bin/bash 之后。 # chkconfig: 2345 10 90 # description: myservice .... 设置为开机启动 如果提示 [root@template sbin]# service tomcat7 stop Stopping tomcat! Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program tomcat中需要做如下修改 vim /usr/local/tomcat7/bin/startup.sh 添加如下环境变量 export JAVA_HOME=/usr/local/jdk1.7.0_79 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:. export PATH=$PATH:$JAVA_HOME/bin export CATALINA_HOME=/usr/local/tomcat7 [root@CentOS ~]# chkconfig tomcat7 on 进行service tomcat7 start/stop/restart测试 还有一种简单的办法 直接在启动文件中加启动命令 在/etc/rc.d/rc.local中加入: /usr/local/tomcat7/bin/startup.sh (责任编辑:IT) |