我正在尝试在 Docker 容器内设置奥尔良筒仓。客户端一开始就不会放在容器中。
我正在 Linux容器模式下在Windows上使用 Docker 。 当客户端也位于容器中时,我能够同时运行客户端和筒仓并进行连接。
筒仓的配置如下:
var builder = new SiloHostBuilder()
.Configure<ClusterOptions>(options =>
{
options.ClusterId = "DOCKER-SILO";
options.ServiceId = "EZ-DOCKER";
})
.UseAdoNetClustering(options =>
{
options.Invariant = "MySql.Data.MySqlClient";
options.ConnectionString = "server=XXX;user id=orleans;password='XXX';persistsecurityinfo=True;database=orleans;SslMode=None";
})
.Configure<EndpointOptions>(options =>
{
var adressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
options.AdvertisedIPAddress = adressList.First();
options.GatewayPort = 30000);
options.SiloPort = 11111);
})
客户端的配置如下:
client = new ClientBuilder()
.Configure<ClusterOptions>(options =>
{
options.ClusterId = "DOCKER-SILO";
options.ServiceId = "EZ-DOCKER";
})
.UseStaticClustering(new IPEndPoint(IPAddress.Parse("192.168.0.13"), 30000))
筒仓是这样运行的:
PS C:\XXX> docker run -p 30000:30000 --expose 11111 --add-host host.docker.internal:192.168.0.13 ezorleanssilolinux
Dockerfile非常简单:
FROM mcr.microsoft.com/dotnet/core/runtime:2.1-stretch-slim AS base
WORKDIR /app
FROM base AS final
WORKDIR /app
#COPY --from=publish /app .
COPY ["eZ.Orleans.Silo/publish", "."]
ENTRYPOINT ["dotnet", "eZ.Orleans.Silo.dll"]
当我在客户端中使用127.0.0.1
作为静态网关ip时,它可以工作。当我使用Docker主机拥有的任何其他IP时,在筒仓日志中会收到以下错误:
Gateway received unexpected non-proxied connection from *sgn/01111111-1111-1111-1111-111111111111/11111111 at source address 172.17.0.1:38428
为什么在尝试使用除localhost以外的任何其他地址时出现此错误? netstat -n -a
告诉我,筒仓正在侦听主机上的0.0.0.0。
答案 0 :(得分:0)
几个小时后,我设法使一切正常,请查看我的筒仓代码:
return new HostBuilder()
.UseOrleans(builder =>
{
builder
.UseDashboard()
.UseAdoNetClustering(options =>
{
options.Invariant = "System.Data.SqlClient";
options.ConnectionString = _connectionString;
})
.Configure<EndpointOptions>(options =>
{
// Port to use for Silo-to-Silo
options.SiloPort = 11111;
// Port to use for the gateway
options.GatewayPort = 30000;
// IP Address to advertise in the cluster
options.AdvertisedIPAddress = IPAddress.Parse(GetExternalIpAddress());
// The socket used for silo-to-silo will bind to this endpoint
options.GatewayListeningEndpoint = new IPEndPoint(IPAddress.Any, 40000);
// The socket used by the gateway will bind to this endpoint
options.SiloListeningEndpoint = new IPEndPoint(IPAddress.Any, 50000);
})
.Configure<ClusterOptions>(options =>
{
options.ClusterId = "ClusterId-ForSign";
options.ServiceId = "ServiceId-ForSign";
})
.ConfigureApplicationParts(parts =>
{
parts.AddApplicationPart(typeof(UserService).Assembly).WithReferences();
parts.AddApplicationPart(typeof(CompanyService).Assembly).WithReferences();
});
})
.ConfigureServices(services =>
{
services.AddTransient<ICompanyRepository, CompanyRepository>();
services.AddTransient<ICompanyService, CompanyService>();
services.Configure<ConsoleLifetimeOptions>(options =>
{
options.SuppressStatusMessages = true;
});
})
.ConfigureLogging(builder =>
{
builder.AddConsole();
})
.RunConsoleAsync();
}
private static string GetExternalIpAddress() => new WebClient().DownloadString("https://api.ipify.org");