我正在使用ProgramEntryPoint在Windows Azure辅助角色中运行命令行程序(恰好是Redis),如下所示
<WorkerRole name="Worker" vmsize="Small">
<Runtime executionContext="limited">
<Environment>
<Variable name="ADDRESS">
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Redis']/@address" />
</Variable>
<Variable name="PORT">
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Redis']/@port" />
</Variable>
</Environment>
<EntryPoint>
<ProgramEntryPoint commandLine="redis-server.exe" setReadyOnProcessStart="true" />
</EntryPoint>
</Runtime>
<Endpoints>
<InternalEndpoint name="Redis" protocol="tcp" port="6379" />
</Endpoints>
</WorkerRole>
到目前为止,这么好(它有效)。 我现在想在另一个WorkerRole
中运行服务器的从属实例<WorkerRole name="SlaveWorker" vmsize="Small">
<Runtime executionContext="limited">
<EntryPoint>
<ProgramEntryPoint commandLine="echo slaveof %ADDRESS% %PORT% | redis-server.exe -" setReadyOnProcessStart="true" />
</EntryPoint>
</Runtime>
<Imports>
<Import moduleName="Diagnostics" />
<Import moduleName="RemoteAccess" />
</Imports>
<Endpoints>
<InternalEndpoint name="Redis" protocol="tcp" port="6379" />
</Endpoints>
</WorkerRole>
你可以看到我需要告诉从服务器主服务器在哪里使用IP地址和端口;在Azure为该角色分配网络资源之前我不知道的事情。我seen @smarx do something along these lines。
但是我认为在我的案例中可能存在一些问题
我在一个角色中设置环境变量,希望在另一个角色中使用它们 - 不会起作用。
即使正确的数据可用,我需要将其传递给redis-server.exe的方式也不会被识别为开头有回声的有效入口点
感谢您的想法。
答案 0 :(得分:2)
一个实例知道另一个IP地址的唯一方法是,如果a。)以编程方式获取它,或b。)另一个实例将其发布到一个众所周知的位置(例如表存储)。在您的情况下,最简单的方法是让slave角色运行一个启动任务来访问RoleEnvironment(可能通过Powershell),并使用Master的IP地址设置一个Environment变量。如果你这样做是一个“简单”类型,我相信它会在你的ProgramEntryPoint执行之前运行(阻塞),你可以在命令行中使用env var。
然而,这里有几个想法: