linux部署tomcat

 系统环境

[root@tomcat1 /]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.6 (Maipo)

tomcat版本:

查询命令

[root@tomcat1 /]# /usr/local/tomcat/bin/catalina.sh version
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Server version: Apache Tomcat/8.5.61
Server built:   Dec 3 2020 14:03:28 UTC
Server number:  8.5.61.0
OS Name:        Linux
OS Version:     3.10.0-957.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_181-b13
JVM Vendor:     Oracle Corporation

或者

[root@tomcat1 /]# /usr/local/tomcat/bin/version.sh

java版本:

[root@tomcat1 /]# java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

 java安装路径查看:

[root@tomcat1 /]# java -verbose
。
。
。
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
[Loaded java.lang.Shutdown from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre/lib/rt.jar]
[Loaded java.lang.Shutdown$Lock from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre/lib/rt.jar]

 

本次采用默认安装,不自定义安装路径,不自定义java版本的路径,java环境采用yum安装

tomcat需要运行在java环境

Apache公司的服务器,是JavaEE规范中Servlet/JSP规范的实现者,是一个轻量级服务器,开源免费。可称为Web容器,或者说是Servlet容器。

*JCP:Java Community Process,Java审核社区,是个开放的国际组织,规范监督Java的发展。通过JCP审核的才能成为Java规范。JCP的创造者为SUN公司。

*SDK:是Software Development Kit 一般指软件开发包,可以包括函数库、编译程序等。

*JRE:Java Runtime Enviroment是指Java的运行环境,是面向Java程序的使用者,而不是开发者。 包含了java虚拟机,java基础类库。

*JDK:Java Development Kit,JDK是面向开发人员使用的SDK,它提供了Java的开发环境和运行环境。包含了JRE,同时还包含了编译java源码的编译器javac,还包含了很多java程序调试和分析的工具:jconsole,jvisualvm等工具软件。

java有两种 jre 和 jdk

jre(a Java Standard Edition Runtime Environment)

jdk(a full Java Development Kit)

根据官方需求文档说明,tomcat 8.5 至少需要jre 7 的版本

部署步骤

1. 准备java环境,此处选择jdk,功能较jre更为强大

yum -y install java-1.8.0-openjdk*

 ****通过yum默认安装的路径为/usr/lib/jvm/java-版本号(如/usr/lib/jvm/java-1.8.0)****

 2. 安装tomcat

    去官网 https://tomcat.apache.org/ 下载安装包

3. 解码tar包,通过mv移动到自己的实例目录

[root@tomcat1 local]# tar zxvf apache-tomcat-8.5.61.tar.gz
[root@tomcat1 local]# mv apache-tomcat-8.5.61 tomcat
[root@tomcat1 local]# pwd

/usr/local

4. 因为tomcat需要依赖java环境,所以启动脚本,停止脚本,都需要指定 java的家目录,当然也可以写进/etc/profile 文件,不过写进/etc/profile 不太灵活

 

[root@tomcat1 bin]# pwd
/usr/local/tomcat/bin
[root@tomcat1 bin]# tail startup.sh
#20201216 begin
export JAVA_HOME=/usr/lib/jvm/java-1.8.0
export TOMCAT_HOME=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
export CLASS_PATH=$JAVA_HOME/bin/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tool.jar
export PATH=$PATH:/usr/lib/jvm/java-1.8.0/bin:/usr/local/tomcat/bin
#20201216 end
[root@tomcat1 bin]# tail shutdown.sh
#20201216 begin
export JAVA_HOME=/usr/lib/jvm/java-1.8.0
export TOMCAT_HOME=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
export CLASS_PATH=$JAVA_HOME/bin/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tool.jar
export PATH=$PATH:/usr/lib/jvm/java-1.8.0/bin:/usr/local/tomcat/bin
#20201216 end

5. 此时tomcat其实已经部署完成,可以启动服务测试一下

[root@tomcat1 bin]# ps -elf|grep tomcat
0 S root       8011   7804  0  80   0 - 28177 pipe_w 14:51 pts/0    00:00:00 grep --color=auto tomcat
[root@tomcat1 bin]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@tomcat1 bin]# ps -elf|grep tomcat
0 S root       8026      1 99  80   0 - 1020873 futex_ 14:52 pts/0  00:00:04 /usr/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 start
0 S root       8080   7804  0  80   0 - 28177 pipe_w 14:52 pts/0    00:00:00 grep --color=auto tomcat

[root@tomcat1 bin]# netstat -anput|grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      8026/java

[root@tomcat1 bin]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:60:f8:a5 brd ff:ff:ff:ff:ff:ff
    inet 172.23.23.32/24 brd 172.23.23.255 scope global noprefixroute dynamic ens33
       valid_lft 24074sec preferred_lft 24074sec
    inet 10.0.0.11/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe60:f8a5/64 scope link
       valid_lft forever preferred_lft forever
[root@tomcat1 bin]# netstat -anput|grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      8026/java
tcp6       0      0 172.23.23.32:8080       172.23.23.17:64413      ESTABLISHED 8026/java

 

6. 浏览器输入ip:8080 可以访问tomcat ,我的默认主页被我改了

 

posted @ 2020-12-21 17:10  augusite  阅读(236)  评论(0编辑  收藏  举报