谷粒商城-个人学习(1)

本文是作者学习谷粒商城分布式系统的个人笔记,包括环境搭建的详细步骤,如虚拟机、docker、数据库(mysql和redis)的配置,以及项目创建、逆向工程、公共依赖的设置。适合初学者入门分布式系统和微服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对于应届生来说,秋招的时候是否有合适的实习、项目、竞赛经验真的很重要。
希望这篇学习总结笔记对他人会有帮助吧。
对拥有相同经历的被导师卡着不能出去实习的专硕表示同情,并共勉。
加油吧。

谷粒商城-个人学习笔记

谷粒学院的微服务分布式电商系统,免费的,B站资源一抓一大把。作为分布式和商城系统的入门项目。
感谢博主的细致总结
https://blog.csdn.net/hancoder/article/details/106922139

分布式系统

在一个分布式系统中,一组独立的计算机展现给用户的是一个统一的整体,就好像是一个系统似的。系统拥有多种通用的物理和逻辑资源,可以动态的分配任务,分散的物理和逻辑资源通过计算机网络实现信息交换。
说人话就是以前的单个计算机无法承载巨大的计算或存储需求,因此,将任务压力分散到各个机器上,多个机器构成一个完整的系统来提供服务(人多力量大,机器多算力强)。最常见的模式就是,按服务功能划分多个服务器,分别部署到多个集群(多个物理机器)当中,服务器间通过网络请求的方式完成互相调用。
当然,增加了算力和存储能力的同时,也引入了其他问题。例如服务器的管理,网络通信,数据一致性等问题,后续慢慢学习。

环境搭建

虚拟机

视频老师采用的是vagrant+virtual box搭建虚拟环境。个人使用的是vmware

docker

官网文档找到合适自己的系统,照着指令敲就完事了
https://docs.docker.com/engine/install/
下面这是中文的
https://www.runoob.com/docker/centos-docker-install.html

#卸载系统之前的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

# 配置镜像
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
    
sudo yum install docker-ce docker-ce-cli containerd.io
# 开启docker
sudo systemctl start docker
# 设置开机自启动
sudo systemctl enable docker

下载镜像可以用阿里云镜像加速,内容略
https://blog.csdn.net/hancoder/article/details/106922139
https://www.cnblogs.com/LUA123/p/11401962.html

mysql

sudo docker pull mysql:5.7

# --name指定容器名字 -v目录挂载 -p指定端口映射  -e设置mysql参数 -d后台运行
sudo 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

安装完mysql对其进行一些配置上的修改

vi /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
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

#重启mysql
docker restart mysql

redis

mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf

docker pull redis

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

# 配置持久化操作
vim /mydata/redis/conf/redis.conf
# conf中添加下面内容
appendonly yes
# 重启
docker restart redis

开机自启动

sudo docker ps
sudo docker ps -a
# 这两个命令的差别就是后者会显示  【已创建但没有启动的容器】

# 我们接下来设置我们要用的容器每次都是自动启动
sudo docker update redis --restart=always
sudo docker update mysql --restart=always
# 如果不配置上面的内容的话,我们也可以选择手动启动
sudo docker start mysql
sudo docker start redis
# 如果要进入已启动的容器
sudo docker exec -it mysql /bin/bash

maven

本地安装本地的maven,idea自带的莫名其妙出问题。修改setting,配置阿里的源,下载时速度快。
安装插件lombok,mybatisX

VScode

主要用作前端开发,需要安装插件
Auto Close Tag
Auto Rename Tag
Chinese
ESlint
HTML CSS Support
HTML Snippets
JavaScript ES6
live Server
open in browser
Vetur

git

安装git,注册码云,github账号,如何使用,强推廖雪峰老师的教程
https://www.liaoxuefeng.com/wiki/896043488029600/

数据库

B站评论下有完整的SQL文件自取,并根据视频直接构建好数据库(无数据)
创建时字符集选utf8mb4
gulimall-oms
gulimall-pms
gulimall-sms
gulimall-ums
gulimall-wms

创建基础项目

gitee上创建仓库后,clone到本地,idea打开
依照各个模块搭建微服务项目
new-module-spring initializer
group: com.atguigu.gulimall
artifact:gulimall-XXX
package:com.atguigu.gulimall.XXX{product/order/ware/coupon/member}
module:gulimall-XXX
依赖选择web和spring cloud构建完成后

完成后,随意拷一份pom到项目根目录,修改成如下样子,聚合所有的项目,这样就能在idea的maven页签中统一集中管理所有的微服务

<?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>
	</modules>
</project>

修改.gitignore把无关文件忽视掉,提交时仅提交src和pom.xml
IDEA安装gitee插件可以实现提交

人人开源

码云上搜人人开源,renren-fast(后台)和renren-fast-vue(前台)组成一套前后端管理系统。
renren-fast中的sql创建数据库同时导入数据,并在项目的pom中聚合,测试连接后台,前台npm install安装依赖,npm run dev打开前台页面。查看前后是否调通

逆向工程

使用renren-generator
配置数据库连接,配置逆向生成的,主目录,包名,模块名等,逐个逆向出数据库中的内容,并解压放到各个微服务中。

公共依赖

各个微服务都要访问数据库,都要发送数据请求,有很多公共的部分,因此构建一个公共模块让所有的微服务依赖

<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.13</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

同时将公共依赖模块也添加到主项目的pom中
在各个微服务模块中添加gulimall-common的依赖

<dependency>
    <groupId>com.atguigu.gulimall</groupId>
    <artifactId>gulimall-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

逆向出来的@RequiresPermissions是shior使用的,在逆向的模板中注释掉,重新生成,并覆盖。
调整需要的内容,例如Query,PageUtils,R,Constant,exception等,都直接从renren-fast中复制到common中
common的pom添加依赖继续解决报错

<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.17</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>

至此公共部分配置完成

测试调通

各个微服务添加application.yml

spring:
  datasource:
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://xxxIP:3306/xxxTABLE?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: root
mybatis-plus:
  mapper-locations: classpath:/mapper/**/*.xml
  global-config:
    db-config:
      id-type: auto

主启动类加上
@MapperScan(“com.atguigu.gulimall.product.dao”)
写测试类测试数据库连接,能看到返回空即可

至此项目初始化完成,后续章节引入spring cloud的内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值