首页 > 数据库 >Docker Desktop部署微软微服务Dapr(Redis+Zipkin+Placement)

Docker Desktop部署微软微服务Dapr(Redis+Zipkin+Placement)

时间:2024-05-16 10:52:33浏览次数:15  
标签:Zipkin app Supported Redis Desktop platforms Dapr dapr js

Docker Desktop部署微软微服务Dapr(Redis+Zipkin+Placement)

说明

  • 系统:Windows 11 专业版 23H2
  • Docker:Docker Desktop v4.29.0+
  • 本文为开发环境学习和测试使用

安装Dapr CLI

使用 MSI 安装程序安装

每个 Dapr CLI 的发布版本还包括一个适用于 Windows 的安装程序。 您可以手动下载MSI:

  1. 从最新的Dapr发布页面下载MSI安装包dapr.msi​。
  2. 导航到下载的MSI文件,双击文件运行它。
  3. 按照安装提示接受许可证和安装目录。 所选文件夹已添加到用户的PATH环境变量中。 默认值设置为$Env:SystemDrive\dapr​。
  4. 点击 Install​ 开始安装。 安装完成后,您将看到一条最终消息。

安装目录“D:\dapr\”,将安装目录添加到用户的PATH环境变量中,PowerShell验证

dapr -h
PS C:\Windows\system32> dapr -h

          __
     ____/ /___ _____  _____
    / __  / __ '/ __ \/ ___/
   / /_/ / /_/ / /_/ / /
   \__,_/\__,_/ .___/_/
             /_/

===============================
Distributed Application Runtime

Usage:
  dapr [flags]
  dapr [command]

Available Commands:
  annotate       Add dapr annotations to a Kubernetes configuration. Supported platforms: Kubernetes
  build-info     Print build info of Dapr CLI and runtime
  completion     Generates shell completion scripts
  components     List all Dapr components. Supported platforms: Kubernetes
  configurations List all Dapr configurations. Supported platforms: Kubernetes
  dashboard      Start Dapr dashboard. Supported platforms: Kubernetes and self-hosted
  help           Help about any command
  init           Install Dapr on supported hosting platforms. Supported platforms: Kubernetes and self-hosted
  invoke         Invoke a method on a given Dapr application. Supported platforms: Self-hosted
  list           List all Dapr instances. Supported platforms: Kubernetes and self-hosted
  logs           Get Dapr sidecar logs for an application. Supported platforms: Kubernetes
  mtls           Check if mTLS is enabled. Supported platforms: Kubernetes
  publish        Publish a pub-sub event. Supported platforms: Self-hosted
  run            Run Dapr and (optionally) your application side by side. Supported platforms: Self-hosted
  status         Show the health status of Dapr services. Supported platforms: Kubernetes
  stop           Stop Dapr instances and their associated apps. Supported platforms: Self-hosted
  uninstall      Uninstall Dapr runtime. Supported platforms: Kubernetes and self-hosted
  upgrade        Upgrades or downgrades a Dapr control plane installation in a cluster. Supported platforms: Kubernetes
  version        Print the Dapr runtime and CLI version

Flags:
  -h, --help                  help for dapr
      --log-as-json           Log output in JSON format
      --runtime-path string   The path to the dapr runtime installation directory
  -v, --version               version for dapr

Use "dapr [command] --help" for more information about a command.

init命令会用到特殊网络,如果没有,可以参考安装及初始化Dapr方式(国内)

dapr init
PS C:\Windows\system32> dapr init
Making the jump to hyperspace...
Container images will be pulled from Docker Hub
Installing runtime version 1.13.2
Downloading binaries and setting up components...
Downloaded binaries and completed components set up.
daprd binary has been installed to C:\Users\sywq6\.dapr\bin.
dapr_placement container is running.
dapr_redis container is running.
dapr_zipkin container is running.
Use `docker ps` to check running containers.
Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started

init完会生成“.dapr”文件夹,存在的文件如下

