億級流量架構|day01-京淘環境搭建
1. 專案環境配置
修改eclipse文件編碼為UTF-8
配置JDK
Window中JDK
檢測是否有JAVA_HOME
檢查是否有path
Path ;%JAVA_HOME%/bin
關閉校驗
新增maven
2. maven配置
2.1 maven作用
說明:
Maven是一站式的專案管理工具.負責專案中jar包管理/依賴.
Maven可以實現專案的自動的打包部署.
Mvn install/mvn package命令
依賴說明:
Maven可以實現jar包自動依賴的下載.同時依賴具有傳遞性.
A.jar-----B.10.jar-----C.2.0.jar
使用原則:
Maven的使用必須基於網路!!!!
2.2 maven使用原理
部件:1.本地倉庫 2.私服映象 3.中央倉庫
2.3 修改本地倉庫路徑
1. 配置倉庫
2. 配置私服映象
<!-- maven 映象伺服器配置 --> <mirror> <id>nexus</id> <name>Tedu Maven</name> <mirrorOf>*</mirrorOf> <url>http://maven.tedu.cn/nexus/content/groups/public/</url> </mirror>
3. 新增JDK配置
<profile> <id>jdk18</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile>
2.4 編輯本地倉庫路徑
更新完成後儲存.
3. maven高階
3.1 Maven的jar包如何自動依賴
說明:Maven載入jar包的過程
- 根據POM檔案的座標首先到本地倉庫/私服映象中查詢jar包.
- 在引入jar包檔案之前,需要先載入該jar包的pom.xml檔案,對其中依賴的jar包再次解析.
- 解析完成後.實現jar包的自動依賴.
3.2 Maven的jar包如何保證不被篡改
SHA1介紹:
安全雜湊演算法(Secure Hash Algorithm)主要適用於數字簽名標準 (Digital Signature Standard DSS)裡面定義的數字簽名演算法(Digital Signature Algorithm DSA)。對於長度小於2^64位的訊息,SHA1會產生一個160位的訊息摘要。當接收到訊息的時候,這個訊息摘要可以用來驗證資料的完整性。在傳輸的過程中,資料很可能會發生變化,那麼這時候就會產生不同的訊息摘要。 SHA1有如下特性:不可以從訊息摘要中復原資訊;兩個不同的訊息不會產生同樣的訊息摘要,(但會有1x10 ^ 48分之一的機率出現相同的訊息摘要,一般使用時忽略)。
王小云提出了密碼雜湊函式的碰撞攻擊理論,即模差分位元分析法,提高了破解了包括MD5、SHA-1在內的5個國際通用雜湊函式演算法的概率;給出了系列訊息認證碼MD5-MAC等的子金鑰恢復攻擊和HMAC-MD5的區分攻擊;提出了格最短向量求解的啟發式演算法二重篩法;設計了中國雜湊函式標準SM3,該演算法在金融、國家電網、交通等國家重要經濟領域廣泛使用。 [1]
3.3 Mavenjar包依賴關係
如果parent專案中依賴jar包.但是自己專案同樣依賴jar包則以自己的依賴為準.
3.4 如何解決jar包衝突問題
依賴A-----B.1.0.jar
依賴C-----B.2.0.jar
解決思路:去除低版本jar包.
3.5 如何確定jar包版本關係
說明:架構師準備專案時需要保證jar包版本匹配.
Jar包依賴關係
4. 專案構建
4.1 分散式專案中存在的問題
問題描述:
1.根據專案拆分的思想,可以將專案根據垂直拆分和水平拆分.將大型專案拆分為不同的小專案但是jar包管理幾份??如果jar包多份,將來擴充套件不易.
4.2 分散式專案中jar包如何管理
說明:採用parent的形式,將專案中公共的jar包進行管理.其他的專案只需要繼承parent即可.實現了jar包的統一管理.
4.3 分散式專案中工具類如何管理
說明:如果將工具程式碼分別儲存到不同的專案中,如果對工具類方法進行編輯.則需要修改多次.對程式設計不易.
4.4 解決方案
說明:在分散式專案中需要使用jar包的統一管理方式,還有工具類的統一的管理方式.所以建立jt-parent和jt-common.
把上述的2個專案叫做業務的支援系統
將jt-manage/jt-cart/jt-web/jt-order等專案稱之為業務系統.搭建一個大型的專案.必須新增業務的支撐系統.
4.5 京淘專案劃分
序號 |
專案名稱 |
主要作用 |
1 |
jt-manage |
京淘後臺管理系統 負責商品的更新和維護 |
2 |
jt-web |
京淘前臺系統,主要負責商品的展現 |
3 |
jt-cart |
京淘購物車系統,負責使用者購物車資訊維護 |
4 |
jt-sso |
京淘單點登陸系統,實現session資料共享 |
5 |
jt-order |
京淘訂單系統,負責訂單維護 |
6 |
jt-search |
京淘專案的全文檢索 |
7 |
jt-rabbitMQ |
訊息佇列系統 |
8 |
jt-parent |
負責jar包的管理和依賴 |
9 |
jt-common |
管理工具類檔案 |
5. 構建jt-parent
5.1 建立專案
5.2 新增jar包檔案
<!-- 集中定義依賴版本號 -->
<properties>
<junit.version>4.10</junit.version>
<spring.version>4.1.3.RELEASE</spring.version>
<mybatis.version>3.2.8</mybatis.version>
<mybatis.spring.version>1.2.2</mybatis.spring.version>
<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
<mysql.version>5.1.32</mysql.version>
<bonecp-spring.version>0.8.0.RELEASE</bonecp-spring.version>
<druid.version>1.0.29</druid.version>
<mapper.version>2.3.2</mapper.version>
<pagehelper.version>3.4.2</pagehelper.version>
<jsqlparser.version>0.9.1</jsqlparser.version>
<slf4j.version>1.6.4</slf4j.version>
<jstl.version>1.2</jstl.version>
<servlet-api.version>2.5</servlet-api.version>
<jsp-api.version>2.0</jsp-api.version>
<joda-time.version>2.5</joda-time.version>
<commons-lang3.version>3.3.2</commons-lang3.version>
<commons-fileupload.version>1.3.1</commons-fileupload.version>
<jackson.version>2.4.2</jackson.version>
<httpclient.version>4.3.5</httpclient.version>
<jedis.version>2.6.2</jedis.version>
</properties>
<dependencies>
<!-- 單元測試 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
<version>${mybatis.paginator.version}</version>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--引入阿里druid監控 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- 通用Mapper -->
<dependency>
<groupId>com.github.abel533</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
<!-- 分頁外掛 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>${jsqlparser.version}</version>
</dependency>
<!-- 連線池 -->
<dependency>
<groupId>com.jolbox</groupId>
<artifactId>bonecp-spring</artifactId>
<version>${bonecp-spring.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- Jackson Json處理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.1</version>
</dependency>
<!-- 訊息佇列 -->
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<!-- JSP相關 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp-api.version}</version>
<scope>provided</scope>
</dependency>
<!-- 時間操作元件 -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<!-- Apache工具元件 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<!-- 檔案上傳元件 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<!-- jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<!--新增spring-datajar包 -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<!-- 字元加密、解密 -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<!-- 資料校驗 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
</dependencies>
6. 構建工具類專案
6.1 建立專案
6.2 新增繼承
說明:jt-parent必須是pom型別
6.3 匯入工具類
說明:將課前資料中的工具類專案中src檔案匯入專案中
說明:編輯完工具類後,分別將jt-parent和jt-common打包
7. 構建jt-manage
7.1 建立專案
1.選擇骨架
2.編輯專案
3.補全專案檔案路徑
7.2 新增繼承和依賴
1. 繼承
2. 依賴
繼承和依賴的關係:
繼承:獲取父級專案全部的jar包(多)
依賴:某些專案中需要引入額外的jar包 所以採用依賴的方式.(單個)
8. tomcat外掛
8.1 傳統tomcat伺服器弊端
1. eclipse中整合tomcat時,配置繁瑣.
2. tomcat使用一段時間後,tomcat啟動時間越來越長.
因為裡邊的專案變多了,生成了大量的臨時檔案.造成啟動慢
3. 搭建tomcat叢集時,必須修改埠 8005/8080/8009
8.2 Tomcat外掛介紹
說明:tomcat外掛在程式啟動時,會開啟單獨的執行緒載入tomcat,在tomcat中部署的專案,只有在執行緒工作時才能正常訪問.即使生成了大量的臨時檔案則也在記憶體中.當執行緒關閉(tomcat服務).
搭建tomcat叢集時只需要修改8080埠即可.
8.3 Tomcat外掛配置
1.新增外掛
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8091</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
2.配置啟動項
3.新增原始碼
4.tomcat啟動報錯
圖中表示tomcat埠被佔用.關閉服務即可.
5.打包報錯
如果出現上述報錯,則按照順序jt-parent/jt-common/jt-manage
9. 專案水平拆分
9.1 概念描述
說明:按照程式的層級進行拆分(聚合專案)
View層----Controller----Service------dao-------pojo
9.2 專案建立
1. 建立專案jt-aa
2. 專案型別劃分
Jt-aa-controller war包
Jt-aa-service jar包
Jt-aa-dao jar包
Jt-aa-pojo jar包
9.3 水平拆分專案建立規則
1. 選擇模組型別
2. 建立子模組
3. 根據規則建立模組專案
9.4 水平拆分後項目依賴關係
依賴順序:
Controller----Service------dao-------pojo
新增繼承和依賴
1.父級專案繼承
2.aa中的依賴
3.聚合專案詳情
打包: