尚硅谷2020微服务分布式电商项目《谷粒商城》
项目简介
资料
-
百度云
链接:https://pan.baidu.com/s/1eGCTi6pLtKbDCwBs-zCOzQ 提取码:1pma
涉及技术
-
前端技术
-
Vue
-
renren-fast-vue基于vue、element-ui构建开发,实现renren-fast后台管理前端功能,提供一套更优的前端解决方案。
http://demo.open.renren.io/renren-fast
-
-
ES6
-
-
后端技术
-
spring boot
-
renren-fast是一个轻量级的Spring Boot2.1快速开发平台,其设计目标是开发迅速、学习简单、轻量级、易扩展;使用Spring Boot、Shiro、MyBatis、Redis、Bootstrap、Vue2.x等框架,包含:管理员列表、角色管理、菜单管理、定时任务、参数管理、代码生成器、日志管理、云存储、API模块(APP接口开发利器)、前后端分离等。
-
-
spring cloud
-
spring alibaba
- nacos(注册配置中心)
-
OpenFeign(微服务远程调用)
-
GateWay(API网关)
-
-
人人开源项目的代码生成器,可在线生成entity、xml、dao、service、vue、sql代码,减少70%以上的开发任务
-
-
数据库技术
- MySQL
- redis
-
包管理工具
- npm
- maven
环境搭建
编辑器
-
链接:https://pan.baidu.com/s/1_3cewjaPwz5yEkRtwEpJfQ 提取码:81fd
- Plugins
- Gitee
- Lombok
- MyBatisX
File | Settings | Editor | File Encodings
设置为UTF-8,勾选Transparent native-to-ascii conversion
- Plugins
-
- extensions
- Auto Close Tag
- Auto Rename Tag
- Chinese(Simplified) Language Pack
- ESLint
- HTML CSS Support
- HTML Snippets
- JavaScript(ES6) code snippets
- Live Server
- open in browser
- Vetur
- extensions
Linux虚拟机chenhao02
- 安装Centos7
- 配置静态IP
安装docker
-
安装docker
$ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine $ sudo yum install -y yum-utils # 官网yum源 $ sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo # 阿里云yum源 $ sudo yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 将软件包信息提前在本地缓存一份,用来提高搜索安装软件的速度 yum makecache fast $ sudo yum install docker-ce docker-ce-cli containerd.io $ sudo systemctl start docker
-
查看docker信息
docker -v docker images # 开机启动 systemctl enable docker
-
修改docker源为阿里云
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://aeb49y3h.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
-
docker镜像自动启动
docker update redis --restart=always docker update mysql --restart=always
安装mysql
-
安装mysql
docker pull mysql:5.7
-
配置mysql
docker run -p 3306:3306 --name mysql \ -v /mydata/mysql/log:/var/log/mysql \ -v /mydata/mysql/data:/var/lib/mysql \ -v /mydata/mysql/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:5.7
-
查看状态
docker images docker ps docker exec -it mysql /bin/bash
-
配置config文件
/mydata/mysql/conf/my.conf
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collection-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve
-
使用资料中的sql文件(gulimall_*.sql)创建微服务数据库基字符集使用utf8mb4
安装redis
-
安装redis
docker pull redis
-
配置redis
mkdir -p /mydata/redis/conf touch /mydata/redis/conf/redis.conf docker run -p 6379:6379 --name redis \ -v /mydata/redis/data:/data \ -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \ -d redis redis-server /etc/redis/redis.conf
-
查看信息
docker ps docker images
-
# 配置持久化 appendonly yes
Maven配置
-
配置setting.xml文件
<mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <profiles> <id>jdk-1.8</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> </profiles>
-
IDEA配置Maven
File | Settings | Build, Execution, Deployment | Build Tools | Maven
配置
码云git配置
node配置淘宝镜像
npm config set registry http://registry.npm.taobao.org/
前端项目搭建
-
开源项目源码下载人人开源 / renren-fast-vue
git clone git@gitee.com:renrenio/renren-fast-vue.git
-
依赖包下载
git install
-
sass安装报错解决方法
完美解决 sass安装失败的问题
- vscode 下在项目根目录打开终端,npm install node-sass@4.13.1,项目默认的 sass地址一直404的话可以考虑这样做
- 安装完成后打开 package-lock.json ctrl+f 查找 sass,当version="4.13.1"时证明安装成功(当然前提是上一步没报错)
- npm run dev
- 补充一点 我事先将 npm版本切换到 6.9.0了 sudo npm -g install npm@6.9.0(这条命令是在根目录下运行,不是项目根)
关于新谷粒P16的前段项目使用npm install报错的问题,首先确保安装了python3.0以上版本,并配置全局变量
其次大部分错误是报node-sass4.9.0安装失败。
执行以下步骤可以完美解决
首先把项目文件夹下的package.json里面的node-sass4.9.0改成4.9.2(不改可能也没关系,不过我改了,防止踩坑)
然后项目文件夹下打开cmd命令窗口(和Visual Studio Code的终端命令是一样的)
执行:
npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
执行成功看看有没有报错,如果没报错执行下面命令
npm install ,
没报错就是安装成功,然后使用npm run dev 就ok了
注:这么做得原理就是先单独从淘宝镜像吧nod-sass下载下来,然后再进行编译,因为这句命令好像是不成功后的,(npm config set registry http://registry.npm.taobao.org/),默认从github下载,导致报错的 -
依赖安装后运行
npm run serve
后端搭建
项目结构创建
-
使用Spring Intitializr创建模块
- Project Metadata
- Group: com.atguigu.gulimall
- Artifact: gulimall-product
- Package: com.atguigu.gulimall.product
- Dependencies添加依赖
- Web-Spring Web
- Spring Cloud Routing-OpenFeign
- Project Metadata
-
创建以下几个微服务模块
- gulimall-coupon
- gulimall-member
- gulimall-order
- gulimall-product
- gulimall-ware
-
创建主pom.xml文件管理这些微服务
<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.atguigu.gulimall</groupId> <artifactId>gulimall</artifactId> <version>0.0.1-SNAPSHOT</version> <name>gulimall</name> <description>聚合服务</description> <packaging>pom</packaging> <modules> <module>gulimall-coupon</module> <module>gulimall-member</module> <module>gulimall-order</module> <module>gulimall-product</module> <module>gulimall-ware</module> <module>renren-fast</module> <module>renren-generator</module> <module>gulimall-common</module> </modules> </project>
-
通过IDEA的Maven可管理所有微服务
-
修改.gitignore文件
target/ pom.xml.tag pom.xml.releaseBackup pom.xml.versionsBackup pom.xml.next release.properties dependency-reduced-pom.xml buildNumber.properties .mvn/timing.properties .mvn/wrapper/maven-wrapper.jar **/mvnw **/mvnw.cmd .mvn .idea **/.gitignore
后台项目搭建
-
git clone git@gitee.com:renrenio/renren-fast.git
-
添加主pom.xml文件管理
<modules> <module>renren-fast</module> </modules>
-
使用数据库文件创建数据库gulimall_admin
-
修改参数配置文件
spring: datasource: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://chenhao02:3306/gulimall_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: root password: root initial-size: 10 max-active: 100 min-idle: 10 max-wait: 60000 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 #Oracle需要打开注释 #validation-query: SELECT 1 FROM DUAL test-while-idle: true test-on-borrow: false test-on-return: false stat-view-servlet: enabled: true url-pattern: /druid/* #login-username: admin #login-password: admin filter: stat: log-slow-sql: true slow-sql-millis: 1000 merge-sql: false wall: config: multi-statement-allow: true
-
启动运行为前端项目提供数据
逆向工程代码生成器
git clone git@gitee.com:renrenio