│  config.yaml
│  
├─bin
│  │  daprd.exe
│  │  dashboard.exe // dapr看板程序
│  │  
│  └─web
│      └─dist
│          │  favicon.ico
│          │  index.html
│          │  main.js
│          │  main.js.map
│          │  polyfills-es5.js
│          │  polyfills-es5.js.map
│          │  polyfills.js
│          │  polyfills.js.map
│          │  runtime.js
│          │  runtime.js.map
│          │  src_app_pages_pages_module_ts.js
│          │  src_app_pages_pages_module_ts.js.map
│          │  styles.css
│          │  styles.css.map
│          │  vendor.js
│          │  vendor.js.map
│          │  
│          ├─assets
│          │  └─images
│          │          dapr.png
│          │          logo-white.svg
│          │          logo.svg
│          │  
│          └─lib
│              └─vs
│                  │  loader.js
│                  │  
│                  ├─base
│                  │  ├─browser
│                  │  │  └─ui
│                  │  │      └─codicons
│                  │  │          └─codicon
│                  │  │                  codicon.ttf
│                  │  │          
│                  │  └─worker
│                  │          workerMain.js
│                  │  
│                  ├─basic-languages
│                  │  ├─abap
│                  │  │      abap.js
│                  │  │  
│                  │  ├─apex
│                  │  │      apex.js
│                  │  │  
│                  │  ├─azcli
│                  │  │      azcli.js
│                  │  │  
│                  │  ├─bat
│                  │  │      bat.js
│                  │  │  
│                  │  ├─bicep
│                  │  │      bicep.js
│                  │  │  
│                  │  ├─cameligo
│                  │  │      cameligo.js
│                  │  │  
│                  │  ├─clojure
│                  │  │      clojure.js
│                  │  │  
│                  │  ├─coffee
│                  │  │      coffee.js
│                  │  │  
│                  │  ├─cpp
│                  │  │      cpp.js
│                  │  │  
│                  │  ├─csharp
│                  │  │      csharp.js
│                  │  │  
│                  │  ├─csp
│                  │  │      csp.js
│                  │  │  
│                  │  ├─css
│                  │  │      css.js
│                  │  │  
│                  │  ├─dart
│                  │  │      dart.js
│                  │  │  
│                  │  ├─dockerfile
│                  │  │      dockerfile.js
│                  │  │  
│                  │  ├─ecl
│                  │  │      ecl.js
│                  │  │  
│                  │  ├─elixir
│                  │  │      elixir.js
│                  │  │  
│                  │  ├─fsharp
│                  │  │      fsharp.js
│                  │  │  
│                  │  ├─go
│                  │  │      go.js
│                  │  │  
│                  │  ├─graphql
│                  │  │      graphql.js
│                  │  │  
│                  │  ├─handlebars
│                  │  │      handlebars.js
│                  │  │  
│                  │  ├─hcl
│                  │  │      hcl.js
│                  │  │  
│                  │  ├─html
│                  │  │      html.js
│                  │  │  
│                  │  ├─ini
│                  │  │      ini.js
│                  │  │  
│                  │  ├─java
│                  │  │      java.js
│                  │  │  
│                  │  ├─javascript
│                  │  │      javascript.js
│                  │  │  
│                  │  ├─julia
│                  │  │      julia.js
│                  │  │  
│                  │  ├─kotlin
│                  │  │      kotlin.js
│                  │  │  
│                  │  ├─less
│                  │  │      less.js
│                  │  │  
│                  │  ├─lexon
│                  │  │      lexon.js
│                  │  │  
│                  │  ├─liquid
│                  │  │      liquid.js
│                  │  │  
│                  │  ├─lua
│                  │  │      lua.js
│                  │  │  
│                  │  ├─m3
│                  │  │      m3.js
│                  │  │  
│                  │  ├─markdown
│                  │  │      markdown.js
│                  │  │  
│                  │  ├─mips
│                  │  │      mips.js
│                  │  │  
│                  │  ├─msdax
│                  │  │      msdax.js
│                  │  │  
│                  │  ├─mysql
│                  │  │      mysql.js
│                  │  │  
│                  │  ├─objective-c
│                  │  │      objective-c.js
│                  │  │  
│                  │  ├─pascal
│                  │  │      pascal.js
│                  │  │  
│                  │  ├─pascaligo
│                  │  │      pascaligo.js
│                  │  │  
│                  │  ├─perl
│                  │  │      perl.js
│                  │  │  
│                  │  ├─pgsql
│                  │  │      pgsql.js
│                  │  │  
│                  │  ├─php
│                  │  │      php.js
│                  │  │  
│                  │  ├─postiats
│                  │  │      postiats.js
│                  │  │  
│                  │  ├─powerquery
│                  │  │      powerquery.js
│                  │  │  
│                  │  ├─powershell
│                  │  │      powershell.js
│                  │  │  
│                  │  ├─pug
│                  │  │      pug.js
│                  │  │  
│                  │  ├─python
│                  │  │      python.js
│                  │  │  
│                  │  ├─qsharp
│                  │  │      qsharp.js
│                  │  │  
│                  │  ├─r
│                  │  │      r.js
│                  │  │  
│                  │  ├─razor
│                  │  │      razor.js
│                  │  │  
│                  │  ├─redis
│                  │  │      redis.js
│                  │  │  
│                  │  ├─redshift
│                  │  │      redshift.js
│                  │  │  
│                  │  ├─restructuredtext
│                  │  │      restructuredtext.js
│                  │  │  
│                  │  ├─ruby
│                  │  │      ruby.js
│                  │  │  
│                  │  ├─rust
│                  │  │      rust.js
│                  │  │  
│                  │  ├─sb
│                  │  │      sb.js
│                  │  │  
│                  │  ├─scala
│                  │  │      scala.js
│                  │  │  
│                  │  ├─scheme
│                  │  │      scheme.js
│                  │  │  
│                  │  ├─scss
│                  │  │      scss.js
│                  │  │  
│                  │  ├─shell
│                  │  │      shell.js
│                  │  │  
│                  │  ├─solidity
│                  │  │      solidity.js
│                  │  │  
│                  │  ├─sophia
│                  │  │      sophia.js
│                  │  │  
│                  │  ├─sparql
│                  │  │      sparql.js
│                  │  │  
│                  │  ├─sql
│                  │  │      sql.js
│                  │  │  
│                  │  ├─st
│                  │  │      st.js
│                  │  │  
│                  │  ├─swift
│                  │  │      swift.js
│                  │  │  
│                  │  ├─systemverilog
│                  │  │      systemverilog.js
│                  │  │  
│                  │  ├─tcl
│                  │  │      tcl.js
│                  │  │  
│                  │  ├─twig
│                  │  │      twig.js
│                  │  │  
│                  │  ├─typescript
│                  │  │      typescript.js
│                  │  │  
│                  │  ├─vb
│                  │  │      vb.js
│                  │  │  
│                  │  ├─xml
│                  │  │      xml.js
│                  │  │  
│                  │  └─yaml
│                  │          yaml.js
│                  │  
│                  ├─editor
│                  │      editor.main.css
│                  │      editor.main.js
│                  │      editor.main.nls.de.js
│                  │      editor.main.nls.es.js
│                  │      editor.main.nls.fr.js
│                  │      editor.main.nls.it.js
│                  │      editor.main.nls.ja.js
│                  │      editor.main.nls.js
│                  │      editor.main.nls.ko.js
│                  │      editor.main.nls.ru.js
│                  │      editor.main.nls.zh-cn.js
│                  │      editor.main.nls.zh-tw.js
│                  │  
│                  └─language
│                      ├─css
│                      │      cssMode.js
│                      │      cssWorker.js
│                      │  
│                      ├─html
│                      │      htmlMode.js
│                      │      htmlWorker.js
│                      │  
│                      ├─json
│                      │      jsonMode.js
│                      │      jsonWorker.js
│                      │  
│                      └─typescript
│                              tsMode.js
│                              tsWorker.js
│                      
└─components
        pubsub.yaml
        statestore.yaml

