Windows Server 2012 Web Farm With Web Deploy 3.0

  • Intended Audience

    This article is intended for system administrators of at least an intermediate skill level when working with Windows Server 2012 operating system operations and administration.

    Introduction

    If you were hoping to launch a nifty IIS Web Farm using Microsoft's Web Farm Framework in IIS8, there is some not-so-happy news: It doesn't work! Microsoft says that they are not abandoning the WFF technology, but so far, the lack of updates, including the ability to function within IIS8, is not really promising.

    So, can you still utilize the awesome new Windows Server 2012 while simultaneously running a fault-tolerant web farm? Yes, you most definitely can! Most of what you will find on Technet or other relater forums on this topic will guide you through using Web Deploy in conjunction with DFS on a third "Content" server, and this usually involves bringing Active Directory into the equation as well.

    Well, what about those of you that are watching the budget and don't want to have to spin up a whole new server simply to store the common configuration to be deployed amongst the various web farm nodes? And what about those of you that want to keep your web deployment simple, without further complications introduced by dealing with Active Directory? Fear not! Below I have highlighted how you can use Web Deploy and Powershell scripts to keep your web content in sync while managing it from a single "Master" server. It is not quite quick to implement and GUI-friendly as WFF, but it uses official Microsoft technology and keeps your web content synced!

    Preparation

    To get started, you will need to create a new user account with the same username and password on each server in the farm. This account will then need to be made a member of the local "Administrators" group on each server, and on the primary server, this account needs to be added to the Log On As Batch security setting. To add the account to the Log On As Batch security setting, navigate to Administrative Tools -> Local Security Policy -> Local Policies -> User Rights Assignment. For this exercise, we are using the below credentials (obviously, you should always select a password that is much more secure):

    Username: SyncMan

    Password: P@ss1234

    Next, on each of your secondary cloud servers, you will want to create a Windows Firewall rule to allow ALL TRAFFIC from the primary server (Master).

    On the Master server only, create a common directory for storing the Web Deploy templates. For example, create a directory like C:\WebSync. Next on the Master server only, open a PowerShell window and execute Set-ExecutionPolicy Unrestricted. When prompted, type Y and hit ENTER.

    Lastly for preparation, for simplicity in your scripts, you will want to modify your Hosts file (located at C:\Windows\system32\drivers\etc\Hosts) to include a listing for each node, matching its internal IP address to an easy host name, such as WEB2.

    Web Deploy

    To use Web Deploy 3.0 on the server, you will need to install it. Go to http://www.iis.net/downloads/microsoft/web-deploy for the install. This must be done on each server in the farm.

    The Scripts

    Now we are going to create a couple scripts on the Master server to be run by the Scheduled Task (we will create this later). The first script is a simple batch script.

    Simply open a new Notepad file, and place the following in the file:

    "powershell.exe -command C:\WebSync\WebDeploySync.ps1"

    We will now save this file as "WDSync.bat" in the C:\WebSync\ folder. As I am sure you can guess from the contents of the batch file, the next script we will be creating is a Powershell script (this type of script has the .ps1 extension). In a new Notepad file, enter the following lines:

    add-pssnapin wdeploysnapin3.0

    New-WDPublishSettings -ComputerName [MasterServerName] -AgentType MSDepSvc -FileName c:\WebSync\[MasterServerName].publishsettings

    New-WDPublishSettings -ComputerName [SecondaryServerName] -AgentType MSDepSvc -FileName c:\WebSync\[SecondaryServerName].publishsettings -UserID SyncMan -Password P@ss1234

    Sync-WDServer -SourcePublishSettings c:\WebSync\[PrimaryServerName].publishSettings -DestinationPublishSettings c:\WebSync\[SecondaryServerName].publishSettings

    **NOTE** The above code reflects a 2-node setup. If you wish to have more secondary nodes, you will need to add another "New-WDPublishSettings -ComputerName [SecondaryServerName]..." line for each secondary server, and you will then need to add a new "Sync-WDServer.." line that syncs the primary server to each subsequent secondary server.

    For the above code, you will save the file with a name of "WebDeploySync.ps1" in the C:\WebSync\ folder.

    Schedule The Task

    Now that the scripts are in place, and all the prep work has been completed. You now need to set up a Scheduled Task to run the scripts at a semi-constant rate to ensure that your web content stays synced across the nodes. This task only needs to be set up on the Master server. When setting it up, we are going to run in with the SyncMan credentials that we specified earlier, and all the task to be run even when the user is not logged on. We will make this a Daily task, that runs every 1 minute for a duration of 1 day. This schedule ensures that it will run indefinitely at a 1 minute interval, as 1 minute is the shortest available interval. To access the Task Scheduler, navigate to START -> Administrative Tools -> Task Scheduler.

    Once in the Task Scheduler, highlight "Task Scheduler Library" in the left column. From this point, click on "Create Task..." in the right-hand Actions pane.

    On the General tab of the Create Task box, enter a descriptive Name for the task, enter the SyncMan credentials by using the "Change User or Group..." button, and then change the radial button selection to "Run whether user is logged on or not". Lastly for the General tab, in the Configure for: drop-down list at the bottom, select Windows Server 2012.

    Your General tab should like like this:

    On the Triggers tab, click the New... button. In the New Trigger box, select Daily from the radial list, and choose a start time of 5 or 10 minutes in the future. Ensure the Recur every: box says "1". In the Advanced settings section, check the box that says Repeat task every:, and manually type in "1 minutes", leaving the for a duration of: box set to 1 Day. (Note, "1 minutes is not a type; make sure you leave minutes plural). Your New Trigger box should look like this:

    Click OK on the New Trigger box. Now click on the Actions tab.

    On the Actions tab, click the New... button. On the Edit Action box, leave the Action: as Start a program, and in the Program/script: field, type in C:\WDSync\WDSync.bat. Your Action should look like this:

    Click OK on the Edit Action tab. On the Conditions tab, make sure to un-check all boxes, so that it looks like this:

    Lastly, on the Settings tab, check the box for Allow task to be run on demand, and leave all other check boxes cleared. In the If the task is already running, then the following rule applies: drop-down list, select Run a new instance in parallel. The Settings tab should look like this:

    You can now click OK on the Create Task box. To ensure that the task runs, you will need to click on Enable All Tasks History in the Actions pane on the right side of the Task Scheduler. Once your task starts running, you can highlight it and click on the History tab to ensure that it is running regularly every minute:

    Testing

    Now that everything is all set up and running, if it was done correctly, you should be able to test this by making a change on the Primary server, and ensuring that it shows up within IIS on the secondary server(s). Likewise, you should be able to make a change on the secondary server(s) in IIS or in the directories controlled by IIS, and you will notice that your change will get overwritten in a minute or less.

    I hope that this has been helpful for those of you trying to implement a web farm in Server 2012 without deploying Active Directory and having to buy additional server!

  • Excellent guide.  Works very well.

    One troubleshooting tip I used after setting this up was to run the content of the batch file "powershell.exe -command C:\WebSync\WebDeploySync.ps1"  in a command prompt.  From there I was able to see and correct any errors in the script.  In my case there was a typo with my password.