Archive for the ‘Windows Server 2008 R2 NLB’ Category

Create IIS NLB Copy Full Website Resource Windows 2008R2 With Powershell

If you are Building a Webfarm you need often Test websites and all the Sites needs to be the same Winking smile

Well below is a powershell Scripts that copy the Site and Creates a new one On the Same Server.

 

# NAME: Copy-Website.ps1
#
# AUTHOR: Robert Smit
# EMAIL: robert.smit@aca-computers.nl
#
# COMMENT: Script to create a Copy-Website.
#   
# You have a royalty-free right to use, modify, reproduce, and
# distribute this script file in any way you find useful, provided that
# you agree that the creator, owner above has no warranty, obligations,
# or liability for such use.
#
# VERSION HISTORY:
# 1.0 4.06.2011 – Initial release
#
###########################################################################
ImportSystemModules
#Importing Microsofts PowerShell-modules

#Set ExecutionPolicy
#Set-ExecutionPolicy -scope LocalMachine RemoteSigned –force

#Importing Microsofts PowerShell-module for administering IIS
Import-Module WebAdministration

#List website
Write-Host "List IIS Website…" -ForegroundColor yellow
get-Item IIS:\Sites\*

#Variables for creating the new Website
#
#
$sourceweb = Read-Host "Enter the Website to Copy"
$destinationweb = Read-Host "Enter the New Websitename"
$ChangedDemoSiteBinding = Read-Host "Enter the Hostheader of the website"
$LogDir = Read-Host "Enter the website path of the new website"

#Copy website
Write-Host "copy IIS Website…" -ForegroundColor yellow
copy-Item IIS:\Sites\$sourceweb -destination IIS:\Sites\$destinationweb

#Create Application pool
Write-Host "Create Application pool…" -ForegroundColor yellow
New-WebAppPool $destinationweb

#Link Application pool
Write-Host "Link Application pool…" -ForegroundColor yellow
get-ItemProperty IIS:\Sites\$destinationweb
Set-ItemProperty IIS:\Sites\$destinationweb -name applicationPool -value "$destinationweb"

#Set nieuwe Host name
Write-Host "Set nieuwe Host name…" -ForegroundColor yellow
get-Item IIS:\Sites\$destinationweb
Set-ItemProperty IIS:\Sites\$destinationweb -Name bindings -Value @{protocol="http";bindingInformation="192.168.123.1:80:$ChangedDemoSiteBinding"} #change the IP here

#Set new Path
Write-Host "Set new Path…" -ForegroundColor yellow
get-Item IIS:\Sites\$destinationweb
Set-ItemProperty IIS:\Sites\$destinationweb -Name physicalPath -Value "$LogDir"

#Scopy site
#Write-Host "Scopy site …" -ForegroundColor yellow
#Copy-Item "C:\Put your folder here\*" $LogDir # change The Filepath here

#Set user account
Write-Host "Set user account…" -ForegroundColor yellow
Set-ItemProperty IIS:\Sites\$destinationweb -Name Username -Value "Username"
Set-ItemProperty IIS:\Sites\$destinationweb -Name Password -Value "Password"

Powershell Create Windows 2008 R2 Cluster

Teched 2010 Berlin #TEE10 #Teched

For Demo and learning Sites you need often thing that takes only a minute but when you play with it it takes more time than you want.So with this in my mind I created 3 powershell scripts that you can use for building a cluster , NLB Cluster and a MSTDC cluster resource.So If you want to create a Cluster you can do this in the GUI or with a Powershell Script.

So make sure the disk are formatted and that Your network is ok. and if you running this script in a environment with a Windows 2003 DC with DNS. You may have to set extra security to get things working.

You can find the Scripts Here : Powershell Scripts

Powershell Create Cluster Teched 2010 Berlin #TEE10 #Teched

This Cluster creation script creates a two node cluster with a witness disk at your choice. First we do the import of the modules and add the feature for failover clusters this section you have to do this on every node. You can do this remote if you want. Or run the script on the other node and abort it on the input section.

 

#Importing Microsofts PowerShell-modules
Write-Host "Install System Modules" -ForegroundColor yellow
ImportSystemModules
#Add-WindowsFeature
Write-Host "Add Failover Clustering" -ForegroundColor yellow
Add-WindowsFeature Failover-Clustering
#Importing Microsoft
s PowerShell-module for administering NLB Clusters
Write-Host "Install ServerManager Modules" -ForegroundColor yellow
Import-Module ServerManager

Here we put the cluster names , netbios, clustername, IP etc.

#Variables for creating the new cluster
Write-Host "Cluster Properties Hostname / Node Names" -ForegroundColor yellow
$Clusternode1 = Read-Host "Enter ClusterNode 1 for the new cluster"
$Clusternode2 = Read-Host "Enter ClusterNode 2 for the new cluster"
$ClusterFqdn = Read-Host "Enter Cluster for the new cluster"
$ClusterIP = Read-Host "Enter cluster primary IP"
#Clear old Cluster info
Write-Host "Old Cluster Configuration Will Be ereased just to make sure" -ForegroundColor yellow
Clear-ClusterNode $Clusternode1 -force
Clear-ClusterNode $Clusternode2 -force

#Validating new cluster
Write-Host "Validate Windows 2008 R2 Cluster…" -ForegroundColor yellow
Test-Cluster $Clusternode1 -ignore network,inventory,storage

#Creating new cluster
Write-Host "Create Windows 2008 R2 Cluster…" -ForegroundColor yellow
New-Cluster -Node "$Clusternode1" -Name $ClusterFqdn -NoStorage -StaticAddress "$ClusterIP"