正常Init完,会看到启动如下三个服务


安装出错(能正常安装可忽略本节)

如果没有使用特殊网络,大概率会因为网络原因,导致安装失败

  • Docker中关闭三个服务(Redis+Zipkin+Placement)
  • 在PowerShell中卸载Dapr。使用不带“--all”参数的uninstall命令(否则会把“.dapr”文件夹内的所有文件清理),会把bin文件夹删除
dapr uninstall

离线下载文件部分可以参考这篇文章:安装及初始化Dapr方式(国内)

验证安装

PowderShell执行

docker ps --format "{{.Image}} - {{.Ports}} - {{.Names}}"
PS C:\Windows\system32> docker ps --format "{{.Image}} - {{.Ports}} - {{.Names}}"
daprio/dapr:1.13.2 - 0.0.0.0:58080->8080/tcp, 0.0.0.0:59090->9090/tcp, 0.0.0.0:6050->50005/tcp - dapr_placement
openzipkin/zipkin - 9410/tcp, 0.0.0.0:9411->9411/tcp - dapr_zipkin
redis:6 - 0.0.0.0:6379->6379/tcp - dapr_redis

启动dapr Dashboard

dapr dashboard Dapr Dashboard running on http://localhost:8080

浏览器打开“http://localhost:8080/”,打开dapr Dashboard

