You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

consul.md 1.8 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Consul
  2. [Consul](https://www.consul.io/) 是一个分布式服务网格,用于跨任何运行时平台和公共或私有云连接,保护和配置服务。
  3. ## Dashboard 中的 Consul 配置
  4. CAP的 Dashboard 使用 Consul 作为服务发现来显示其他节点的数据,然后你就在任意节点的 Dashboard 中切换到 Servers 页面看到其他的节点。
  5. ![](https://camo.githubusercontent.com/54c00c6ae65ce1d7b9109ed8cbcdca703a050c47/687474703a2f2f696d61676573323031372e636e626c6f67732e636f6d2f626c6f672f3235303431372f3230313731302f3235303431372d32303137313030343232313030313838302d313136323931383336322e706e67)
  6. 通过点击 Switch 按钮来切换到其他的节点看到其他节点的数据,而不必访问很多地址来分别查看。
  7. 以下是一个配置示例, 你需要在每个节点分别配置:
  8. ```C#
  9. services.AddCap(x =>
  10. {
  11. x.UseMySql(Configuration.GetValue<string>("ConnectionString"));
  12. x.UseRabbitMQ("localhost");
  13. x.UseDashboard();
  14. x.UseDiscovery(_ =>
  15. {
  16. _.DiscoveryServerHostName = "localhost";
  17. _.DiscoveryServerPort = 8500;
  18. _.CurrentNodeHostName = Configuration.GetValue<string>("ASPNETCORE_HOSTNAME");
  19. _.CurrentNodePort = Configuration.GetValue<int>("ASPNETCORE_PORT");
  20. _.NodeId = Configuration.GetValue<string>("NodeId");
  21. _.NodeName = Configuration.GetValue<string>("NodeName");
  22. });
  23. });
  24. ```
  25. Consul 1.6.2:
  26. ```
  27. consul agent -dev
  28. ```
  29. Windows 10, ASP.NET Core 3.1:
  30. ```sh
  31. set ASPNETCORE_HOSTNAME=localhost&& set ASPNETCORE_PORT=5001&& dotnet run --urls=http://localhost:5001 NodeId=1 NodeName=CAP-1 ConnectionString="Server=localhost;Database=aaa;UserId=xxx;Password=xxx;"
  32. set ASPNETCORE_HOSTNAME=localhost&& set ASPNETCORE_PORT=5002&& dotnet run --urls=http://localhost:5002 NodeId=2 NodeName=CAP-2 ConnectionString="Server=localhost;Database=bbb;UserId=xxx;Password=xxx;"
  33. ```