centos 7中设置tomcat 7为系统服务的方法详解
本文主要给大家介绍了关于在centos7中设置tomcat7为系统服务的相关内容,分享出来供大家参考学习,下面来一起看看详细的介绍:
1、准备工作:
- JKD:jdk-7u72-Linux-x64.gz
- Tomcat:apache-tomcat-7.0.70.tar.gz
- OS:CentOSlinuxrelease7.2.1511(Core)
2、安装jdk
A,解压jdk在/usr/目录下
B,root用户配置全局环境变量,
vi/etc/profile 追加以下内容 exportJAVA_HOME=/usr/jdk1.7.0_72 exportPATH=$JAVA_HOME/bin:$PATH exportCLASSPATH=.:$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,内容如下:
[Unit] Description=Tomcat7 After=syslog.targetnetwork.targetremote-fs.targetnss-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-sHUP$MAINPID ExecStop=/bin/kill-sQUIT$MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
C,设置为开启机启动:systemctlenabletomcat7
4、启停服务
A,启动服务:systemctlstarttomcat7
B,停止服务:systemctlstoptomcat7
C,重启服务:systemctlrestarttomcat7
检查状态:systemctlstatustomcat7
运行的状态:
[root@localhostmerrick]#systemctlstatustomcat7 ●tomcat7.service-Tomcat7 Loaded:loaded(/usr/lib/systemd/system/tomcat7.service;disabled;vendorpreset:disabled) Active:active(running)since四2016-09-0811:34:16CST;17minago Process:3231ExecStop=/bin/kill-sQUIT$MAINPID(code=exited,status=0/SUCCESS) Process:3239ExecStart=/usr/apache-tomcat-7.0.70/bin/startup.sh(code=exited,status=0/SUCCESS) MainPID: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月0811:34:16localhost.localdomainstartup.sh[3239]:UsingCATALINA_BASE:/usr/apache-tomcat-7.0.70/ 9月0811:34:16localhost.localdomainstartup.sh[3239]:UsingCATALINA_HOME:/usr/apache-tomcat-7.0.70/ 9月0811:34:16localhost.localdomainstartup.sh[3239]:UsingCATALINA_TMPDIR:/usr/apache-tomcat-7.0.70//temp 9月0811:34:16localhost.localdomainstartup.sh[3239]:UsingJRE_HOME:/usr/jdk1.7.0_72 9月0811:34:16localhost.localdomainstartup.sh[3239]:UsingCLASSPATH:/usr/apache-tomcat-7.0.70//bin/bootstrap.jar...i.jar 9月0811:34:16localhost.localdomainstartup.sh[3239]:UsingCATALINA_PID:/usr/apache-tomcat-7.0.70/bin/tomcat.pid 9月0811:34:16localhost.localdomainstartup.sh[3239]:ExistingPIDfilefoundduringstart. 9月0811:34:16localhost.localdomainstartup.sh[3239]:Removing/clearingstalePIDfile. 9月0811:34:16localhost.localdomainstartup.sh[3239]:Tomcatstarted. 9月0811:34:16localhost.localdomainsystemd[1]:StartedTomcat7. Hint:Somelineswereellipsized,use-ltoshowinfull.
5、测试服务
浏览器中输入:http://ip:8080/
检查服务器能正确响应。
或者终端命令行输入:wgethtp://localhost:8080/
正常响应:
[root@localhostmerrick]#wgethttp://localhost:8080/ --2016-09-0811:54:47--http://localhost:8080/ 正在解析主机localhost(localhost)...::1,127.0.0.1 正在连接localhost(localhost)|::1|:8080...已连接。 已发出HTTP请求,正在等待回应...200OK 长度:未指定[text/html] 正在保存至:“index.html” [<=>]11,197--.-K/s用时0s 2016-09-0811:54:47(245MB/s)-“index.html”已保存[11197]
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对毛票票的支持。