Automatisation de l’installation et de la configuration d’ARR dans Azure–Automating installation and configuration of ARR in Azure

Français English
Dans un billet précédent, j’ai testé ARR dans une ferme de type worker role devant un ferme de type web role Azure de façon à pouvoir disposer d’affinité de session. Dans ce billet, il est question de l’automatisation de cela de façon à ce que cela puisse être utilisé dans une solution réelle, avec entre autres de l’élasticité.NB: Dans cette solution, le Web Role est juste un exemple d’une solution ASP.NET presque vide qui aurait besoin d’affinité de session. Cela pourrait être un Web Role avec une application Web PHP ou un worker role avec TomCat qui héberge une application Web Java.De façon à automatiser l’installation et la configuration d’ARR, on peut s’appuyer sur les tâches de démarrage qui peuvent tourner avec des privilèges élevés, mais le rôle tournera toujours avec de faibles privilèges.C’est pourquoi on crée un service Windows qui est installé par la tâche de démarrage, et qui tourne en tant que Local System (ce qui lui donne les droits de changer la configuration IIS). Ce processus du service Windows, comme n’importe quel processus dans l’environnement Azure, peut utiliser RoleEnvironment et s’abonner aux événements de façon à adapter ARR à la topologie de la ferme qu’il expose avec affinité de session.La solution supporte l’ajout et la suppression de noeuds dans le worker role et dans le web role. On notera cependant que cet exemple de code n’a été l’objet que de tests minimums.La solution peut être téléchargée à l’URL suivante: In a previous post, I tested ARR in an Azure worker role farm in front of a web role farm so that session affinity can be achieved. In this post, I’ll automate that so that in can be used in a real solution, with elasticity for instance. NB: The Web Role in this solution is just an example of a nearly empty ASP.NET farm that would need session affinity. It could be a Web role with a PHP Web Application or a worker role with TomCat running Java Web Applications. In order to automate the installation and configuration of ARR, we can leverage the startup task that can run in an elevated priviledge account, but the role still runs in a low priviledge account.For that reason, we create a Windows Service that is installed by the startup task, and that runs as Local System (which gives it the right to change IIS configuration). This Windows Service process, as any process in Azure environment can use RoleEnvironment and listen to events in order to adapt ARR to the topology of the farm it exposes with session affinity.The solution supports adding and removing nodes in the Worker Role and in the Web Role. Be aware that basic testing only was done on this sample code.The solution can be downloaded from the following URL:

https://go.archims.fr/kzlRiB

 

Mise à jour (10 mai 2011)

 Il aurait été possible d'éviter de créer un service Windows en configurant le Worker role avec un contexte d'exécution élevé.

https://msdn.microsoft.com/en-us/library/gg557552.aspx#Runtime

Update (10-MAY-2011)

The Windows Service could have been avoided by seeting the worker role to an elevated execution context.

https://msdn.microsoft.com/en-us/library/gg557552.aspx#Runtime

 

Voici quelques détails sur la solutionUn service Windows tourne en tant que SYSTEM Here are a few details of the solutionA Windows Service runs as SYSTEM

image

 

Un endpoint interne doit être ajoutée pour qu’il puisse être découvert par le code An internal endpoint must be added so that is can be discovered by the code

image

                 // get the list of nodes in the Web Farm Role
                Dictionary<string, IPEndPoint> webFarmRoleNodes = new Dictionary<string, IPEndPoint>();
                foreach (RoleInstance instance in webfarmRole.Instances)
                {
                    Trace.WriteLine(string.Format("Role instance {0}", instance.Id));

                    foreach (var endpoint in instance.InstanceEndpoints.Where(e => e.Key == webFarmEndpointName))
                    {
                        string nodeKey = string.Format("{0}", endpoint.Value.IPEndpoint.Address.ToString());
                        webFarmRoleNodes.Add(nodeKey, endpoint.Value.IPEndpoint);
                        Trace.WriteLine(string.Format("WebFarmRoleNode: {0}:{1}", nodeKey, endpoint.Value.IPEndpoint.Port));
                    }
                }
 
La tâche de démarrage The startup task

image

image

 

Le démarrage du service Windows Windows Service start
         protected override void OnStart(string[] args)
        {
            try
            {
                Trace.WriteLine("ARRConfigurationService is starting - V110329k");
                ConfigureArrOnce();

                RoleEnvironment.Changed += new EventHandler<RoleEnvironmentChangedEventArgs>(RoleEnvironment_Changed);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Exception OnStart: '{0}'", ex));
                throw ex;
            }
        }

 

Vous souhaitez tester cela mais vous n’avez pas de compte Windows Azure? Allez sur le site de windowsazure.fr, qui contient en particulier une page pour aider les développeurs à débuter rapidement. You want to test it, but you don’t have an account yet. You can go to windowsazure.com, or more specifically to the Getting Started page

 

Smile

Benjamin