纯手工打造每一篇开源资讯与技术干货,数十万程序员和Linuxer已经关注。
Linux技术交流QQ群:2636170(七月份最新!!)
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。
本文主要给大家介绍了关于在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]
点击左下角查看更多热门技术