Detailed CentOS6.7 deploy Tomcat and the main configuration file

Java program to achieve the deployment and application

POSIX: Portable Operating System , programming interface specification operating system, cross-platform compiler run.

API: Application Programming Interface

ABI: describes the application binary interface between applications and the operating system, the interface between the lower part of an application and between its library or application .

JAVA: contains four separate but interrelated technologies

Java language

JavaAPI: the Java application programming interface

Java class file format, you need to run in a Java virtual machine

the JVM: the Java Virtual Machine

JAVA process

 

1, JavaAPI and programming language source code developed

2, the Java source file, usually .java ending

3, using the Java compiler to compile Java source files

4, after the compilation is completed save for the class file to .class end

5, these types of documents have to find a Java virtual machine can run up

6, these class files in Java virtual machine needs libraries in order to run up!

7. public class needs to use class loader to load before!

 

JVM implementations:

1, a disposable interpreter: is interpreted byte code and execute, interpret the process is to convert the byte code into a binary process.

2, time compiler: Each class class at runtime, complete explanation of the content to be cached, when the second execution, to get the cache. Dependent on the result of decoding additional memory cache.

3, the adaptive compiler: automatically caching 20% of the relatively high frequency of execution code, increase 80% speed.

 

The JDK: Java Development Environment + run , is to achieve Java development environment minimum

Java applications in different fields are divided into three categories:

SE the Java: the Java Standard Edition,

EE the Java: the Java Enterprise Edition

ME the Java: the Java Mobile Edition

 

CGI (protocol ) : Common Gateway Interface, the dynamic interfacial processed formatted into HTML format to the user.

 

Servlet (Applet Server), full name of the Java Servlet , is to use Java to write server-side program. Its main function is to interactively view and modify data, generate dynamic Web content. Narrow Servlet refers to the Java interface language to achieve,

JSP full name of the Java Server Pages, Chinese named java server pages, it simply is a simplified Servlet design,

It is a traditional page HTML file (* .htm, *. Html) insert Java block (Scriptlet) and JSP tag (Tag) , thereby forming a JSP file suffix (* .jsp) . With JSP development of Web applications are cross-platform, both in Linux run, it can also run on other operating systems.

.jsp ---> .java --->(JVM).class

jasper help .jsp convert .java , the Java compiler to help .java converted into .class , the JVM to help .class converted into a program file.

JDK: provides javac, to help .java converted into .class .

 

servlet container: it contains the JDK , but also contains the JDK additional components not available

Workflow-based servlet container:

1, a front end web application, is responsible for receiving a user request, if it is found the user is requesting CGI content,

2, the servlet is responsible by CGI with the protocol web interaction program

3, after receiving the requested content in, the JVM completion of execution of the program

servlet container is responsible for receiving CGI request is passed over, responsible for monitoring the local .Java program modification has occurred, if modified, is responsible for converting it into .class format. ( Includes JDK)

web container : comprising the servlet and JSP application framework

Connector : http request really wants to request the user interaction, but also relies on the front end of web servers, the connector can be achieved even without the web server decodes http request package http response, may be done directly interacts with the user,

 

If a large number of user requests directly to the connector of the pressure becomes great, if he put a front-end to a web server , web server with a caching function again, and that the rear end of the connector pressure will be much smaller, this model is called the Java web container or application server !

 

Install the JDK

1, installed by default in / usr / java / directory,

2, using the rpm installed Java

3, in /etc/profile.d/ create java.sh , says:

export JAVA_HOME=/usr/local/jdk1.6.0_45

export PATH=$PATH:$JAVA_HOME/bin

4、执行一下文件:. /etc/profile.d/java.sh

5、使用命令查看Java版本号:java -version

 

Java配置参数方法:

-XX:+选项 :开启 此参数指定的功能

-XX:-选项 :关闭功能

         -XX:选项=值 :给指定的选项赋值

java -XX:+PrintFlagsFinal :显示Java全部选项及其参数

 

Tomcat详解

tomcat架构详解

整个Tomcat容器架构从外向内一共5

Tomcat在自己内部开发了一个使用Java语言开发了一个web服务器。

Tomcat自身内部就有一个web服务器,而这个web服务器本身运行起来以后,完全可以直接工作在前台,让用户对本机发起web请求。

 

第一层是Tomcat服务器(server):每一个server就是一个Tomcat实例,意味着启动一个Tomcat就是启动一个serve

可以直接响应解析http请求

第二层是Tomcat 服务(service):将一个或多个连接器关联至一个引擎,

连接器(Connector):贯穿第一层到第三层,用于将server和引擎建立起来关联关系,将server收到的请求转发给某一个引擎的组件。有多个!

第三层是Tomcat 引擎:就是一个具有servlet 容器的Java虚拟机,也是具备了web容器功能的容器,解码.java

第四层是Tomcat 主机:可以有多个,用来在引擎内部实现虚拟主机

第五层是上下文 :定义类似于Apache的路径别名,配置一个Context最主要的是指定Web应用程序的根目录,以便Servlet容器能够将用户请求发往正确的位置。

 

容器类组件

Engine(引擎)

Host (主机)

Context(上下文)

顶级组件

server (服务器)

service (服务)

其余组件

Realm(领域):用户账户数据库,

Valve (阀门):实现用户的认证

Logger:日志记录器

 

常用组件

1、Loader(类加载器)

Java的动态装载功能是其语言功能强大表现之一,Servlet容器使用此功能在运行时动态装载servlet和它们所依赖的类。Loader可以用于Context中控制java类的加载

2、Manager

Manger对象用于实现HTTP会话管理的功能,Tomcat6中有5Manger的实现:

1) StandardManager(标准管理器)

