文章目录
1 tomcat介绍
Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta项目中的一个核心项目,由Apache、Sun和其他一些公司及个人共同开发而成。
java程序写的网站用tomcat+jdk来运行
tomcat是一个中间件,真正起作用的,解析java脚本的是jdk
jdk(java development kit)是整个java的核心,它包含了java运行环境和一堆java相关的工具以及java基础库。
最主流的jdk为sun公司发布的jdk,除此之外,其实IBM公司也有发布JDK,CentOS上也可以用yum安装openjdk
2 安装jdk
jdk版本1.6,1.7,1.8
官网下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下载jdk8,放到/usr/local/src/目录下,解压jdk包
[root@linux01 src]# tar zxvf jdk-8u162-linux-x64.tar.gz
[root@linux01 src]# mv jdk1.8.0_162 /usr/local/jdk1.8
编辑配置文件
[root@linux01 src]# vi /etc/profile //最后面增加
JAVA_HOME=/usr/local/jdk1.8/
JAVA_BIN=/usr/local/jdk1.8/bin
JRE_HOME=/usr/local/jdk1.8/jre
PATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin
CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar
更新文件环境变量
[root@linux01 src]# source /etc/profile
查看jdk包是否生效
[root@linux01 src]# java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
3 安装tomcat
下载tomcat包:
[root@linux01 ~]# cd /usr/local/src
[root@linux01 src]# wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz
解压tomcat包
[root@linux01 src]# tar zxvf apache-tomcat-8.5.20.tar.gz
[root@linux01 src]# mv apache-tomcat-8.5.20 /usr/local/tomcat
启动tomcat服务
[root@linux01 src]# /usr/local/tomcat/bin/startup.sh //启动tomcat
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/src/jdk1.8.0_162
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
关闭tomcat服务
[root@linux01 src]# /usr/local/tomcat/bin/shutdown.sh //关闭tomcat
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/src/jdk1.8.0_162
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
查看tomcat进程
[root@linux01 src]# ps aux|grep tomcat
查看tomcat端口
[root@linux01 src]# netstat -lntp |grep java
tcp6 0 0 127.0.0.1:59132 :::* LISTEN 1697/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 1675/java
tcp6 0 0 :::8009 :::* LISTEN 1675/java
tcp6 0 0 127.0.0.1:49132 :::* LISTEN 1697/java
tcp6 0 0 127.0.0.1:29132 :::* LISTEN 1697/java
tcp6 0 0 :::80 :::* LISTEN 1675/java
三个端口8080
为提供web服务的端口,8005
为管理端口,8009
端口为第三方服务调用的端口,比如httpd和Tomcat结合时会用到,如果端口没启动,查看防火墙是不是开着
出现问题:
Oct 24, 2018 1:08:43 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Could not contact [localhost:[8005]]. Tomcat may not be running.
Oct 24, 2018 1:08:43 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:497)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:406)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:498)
解决方法:
ntpdate ntp1.aliyun.com //因为系统时间不正确,需要更新
扩展
java容器比较 http://my.oschina.net/diedai/blog/271367
http://www.360doc.com/content/11/0618/21/16915_127901371.shtml
j2ee、j2se、ejb、javabean、serverlet、jsp之间关系 http://bbs.csdn.net/topics/50015576
tomcat server.xml配置详解 http://blog.csdn.net/yuanxuegui2008/article/details/6056754
tomcat常用数据库连接的方法 http://wjw7702.blog.51cto.com/5210820/1109263