Setting Up a Windows Server 2012 Web Farm with Web Deploy 3.0
This article is intended for system administrators who have at least an intermediate skill level when working with Windows Server 2012 operating system operations and administration.
If you were hoping to launch an IIS web farm by using the Microsoft Web Farm Framework in IIS version 8, here is some bad news: it doesn't work. Microsoft says that it is not abandoning the Web Farm Framework technology, but so far, the lack of updates, including the ability to function within IIS 8, is not really promising.
So, can you still use the new Windows Server 2012 while simultaneously running a fault-tolerant web farm? Yes, you can. Most of the information you can 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 method usually involves Active Directory as well.
However, what if you are watching the budget and don't want to spin up a whole new server simply to store the common configuration to be deployed amongst the various web farm nodes? And what if you want to keep your web deployment simple, without further complications introduced by Active Directory? The good news is that you can. This article highlights how you can use Web Deploy and Powershell scripts to keep your web content in sync while managing it from a single "Master" server. This method is not quite as quick to implement and GUI-friendly as Web Fam Framework, but it uses official Microsoft technology and keeps your web content synced.
Perform the following steps to get started:
- Create a new user account with the same username and password on each server in the farm.
This exercise uses the following credentials, but you should select a password that is more secure.
- On each server, make this new account a member of the local Administrators group.
- On the primary server, add this account to the Log On As Batch security setting, which you can access by navigating to Administrative Tools -> Local Security Policy -> Local Policies -> User Rights Assignment.
- On each of your secondary cloud servers, 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.
- On the Master server only, open a PowerShell window and execute Set-ExecutionPolicy Unrestricted. When prompted, type Y and hit ENTER.
- For simplicity in your scripts, 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.
Install Web Deploy
To use Web Deploy 3.0, you must install it on each server in the farm. Go to http://www.iis.net/downloads/microsoft/web-deploy to install Web Deploy.
Create the Scripts
Now you need to create a couple of scripts on the Master server to be run by the scheduled task (which you will create later). The first script is a simple batch script.
Open a new file in Notepad, and place the following line in the file:
powershell.exe -command C:\WebSync\WebDeploySync.ps1
Save this file as "WDSync.bat" in the C:\WebSync\ folder.
The next script to create is a Powershell script (this type of script has the .ps1 extension). In a new Notepad file, enter the following lines:
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 preceding code reflects a two-node setup. If you want to have more secondary nodes, you need to add another
New-WDPublishSettings -ComputerName [SecondaryServerName]... line for each secondary server, and you then need to add a
line that syncs the primary server with each subsequent secondary server.
Save the file with a name of "WebDeploySync.ps1" in the C:\WebSync\ folder.
Schedule the Task
Now that the scripts are in place, you need to set up a scheduled task to run the scripts at a semi-constant rate to ensure that your web content stays synchronized across the nodes. You need to set this task up only on the Master server. When setting it up, use the credentials that you specified when creating the account (in this example, SyncMan), and specify that the task should run even when the user is not logged on. 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.
- From the Start menu, go to Administrative Tools > Task Scheduler.
- In the Task Scheduler, select Task Scheduler Library in the left navigation pane.
- In the Actionspane on the right, click Create Task.
- On the General tab of the Create Task dialog box, perform the following steps:
a.Enter a descriptive name for the task.
b. Enter your credentials (SyncMan in this example) by clicking the Change User or Group button.
c. Select the Run whether user is logged on or not option.
d. In the Configure for list at the bottom of the dialog box, select Windows Server 2012.
Your General tab should look as follows:
- On the Triggers tab, click the New.
- In the New Trigger box, select the Daily option, and choose a start time of 5 or 10 minutes in the future.
- Ensure that the Recur every n days box has a value of 1.
- In the Advanced settings section, select the Repeat task every check box and manually type in 1 minutes (ensure that you type plural minutes.) Leave the for a duration of value set to 1 Day.
- Ensure the Enabled check box is selected.
- Your New Trigger box should look like this:
- Click OK on the New Trigger box and then click on the Actions tab.
On the Actions tab, click the New.
In the New Action dialog box, leave the value of 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 New Action dialog box tab.
Click the Conditions tab, and clear all the chck boxes, so that it looks as follows:
On the Settings tab, select the Allow task to be run on demand check box, and leave all other check boxes cleared.
In the If the task is already running, then the following rule applies: list, select Run a new instance in parallel.
The Settings tab should look like this:
Click OK on the Create Task dialog box.
To ensure that the task runs, 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, as shown in the following screenshot:
You can verify a successful setup by making a change on the Master server, and ensuring that it appears within IIS on the secondary servers. Likewise,if you make a change on a secondary server in IIS or in the directories controlled by IIS, and you should notice that your change is overwritten in a minute or less.
After completing your setup, run the following batch file in a command prompt:
powershell.exe –command C:\WebSync\WebDeploySync.ps1
As a result, you should be able to see and correct any errors in the script.
© 2014 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License
See license specifics and DISCLAIMER