一.編程語言基礎
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.www58058.com/62083