If you have multiple disks and you don’t know what is cluster disk 4 or 6 or what disk should be used for the Quorum disk ? Well I did make a selection that shows only the smallest disk that are available

#Show Cluster Disk Available
Write-Host "Show Cluster Disk Available…" -ForegroundColor yellow
Get-ClusterAvailableDisk
#Show Wittness Disk Capable
Write-Host "Show Wittness disk for Cluster Available…" -ForegroundColor yellow
Get-ClusterAvailableDisk | ?{ $_.Size -lt 1573741824}

Sure You can change this for not to put in “cluster disk 1” but use only the disk number.

# Place the Wittness disk
Write-Host "Choose a Wittness disk for the Windows 2008 R2 Cluster… Must be "Cluster Disk # "" -ForegroundColor yellow
$ClusterQuorumdisk = Read-Host "Enter Wittness disk Cluster Disk number"

# Add disks to the Cluster
Write-Host "Add disks to Windows 2008 R2 Cluster…" -ForegroundColor yellow
Get-ClusterAvailableDisk | Add-ClusterDisk

Here Is the mounting off the cluster disk and I put a sleep in it this way I make sure the disk is online

#Show Wittness Disk Capable
Write-Host "Show Wittness disk for Cluster Available…" -ForegroundColor yellow
Get-ClusterAvailableDisk | ?{ $_.Size -lt 1573741824}
Start-Sleep -Seconds 5
# Change the quorum model
Write-Host "Change the Quorum model Windows 2008 R2 Cluster…" -ForegroundColor yellow
Set-ClusterQuorum -NodeAndDiskMajority $ClusterQuorumdisk

The Second node is added If you have a four node cluster just add them here

Add-Clusternode $Clusternode2 ,$Clusternode3 , $Clusternode4

But you must also use the input section above

$Clusternode3 = Read-Host "Enter ClusterNode 3 for the new cluster"

$Clusternode4 = Read-Host "Enter ClusterNode 4 for the new cluster"

 

# Add Cluster node
Write-Host "Add Cluster node to Windows 2008 R2 Cluster…" -ForegroundColor yellow
Add-Clusternode $Clusternode2

You can find the Scripts Here : Powershell Scripts

Powershell Create Cluster 

Teched 2010 Berlin #TEE10 #Teched

Powershell Network Load Balancing

Teched 2010 Berlin #TEE10 #Teched

For Demo and learning Sites you need often thing that takes only a minute but when you play with it it takes more time than you want. So with this in my mind I created 3 powershell scripts that you can use for building a cluster , NLB Cluster and a MSTDC cluster resource.

This powershell script is fully unattended an yes it is not complete it can be improved.  But you can always adjust this. Similar scripts are there for creating Exchange NLB.

This script runs on node 1 and is creating the NLB on the two or more nodes. ( tested only on two nodes )

You can find the Scripts Here : Powershell Scripts

Powershell Create NLB

The first thing you might want to change is the network adapter name I used adapter 3 and renamed it to NLB later in the NLB name is used as parameter,

#Set IP for NLB Write-Host "Set NLB IP and change Network adapter" -ForegroundColor yellow Netsh interface ip set address name="Local Area Connection 3" static 1.1.1.1 255.255.255.0 Netsh interface set interface name="local area connection 3" newname="NLB"

The Ip adress is needed to set the NLB don’t worry the IP will be removed when the NLB is complete.

The other part is the powershell script is connecting thrue powershell to the other node.

First give the netbios name from the second node ( make sure your DNS is OK )

#Adding additional cluster nodes based on user input
Write-Host "Give Second NLB host" -ForegroundColor yellow
$Node2Fqdn = Read-Host "Enter 2e NLB node"

Here with the “function EndPSS { get-pssession | remove-pssession } “
and “endpss “ I connect and disconnect to the other node. the problem here was. in the basic security you can only use 5 remote connections. I can adjust this or make a workaround so the script works in the default security template.

Now I connect from node 1 to node 2 and placed a IP and renamed the NIC

function EndPSS { get-pssession | remove-pssession }
#Set Network Adapter
#Enter-PSSession -ComputerName $Node2Fqdn
invoke-command -computername $Node2Fqdn -scriptblock { Netsh interface ip set address name="local area connection 3" static 1.1.1.2 255.255.255.0}
invoke-command -computername $Node2Fqdn -scriptblock { Netsh interface set interface name="local area connection 3" newname="NLB"}
Write-Host "Placed NLB IP and changed NIC to NLB" -ForegroundColor yellow
exit-PSSession
endpss

#Import-Module NetworkLoadBalancingClusters
Write-Host "Import-Module NetworkLoadBalancingClusters On Remote Node" -ForegroundColor yellow
Enter-PSSession -ComputerName $Node2Fqdn
invoke-command -computername $Node2Fqdn { Import-Module NetworkLoadBalancingClusters}
exit-pssession
endpss

#Add Remote Node To NLB
Write-Host "Adding cluster node $Node2Fqdn" -ForegroundColor yellow
Get-NlbCluster | Add-NlbClusterNode -NewNodeName $Node2Fqdn -NewNodeInterface NLB

#Remove Old IP
Remove-NlbClusterNodeDip 1.1.1.2 -Hostname $Node2Fqdn -force
Write-Host " Remove old IP node " -ForegroundColor yellow

Here I removed the IP that was needed to create the NLB.

You can find the Scripts Here : Powershell Scripts

Powershell Create NLB

  • Tag