Tuesday, January 31, 2012

Running SSH commands from Powershell

There is a really simple way of running ssh commands on unix/linux boxes from a Powershell script. In fact, altough Powershell does not natively support running ssh commands, it can rely on external third party tools to get the job done. The tool I am talking about today is Plink.

Plink (Putty link) is a Putty command line tool similar to ssh that you can get from here

The Powershell  script can call the Plink.exe executable this way:

$sshcommand = & .\plink.exe unixhost -load unixhostsession "mkdir testfolder/testsubfolder;"


$sshcommand = & .\plink.exe unixhost -load unixhostsession "chmod 2750 /testfolder/testsubfolder;"

or even:

$sshcommand = & .\plink.exe unixhost -load unixhostsession "useradd testuser -d /testuser/workshop/home"

As you can understand any command can be fired with Plink.

Of course you can use Powershell variables inside these commands: 

$unixhostname = "sysx.yourcompany.com"
$folder1 = "testfolder"
$folder2 = "testsubfolder"
$sshcommand = & .\plink.exe $unixhostname -load unixhostsession "mkdir $folder1/$folder2;"

In these examples we are using the pretty useful -load switch, which is used by plink to load a saved Putty session. In this case the credentials (username and password, or username and key) are retrieved by Plink from the session named 'unixhostsession'. The session parameters are stored in the Windows Registry under the following registry key:


Remark also the use of the Powershell Call operator (the ampersand, &), which is used to lanch any exe/script.

Last but not least, know that you can concatenate commands using a semi-colon. Just be sure to enclose everything in quotes.

Monday, January 30, 2012

vMotion of MSCS cluster nodes running Windows 2008

Being able to vMotion MSCS cluster nodes is something that is quite difficult to achieve and that need some fine tuning of Windows cluster parameters. The modifications I am going to show you are meant to increase the cluster heartbeat timeout and to decrease the cluster sensitivity to network connection interruptions.

By default MSCS will fail your node if five pings are lost and will initiate a failover.

Unfortunately 5 seconds is sometimes an insufficient time slot for VMWare to complete the vMotion process because while the contents of the guest's memory are copied from one physical host to another, the guest is queisced for a few seconds in order to allow the synchronization of changed blocks of memory. Typically you may lose up to 3 pings.

You need then to change the heartbeat values to their maximums by issuing the commands below on just one of your cluster nodes:

cluster /prop SameSubnetThreshold=10:DWORD
cluster /prop SameSubnetDelay=2000:DWORD

Here's the explanation of these parameters:
  • SameSubnetDelay: The value in milliseconds of the cluster heartbeat frequency.  By default, this value is 1,000 milliseconds. The maximum possible value is 2000.
  • SameSubnetThreshold: The value represents the amount of missed heartbeats that will be tolerated before a failover event occurs. The default value is 5. The maximum value is 10.
Setting these values to 2000 and 10 means that the cluster service will wait for 20 seconds before initiating a failover. 

The commands above are a new feature of the cluster service under Windows 2008. There have been in fact many improvements to the Windows Server 2008 failover clustering service. One of this improvements concerns exactly the cluster heartbeat mechanism.

If these modifications don't resolve your failover problem, then you might also play with some more parameters:
  • check the cluster resource health check policy for each cluster resource
  • increase the value of the Timeoutvalue of the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk registry key, as shown here.
I hope this helps.

Related Posts Plugin for WordPress, Blogger...