In the previous posting has introduced the Web system through Tomcat CentOS7 under the introduction, today will use the INIT.D startup script, the service script to join the boot service queue, to achieve the boot boot of Tomcat service. 1. Environment Preparation 1.1 system
Operating system: CentOS 7 (64-bit) 1.2 Tools/software
The JDK is installed and the environment variables are configured
Tamcat is installed and can be started manually 2. Method/Step 2.1 JDK Environment Configuration
CentOS7 the OPENJDK is installed by default, and it is no problem to support Tomcat startup. If your project needs to use the sun's JDK features, you will need to reconfigure the sun's JDK environment. Here you can refer to my previous blog: "17101501_centos7 uninstall OpenJDK install Sun company JDK." 2.2 Scripting files for Tomcat services
Create the TOMCAT8 service script file under the/etc/init.d/directory.
Execute script:
[Root@localhost/]# vim/etc/init.d/tomcat8
[root@localhost/]# cat/etc/init.d/tomcat8
Paste the following:
#!/bin/bash
#
Tomcat startup script for the Tomcat server #
#
chkconfig:345 #
Descripti On:start the Tomcat deamon
#
Source function library
/etc/rc.d/init.d/functions
prog=tomcat8
java_home=/usr/java/jdk1.8.0_151/ # rewrite Java_home export java_home on its own path
catalana_home=/usr/ local/tomcat/ # rewrite Catalana_home
export catalina_home case
' in start '
echo according to its own path Starting Tomcat ... "
$CATALANA _home/bin/startup.sh
;;
Stop)
echo "Stopping Tomcat ..."
$CATALANA _home/bin/shutdown.sh
;;
Restart)
echo "Stopping Tomcat ..."
$CATALANA _home/bin/shutdown.sh sleep
2
echo
echo " Starting Tomcat ... "
$CATALANA _home/bin/startup.sh
;;
*)
echo "Usage: $prog {start|stop|restart}"
;;
Esac
Exit 0
Save Exit 2.3 Assignment, test startup script
Execute script:
[Root@localhost/]# cd/etc/init.d/
[root@localhost init.d]# chmod 755 tomcat8 #赋予权限
[root@localhost init.d]# service tomcat8 start #启动服务
starting tomcat8 (via Systemctl): [ OK ]
[ Root@localhost init.d]# service tomcat8 stop #停止服务
stopping tomcat8 (via Systemctl): [ OK ]
[root@localhost init.d]# service tomcat8 Restart #重启服务
restarting Tomcat8 (via Systemctl): [ OK ]
2.4 Adding service scripts to the system boot queue
Execute script:
[Root@localhost zm]# chkconfig tomcat8 on #服务脚本加入到系统启动队列
[root@localhost zm]# chkconfig--list the Tomcat8 #检查 Whether the Oracle service is
in effect note: The output shows only SYSV services and does not contain native SYSTEMD services. SYSV configuration data may be overwritten by a native SYSTEMD configuration.
If you would like to list the SYSTEMD service, please perform ' Systemctl list-unit-files '.
to view services enabled for a specific target, perform
' Systemctl list-dependencies [target] '.
tomcat8 0: Off 1: Off 2: Open 3: Open 4: open 5 : Open 6: Off
2.5 reboot system, test configuration results
Under normal circumstances, startup is no problem.
Here's a little bit more, because the CentOS7 service started by Systemctl gradually replaces the chkconfig and service forms in earlier versions.
Here I tried it. With instructions: Systemctl start tomcat8 service, System prompts systemctl daemon-reload command to load the service, after execution, found that the SYSTEMCTL command can be used for simple control, such as query status, start the service , terminate the service, restart the service, and other operations. However, about the boot boot settings is not possible, but also through the old command Chkconfig implementation.