1.后端使用的技术栈
注册中心:Spring Cloud Eureka
网关中心:Spring Cloud Zuul
服务配置:Spring Cloud Config
链路追踪:Spring Cloud Zipkin
数据库连接:Druid、Mybatis
服务鉴权:Shiro+JWT
数据库:MySQL
日志收集:ELK(服务安装在虚拟机)
服务之间调用: Feign
熔断机制:Hystrix
消息队列:RabbitMQ
数据缓存:Redis
2.项目架构图
3.系统各模块介绍
cloud-ida:项目父模块,所有以下子模块依赖该父模块(可在该pom文件加入所需要的依赖)
cloud-ida-admin : 后台管理模块(包含前后端),包括用户、角色、权限管理及服务监控
cloud-ida-admin-server : 使用springboot admin,监控各服务运行状况
cloud-ida-common : common模块,封装模块常用bean及工具类
cloud-ida-config : 分布式配置中心,可将各模块所需的配置放到该中心(dev/uat/pro)
cloud-ida-eureka : 服务发现、注册中心
cloud-ida-service : 业务服务模块(可按业务拆分成多个服务)
cloud-ida-zipkin : 服务链路追踪
cloud-ida-zuul : 微服务网关层,所有请求都经过网关请求,此模块中也有shiro认证、鉴权
4.端口分配
cloud-ida-admin: 9000
cloud-ida-admin-server: 9010
cloud-ida-config : 8888
cloud-ida-eureka : 8761
cloud-ida-service-tag : 8087
cloud-ida-zipkin : 9411
cloud-ida-zuul : 9084
5.运行该项目
5.1 运行基本环境安装
5.1.1 安装Redis 详情步骤查看本人博文 Window 7 系统下安装Redis
5.1.2 安装RabbitMQ 详情步骤查看博文 Windows下RabbitMQ安装及配置
5.1.3 安装配置MySQL数据库
5.1.4 安装Maven环境
5.1.5 安装Vue运行环境(NodeJS) 及设置淘宝镜像 详情步骤查看博文 搭建 vue 开发环境: node.js安装+vue脚手架配置
5.2 下载项目导入Eclipse环境及运行
5.2.1 开源项目下载地址: Spring-Cloud-Cli
5.2.2 下载项目后将项目导入Eclipse开发环境中,MySQL数据库新建库cloud-ida
5.2.3 将工程表模型文件夹下的“初始化表模型”和"初始化表模型测试数据"文本文件复制到MySQL客户端编译执行,建表,插入数据
5.2.4 在cloud-ida-admin子模块下新建schema.sql和data.sql,文件如下:
schema.sql
DROP TABLE IF EXISTS ida_permission;
create table ida_permission(
permission_id serial PRIMARY KEY,
permission_name varchar(255),
permission_url varchar(255),
parent_permission_id integer,
permission_lv integer,
permission_auth varchar(255)
);
DROP TABLE IF EXISTS ida_role;
CREATE TABLE ida_role (
role_id serial PRIMARY KEY,
role_name varchar(255)
);
DROP TABLE IF EXISTS ida_role_permission;
CREATE TABLE ida_role_permission (
id serial PRIMARY KEY,
role_id integer,
permission_id integer
);
DROP TABLE IF EXISTS ida_user;
CREATE TABLE ida_user (
user_id serial PRIMARY KEY,
user_name varchar(255),
user_role_names varchar(255),
user_account varchar(255),
user_password varchar(255)
);
DROP TABLE IF EXISTS ida_user_role;
CREATE TABLE ida_user_role (
id serial PRIMARY KEY,
user_id integer,
role_id integer
);
data.sql
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (1, '用户管理', null, '0', '1','');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (2, '新增修改', '/user-post', '1', '2','upost');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (3, '列表查询', '/user-get', '1', '2','uget');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (4, '删除用户', '/user/{id}-delete', '1', '2','udelete');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (5, '角色管理', null, '0', '1','');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (6, '新增修改', '/role-post', '5', '2','rpost');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (7, '列表查询', '/role-get', '5', '2','rget');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (8, '删除角色', '/role/{id}-delete', '5', '2','rdelete');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (9, '角色授权', '/role-authorization-post', '5', '2','rauth');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (10, '权限管理', null, '0', '1','');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (11, '新增修改', '/permission-post', '10', '2','ppost');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (12, '列表查询', '/permission-get', '10', '2','pget');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (13, '删除权限', '/permission/{id}-delete', '10', '2','pdelete');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (14, '预览权限', '/permission-view-get', '10', '2','pview');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (15, '菜单', null, '0', '1','');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (16, '标签取数','/tag-index','15','2','tindex');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (17,'模板取数','/tag-fetch-data','15','2','tftemplet');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (18, '客户群','/tag-cluster','15','2','tcluster');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (19, '常规标签配置','/tag-simple','15','2','tsconfig');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (20, '标签工厂','/tag-factory','15','2','tfconfig');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (21, 'tag服务权限控制',null,'0','1','');
INSERT INTO ida_permission(permission_id, permission_name, permission_url, parent_permission_id, permission_lv, permission_auth)
VALUES (22, '通过id获取用户信息','/api-tag/tag/getUserById','21','2','tag:get');
INSERT INTO ida_role(role_id, role_name) VALUES (1, '用户管理员');
INSERT INTO ida_role(role_id, role_name) VALUES (2, '角色管理员');
INSERT INTO ida_role(role_id, role_name) VALUES (3, '权限管理员');
INSERT INTO ida_role(role_id, role_name) VALUES (4, '超级管理员');
INSERT INTO ida_user(user_id, user_name, user_role_names, user_account, user_password) VALUES (1, '许耀辉', '超级管理员','admin', '123456');
INSERT INTO ida_user(user_id, user_name, user_role_names, user_account, user_password) VALUES (2, '用户管理员', '用户管理员', 'user', '123456');
INSERT INTO ida_user_role(user_id, role_id) VALUES (1,4);
INSERT INTO ida_user_role(user_id, role_id) VALUES (2,1);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,2);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,3);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,4);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,6);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,7);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,8);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,9);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,11);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,12);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,13);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (4,14);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (1,1);
INSERT INTO ida_role_permission(role_id, permission_id) VALUES (1,2);
5.2.5 在C:\Windows\System32\drivers\etc 目录下打开编辑hosts文件,添加服务节点eurekaserver1,eurekaserver2
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
0.0.0.0 account.jetbrains.com
127.0.0.1 eureka-server
127.0.0.1 eurekaserver1
127.0.0.1 eurekaserver2
127.0.0.1 master
127.0.0.1 slave01
127.0.0.1 slave02
5.2.6 修改如下微服务对应的配置文件 中的数据库链接地址
服务工程 | 修改文件 |
cloud-ida-service-tag | application.properties |
cloud-ida-zuul | application.yml |
cloud-ida-config | application.properties等文件,此处有测试环境和生产环境配置的切换 |
5.2.7 解决RabbitMQ无法连接问题
由于初始化的RabbitMQ是没有工程中配置的消息队列DIRECT_QUEUE 的,所以启动RabbitMQ服务,手动创建一个消息队列
rabbitmq启动成功,浏览器中http://localhost:15672,输入guest,guest进入rabbitMQ管理控制台:
5.2.8 启动运行该项目
- 保证各服务模块使用的端口未被占用
- 确保redis,rabbitmq服务已经启动
- 启动顺序:cloud-ida-eureka->cloud-ida-config->cloud-ida-admin server->cloud-ida-admin->cloud-ida-service->cloud-ida-zuul->cloud-ida-zipkin
- 启动Vue前端
6.后端管理系统启动成功显示结果
7.启动前端项目和解决前端不显示菜单问题
7.1.定位到工程所在的目录,我的地址是E:\微服务学习项目\Spring-Cloud-Cli-master\vue-front,按“”Shift”加鼠标右键“在此处打开命令窗口”,先运行cnpm install,进行vue依赖模块的下载,再运行cnpm run dev访问系统,注意一定要确保在运行前端系统前已经安装配置好node.js、cnpm、vue
7.2 9521端口的是前端部分,在使用过程之中可能看不见菜单。是因为没有给角色授权菜单信息。需要用管理员账户在后台管理系统给超级管理员账户角色授权
7.3 前端结果显示
8.系统运行的登录链接,账号,密码
后台管理系统:http://localhost:9000/index 用户名/密码:admin/123456
前端系统: http://localhost:9521 用户名/密码:admin/123456