安装tye
首先我们安装tye,使用dotnet cli命令。
代码语言:javascript复制dotnet tool install -g Microsoft.Tye --version "0.11.0-alpha.22111.1"
安装完后即可使用tye命令
配置tye
首先我们使用tye init命令初始化tye.yaml配置文件 结构大致入下:
代码语言:javascript复制name: funshow
services:
- name:
project:
- name:
project:
我们需要在配置文件中添加我们的服务,包括绑定端口,环境变量等。 这里完整的配置文件如下:
代码语言:javascript复制name: FunShow
services:
- name: auth-server
project: apps/auth-server/src/FunShow.AuthServer/FunShow.AuthServer.csproj
bindings:
- protocol: https
port: 44322
env:
- Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
- Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f
- name: administration-service
project: services/administration/src/FunShow.AdministrationService.HttpApi.Host/FunShow.AdministrationService.HttpApi.Host.csproj
bindings:
- protocol: https
port: 44367
env:
- Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
- Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f
- name: identity-service
project: services/identity/src/FunShow.IdentityService.HttpApi.Host/FunShow.IdentityService.HttpApi.Host.csproj
bindings:
- protocol: https
port: 44388
env:
- Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
- Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f
- name: logging-service
project: services/logging/src/FunShow.LoggingService.HttpApi.Host/FunShow.LoggingService.HttpApi.Host.csproj
bindings:
- protocol: https
port: 45124
env:
- Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
- Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f
- name: web-gateway
project: gateways/web/src/FunShow.WebGateway/FunShow.WebGateway.csproj
bindings:
- protocol: https
port: 44325
env:
- Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
- Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f
bindings表示我们绑定https以及端口号。 env里面配置了我们的本地开发HTTPS证书。
创建本地证书
上面配置里面我们有加载本地证书,那么怎么创建证书呢,在tye仓库中也有说明 https://github.com/dotnet/tye/blob/main/docs/tutorials/hello-tye/00_run_locally.md#generate-the-certificate 仓库中是在linux环境,但是在windows环境中localhost.conf是一样的
代码语言:javascript复制[req]
default_bits = 2048
default_keyfile = localhost.key
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_ca
[req_distinguished_name]
commonName = Common Name (e.g. server FQDN or YOUR name)
commonName_default = localhost
commonName_max = 64
[req_ext]
subjectAltName = @alt_names
[v3_ca]
subjectAltName = @alt_names
basicConstraints = critical, CA:false
keyUsage = keyCertSign, cRLSign, digitalSignature,keyEncipherment
[alt_names]
DNS.1 = localhost
DNS.2 = 127.0.0.1
创建etc/dev-cert目录,在目录下添加localhost.conf文件,内容如上。 然后执行dotnet dev-certs命令
代码语言:javascript复制dotnet dev-certs https -v -ep localhost.pfx -p e8202f07-66e5-4619-be07-72ba76fde97f -t
就会在目录下面生成localhost.pfx证书文件。
使用tye运行微服务
在目录下面执行tye运行命令
代码语言:javascript复制tye run --watch
效果如下:
当然运行服务前我们需要把我们的基础服务都启动,如数据库,消息队列,redis等。 在tye dashboard可以查看服务的日志以及Metrics信息
下面是服务启动页面。 网关服务
认证服务
到这我们后端功能就基本完成啦