1. Preparation:
JKD:jdk-7u72-linux-x64.gz
Tomcat:apache-tomcat-7.0.70.tar.gz
OS:CentOS Linux release 7.2.1511 (Core)
2, install jdk
A, unzip the jdk in the /usr/ directory
B, the root user configures global environment variables,
vi /etc/profile Append the following 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 with the following contents:
[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 start the machine: systemctl enable tomcat7
4. Start and stop the service
A, start the service: systemctl start tomcat7
B, stop the 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 四 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... 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_BASE: /usr/apache-tomcat-7.0.70/ 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_HOME: /usr/apache-tomcat-7.0.70/ 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_TMPDIR: /usr/apache-tomcat-7.0.70//temp 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using JRE_HOME: /usr/jdk1.7.0_72 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CLASSPATH: /usr/apache-tomcat-7.0.70//bin/bootstrap.jar...i.jar 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_PID: /usr/apache-tomcat-7.0.70/bin/tomcat.pid 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Existing PID file found during start. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Removing/clearing stale PID file. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Tomcat started. 9月 08 11:34:16 localhost.localdomain systemd[1]: Started Tomcat7. Hint: Some lines were ellipsized, use -l to show in full.
5. Test service
Enter in the browser: http://ip:8080/
Check that the server responds correctly.
Or terminal command line input: wget http://localhost:8080/
Normal response:
[root@localhost merrick]# wget http://localhost:8080/ --2016-09-08 11:54:47-- http://localhost:8080/ Resolving host localhost (localhost)... ::1, 127.0.0.1 Connecting to localhost (localhost)|::1|:8080... Connected. An HTTP request has been made, waiting for a response... 200 OK length: unspecified [text/html] Saving to: "index.html" [ <=> ] 11,197 --.-K/s time 0s 2016-09-08 11:54:47 (245 MB/s) - "index.html" saved [11197]