简体   繁体   English

在Azure云服务工作者角色上设置Redis

[英]Setting up Redis on Azure cloud service worker role

I'm creating a cloud service where I have a worker role running some heavy processing in the background, for which i would like a Redis instance to be running locally on the worker. 我正在创建一个云服务,其中有一个工作人员角色在后台运行一些繁重的处理,为此,我希望Redis实例在该工作人员本地运行。

What i want to do is set up the worker role project in a way that the Redis instance is installed/configured when the worker is deployed. 我要做的是以部署工作人员时安装/配置Redis实例的方式设置工作人员角色项目。

The redis database would be cleared on every job startup. Redis数据库将在每次作业启动时清除。

I've looked at the MSOpenTech redis for windows with nuget installation, but i'm unsure how i would get this working on the worker role instance. 我已经看过了MSOpenTech的Redis用的NuGet安装Windows,但我不能确定我怎么会得上的工人角色实例这个工作。 Is there a smart way to set it up, or would it be by command-line calls? 是否有聪明的方法来设置它,还是通过命令行调用来设置它?

Thanks. 谢谢。

I'm not expecting to get this marked as an answer, but just wanted to add the add that this is a really bad approach for a real-world deployment . 我不希望将其标记为答案,而只是想添加一个补充,即对于实际部署而言 ,这是一种非常糟糕的方法

I can understand why you might want to do this from a learning perspective, however in a production environment its a really bad idea, for several reasons: 我可以从学习的角度理解为什么要这样做,但是在生产环境中,这确实是个坏主意,原因有以下几个:

  1. You cannot guarantee when a Worker Role will be restarted by the Azure Service Fabric (and you're not guaranteed to get the underlying VM in the same state before it went down) - you could potentially be re-populating the cache simply because the role was re-started. 您无法保证何时由Azure Service Fabric重新启动工作角色(并且不保证在基础VM发生故障之前将其置于相同状态)-您可能仅因为该角色而重新填充了缓存重新启动。
  2. In a real-world implementation of Redis, you would run multiple nodes within a cluster so you benefit from a) the ability to automatically split your dataset among multiple nodes and b) continue operations when a subset of the nodes are experiencing failures - running within a Worker Role doesn't give you any of this. 在Redis的实际实现中,您将在集群中运行多个节点,因此您将受益于a)自动在多个节点之间拆分数据集的能力,以及b)当一部分节点出现故障时继续操作-在内部运行工作者角色不会给您任何这些。 You also run the risk of multiple Redis instances (unaware of each other) every time you scale-out your Worker Role. 每次横向扩展辅助角色时,您还冒着多个Redis实例(彼此之间不知道)的风险。
  3. You will need to manage your Redis installation within the Worker Role and they simply aren't designed for this. 您将需要在辅助角色中管理您的Redis安装,而根本不是为此而设计的。 PaaS Worker Roles are designed to run the Worker Role Package that is deployed and nothing else. PaaS辅助角色旨在运行已部署的辅助角色包,而无其他操作。 If you really want to run Redis yourself, you should probably look at IaaS VM's. 如果您真的想自己运行Redis,则可能应该看一下IaaS VM。

I would recommend that you take a look at the Azure Redis Cache SaaS offering (see http://azure.microsoft.com/en-gb/services/cache/ ) which offers a fully managed, highly-available, implementation of the Redis Cache. 我建议您看一下Azure Redis缓存SaaS产品(请参阅http://azure.microsoft.com/en-gb/services/cache/ ),该产品提供了Redis的完全托管的,高度可用的实现。缓存。 I use it on several projects and can highly recommend it. 我在几个项目上使用它,可以高度推荐它。

To install any software on a worker role instance, you'd need to set this up to happen as a startup task. 要在辅助角色实例上安装任何软件,您需要将其设置为启动任务。

You'll reference startup tasks in your ServiceDefinition.csdef file, in the <Startup> element, with a reference to your command file which installs whatever software you want (such as Redis). 您将在ServiceDefinition.csdef文件中的<Startup>元素中引用启动任务,并引用命令文件来安装所需的任何软件(例如Redis)。

I haven't tried installing Redis in a worker role instance, so I can't comment about whether this will succeed. 我没有尝试在辅助角色实例中安装Redis,因此无法评论它是否会成功。 And you'll also need to worry about opening the right ports (whether external- or internal-facing), and scaling (eg what happens when you scale to two worker role instances, both running redis?). 而且,您还需要担心打开正确的端口(无论是面向外部的端口还是面向内部的端口)并进行扩展(例如,当扩展到两个都运行redis的辅助角色实例时会发生什么情况?)。 My answer is specific to how you install software on a role instance. 我的答案是特定于您如何在角色实例上安装软件的。

More info on startup task setup is here . 有关启动任务设置的更多信息,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM