本文主要给大家介绍了关于在centos 7中设置tomcat 7为系统服务的相关内容,分享出来供大家参考学习,下面来一起看看详细的介绍:
1、准备工作:
- JKD:jdk-7u72-Linux-x64.gz
- Tomcat:apache-tomcat-7.0.70.tar.gz
- OS:CentOS linux release 7.2.1511 (Core)
2、安装jdk
A,解压jdk在 /usr/ 目录下
B, root用户配置全局环境变量,
1
2
3
4
5
|
vi /etc/profile 追加以下内容 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 |
生效:source /etc/profile
3、安装tomcat7
A,解压tomcat至 /usr/目录下
B,在/usr/lib/systemd/system/目录下新建文件tomcat7.service,内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[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,设置为开启机启动:systemctl enable tomcat7
4、启停服务
A,启动服务:systemctl start tomcat7
B,停止服务:systemctl stop tomcat7
C,重启服务:systemctl restart tomcat7
检查状态:systemctl status tomcat7
运行的状态:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[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、测试服务
浏览器中输入 : http://ip:8080/
检查服务器能正确响应。
或者终端命令行输入: wget htp://localhost:8080/
正常响应:
1
2
3
4
5
6
7
8
9
10
11
|
[root@localhost merrick] # wget http://localhost:8080/ --2016-09-08 11:54:47-- http: //localhost :8080/ 正在解析主机 localhost (localhost)... ::1, 127.0.0.1 正在连接 localhost (localhost)|::1|:8080... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:未指定 [text /html ] 正在保存至: “index.html” [ <=> ] 11,197 --.-K /s 用时 0s 2016-09-08 11:54:47 (245 MB /s ) - “index.html” 已保存 [11197] |
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对服务器之家的支持。
原文链接:http://blog.csdn.net/fall10/article/details/52469712