Tomca杂记

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tomca杂记相关的知识,希望对你有一定的参考价值。

Tomcat

Tomcat基础

1、安装jdk

1.1 安装jdk

[[email protected] tomcat]# ls
apache-tomcat-8.0.41.tar.gz  jdk-8u121-linux-x64.rpm

安装jdk
[[email protected] tomcat]# rpm -ivh jdk-8u121-linux-x64.rpm

1.2 设置java环境变量

[[email protected] jdk1.8.0_121]# vim /etc/profile.d/java.sh

export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH

[[email protected] jdk1.8.0_121]# . /etc/profile.d/java.sh
[[email protected] jdk1.8.0_121]# echo $PATH
/usr/java/latest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] jdk1.8.0_121]# 

1.3 显示java版本版本号

[[email protected] jdk1.8.0_121]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

2、安装tomcat

2.1 解压tomcat

[[email protected] tomcat]# tar xf apache-tomcat-8.0.41.tar.gz -C /usr/local/

2.2 创建软连接

[[email protected] local]# ln -sv apache-tomcat-8.0.41 tomcat
‘tomcat’ -> ‘apache-tomcat-8.0.41’
[[email protected] local]# ll
total 0
drwxr-xr-x  9 root root 149 Jan 16 22:47 apache-tomcat-8.0.41
lrwxrwxrwx  1 root root  20 Jan 16 22:49 tomcat -> apache-tomcat-8.0.41
[[email protected] local]# 

2.3 设置tomcat目录

[[email protected] tomcat]# vim /etc/profile.d/tomcat.sh

export CATALINA_HOME=/usr/local/tomcat
export PATH=$CATALINA_HOME/bin:$PATH

重载环境变量:
[[email protected] tomcat]# . /etc/profile.d/tomcat.sh
[[email protected] tomcat]# echo $PATH
/usr/local/tomcat/bin:/usr/java/latest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] tomcat]# 

显示tomcat版本号:
[[email protected] tomcat]# 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/java/latest
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.0.41
Server built:   Jan 18 2017 22:19:39 UTC
Server number:  8.0.41.0
OS Name:        Linux
OS Version:     3.10.0-327.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_121-b13
JVM Vendor:     Oracle Corporation
[[email protected] tomcat]# 

由于所有脚本集中在catalina.sh,可以通过在catalina传递脚本参数,调用其他shell
[[email protected] tomcat]# 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/java/latest
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.0.41
Server built:   Jan 18 2017 22:19:39 UTC
Server number:  8.0.41.0
OS Name:        Linux
OS Version:     3.10.0-327.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_121-b13
JVM Vendor:     Oracle Corporation
[[email protected] tomcat]# 

2.4 启动tomcat并查看默认是否监听8080端口

[[email protected] tomcat]# catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/latest
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[[email protected] tomcat]# 

[[email protected] tomcat]# ss -tnlp | grep 80
LISTEN     0      100         :::8009                    :::*                   users:(("java",pid=23581,fd=52))
LISTEN     0      100         :::8080                    :::*                   users:(("java",pid=23581,fd=47))

[[email protected] ~]# curl -I http://10.201.106.131:8080
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 16 Jan 2017 15:17:12 GMT

[[email protected] ~]# 

手动添加一个测试应用程序

1、创建webapp特有的目录结构

[[email protected] webapps]# mkdir myapp/{lib,classes,WEB-INF,META-INF} -pv
mkdir: created directory ‘myapp’
mkdir: created directory ‘myapp/lib’
mkdir: created directory ‘myapp/classes’
mkdir: created directory ‘myapp/WEB-INF’
mkdir: created directory ‘myapp/META-INF’
[[email protected] webapps]# tree myapp/
myapp/
├── classes
├── lib
├── META-INF
└── WEB-INF

4 directories, 0 files
[[email protected] webapps]# 

1.1 制作测试页

    [[email protected] webapps]# vim myapp/index.jsp

    <%@ page language="java" %>
    <%@ page import="java.util.*" %>
    <html>
        <head>
                <title>JSP Test Page</title>
        </head>
        <body>
                <% out.println("Hello,world."); %>
        </body>
    </html>

访问测试:
[[email protected] ~]# curl http://10.201.106.131:8080/myapp/index.jsp

<html>
    <head>
        <title>JSP Test Page</title>
    </head>
    <body>
        Hello,world.

    </body>
</html>

[[email protected] tomcat]# tree work
work
└── Catalina
    └── localhost
        ├── docs
        ├── examples
        ├── host-manager
        ├── manager
        │?? └── org
        │??     └── apache
        │??         └── jsp
        │??             └── WEB_002dINF
        │??                 └── jsp
        │??                     ├── _401_jsp.class
        │??                     └── _401_jsp.java
        ├── myapp
        │?? └── org
        │??     └── apache
        │??         └── jsp
        │??             ├── index_jsp.class
        │??             └── index_jsp.java
        └── ROOT
            └── org
                └── apache
                    └── jsp
                        ├── index_jsp.class
                        └── index_jsp.java

19 directories, 6 files
[[email protected] tomcat]# 

3、创建用户访问tomcat的管理程序

[[email protected] conf]# pwd
/usr/local/tomcat/conf
[[email protected] conf]# vim tomcat-users.xml 

  <role rolename="manager-gui"/>
  <user username="tomcat" password="tomcat" roles="manager-gui"/>

重启服务,间隔操作:5秒:
[[email protected] conf]# catalina.sh stop
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/latest
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[[email protected] conf]# catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/latest
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[[email protected] conf]# 

4、创建访问图片界面【Host Manager】的账户

/usr/local/tomcat/conf
[[email protected] conf]# vim tomcat-users.xml 

  <role rolename="admin-gui"/>
  <user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>

重启tomcat
[[email protected] bin]# catalina.sh stop
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/latest
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[[email protected] bin]# catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/latest
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[[email protected] bin]# 

5、配置server.xml

5.1 备份server.xml

5.2 通过8005端口关闭虚拟机实例

通过8005端口关闭虚拟机实例:
[[email protected] ~]# ss -tnl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128           *:22                        *:*                  
LISTEN      0      100    127.0.0.1:25                        *:*                  
LISTEN      0      100          :::8009                     :::*                  
LISTEN      0      100          :::8080                     :::*                  
LISTEN      0      128          :::22                       :::*                  
LISTEN      0      100         ::1:25                       :::*                  
LISTEN      0      1      ::ffff:127.0.0.1:8005                     :::*                  
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# telnet 127.0.0.1 8005
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is ‘^]‘.
SHUTDOWN
Connection closed by foreign host.
[[email protected] ~]# ss -tnl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128           *:22                        *:*                  
LISTEN      0      100    127.0.0.1:25                        *:*                  
LISTEN      0      128          :::22                       :::*                  
LISTEN      0      100         ::1:25                       :::*                  
[[email protected] ~]# 

5.3

以上是关于Tomca杂记的主要内容,如果未能解决你的问题,请参考以下文章

杂记之--苹果4s手机呼叫转移怎么设置

canvas杂记

python杂记

QT 使用杂记

网站优化杂记

Python学习杂记_10_三元运算符