Detailed explanation of the method of setting tomcat 7 as system Service in centos 7
This article mainly introduces the relevant content about setting tomcat 7 as the system service in centos 7, which is shared for your reference and study. Let's take a look at the detailed introduction:
1. Preparatory work:
JKD:jdk-7u72-Linux-x64.gzTomcat:apache-tomcat-7.0.70.tar.gzOS:CentOS linux release 7.2.1511 (Core)
2. Install jdk
A, decompress jdk in / usr/ directory
B, root users configure global environment variables
Vi / etc/profile appends the following content export JAVA_HOME=/usr/jdk1.7.0_72 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Effective: source / etc/profile
3. Install tomcat7
A, decompress tomcat to / usr/ directory
B, create a new file tomcat7.service in the / usr/lib/systemd/system/ directory, as follows:
[Unit] Description=Tomcat7 After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking Environment='JAVA_HOME=/usr/jdk1.7.0_72' Environment='CATALINA_PID=/usr/apache-tomcat-7.0.70/bin/tomcat.pid' Environment='CATALINA_HOME=/usr/apache-tomcat-7.0.70/' Environment='CATALINA_BASE=/usr/apache-tomcat-7.0.70/' Environment='CATALINA_OPTS=-Xms512M-Xmx1024M-server-XX:+UseParallelGC' WorkingDirectory=/usr/apache-tomcat-7.0.70/ ExecStart=/usr/apache-tomcat-7.0.70/bin/startup.sh ExecReload=/bin/kill-s HUP $MAINPID ExecStop=/bin/kill-s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
C, set to boot: systemctl enable tomcat7
4. Start and stop the service
A, start the service: systemctl start tomcat7
B, stop service: systemctl stop tomcat7
C, restart the service: systemctl restart tomcat7
Check status: systemctl status tomcat7
Running status:
[root@localhost merrick] # systemctl status tomcat7 ● tomcat7.service-Tomcat7 Loaded: loaded (/ usr/lib/systemd/system/tomcat7.service; disabled; vendor preset: disabled) Active: active (running) since four 2016-09-08 11:34:16 CST 17min ago Process: 3231 ExecStop=/bin/kill-s QUIT $MAINPID (code=exited, status=0/SUCCESS) Process: 3239 ExecStart=/usr/apache-tomcat-7.0.70/bin/startup.sh (code=exited, status=0/SUCCESS) Main PID: 3249 (java) CGroup: / system.slice/tomcat7.service └─ 3249 / usr/jdk1.7.0_72/bin/java-Djava.util.logging.config.file=/usr/apache-tomcat-7.0.70//conf/logging.properties-D. September 08 11:34:16 localhost.localdomain startup.sh [3239]: Using CATALINA_BASE: / usr/apache-tomcat-7.0.70/ September 08 11:34:16 localhost.localdomain startup.sh [3239]: Using CATALINA_HOME: / usr/apache-tomcat-7.0.70/ September 08 11:34:16 localhost.localdomain startup.sh [3239]: Using CATALINA_TMPDIR: / usr/apache-tomcat-7.0.70//temp September 08 11:34: 16 localhost.localdomain startup.sh [3239]: Using JRE_HOME: / usr/jdk1.7.0_72 September 08 11:34:16 localhost.localdomain startup.sh [3239]: Using CLASSPATH: / usr/apache-tomcat-7.0.70//bin/bootstrap.jar...i.jar September 08 11:34:16 localhost.localdomain startup.sh [3239]: Using CATALINA_PID: / usr/apache-tomcat-7.0.70/bin/tomcat.pid September 08 11 : 34:16 localhost.localdomain startup.sh [3239]: Existing PID file found during start. September 08 11:34:16 localhost.localdomain startup.sh [3239]: Removing/clearing stale PID file. September 08 11:34:16 localhost.localdomain startup.sh [3239]: Tomcat started. September 08 11:34:16 localhost.localdomain systemd [1]: Started Tomcat7. Hint: Some lines were ellipsized, use-l to show in full.
5. Testing service
Enter: http://ip:8080/ in browser
Check that the server is responding correctly.
Or terminal command line input: wget htp://localhost:8080/
Normal response:
[root@localhost merrick] # wget http://localhost:8080/-- 2016-09-08 11 wget 54 wget 47-http://localhost:8080/ is parsing the host localhost (localhost). :: 1,127.0.0.1 localhost (localhost) is being connected |:: 1 |: 8080. Connected. HTTP request issued, waiting for response. 200OK length: unspecified [text/html] is being saved to: "index.html" [] 11197-K s time used 0s 2016-09-08 11:54:47 (245 MB/s)-"index.html" has been saved [11197]
Summary
The above is the whole content of this article, I hope that the content of this article can bring some help to your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.