进阶主要是对微服务项目的鉴权升级,不管是使用Spring Cloud GateWay作为网关,还是采用Zuul作为网关,都离不开鉴权中心
启动Auth中心
Auth中心的作用是起到从各个服务和网关之间的鉴权名单同步。
下载解压
首先到Release中下载katool-security-auth,解压即可
编写application.yml
进入./config文件夹,对application.yml进行配置,如果没有,那么创建一个
配置如下
spring:
web:
resources:
static-locations: [ classpath:/META-INF/resources/, classpath:/resources/, classpath:/static/, classpath:/public/ ]
main:
allow-bean-definition-overriding: true
application:
name: KaTool-Security-Auth
# todo
cloud:
nacos:
discovery:
server-addr: 1自行配置
config:
username: nacos
password: nacos
# 默认 dev 环境
profiles:
active: dev
# 支持 swagger3
mvc:
pathmatch:
matching-strategy: ant_path_matcher
# session 配置
session:
# todo 取消注释开启分布式 session(须先配置 Redis)
store-type: redis
# 30 天过期
timeout: 2592000
# 数据库配置
# todo
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/katool_security?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: # 自行填写
password: # 自行填写
# Redis 配置
# todo
redis:
database: 0
host:
port:
timeout: 5000
password:
servlet:
multipart:
location: /data/upload_tmp
# 大小限制
max-file-size: 10GB
max-request-size: 100GB
aop:
proxy-target-class: true
# MybatisPlus 配置
server:
# todo 自行配置
address: 0.0.0.0
port: 7777
servlet:
# cookie 30 天过期
session:
cookie:
max-age: 2592000
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
configuration:
map-underscore-to-camel-case: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
logic-delete-field: isDelete # 全局逻辑删除的实体字段名
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
katool:
security:
mode: single # 对于网关来说,只能选择单体模式,因为网关通常只进行转发
core:
token-header: "Authorization"
util:
redis:
policy: caffeine
time-unit: days
exp-time: 7
lock:
internal-lock-lease-time: 30
time-unit: minutes
dubbo:
application:
name: dubbo-KaTool-Security-Auth
protocol:
name: dubbo
port: -1
registry:
id: nacos-registry
address: nacos://localhost:8848 # todo: 自行配置
其中,标记了todo的都是需要自行配置的
项目启动
进入./bin/目录,选择startup.cmd进行启动