启动Zipkin看板

浏览器打开“http://localhost:9411/”,打开Zipkin看板

创建.NET项目

打开VS Code,打开终端,新建.NET项目

dotnet new webapi -o dapr.microservice.webapi
cd .\dapr.microservice.webapi\
dotnet add package Dapr.AspNetCore

修改文件Program.cs​的内容

var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers().AddDapr();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
//app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.MapSubscribeHandler();
app.Run("http://localhost:5000");

新建文件HelloWorldController.cs

using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("[controller]")]
public class HelloController : ControllerBase
{
    private readonly ILogger<HelloController> _logger;
 
    public HelloController(ILogger<HelloController> logger)
    {
        _logger = logger;
    }
 
    [HttpGet()]
    public ActionResult<string> Get()
    {
        Console.WriteLine("Hello, World.");
        return "Hello, World";
    }
}

终端启动项目

dotnet run

使用PowerShell查看结果

PS C:\Users\sywq6> curl http://localhost:5000/hello                                                                   

StatusCode        : 200
StatusDescription : OK
Content           : Hello, World
RawContent        : HTTP/1.1 200 OK
                    Transfer-Encoding: chunked
                    Content-Type: text/plain; charset=utf-8
                    Date: Wed, 15 May 2024 05:31:32 GMT
                    Server: Kestrel

                    Hello, World
Forms             : {}
Headers           : {[Transfer-Encoding, chunked], [Content-Type, text/plain; charset=utf-8], [Date, Wed, 15 May 2024 0
                    5:31:32 GMT], [Server, Kestrel]}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 12

使用Dapr启动应用程序

dapr run --app-id hello-world --app-port 5000 --dapr-http-port 5010 dotnet run

说明:

  • app-id:用于服务发现的应用程序 Id
  • app-port:应用程序正在侦听的端口
  • dapr-http-port:Dapr 要监听的 HTTP 端口

这时,再次浏览器打开“http://localhost:8080/”,打开dapr Dashboard,会看到app-id为“hello-world”程序

Zipkin链路追踪

传统微服务中,要实现链路追踪,对代码的侵入强

Dapr 在 Sidecar 中添加了一个 http/grpc中间件。拦截所有应用程序流量,并自动注入关联 ID 以跟踪分布式事务

使用 Zipkin 协议进行分布式跟踪,无需代码检测,使用可配置的跟踪级别自动跟踪所有流量

浏览器打开“http://localhost:9411/”,打开Zipkin管理页面,【RUN QUERY】会看到如下结果

PowerShell执行,及其结果如下

curl http://localhost:5010/v1.0/invoke/hello-world/method/hello
PS C:\Windows\system32> curl http://localhost:5010/v1.0/invoke/hello-world/method/hello                             

