day68_淘淘商城專案_01_電商介紹 + 網際網路術語 + SOA + 分散式 + 叢集介紹 + 環境配置 + 框架搭建_匠心筆記
阿新 • • 發佈:2019-01-12
淘淘商城專案_01
- 1、電商行業的背景介紹--電子商務
- 2、淘淘商城的系統架構
- 3、技術選型和開發環境
- 4、工程搭建--後臺工程
- 4.1、使用maven的好處
- 4.2、後臺工程搭建分析
- 4.3、工程搭建
- 4.3.1、taotao-parent
- 4.3.2、taotao-common
- 4.3.3、taotao-manager
- 4.3.4、taotao-manager-pojo
- 4.3.5、taotao-manager-dao
- 4.3.6、taotao-manager-interface
- 4.3.7、taotao-manager-service
- 4.3.8、taotao-manager-web
- 4.4、使用maven的tomcat外掛啟動web工程
- 4.5、使用maven的tomcat外掛啟動聚合工程
- 5、SVN的使用
課程計劃
- 第一天:
- 1、電商行業的背景介紹–電子商務
- 2、淘淘商城的系統架構
- a) 功能介紹
- b) 架構講解
- 3、工程搭建–後臺工程
- a) 使用maven搭建工程(工程大)
- b) 使用maven的tomcat外掛啟動工程
- 4、SVN的使用
- 第二天:
- 1、服務中介軟體dubbo–遠端呼叫技術
- 2、SSM框架整合
- 3、整合測試
- 4、商品列表查詢功能實現
- 第三天:
- 1、商品類目選擇
- 2、圖片上傳
- a) 圖片伺服器FastDFS
- b) 圖片上傳功能實現
- 3、富文字編輯器KindEditor的使用
- 4、商品新增功能完成
- 第四天:
- 1、前臺系統搭建
- 2、CMS系統的實現–內容管理系統
- a) 內容分類管理
- b) 內容管理
- 3、前臺內容動態展示
- 第五天:
- 1、Redis伺服器搭建–快取
- 2、向業務邏輯中新增快取
- 3、使用redis做快取
- 4、快取同步
- 5、Solr伺服器安裝–搜尋
- 第六天:
- 1、Solrj使用測試–Solr服務的java客戶端
- 2、把資料庫中的資料匯入索引庫
- 3、搜尋功能的實現
- 第七天:
- 1、Solr叢集搭建–SlorCloud
- 2、使用solrj管理solr叢集
- 3、把搜尋功能切換到叢集版
- 第八天:
- 1、什麼是MQ–訊息佇列
- 2、MQ的應用場景
- 3、ActiveMQ的使用方法
- 4、使用訊息佇列實現商品同步
- 第九天:
- 1、商品詳情頁面展示–動態展示 jsp + redis
- 2、使用freemarker實現網頁靜態化
- 3、ActiveMq同步生成靜態網頁
- 第十天:
- 1、Nginx的安裝–訪問靜態資源
- 2、Nginx配置虛擬機器
- 3、Nginx實現反向代理
- 4、Nginx實現負載均衡
- 5、SSO系統工程搭建–單點登入系統
- 第十一天:
- 1、SSO註冊功能實現
- 2、SSO登入功能實現
- 3、通過token獲得使用者資訊
- 4、Ajax跨域請求(jsonp)
- 第十二天:
- 1、購物車實現
- 2、訂單確認頁面展示
- 第十三天:
- 1、訂單系統完成
- 2、系統部署–上線流程
- 第十四天~十六天:
- 專案實戰–需求、分組、實現
- 專案總結
1、電商行業的背景介紹–電子商務
近年來,中國的電子商務快速發展,交易額連創新高,電子商務在各領域的應用不斷拓展和深化、相關服務業蓬勃發展、支撐體系不斷健全完善、創新的動力和能力 不斷增強。電子商務正在與實體經濟深度融合,進入規模性發展階段,對經濟社會生活的影響不斷增大,正成為我國經濟發展的新引擎。
中國電子商務研究中心資料顯示,截止到2012年底,中國電子商務市場交易規模達7.85萬億人民幣,同比增長30.83%。其中,B2B電子商務交易額達6.25萬億,同比增長27%。而2011年全年,中國電子商務市場交易額達6萬億人民幣,同比增長33%,佔GDP比重上升到13%;2012年,電子商務佔GDP的比重已經高達15%。預計2013年我國電子商務規模將突破十萬億大關。
1.1、11.11
- 結論:
- 1、電商行業很掙錢,找網際網路相關的工作。
- 2、電商行業技術要求很高、高可用、海量資料的儲存。
1.2、電商行業技術特點
- 技術新
- 技術範圍廣
- 分散式
- 高併發、叢集、負載均衡、高可用
- 海量資料
- 業務複雜
- 系統安全
2、淘淘商城的系統架構
2.1、淘淘商城介紹
淘淘網上商城是一個綜合性的B2C平臺,類似京東商城、天貓商城。會員可以在商城瀏覽商品、下訂單,以及參加各種活動。
管理員、運營可以在平臺後臺管理系統中管理商品、訂單、會員等。
客服可以在後臺管理系統中處理使用者的詢問以及投訴。
- 電商模式:
- B2B:商家到商家。阿里巴巴、1688(批發)、慧聰網、銘萬網。
- B2C:商家(京東)到使用者。京東(自營)。
- C2C:使用者到使用者。淘寶(趕集)。
- B2B2C:商家(天貓)到商家(耐克)到使用者。天貓(開發票)。
- O2O:線上到線下。百度外賣、美團外賣、餓了麼。
2.2、功能介紹
- 後臺管理系統:管理商品、訂單、類目、商品規格屬性、使用者管理以及內容釋出等功能。
- 前臺系統:使用者可以在前臺系統中進行註冊、登入、瀏覽商品、首頁、下單等操作。
- 會員系統:使用者可以在該系統中查詢已下的訂單、收藏的商品、我的優惠券、團購等資訊。
- 訂單系統:提供下單、查詢訂單、修改訂單狀態、定時處理訂單。
- 搜尋系統:提供商品的搜尋功能。
- 單點登入系統:為多個系統之間提供使用者登入憑證以及查詢登入使用者的資訊。
2.3、系統架構
2.3.1、傳統架構
- 存在的問題:
- 1、功能耦合度高
- 2、系統維護成本高
- 3、如果併發量大,無法解決高併發的問題
2.3.2、1000個併發
- 存在的問題:
- 1、系統無法有效進行水平擴充套件(叢集不能針對功能模組)
- 2、使用者存在重複登入的問題
- 針對第二點:需要session共享,是以session廣播的形式,比較消耗資源(寬頻)。
- 如果要達到10000併發
- 需要20臺伺服器做tomcat叢集。
- 注意:當tomcat叢集中節點數量增加,服務能力先增加後下降。所以叢集中節點數量不能太多,一般也就
5個
左右。
2.3.3、分散式架構(10000個併發)
- 需要按照功能點把系統
拆分
,拆分成獨立的功能。單獨為某一個節點新增伺服器。需要系統之間配合才能完成整個業務邏輯。叫做分散式
。
- 分散式架構:多個子系統相互協作才能完成業務流程。系統之間需要進行
通訊
。 - 叢集:
同一個工程部署到多臺伺服器上
。相當於同一個工程程式碼拷貝多份部署到多臺伺服器,每臺伺服器單獨獨立部署執行。 - 分散式架構:
- 把系統按照模組拆分成多個子系統,多個子系統相互協作才能完成業務流程系統之間需要進行通訊。
- 優點:
- 1、把模組拆分,
使用介面通訊
,降低
模組之間的耦合度
。 - 2、把專案拆分成若干個子專案,不同的團隊負責不同的子專案。
- 3、增加功能時只需要再增加一個子專案,呼叫其他系統的介面就可以。
- 4、可以
靈活
的進行分散式部署
。
- 1、把模組拆分,
- 缺點:
- 1、系統之間互動需要使用遠端通訊,介面開發
增加工作量
。 - 2、各個模組有一些通用的
業務邏輯無法共用
。
- 1、系統之間互動需要使用遠端通訊,介面開發
2.3.4、基於SOA的架構
SOA:Service Oriented Architecture
面向服務的架構
。也就是把工程拆分成服務層
、表現層
兩個工程。服務層中包含業務邏輯,只需要對外提供服務即可。表現層只需要處理和頁面的互動,業務邏輯都是呼叫服務層的服務來實現。
2.3.5、淘淘商城系統架構
3、技術選型和開發環境
3.1、技術選型
- Spring、SpringMVC、Mybatis
- JSP、JSTL、jQuery、EasyUI、KindEditor(富文字編輯器)
- Redis(快取伺服器,單點登入,購物車)
- Solr(全文搜尋)
- dubbo(分散式服務框架)
- HttpClient(HTTP 協議訪問客戶端)
- ActiveMQ(訊息佇列)
- Quartz(定時任務)
- FastDFS(圖片伺服器)
- FreeMarker(網頁靜態化)
- Nginx(反向代理伺服器)
- MyCat(資料庫中介軟體)
3.2、開發工具版本和環境
- Eclipse Mars.2 Release (4.5.2)
- Maven 3.5.4
- Tomcat 7.0.47(Maven Tomcat Plugin)
- JDK 1.7
- Mysql 5.7
- Dubbo 2.5.3
- Nginx 1.8.0
- Redis 3.0.0
- ActiveMQ 5.13.0
- Win10 作業系統
- SVN (版本管理)
4、工程搭建–後臺工程
4.1、使用maven的好處
- 使用maven管理工程的好處如下:
-
- jar包的管理
-
- 工程之間的依賴管理
-
- 自動打包
-
- 統一的版本的控制
-
4.2、後臺工程搭建分析
詳解如下:
Maven的常見打包方式:jar、war、pom
pom工程一般都是父工程,管理jar包的版本、maven外掛的版本、統一的依賴管理。聚合工程。
taotao-parent:父工程,打包方式pom,管理jar包的版本號。
| 專案中所有工程都應該繼承父工程。
|--taotao-common:通用的工具類、通用的pojo。打包方式jar
|--taotao-manager:服務層工程。聚合工程。pom工程
|--taotao-manager-pojo:打包方式jar
|--taotao-manager-dao:打包方式jar
|--taotao-manager-interface:打包方式jar
|--taotao-manager-service:打包方式war (為了釋出服務的方便)
|--taotao-manager-web:表現層工程。打包方式war
4.3、工程搭建
Maven相關配置:
- M2Eclipse是eclipse中的Maven外掛。(低版本的ecplise需要手動安裝,高版本的eclipse自帶,本博主用的是高版本的ecplise)
- M2Eclipse是MyEclipse中自帶的Maven外掛。
- 注意:
- 如果我們單獨用命令列的方式進行maven的使用時,我們使用者的配置檔案預設在~/.m2/setting.xml
- 如果我們使用Eclipse或者MyEclipse的方式進行maven的使用時,我們使用者的配置檔案可以想放哪裡就放哪裡,只需要指定配置檔案的路徑即可。
- 注意:
- 本地倉庫目錄:預設位置在:~/.m2/repository
- 因為我們使用eclipse開發,所以我們把本地倉庫放到我們安排好的目錄中,需要在eclipse中指定使用者的配置檔案路徑即可。如下圖:
- 本地倉庫的使用,我們既可以提前下好所需要的jar包,也可以邊開發邊聯網下載!
Eclipse相關配置:
- eclipse 設定預設編碼為Utf-8
- 需要設定的幾處地方為:
- Window --> Preferences --> General --> Content Type --> Text --> JSP 最下面設定為UTF-8
- Window --> Preferences --> General --> Workspace 面板Text file encoding 選擇UTF-8
- Window --> Preferences --> Web --> JSP Files 面板選擇 ISO 10646/Unicode(UTF-8)
- Window --> Preferences --> General --> Workspace 面板 New text file line delimiter 選擇 Unix
4.3.1、taotao-parent
- 父工程必須是pom工程。
- 建立步驟如下:
(1)
(2)
(3)
- 建立步驟如下:
- pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.taotao</groupId>
<artifactId>taotao-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<!-- 集中定義依賴版本號 -->
<properties>
<junit.version>4.12</junit.version>
<spring.version>4.2.4.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>
<slf4j.version>1.6.4</slf4j.version>
<jackson.version>2.4.2</jackson.version>
<druid.version>1.0.9</druid.version>
<httpclient.version>4.3.5</httpclient.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-io.version>1.3.2</commons-io.version>
<commons-net.version>3.3</commons-net.version>
<pagehelper.version>3.4.2-fix</pagehelper.version>
<jsqlparser.version>0.9.1</jsqlparser.version>
<commons-fileupload.version>1.3.1</commons-fileupload.version>
<jedis.version>2.7.2</jedis.version>
<solrj.version>4.10.3</solrj.version>
<dubbo.version>2.5.3</dubbo.version>
<zookeeper.version>3.4.7</zookeeper.version>
<zkclient.version>0.1</zkclient.version>
<activemq.version>5.13.0</activemq.version>
<freemarker.version>2.3.23</freemarker.version>
<quartz.version>2.2.2</quartz.version>
</properties>
<!-- 統一依賴jar包版本的管理, 其下的標籤dependencies只是版本的管理,並不是依賴jar包-->
<dependencyManagement>
<dependencies>
<!-- 時間操作元件 -->
<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>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>${commons-net.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>
<!-- quartz任務排程框架 -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
</dependency>
<!-- 單元測試 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope><!-- test表示該範圍傳遞不到下面去 -->
</dependency>
<!-- 日誌處理 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.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>
<!-- mybatis分頁 相關的,暫時沒有用到 -->
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
<version>${mybatis.paginator.version}</version>
</dependency>
<!-- 分頁外掛pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- 連線池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<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>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</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