Tomcat简介

Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun和其他一些公司及个人共同开发而成。Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP程序的首选。Tomcat和Nginx、Apache(httpd)、lighttpd等Web服务器一样,具有处理HTML页面的功能,另外它还是一个Servlet和JSP容器,独立的Servlet容器是Tomcat的默认模式。不过,Tomcat处理静态HTML的能力不如Nginx/Apache服务器。目前Tomcat最新版本为9.0。Java容器还有resin、weblogic等。

JDK介绍

JDK是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具。 DK包含了一批用于Java开发的组件,其中包括: javac:编译器,将后缀名为.java的源代码编译成后缀名为“.class”的字节码 java:运行工具,运行.class的字节码 jar:打包工具,将相关的类文件打包成一个文件 javadoc:文档生成器,从源码注释中提取文档,注释需匹配规范 jdb debugger:调试工具 jps:显示当前java程序运行的进程状态 javap:反编译程序 appletviewer:运行和调试applet程序的工具,不需要使用浏览器 javah:从Java类生成C头文件和C源文件。这些文件提供了连接胶合,使Java和C代码可进行交互。 javaws:运行JNLP程序 extcheck:一个检测jar包冲突的工具 apt:注释处理工具 jhat:java堆分析工具 jstack:栈跟踪程序 jstat:JVM检测统计工具 jstatd:jstat守护进程 jinfo:获取正在运行或崩溃的java程序配置信息 jmap:获取java进程内存映射信息 idlj:IDL-to-Java编译器。将IDL语言转化为java文件 policytool:一个GUI的策略文件创建和管理工具 jrunscript:命令行脚本运行


准备环境

[root@centos7 ~]# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core) [root@centos7 ~]# uname -r 3.10.0-693.el7.x86_64 [root@centos7 ~]# getenforce Disabled [root@centos7 ~]# systemctl stop firewalld.service [root@centos7 ~]# cd /opt/ [root@centos7 opt]# wget -c http://download.oracle.com/otn-pub/java/jdk/10.0.2+13/19aef61b38124481863b1413dce1855f/jdk-10.0.2_linux-x64_bin.tar.gz [root@centos7 opt]# tar xf jdk-10.0.2_linux-x64_bin.tar.gz -C /usr/local/ [root@centos7 opt]# ln -s /usr/local/jdk-10.0.2/ /usr/local/jdk [root@centos7 opt]# java -version java version “1.8.0_60” Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

下载安装Tomcat

[root@centos7 opt]# wget -c https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.50/bin/apache-tomcat-8.0.50.tar.gz [root@centos7 opt]# tar xf apache-tomcat-8.0.50.tar.gz -C /usr/local/ [root@centos7 opt]# ln -s /usr/local/apache-tomcat-8.0.50/ /usr/local/tomcat [root@centos7 opt]# /usr/local/tomcat/bin/version.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/jdk Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar NOTE: Picked up JDK_JAVA_OPTIONS: –add-opens=java.base/java.lang=ALL-UNNAMED –add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED Server version: Apache Tomcat/8.0.50 Server built: Feb 7 2018 20:06:05 UTC Server number: 8.0.50.0 OS Name: Linux OS Version: 3.10.0-693.el7.x86_64 Architecture: amd64 JVM Version: 10.0.2+13 JVM Vendor: “Oracle Corporation”

配置相关环境变量信息

[root@centos7 opt]# cat >>/etc/profile<<'EOF' export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar export TOMCAT_HOME=/usr/local/tomcat EOF [root@centos7 opt]# source /etc/profile

设置jdk程序目录权限信息

[root@centos7 opt]# chown -R root.root /usr/local

检查所有环境变量信息是否配置成功

[root@centos7 opt]# env|egrep -i "JAVA_HOME|PATH|CLASSPATH|TOMCAT_HOME" TOMCAT_HOME=/usr/local/tomcat PATH=/usr/local/jdk/bin:/usr/local/jdk/jre/bin:/application/jdk/bin:/application/jdk/jre/bin:/application/jdk/bin:/application/jdk/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin JAVA_HOME=/usr/local/jdk CLASSPATH=.:/usr/local/jdk/lib:/usr/local/jdk/jre/lib:/usr/local/jdk/lib/tools.jar

启动tomcat服务程序

[root@centos7 opt]# /usr/local/tomcat/bin/startup.sh [root@centos7 opt]# netstat -lntup|grep java tcp6 0 0 :::8080 :::* LISTEN 1781/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 1781/java tcp6 0 0 :::8009 :::* LISTEN 1781/java

网页测试进行访问

http://10.0.0.202:8080/

安装数据库程序并进行配置

[root@centos7 opt]# yum -y install mariadb-server [root@centos7 opt]# systemctl start mariadb.service [root@centos7 opt]# systemctl enable mariadb.service [root@centos7 opt]# mysql MariaDB [(none)]> create database jpress DEFAULT CHARACTER SET utf8; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all on jpress.* to jpress@’localhost’ identified by ‘123456’; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit Bye

将开源代码程序包上传到tomcat站点目录下

[root@centos7 ~]# mv jpress-web-newest.war /usr/local/tomcat/webapps/ [root@centos7 ~]# /usr/local/tomcat/bin/shutdown.sh [root@centos7 ~]# /usr/local/tomcat/bin/startup.sh [root@centos7 ~]# ll /usr/local/tomcat/webapps/ total 20316 drwxr-xr-x 14 root root 4096 Sep 1 00:10 docs drwxr-xr-x 6 root root 83 Sep 1 00:10 examples drwxr-xr-x 5 root root 87 Sep 1 00:10 host-manager drwxr-xr-x 7 root root 102 Sep 1 01:09 jpress-web-newest -rw-r–r– 1 root root 20797013 Mar 3 2017 jpress-web-newest.war drwxr-xr-x 5 root root 103 Sep 1 00:10 manager drwxr-xr-x 3 root root 306 Sep 1 00:10 ROOT

浏览器访问jpress网站向导界面

http://10.0.0.202:8080/jpress-web-newest/install [root@centos7 ~]# /usr/local/tomcat/bin/shutdown.sh [root@centos7 ~]# /usr/local/tomcat/bin/startup.sh http://10.0.0.202:8080/jpress-web-newest/admin/login