Tomcat6的默认会话管理器,用于非集群环境中对单个处于运行状态的Tomcat实例会话进行管理。当Tomcat关闭时,这些会话相关的数据会被写入磁盘上的一个名叫SESSION.ser的文件,并在Tomcat下次启动时读取此文件。

2) PersistentManager(持久会话管理器)

当一个会话长时间处于空闲状态时会被写入到swap会话对象,这对于内存资源比较吃紧的应用环境来说比较有用。

3)DeltaManager

用于Tomcat集群的会话管理器,它通过将改变了会话数据同步给集群中的其它节点实现会话复制。这种实现会将所有会话的改变同步给集群中的每一个节点,也是在集群环境中用得最多的一种实现方式。

4) BackupManager

用于Tomcat集群的会话管理器,与DeltaManager不同的是,某节点会话的改变只会同步给集群中的另一个,而非所有节点。

5)SimpleTcpReplicationManager

Tomcat4时用到的版本,过于老旧了。

3、Stores(存储)

持久管理器必须包含一个Store元素以指定将会话数据存储至何处。这通常有两种实现方式:FileStore(文件存储)JDBCStore(数据库存储)

4、Resources

经常用于实现在Context中指定需要装载的但不在Tomcat本地磁盘上的应用资源,如Java类,HTML页面,JSP文件等。

5、Cluster

专用于配置Tomcat集群的元素,可用于EngineHost容器中。在用于Engine容器中时,Engine中的所有Host均支持集群功能。在Cluster元素中,需要直接定义一个Manager元素,这个Manager元素有一个其值为org.apache.catalina.ha.session.DeltaManagerorg.apache.catalina.ha.session.BackupManagerclassName属性。同时,Cluster中还需要分别定义一个ChannelClusterListener元素。

5.1、Channel(通告)

用于Cluster中给集群中同一组中的节点定义通信"信道"。Channel中需要至少定义MembershipReceiverSender三个元素,此外还有一个可选元素Interceptor

5.2、Membership(成员关系管理)

用于Channel中配置同一通信信道上节点集群组中的成员情况,即监控加入当前集群组中的节点并在各节点间传递心跳信息,而且可以在接收不到某成员的心跳信息时将其从集群节点中移除。Tomcat6Membership的实现是org.apache.catalina.tribes.membership.McastService

5.3、Sender(心跳发送)

用于Channel中配置"复制信息"的发送器,实现发送需要同步给其它节点的数据至集群中的其它节点。发送器不需要属性的定义,但可以在其内部定义一个Transport元素。

5.4 Transport(发送集群事务信息)

用于Sender内部,配置数据如何发送至集群中的其它节点。Tomcat6有两种Transport的实现:

1) PooledMultiSender

基于Java阻塞式IO,可以将一次将多个信息并发发送至其它节点,但一次只能传送给一个节点。

2)PooledParallelSener

基于Java非阻塞式IO,即NIO,可以一次发送多个信息至一个或多个节点。

5.5 Receiver(接受集群事务信息)

用于Channel定义某节点如何从其它节点的Sender接收复制数据,Tomcat6中实现的接收方式有两种BioReceiverNioReceiver

 

Tomcat的主配置文件(server.xml)及其各组件之间的关系

<server>

<service>

<Connector />

<Engine>

<Host>

<Context> </Context>

</Host>

</Engine>

</service>

</server>

安装Tomcat之前需要先安装JDK,因为要依赖于开发环境!

 

Tomcat的安装配置

1、解压包:tar xf apache-tomcat-7.0.69.tar.gz -C /usr/local/

2、包名太长,进行软连接:ln -sv apache-tomcat-7.0.69 tomcat

3、目录结构

bin :二进制程序路径,里面有 .jar文件(Java归档压缩包)shell脚本,还有 .bat(windows的批处理脚本)

conf :配置文件

server.xml:主配置文件

tomcat-users.xml:用户认证

web.xml:默认的应用程序部署描述符 (部署:将一个web应用程序所依赖到的类装载进JVM)

context.xml :默认为上下文所提供的配置文件

logging.properties :定义日志属性

catalina.properties :定义应用程序本身属性

catalina.policy :定义Tomecat自身安全策略,资源授权

lib :类库文件

logs :日志文件

temp :临时文件目录

webapps :应用程序目录,每一个程序文件夹中都有一个WEB-INF,这是程序的私有目录。

work :工作目录,

4、启动Tomcat

4.1、输出一个变量:vim /etc/profile.d/tomcat.sh ,内容为:

export CATALINA_HOME=/usr/local/tomcat

export PATH=$PATH:$CATALINA_HOME/bin

4.2、 启动 catalina.sh start ,然后查看端口:netstat -lnpt中的8080、8009

5、访问网页: 格式为(IP地址:8080

5、使用service启动Tomcatvim /etc/rc.d/init.d/tomcat

脚本:

#!/bin/sh

# Tomcat init script for Linux.

#

# chkconfig: 2345 96 14

# description: The Apache Tomcat servlet/JSP container.

JAVA_HOME=/usr/java/jdk1.7.0_67

CATALINA_HOME=/usr/local/tomcat

export JAVA_HOME CATALINA_HOME

exec $CATALINA_HOME/bin/catalina.sh $*

 

Tomcat优化

Tomcat的优化分成两块:

Tomcat启动命令行中的优化参数即JVM优化(catalina.sh)

ü 系统响应时间增快

ü JVM回收速度增快同时又不影响系统的响应率

ü JVM内存最大化利用

ü 线程阻塞情况最小化

 

Tomcat容器自身参数的优化(server.xml

Guess you like

Origin www.cnblogs.com/linux-s/p/11289288.html