StatusCode        : 200
StatusDescription : OK
Content           : Hello, World
RawContent        : HTTP/1.1 200 OK
                    Traceparent: 00-ebd2a75c457c6a6c5fefa8d50be51cfe-ee934c87a7cf2b7b-01
                    Content-Length: 12
                    Content-Type: text/plain; charset=utf-8
                    Date: Wed, 15 May 2024 02:57:08 GMT
                    Server: Kestrel...
Forms             : {}
Headers           : {[Traceparent, 00-ebd2a75c457c6a6c5fefa8d50be51cfe-ee934c87a7cf2b7b-01], [Content-Length, 12], [Con
                    tent-Type, text/plain; charset=utf-8], [Date, Wed, 15 May 2024 02:57:08 GMT]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 12

Zipkin管理页面,能够查询到刚才调用Api的记录

参考

标签:Zipkin,app,Supported,Redis,Desktop,platforms,Dapr,dapr,js
From: https://www.cnblogs.com/vinciyan/p/18195538

相关文章

  • 使用Docker Desktop部署Apache APISIX
    使用DockerDesktop部署ApacheAPISIX说明测试系统:Windows11专业版23H2Docker:DockerDesktopv4.29.0+关于路径,“/e/Soft/conf/apisix/conf/config.yaml”代表windows系统下的文件“E:\Soft\conf\apisix\conf\config.yaml”Windows使用PowerShell运行Docker的Run......
  • redis
    redis介绍安装#0数据库-存数据的软件#1关系型数据库-PostgreSQL(后面安装了解看看),mysql,sqlserver,oracle。。。-sql语句,通用#2非关系型数据库-redis,mongod,clickhouse,infludb,elasticsearch。。。#3非关系型数据库:nosql-c语言写的服务(监听端......
  • redis之哈希类型
    在Redis中,哈希(Hash)类型是一种将多个键值对存储在单个键中的数据结构。哈希类型被用来表示对象,其中每个键都是对象的属性,并且每个属性都与一个值相关联。哈希类型在Redis中通常用于存储对象的属性集合。哈希类型和python中的字典类型很像哈希类型常用方法【1】hset#用于设置......
  • redis之字符串
    【1】set#1SET命令用于设置给定key的值。如果key已经存储其他值,SET就覆写旧值,且无视类型。res=conn.set(name='name',value='green')print(res)#插入成功后返回True#1.1设置过期时间conn.set(name='name',value='green',ex=5)#ex=5在5秒后过期conn.s......
  • django中使用redis
    【1】通用方式########写个pool.pyimportredisPOOL=redis.ConnectionPool(max_connections=10,decode_responses=True)######在哪里用,导入用即可fromutils.poolimportPOOLimportredisclassRedisView(ViewSet):deflist(self,request):conn=red......
  • redis通用操作
    通用操作的意思就是与数据类型无关,都可以操作的方法【1】delete#删除某个键对应的值可用一次性删多个res=conn.delete('color')#删除color对应的数据【2】exists#判断某个键是否存在存在返回1不存在返回0res=conn.exists('girls')【3】keys#返回所有键或......
  • redis之list类型
    在redis中,list类型是一种有序的字符串元素集合。redis的list和python中的列表类型有一些相似之处,但也有一些不同点redis列表类型的特点有序性:列表中的元素是按照插入顺序存储的,每个元素都有一个索引位置。允许重复元素:列表中可以包含重复的元素。支持头部和尾部的操作:Redis......
  • Redis总结
    【一】redis基础【二】python连接redis【三】Redis连接池【四】redis之字符串【五】redis之哈希类型【六】redis之list类型【七】redis通用操作【八】django中使用redis......
  • Redis连接池
    【一】Redis连接池的优点​ Redis连接池的存在主要是为了优化Redis客户端和Redis服务器之间的连接管理,提升性能和稳定性。具体而言,Redis连接池具有以下几个优点:提升响应速度:由于连接池中已经存在可用的连接,客户端可以快速获取连接并执行操作,而不需要等待新的连接建立过程。这......
  • redis基础
    redis介绍Redis是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库。Redis与其他key-value缓存产品有以下三个特点:Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用。Redis不仅仅支持简单的key-value类型的数据,同时还提供l......