Details of the method in centos 7 to set tomcat 7 to serve the system
- 2020-06-07 05:59:23
- OfStack
This paper mainly introduces the relevant content about setting tomcat 7 as the system service in centos 7, and shares it for your reference and study. Let's start with 1 to see the detailed introduction:
1. Preparation:
2. Install jdk
A, unzip jdk under /usr/
B, root users configure 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
Effect:
source /etc/profile
3. Install tomcat7
A, unzip tomcat to /usr/
B in/usr lib systemd/system/directory file tomcat7. New service, content is 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 Start machine Start:
systemctl enable tomcat7
4. Start and stop service
A, Start service:
systemctl start tomcat7
B, out of service:
systemctl stop tomcat7
C, restart service:
systemctl restart tomcat7
Check status:
systemctl status tomcat7
Operation status:
[root@localhost merrick]# systemctl status tomcat7
low tomcat7.service - Tomcat7
Loaded: loaded (/usr/lib/systemd/system/tomcat7.service; disabled; vendor preset: disabled)
Active: active (running) since 4 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 month 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_BASE: /usr/apache-tomcat-7.0.70/
9 month 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_HOME: /usr/apache-tomcat-7.0.70/
9 month 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_TMPDIR: /usr/apache-tomcat-7.0.70//temp
9 month 08 11:34:16 localhost.localdomain startup.sh[3239]: Using JRE_HOME: /usr/jdk1.7.0_72
9 month 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CLASSPATH: /usr/apache-tomcat-7.0.70//bin/bootstrap.jar...i.jar
9 month 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_PID: /usr/apache-tomcat-7.0.70/bin/tomcat.pid
9 month 08 11:34:16 localhost.localdomain startup.sh[3239]: Existing PID file found during start.
9 month 08 11:34:16 localhost.localdomain startup.sh[3239]: Removing/clearing stale PID file.
9 month 08 11:34:16 localhost.localdomain startup.sh[3239]: Tomcat started.
9 month 08 11:34:16 localhost.localdomain systemd[1]: Started Tomcat7.
Hint: Some lines were ellipsized, use -l to show in full.
5. Test service
In the browser, type http://ip:8080/
Check that the server is responding correctly.
wget htp://localhost:8080/
Normal response:
[root@localhost merrick]# wget http://localhost:8080/
--2016-09-08 11:54:47-- http://localhost:8080/
Parsing the host localhost (localhost)... ::1, 127.0.0.1
Are connected localhost (localhost)|::1|:8080... The connected.
Has issued a HTTP Request, waiting for a response ... 200 OK
Length: not specified [text/html]
Saving to : " index.html "
[ <=> ] 11,197 --.-K/s when 0s
2016-09-08 11:54:47 (245 MB/s) - " index.html " The saved [11197]
conclusion