一.编程语言基础
1.1 编程语言:
硬件级:微码编程,汇编语言
系统级:C,C++,…
应用级:Java, PHP, Python, Ruby, Perl, C#, …
Python: PVM
Standard Library
Web Framework:Django, Flask, …
Java:JVM,JDK
bash:bash explainer
…
1.2 程序简要概念
程序:指令+数据
过程式编程:以指令为中心,数据服务于代码;
对象式编程:以数据为中心,指令服务于数据;
对象,方法(method)
二.java基础概念
2.1 Java 历史:
Sun, Green Project, Oak, James Gosling;
1995:Java 1.0, Write once, Run Anywhere;
1996:JDK(Java Development Kit),包含类库、开发工具(javac)、JVM(SUN Classic VM)
JDK 1.0, Applet, AWT
1997:JDK 1.1
1998: JDK 1.2
Sun分拆Java技术为三个方向:
J2SE:Standard Edition
J2EE:Enterprise Edition
J2ME:Mobile Edition
代表性技术:EJB,java plugin, Swing, JIT(Just In Time,即时编译)
2000:JDK 1.3
HotSpot VM
2002:JDK 1.4
2006:Sun开源了Java技术,GPL,建立一个称为OpenJDK组织;
Java 2 SE, Java 2 EE, Java 2 ME
2011:JDK 1.7
2014:JDK 1.8
2016:JDK 1.9
2.2 Java代码的运行流程:
*.java(source code源代码) –> javac(编译工具) –> *.class(bytecode,字节码,类文件)
jvm:class loader,加载程序的类文件,及程序的类文件依赖到的其它的类文件而后运行;
整个运行表现为一个jvm进程;
threads;
#备注: 目前,单jvm进程运行内存超过32G时候,会导致内存泄露等错误
2.3 java技术体系:
Java编程语言
Java Class文件格式
Java API
Java VM
class loader
执行引擎
2.4 JVM运行时的内存区域:
class loader: 负责将代码加载到指定内存空间
GC: 垃圾清理器,用于清理堆中的垃圾
方法区:线程; 用于存储被JVM加载的class信息、常量、静态变量、方法等;
堆:是jvm所管理的内存中占用空间最大的一部分;也是GC管理的主要区域;用于存储对象;
每个对象有对应的引用计数器,当计数器值为0,则会被GC认为是垃圾而清出
Java栈:线程私有,存储 线程自己的局部变量;存放上下文
PC寄存器:线程私有的内存空间,程序的指令指针;
本地方法栈:调用本地的C库或者命令等本地资源时,本地资源的临时存放位置
总结:
Java 2 SE: JDK
Java 2 EE: (添加了多个类库,组件)
JDK + Servlet, JSP, EJB, JMS, JMX, JavaMail, …
商业实现:
BEA(oracle):WebLogic
IBM:WebSphere
Oracle: oc4j
…
2.5 java – JDK
2.5.1 JDK
2.5.2 安装JDK
1. 先有两种JDK ,一种为ORICLE官方的JDK,另一种为开源OPENJDK,两者都可以使用,
自行选择其中一个即可
2. oricle官方版JDK安装:
准备好JDK包,直接使用RPM命令安装即可:[root@node74 ~]# rpm -ivh jdk-8u25-linux-x64.rpm安装路径:[root@node74 ~]# cd /usr/java/
[root@node74 java]# ls
default jdk1.8.0_25 latest
版本指定方式:当多个版本都安装时候,latest软链接到的需要使用的版本,再通过在/etc/profile.d/下定义jdk.sh:export JAVA_HOME=/usr/java/latestexport PATH=$JAVA_HOME/sbin:$PATH
3. openJDK安装:
1) base仓库中已经默认包含有,直接使用YUM安装即可
通常需要安装如下几个:
java-###-openjdk java-###-openjdk-devel java-##-openjdk-headless
2 ) 安装相应版本的rpm包;
jdk-VERSION-OS-ARCH.rpm
例如:jdk-1.8.0_25-linux-x64.rpm
了解当前的java环境:
~]# java -version
2.5.3 OpenJDK
java-VERSION-openjdk:
The OpenJDK runtime environment.
java-VERSION-openjdk-headless:
The OpenJDK runtime environment without audio and video support.
java-VERSION-openjdk-devel:
The OpenJDK development tools.
注意:多版本并存时,可使用 alternatives命令设定默认使用的版本;
注意:安装完成后,要配置JAVA_HOME环境变量,指向java的安装路径;
OpenJDK:
JAVA_HOME=/usr
Oracle JDK:
JAVA_HOME=/usr/java/jdk_VERSION
2.5.3 Java 2 EE:
CGI: Common Gateway Interface
Servlet:
<title>TITLE</title>
<body>
<h1>…</h1>
<%
… java code…
%>
</body>
</html>
Web Container:
Servlet Container
Java Web Server:JWS
ASF:JServ
Tomcat 3.x
Tomcat 4.x
Catalina
http://tomcat.apache.org/
商业实现:
WebSphere, WebLogic, Oc4j, Glassfish, Geronimo, JOnAS, JBoss, …
开源实现:
Tomcat, Jetty, Resin, …
Tomcat: Java 2 EE技术体系的不完整实现;
三.Tomcat 简介
1.1 核心组件
<Server><Service><connector/><connector/>…<Engine><Host><Context/> #相当于alias<Context/>…<Value/></Host> #virtual host<Host>…</Host>…</Engine></Service></Server>
1.2 组件类型简介
1.3. 组件架构:
二. 安装Tomcat:
2.1 依赖环境JDK安装:
[root@node74 ~]# cd /usr/java/[root@node74 java]# lsdefault jdk1.8.0_25 latest
2.2 安装方式
2.3 tomcat程序环境
1. tomcat的目录结构#此为使用源码创建软链接形式安装时的程序环境
bin:脚本,及启动时用到的类;conf:配置文件目录;lib:库文件,Java类库,jar;logs:日志文件目录;temp:临时文件目录;webapps:webapp的默认目录,即应用程序的根目录work:工作目录;jsp文件编译为类文件以及执行等涉及的全部过程文件,都放于此处webapps/host-manager ,manager : WEB GUI管理界面用到的管理程序webapps/doc : 使用文档使用方式: http://ip:8080/docs/webapps/examle: 示例webapps/ROOT: 默认的应用根目录2. rpm包安装的程序环境:配置文件:/etc/tomcatwebapps存放位置:/var/lib/tomcat/webapps/examplesmanagerhost-managerdocs
三.tomcat的配置详解:
3.1 yum 安装下的配置文件分类(/etc/tomcat):
3.2 catalina.sh 工具
# catalina.sh –helpdebug Start Catalina in a debuggerdebug -security Debug Catalina with a security managerjpda start Start Catalina under JPDA debuggerrun Start Catalina in the current windowrun -security Start in the current window with security managerstart Start Catalina in a separate windowstart -security Start in a separate window with security managerstop Stop Catalina, waiting up to 5 seconds for the process to endstop n Stop Catalina, waiting up to n seconds for the process to endstop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still runningstop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still runningconfigtest Run a basic syntax check on server.xml – check exit code for resultversion What version of tomcat are you running?
[root@node74 apache-tomcat-8.0.23]# bin/catalina.sh versionUsing CATALINA_BASE: /root/apache-tomcat-8.0.23Using CATALINA_HOME: /root/apache-tomcat-8.0.23Using CATALINA_TMPDIR: /root/apache-tomcat-8.0.23/tempUsing JRE_HOME: /usrUsing CLASSPATH: /root/apache-tomcat-8.0.23/bin/bootstrap.jar:/root/apache-tomcat-8.0.23/bin/tomcat-juli.jarServer version: Apache Tomcat/8.0.23Server built: May 19 2015 14:58:38 UTCServer number: 8.0.23.0OS Name: LinuxOS Version: 3.10.0-327.el7.x86_64Architecture: amd64JVM Version: 1.8.0_65-b17JVM Vendor: Oracle Corporation
3.3 JSP WebAPP的组织结构:
.war:webapp#默认使用的java应用文件,一般都打包成此格式#tomcat可以自动识别解压使用.jar:EJB的类打包文件;.rar:资源适配器类打包文件;.ear:企业级webapp;
3.4 部署(deploy)webapp的相关操作:
# mkdir -pv /usr/local/tomcat/webapps/test/{classes,lib,WEB-INF}创建文件/usr/local/tomcat/webapps/test/index.jsp<%@ page language=”java” %><%@ page import=”java.util.*” %><html><head><title>Test Page</title></head><body><% out.println(“hello world”);%></body></html>
[root@node74 webapps]# tree /var/cache/tomcat/work//var/cache/tomcat/work/└── Catalina└── localhost├── _│ └── org│ └── apache│ └── jsp│ ├── index_jsp.class│ └── index_jsp.java├── docs├── examples├── host-manager├── manager├── sample└── test└── org└── apache└── jsp├── index_jsp.class└── index_jsp.java
3.5 tomcat的两个管理应用:
managerhost-manager#要使用此功能,需要安装 tomcat-admin-webapps, tomcat-webapps两个包使用方式:在web gui页面中,点击nanger app/host manager 输入管理员账号密码即可使用#注意默认管理功能不开启,需要手动授权账号
<!– <role rolename=”admin-gui”/> –><!– <role rolename=”admin-script”/> –><!– <role rolename=”manager”/> –><!– <role rolename=”manager-gui”/> –><!– <role rolename=”manager-script”/> –><!– <role rolename=”manager-jmx”/> –><!– <role rolename=”manager-status”/> –>授权用户:<user username=”role1″ password=”tomcat” roles=”manager-gui“/>#授权给用户的权限,需要在上面先开启对应权限功能
401 Unauthorized
You are not authorized to view this page. If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.
For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.
<role rolename="manager-gui"/>
#此处用于定义开启manager-gui功能
<user username="tomcat" password="s3cret" roles="manager-gui"/>
$授权拥有manager-gui功能的账户
Note that for Tomcat 7 onwards, the roles required to use the manager application were changed from the single manager role to the following four roles. You will need to assign the role(s) required for the functionality you wish to access.
#可开启的功能:
- manager-gui – allows access to the HTML GUI and the status pages
- manager-script – allows access to the text interface and the status pages
- manager-jmx – allows access to the JMX proxy and the status pages
- manager-status – allows access to the status pages only
The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:
- Users with the manager-gui role should not be granted either the manager-script or manager-jmx roles.
- If the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session.
For more information – please see the Manager App HOW-TO.
eg:<role rolename=”manager-gui”/>#开启manager-gui功能<user username=”tomcat” password=”tomcat” roles=”manager-gui“/>#将开启的manager-gui功能授权给tomcat用户,密码为tomcat
服务器状态信息server status-JVM
3.6 WEB-GUI 中的 部署功能
四.tomcat 配置详解
4.1 tomcat的常用组件配置
4.1.1 server 组件
4.1.2 service 组件
4.1.3 connector 组件
进入tomcat的请求可分为两类:(1) standalone : 请求来自于客户端浏览器;(2) 由其它的web server反代:来自前端的反代服务器;nginx –> http connector –> tomcathttpd –> http connector –> tomcathttpd –> ajp connector –> tomcat常用属性:port=”8080″ 监听端口protocol=”HTTP/1.1″ 使用的协议connectionTimeout=”20000″ 连接超时address:监听的IP地址;默认为本机所有可用地址;maxThreads:最大并发连接数,默认为150;enableLookups:是否启用DNS查询功能;acceptCount:等待队列的最大长度;secure:true|false 是否启用sslProtocol: ssl通信协议指定SSLEnabled=”true” 是否启用SSLredirectPort=”8443″ 重定向端口eg:
<Connector port=”8443″ protocol=”org.apache.coyote.http11.Http11Protocol”maxThreads=”150″ SSLEnabled=”true” scheme=”https” secure=”true”clientAuth=”false” sslProtocol=”TLS” />
#详细配置实例,见server.xml文件,里面有官方示例
4.1.4 Engine组件:
<Engine name=”Catalina” defaultHost=”localhost”>属性:name=defaultHost=”localhost”jvmRoute=
4.1.5 host组件
<Host name=”localhost” appBase=”webapps”unpackWARs=”true” autoDeploy=”true”></Host>
<head>
<title>Test Page</title>
</head>
<body>
hello mygirl
</body>
</html>
<html><head><title>Test Page</title></head><body>hello mygirl</body></html>
4.1.6 context 组件
4.1.7 valve 组件
五. LNMT:Linux Nginx MySQL Tomcat
5.1 client请求传送流程
5.2 nginx配置:
六. LAMT:Linux Apache(httpd) MySQL Tomcat
6.1 httpd 反代模块:
6.2 proxy_http_module配置实例:
6.3 proxy_ajp_module 配置实例
原创文章,作者:ldt195175108,如若转载,请注明出处:http://www.178linux.com/62083