Automatic replication areas failover DHCP server Windows Server 2012
With the release of Windows Server 2012 DHCP server administrator an opportunity to use DHCP server in the failover mode replication reserved addresses on the secondary DHCP server in load balancing mode or hot-swappable. This is a big step forward, which allowed to achieve high-availability DHCP server, reducing downtime for maintenance, installation of software updates and other operations. How to hobnob among the huge number of advantages not without a small but uncomfortable minus. The problem is that after making a reservation on one node failover cluster DHCP, updates are not automatically replicated to the secondary server. For data replication must use the manual mode, it is necessary to right-click on the area in which the changes were made, and from the drop down menu, select "Replicate relations"
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Avtomaticheskaya-replikatsiya-oblastej-otkazoustojchivogo-DHCP-servera-Windows-Server-2012.png
For replication, you can use the command line, namely shell PowerShell running in administrator mode in which you want to execute the command:
Invoke-DhcpServerv4FailoverReplication -ComputerName «name dhcp server to which you want to replicate"
An example of using the command Invoke-DhcpServerv4FailoverReplication
The command below will replicate all the areas involved in the replication group named MS-NN-Failover:
Invoke-DhcpServerv4FailoverReplication -ComputerName dhcpserver.contoso.com -Name MS-NN-Failover
This example starts the replication of all areas located on the server dhcpserver.example.com
Invoke-DhcpServerv4FailoverReplication -ComputerName dhcpserver.example.com
The example below will replicate areas with ScopeID 10.10.10.0 and 20.20.20.0
Invoke-DhcpServerv4FailoverReplication -ComputerName dhcpserver.contoso.com -ScopeId 10.10.10.0,20.20.20.0
Keep in mind that this is not the name of ScopeID area, namely the address pool allocated for the area:
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Avtomaticheskaya-replikatsiya-oblastej-otkazoustojchivogo-DHCP-servera-Windows-Server-20121.png
Automatic replication areas failover DHCP server Windows Server 2012
At the beginning of this article, we reviewed the options area replication from the primary server to the secondary manual. Next, consider the option of establishing an automatic replication. To do this we need to write the script of a single line to create a user with local administrator privileges on the DHCP server, as well add it to the Administrators group and DHCP server in Task Scheduler to create a simple task to start replication.
The script replication
Create the disk C: \ PowerShell file with an arbitrary name, for example:DhcpServerFailoverReplication.ps1. Let's open it for editing and add the following line:
Invoke-DhcpServerv4FailoverReplication -ComputerName dhcp.example.com -force
-force The key will perform the command without displaying confirmation action.
Save the file and proceed to create the user.
Create User
Since my script is in an Active Directory environment, I will not be using a local user, and will create a domain. We'll need to run a scheduled task. And so, we will create a regular user with the nameDhcpServerReplication, add it to the Local Administrators group on each DHCP server participating in failover scenarios.
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Avtomaticheskaya-replikatsiya-oblastej-otkazoustojchivogo-DHCP-servera-Windows-Server-20122.png
Then we add our user to the local Administrators group DHCP.
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Avtomaticheskaya-replikatsiya-oblastej-otkazoustojchivogo-DHCP-servera-Windows-Server-20123.png
Let me remind you once again that the user must be added to these groups on each DHCP server.
Create a job scheduler
It's time to go to the creation of jobs in the Scheduler. It would seem that you can create a simple task scheduler and run it, for example, every 5 minutes. But this option will start shipping channel is useless replication traffic, regardless of whether the record has been updated backup or not.We will use the launch on event. When creating a new backup server logs the Microsoft-Windows-DHCP Server Events / Works Event ID 106.
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike8.png
that's what we'll use to create jobs:
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike.png
Click Next
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike1.png
On the Settings page select trigger: When logging of the specified event.
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike2.png
For security purposes, PowerShell scripts can be executed only interactively, ie you first need to run PowerShell shell and in it specify the path to the script. Therefore, in the «Action» indicate the start powershell.exe, and in the field «Add Arguments» -File option and the path to our script, like so:
-WindowStyle Hidden -File «C: \ DhcpServerFailoverReplication.ps1"
-File - Path to the PowerShell
-WindowStyle Hidden - skip shell window PowerShell
Also in the case, you can specify:
-Command - Performs the command and any other options. This option can also be used to run the script, for example: -Command "& {C: \ Scripts \ start.ps1}". In addition, it can be used to transfer the parameters to the script: -Command "& {C: \ Scripts \ start.ps1 -a 1 -b 3}";
-ExecutionPolicy - Sets the execution policy for the current browser session can be set to Unrestricted, RemoteSigned, AllSigned and Restricted. Sets the policy will apply only to the current session, and takes precedence over any previously established policy;
-NonInteractive - Disable this interactive queries to the user;
-WindowStyle Hidden - Windows PowerShell run in stealth mode, invisible to the user;
-NoProfile - Prevents the load profile, which can slightly speed up the script;
-NoExit - Leave the shell open after execution of the script. This can be useful when testing and debugging the script.
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike3.png
After creating the task run the script on the event, go to the Actions tab and check the start line.
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike4.png
On the General tab, select from any user to run the task, his password, check the box to run for all users, and perform with highest privileges.
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike5.png
Click the Triggers tab, check the source and trigger event.
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike6.png
As a result of these actions is not complex, our scheduler will respond to the occurrence of event ID106 and replicate database. But that is not all. We forgot to set up automatic replication when removing DHCP reservation database. For this we need an event ID 107.
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike9.png
Open the Triggers tab again, and then click Create. In the wizard, complete the required fields, as in the example below:
Journal: Microsoft-Windows-DHCP Server Events / Works
Source: DHCP-server
Event ID: 107
https://blog.eaglenn.ru/wp-content/uploads/2015/07/Sozdanie-zadaniya-v-planirovshhike7.png
After creating this trigger, when logging event ID 107, will also run database replication to the secondary DHCP server.
Afterword
DHCP Manager server creates a reservation for the computer. In the event log Microsoft-Windows-DHCP Server Events / Works event occurs, scheduler receives information about an event and automatically starts the task, which in turn runs the command replication. That's not such a clever way we set up automatic replication failover DHCP server.
More articles in the blog: Notes IT engineer on technologies Microsoft.