centos 7中设置tomcat 7为系统服务的方法详解
程序员文章站
2022-06-08 13:34:50
本文主要给大家介绍了关于在centos 7中设置tomcat 7为系统服务的相关内容,分享出来供大家参考学习,下面来一起看看详细的介绍:
1、准备工作:
j...
本文主要给大家介绍了关于在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用户配置全局环境变量,
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,内容如下:
[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
运行的状态:
[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/
正常响应:
[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]
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对的支持。
下一篇: 愚蠢的热点营销会带来什么样的结果