centos7上部署spring cloud微服务


前言

基于上一章部署了spring cloud主要基础服务,本章部署一套spring cloud微服务,用于学习。
代码仓库和分支地址

一、技术架构

在这里插入图片描述

二、模块划分

在这里插入图片描述

三、数据库设计

字段对不上的以代码库中的flyway的脚本内容为准

-- 建立用户数据库
-- 创建对应的数据库用户
create database userinfo;
create user 'userinfo'@'%' IDENTIFIED by 'userinfo';
GRANT ALL PRIVILEGES ON userinfo.* TO 'userinfo'@'%';

create database productinfo;
create user 'productinfo'@'%' IDENTIFIED by 'productinfo';
GRANT ALL PRIVILEGES ON productinfo.* TO 'productinfo'@'%';

create database orderinfo;
create user 'orderinfo'@'%' IDENTIFIED by 'orderinfo';
GRANT ALL PRIVILEGES ON orderinfo.* TO 'orderinfo'@'%';

-- 使用flyaway管理数据库初始化信息,项目启动时自动创建表

-- 用户表
CREATE TABLE user_info (
  id bigint PRIMARY KEY AUTO_INCREMENT,
  name varchar(255) comment '名字',
  birth_day datetime comment '出生日期',
  gender varchar(255) comment '性别',
  mobile varchar(255) comment '手机号',
  email varchar(255) comment '邮箱',
  password varchar(255) comment '密码',
  type varchar(255) comment '类型:商家、消费者、管理员',
  create_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  update_time datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  deleted int comment '删除状态 0未删除1已删除',
  index idx_name(name,password,type) comment 'name索引'
)comment='用户表';

-- 地址信息表
CREATE TABLE user_address (
  id bigint PRIMARY KEY AUTO_INCREMENT,
  name varchar(255) comment '地址名称',
  detail varchar(255) comment '地址详情',
  user_id bigint comment '用户id',
  create_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  update_time datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  deleted int comment '删除状态 0未删除1已删除',
  index idx_user_id(user_id) comment 'user_id索引'
)comment='用户地址表';



-- 商品信息表
CREATE TABLE product_info(
  id bigint PRIMARY KEY AUTO_INCREMENT,
  name varchar(255) comment '商品名称',
  type varchar(255) comment '商品类型',
  price bigint comment '价格,单位为分',
  cover_image varchar(500) comment '封面图',
  detail varchar(255) comment '详细描述',
  store_count bigint comment '商品数量',
  user_id bigint comment '所属商家',
  create_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  update_time datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  deleted int comment '删除状态 0未删除1已删除',
  index idx_name(name_price) comment 'name索引',
  index idx_type(type_price) comment '类型索引',
  index idx_user_id(user_id) comment '商家id索引'
)comment='商品表';

-- 商品评论表
CREATE TABLE product_comment(
  id bigint PRIMARY KEY AUTO_INCREMENT,
  parent_comment_id bigint comment '回复评论的内容',
  product_order_id bigint comment '订单号,可以为空',
  product_id bigint comment '商品id',
  user_id bigint comment '用户',
  comment_content varchar(500) comment '评论内容',
  create_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  update_time datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  deleted int comment '删除状态 0未删除1已删除',
  index idx_product_id(product_id) comment '产品id索引',
  index idx_user_id(user_id) comment '用户索引'
)comment='商品评论表';


-- 商品订单表
CREATE TABLE order_info(
  id bigint PRIMARY KEY AUTO_INCREMENT,
  order_no varchar(255) comment '订单号',
  user_id bigint comment '用户',
  user_name varchar(255) comment '用户名称',
  user_address varchar(255) comment '地址',
  user_payment bigint comment '支付价格,单位为分',
  sale_user_id bigint comment '卖家id',
  sale_user_name varchar(255) comment '卖家名称',
  create_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  update_time datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  status varchar(255) comment '订单状态',
  deleted int default 0 comment '删除状态 0未删除1已删除',
  index idx_user_id(user_id) comment 'user_id索引',
  index idx_sale_user_id(sale_user_id) comment 'sale_user_id索引'
)comment='商品订单表';

-- 商品订单详情
create table order_detail(
  id bigint PRIMARY KEY AUTO_INCREMENT,
  order_info_id bigint comment '订单id',
  product_id bigint comment '商品id',
  product_name varchar(255) comment '商品名称',
  product_type varchar(255) comment '商品类型',
  product_price bigint comment '价格,单位为分',
  product_cover_image varchar(500) comment '封面图',
  product_detail varchar(255) comment '详细描述',
  index idx_order_info_id (order_info_id) comment 'order_info_id 索引'
)comment='商品订单详情表';

四、接口设计

登录(/gateway/user/login)
新增订单(/orderinfo/order/createOrder)
订单列表(/orderinfo/order/orderList)

四、linxu上部署

在这里插入图片描述
先启动eureka和configserver,然后再启动其他服务

nohup /root/program/jdk-17/bin/java -jar /root/program/springcloud/eurekaserver-0.0.1-SNAPSHOT.jar > /root/program/springcloud/eurekaserver.log 2>&1 &
nohup /root/program/jdk-17/bin/java -jar /root/program/springcloud/configserver-0.0.1-SNAPSHOT.jar > /root/program/springcloud/configserver.log 2>&1 &
nohup /root/program/jdk-17/bin/java -jar /root/program/springcloud/gateway-0.0.1-SNAPSHOT.jar > /root/program/springcloud/gateway.log 2>&1 &
nohup /root/program/jdk-17/bin/java -jar /root/program/springcloud/orderinfo-server-0.0.1-SNAPSHOT.jar > /root/program/springcloud/orderinfo-server.log 2>&1 &
nohup /root/program/jdk-17/bin/java -jar /root/program/springcloud/productinfo-server-0.0.1-SNAPSHOT.jar > /root/program/springcloud/productinfo-server.log 2>&1 &
nohup /root/program/jdk-17/bin/java -jar /root/program/springcloud/userinfo-server-0.0.1-SNAPSHOT.jar > /root/program/springcloud/userinfo-server.log 2>&1 &

五、配置nginx

 添加个upstream
 upstream springGateway {
         server 192.168.18.11:8080;
 }
 server模块中添加location
 location /gateway {
  proxy_pass http://springGateway;
 }
 location /userinfo {
     proxy_pass http://springGateway;
 }
 location /productinfo {
     proxy_pass http://springGateway;
 }
 location /orderinfo {
     proxy_pass http://springGateway;
 }

欢迎添加好友,相互学习进步~
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值