16.1 Tomcat介绍
tomcat是Apache基金会的Jakarta项目中的一个核心项目,由Apache、sun与其他公司及个人共同开发维护,是一个web服务中间件,真正起作用的解析java脚本的是jdk(java develoment kit):java的核心,它包含了jre、java工具、java基础库。
主流的jdk由sun发布,IBM公司也有发布jdk,Centos上yum安装的是openjdk。
16.2 安装jdk
在官网下载tar.gz包,再传到linux系统里,不用wget。
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html // 下载jdk-8u171-linux-x64.tar.gz。//使用rz命令,从Windows传到linux系统里,存放到/usr/local/src目录下。
解压jdk:
[root@nginx src]# tar xzvf jdk-8u171-linux-x64.tar.gz##省略部分过程jdk1.8.0_171/jre/bin/unpack200jdk1.8.0_171/jre/plugin/jdk1.8.0_171/jre/plugin/desktop/jdk1.8.0_171/jre/plugin/desktop/sun_java.pngjdk1.8.0_171/jre/plugin/desktop/sun_java.desktopjdk1.8.0_171/jre/READMEjdk1.8.0_171/jre/COPYRIGHT
移动单独的目录下,并改名:
[root@nginx src]# mv jdk1.8.0_171 /usr/local/jdk1.8[root@nginx src]# cd ..[root@nginx local]# lsbin etc games include jdk1.8 lib lib64 libexec mysql nginx php-fpm sbin share src[root@nginx local]# cd jdk1.8/[root@nginx jdk1.8]# lsbin db javafx-src.zip lib man release THIRDPARTYLICENSEREADME-JAVAFX.txtCOPYRIGHT include jre LICENSE README.html src.zip THIRDPARTYLICENSEREADME.txt
修改环境变量:/etc/profile,增加下面几行
[root@nginx jdk1.8]# vim /etc/profileJAVA_HOME=/usr/local/jdk1.8/JAVA_BIN=/usr/local/jdk1.8/binJRE_HOME=/usr/local/jdk1.8/jrePATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/binCLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar[root@nginx jdk1.8]# source /etc/profile //重新加载profile
验证是否安装成功:显示版本号,代表安装成功
[root@nginx jdk1.8]# java -versionjava version "1.8.0_171"Java(TM) SE Runtime Environment (build 1.8.0_171-b11)Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
如果显示的版本号是1.7,与你安装的1.8版本不符,查看是否yum安装过openjdk
[root@nginx jdk1.8]# rpm -qa|grep openjdk //如果有,就卸载掉,但是在生成环境中,别乱下载,可能有服务在使用openjdk,可以升级openjdk到1.8
16.3 安装Tomcat
下载tomcat:
[root@nginx src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar.gz--2018-06-26 22:48:17-- http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar.gz正在解析主机 mirror.bit.edu.cn (mirror.bit.edu.cn)... 202.204.80.77, 2001:da8:204:2001:250:56ff:fea1:22正在连接 mirror.bit.edu.cn (mirror.bit.edu.cn)|202.204.80.77|:80... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:9552281 (9.1M) [application/octet-stream]正在保存至: “apache-tomcat-8.5.31.tar.gz”100%[====================================================================================================================>] 9,552,281 419KB/s 用时 26s 2018-06-26 22:48:47 (363 KB/s) - 已保存 “apache-tomcat-8.5.31.tar.gz” [9552281/9552281])[root@nginx src]# lsapache-tomcat-8.5.31.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz nginx-1.14.0 php-5.6.32jdk-8u171-linux-x64.tar.gz mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz nginx-1.14.0.tar.gz php-5.6.32.tar.bz2
解压并移动改名:
[root@nginx src]# tar xzvf apache-tomcat-8.5.31.tar.gzapache-tomcat-8.5.31/conf/apache-tomcat-8.5.31/conf/catalina.policyapache-tomcat-8.5.31/conf/catalina.propertiesapache-tomcat-8.5.31/conf/context.xmlapache-tomcat-8.5.31/conf/jaspic-providers.xmlapache-tomcat-8.5.31/conf/jaspic-providers.xsd[root@nginx src]# mv apache-tomcat-8.5.31 /usr/local/tomcat[root@nginx src]# cd ..[root@nginx local]# lsbin etc games include jdk1.8 lib lib64 libexec mysql nginx php-fpm sbin share src tomcat[root@nginx local]# cd tomcat/[root@nginx tomcat]# lsbin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
因为是二进制包,可以直接运行:启动脚本starup.sh
[root@nginx ~]# /usr/local/tomcat/bin/startup.shUsing CATALINA_BASE: /usr/local/tomcatUsing CATALINA_HOME: /usr/local/tomcatUsing CATALINA_TMPDIR: /usr/local/tomcat/tempUsing JRE_HOME: /usr/local/jdk1.8Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarTomcat started.[root@nginx ~]# ps aux|grep tomcatroot 1519 29.2 5.2 2997944 97744 pts/0 Sl 22:51 0:04 /usr/local/jdk1.8/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap startroot 1567 0.0 0.0 112720 972 pts/0 S+ 22:52 0:00 grep --color=auto tomcat
如果启动后没有进程,要先shutdown.sh,再重新startup.sh。因为tomcat没有restart命令。
查看监听端口:8080web服务端口、8009第三方服务调用的端口,如httpd和tomcat结合用、8005管理端口,8005起来才能够使用tomcat
[root@nginx ~]# netstat -lntpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 948/nginx: master p tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 892/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1221/master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 948/nginx: master p tcp6 0 0 :::8080 :::* LISTEN 1519/java tcp6 0 0 :::22 :::* LISTEN 892/sshd tcp6 0 0 ::1:25 :::* LISTEN 1221/master tcp6 0 0 127.0.0.1:8005 :::* LISTEN 1519/java tcp6 0 0 :::8009 :::* LISTEN 1519/java tcp6 0 0 :::3306 :::* LISTEN 1182/mysqld
访问验证:先关闭防火墙firewalld
[root@nginx ~]# systemctl stop firewalld[root@nginx ~]# systemctl disable firewalldRemoved symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.[root@nginx ~]# curl 127.0.0.1:8080 -IHTTP/1.1 200 Content-Type: text/html;charset=UTF-8Transfer-Encoding: chunkedDate: Tue, 26 Jun 2018 15:00:10 GMT
浏览器访问:192.168.87.128:8080