1. 切换到tomcat/bin目录下
用vi startup.sh文件
#cp startup.sh autoStart.sh
vim autoStart.sh
2.
在autoStart.sh开头出增加
文件开头的地方添加如下内容
#chkconfig: 2345 80 90
#description:tomcat auto start
#processname: tomcat
并且在# Better OS/400 detection: see Bugzilla 31132 后面增加如下四个环境变量
export JAVA_HOME=/usr/programfile/java/jdk1.8.0_60
export CATALINA_BASE=/usr/programfile/tomcat/apache-tomcat-8.0.27
export CATALINA_HOME=/usr/programfile/tomcat/apache-tomcat-8.0.27
export CATALINA_TMPDIR=/usr/programfile/tomcat/apache-tomcat-8.0.27/temp
3. 添加一个从autoSave .sh到init.d路径下的一个软链接
ln -s /usr/programfile/tomcat/apache-tomcat-8.0.27/bin/autoStart.sh /etc/rc.d/init.d/tomcat8
注意,原路径和目标路径都必须是绝对路径。才能成功构造软链接。 不然。 ll命令下会闪烁,提示软链接失败
4.
查看软链接
[root@iZ23psiz6rgZ ~]# cd /etc/rc.d/init.d/
[root@iZ23psiz6rgZ init.d]# ls
aegis functions iprinit netconsole README
agentwatch iprdump iprupdate network tomcat8
[root@iZ23psiz6rgZ init.d]# ll
total 56
-rwxr-xr-x 1 root root 2265 Jan 5 2015 aegis
-r-xr-xr-x 1 root root 3798 Oct 7 08:58 agentwatch
-rw-r--r--. 1 root root 13430 Apr 2 2014 functions
-rwxr-xr-x. 1 root root 2256 Jun 10 2014 iprdump
-rwxr-xr-x. 1 root root 2247 Jun 10 2014 iprinit
-rwxr-xr-x. 1 root root 2269 Jun 10 2014 iprupdate
-rwxr-xr-x. 1 root root 2989 Apr 2 2014 netconsole
-rwxr-xr-x. 1 root root 6354 Apr 2 2014 network
-rw-r--r--. 1 root root 1160 Oct 23 2014 README
lrwxrwxrwx 1 root root 61 Oct 8 16:27 tomcat8 -> /usr/programfile/tomcat/apache-tomcat-8.0.27/bin/autoStart.sh
软链接
如果没有的话使用chmod +x tomcat7添加执行权限
5. chkconfig --add tomcat8 添加开机启动服务
最后使用chkconfig --list确认一下是否添加成功
[root@iZ23psiz6rgZ init.d]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off
agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprdump 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprinit 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprupdate 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
tomcat8 0:off 1:off 2:on 3:on 4:on 5:on 6:off
6 reboot 看效果
更多请参见资料http://jingyan.baidu.com/article/6525d4b1382f0aac7d2e9421.html