dev
This commit is contained in:
parent
b8e17ce7d4
commit
cbaddad46d
|
@ -2,96 +2,84 @@
|
||||||
|
|
||||||
## 介绍
|
## 介绍
|
||||||
|
|
||||||
Gateway 网关服务是一个用 Go 语言开发的高性能 API 网关,旨在帮助开发者轻松管理和路由微服务请求。通过使用此网关,您可以集中处理身份验证、负载均衡、API 版本控制以及请求和响应的转换等功能。
|
Initialize 微服务负责在初始化数据、检测新版本或新的配置、获取应用的相关配置信息、系统区域数据、系统标签数据等其它应用相关数据。
|
||||||
|
|
||||||
## 源码仓库
|
## 源码仓库
|
||||||
```
|
```
|
||||||
https://git.apinb.com/bsm-service-base/initialize
|
https://git.apinb.com/bsm-service-base/initialize
|
||||||
```
|
```
|
||||||
|
|
||||||
## 功能特性
|
|
||||||
|
|
||||||
- **路由管理**:自动发现注册的GRPC微服务,实现动态管理路由。
|
|
||||||
- **支持协议**:同时支持Grpc/Restful协议,自动映射转发。
|
|
||||||
- **负载均衡**:支持多种负载均衡策略(轮询、随机等)。
|
|
||||||
- **身份验证**:网关实现身份验证,采用不可视化的JWT机制。
|
|
||||||
- **监控和日志**:实时监控请求日志,方便问题排查和性能优化。
|
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
要安装 Gateway 网关服务,请确保您已经安装了 bsm cli。:
|
要安装 Initialize 初始化微服务,请确保您已经安装了 bsm cli。:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bsm install gateway
|
bsm install initialize
|
||||||
```
|
```
|
||||||
|
|
||||||
## 配置文件说明
|
## 配置文件说明
|
||||||
|
|
||||||
在 `etc/` 目录中,根据dev,test,prod环境不同读取不同的配置文件,您可以配置网关的基本设置,例如:
|
在 `etc/` 目录中,根据dev,test,prod环境不同读取不同的配置文件,通过配置微服务决定是否启用相关服务,例如:
|
||||||
|
|
||||||
gateway_prod.yaml
|
initialize_prod.yaml
|
||||||
```yaml
|
```yaml
|
||||||
Name: bsm-gateway
|
Name: {ServiceKey}
|
||||||
|
ListenOn: 0.0.0.0:12202
|
||||||
|
|
||||||
Open:
|
Dsn: postgres://postgres:******@127.0.0.1:5432/{Workspace}_prod?sslmode=disable&TimeZone=Asia/Shanghai
|
||||||
- rpc
|
|
||||||
- http
|
|
||||||
|
|
||||||
TLS:
|
# cache DB的选择请在后面直接带参数,不带会自动HASH计算选择DB库。
|
||||||
Ca: /usr/local/bsm/cert/ca.crt
|
Cache: redis://null:******@127.0.0.1:6379/
|
||||||
Cert: /usr/local/bsm/cert/server.crt
|
|
||||||
Key: /usr/local/bsm/cert/server.key
|
|
||||||
|
|
||||||
Rpc:
|
|
||||||
Addr: 0.0.0.0:10020
|
|
||||||
|
|
||||||
Http:
|
|
||||||
Addr: 0.0.0.0:10021
|
|
||||||
|
|
||||||
Https:
|
|
||||||
Addr: 0.0.0.0:10022
|
|
||||||
|
|
||||||
Etcd:
|
Etcd:
|
||||||
Endpoints:
|
Hosts:
|
||||||
- 127.0.0.1:2379
|
- 127.0.0.1:2379
|
||||||
|
Key: service.{Workspace}.{ServiceKey}.rpc
|
||||||
|
|
||||||
|
# 匿名访问清单,自动注入网关层
|
||||||
|
Anonymous:
|
||||||
|
Key: anonymous.{Workspace}
|
||||||
|
Urls:
|
||||||
|
- initialize.Check.Hello
|
||||||
|
- initialize.Check.Updates
|
||||||
|
- initialize.Data.Configure
|
||||||
|
- initialize.Data.Areas
|
||||||
|
- initialize.Data.Tags
|
||||||
|
|
||||||
|
|
||||||
|
# 日志记录, 注释将不启用此功能
|
||||||
|
Log:
|
||||||
|
ServiceName: {ServiceKey}
|
||||||
|
Mode: file
|
||||||
|
Path: logs/{ServiceKey}
|
||||||
|
Stat: false
|
||||||
|
|
||||||
|
# 性能监控, 注释将不启用此功能
|
||||||
|
Prometheus:
|
||||||
|
Host: 127.0.0.1
|
||||||
|
Port: 22202
|
||||||
|
Path: /metrics
|
||||||
|
|
||||||
|
# 链路追踪, 注释将不启用此功能
|
||||||
|
Telemetry:
|
||||||
|
Name: {Workspace}.{ServiceKey}.{RuntimeMode}
|
||||||
|
Endpoint: http://127.0.0.1:14268/api/traces
|
||||||
|
Sampler: 1.0
|
||||||
|
Batcher: jaeger
|
||||||
|
|
||||||
|
# MQ Pulsar, 不启用
|
||||||
|
#Pulsar:
|
||||||
|
# Endpoints: 127.0.0.1
|
||||||
|
# Token: 9091
|
||||||
|
# Namespaces: {Workspace}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 配置项说明
|
## 启动微服务
|
||||||
|
|
||||||
- **Open**:要开通的服务。
|
|
||||||
- **TLS**:数字证书,用于SSL和GRPC客户端连接。
|
|
||||||
- **Rpc/Http/Https**:Rpc/Http/Https监听端口。
|
|
||||||
- **Etcd**:ETCD服务配置。
|
|
||||||
|
|
||||||
## 启动网关
|
|
||||||
|
|
||||||
使用以下命令启动网关服务:
|
使用以下命令启动网关服务:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bsm start gateway
|
bsm start initialize
|
||||||
```
|
```
|
||||||
查看启动日志 `./logs/gateway-v0.2.4.log`
|
|
||||||
```
|
|
||||||
2024/10/04 11:27:15 [Blocks Service] gateway Starting...
|
|
||||||
2024/10/04 11:27:15 [Blocks Service] gateway Runtime Mode: test
|
|
||||||
2024/10/04 11:27:15 [Blocks Service] Service Route Prefix: service.
|
|
||||||
2024/10/04 11:27:15 [Blocks Service] Service Anonymous Prefix: anonymous.
|
|
||||||
2024/10/04 11:27:15 [Blocks Service] gateway Service Build: Version v0.2.3, Go Version linux/amd64 golang:1.23.1-bookworm By 2024-10-03 20:56:05
|
|
||||||
2024/10/04 11:27:15 [Blocks Service] Connectd ETCD:[127.0.0.1:2379]
|
|
||||||
2024/10/04 11:27:15 [Blocks Service] gateway HTTP Proxy Addr [0.0.0.0:10021] Runing Success!
|
|
||||||
2024/10/04 11:27:15 [Blocks Service] gateway RPC Proxy Addr [0.0.0.0:10020] Runing Success!
|
|
||||||
```
|
|
||||||
## 测试网关
|
|
||||||
|
|
||||||
一旦服务启动,您可以使用 `curl` 或 Postman 等工具发送请求。例如:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl http://localhost:10021/ping
|
|
||||||
```
|
|
||||||
正常时,返回:
|
|
||||||
```
|
|
||||||
PONG
|
|
||||||
```
|
|
||||||
## 查看日志
|
|
||||||
|
|
||||||
网关服务会将日志存储至: `/usr/local/bsm/logs/` 目录下。
|
|
||||||
|
|
Loading…
Reference in New Issue