億級流量架構|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 Mavenjar包如何自動依賴

說明:Maven加載jar包的過程

  1. 根據POM文件的座標首先到本地倉庫/私服鏡像中查詢jar包.
  2. 在引入jar包文件之前,需要先加載該jar包的pom.xml文件,對其中依賴的jar包再次解析.
  3. 解析完成後.實現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包版本匹配.

網址: http://mvnrepository.com/

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.聚合項目詳情

打包:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章