继续上一篇(https://blog.csdn.net/wjj1991/article/details/126054874)的配置
步骤
- 创建多2个站点,模拟部署3台服务
- 修改consul配置
- 修改ocelot网关配置
1. 创建多2个站点,模拟部署3台服务
1.1 再按sys1复制两个iis站点,sys2(端口10041),sys3(10042),全部有3个站点,模拟服务部署了3台,如下:
1.2 为了方便识别,改sys2,sys3的do.json内容,如下
2. 修改consul配置
2.1 把之前consul配置修改如下,增加sys2和sys3的配置,注意name要一样,id不能一样
{
"services": [
{
"id": "sys1",
"name": "sys",
"address": "localhost",
"port": 10040
},{
"id": "sys2",
"name": "sys",
"address": "localhost",
"port": 10041
},{
"id": "sys3",
"name": "sys",
"address": "localhost",
"port": 10042
}]
}
2.2 改完重启,或使用如下命令
consul.exe reload
2.3 打开http://localhost:8500
,确认一下配置是否成功
3. 修改ocelot网关配置
3.1 ocelot网关的ocelot.json增加负载均衡配置,改完重启,配置如下
{
"Routes": [
{
"UpstreamPathTemplate": "/sys/{everything}",
"UpstreamHttpMethod": [ "Get", "Post" ],
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"ServiceName": "sys",
//配置负载均衡
"LoadBalancerOptions": {
"Type": "RoundRobin" //负载均衡方式
}
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5000",
"ServiceDiscoveryProvider": {
"Scheme": "http",
"Host": "localhost",
"Port": 8500,
"Type": "Consul"
}
}
}
LoadBalancerOptions更多描述,参考官网