Windows, Scripting, Virtualization, Cloud Computing - tricks for getting around in the world of Technology

Windows, Scripting, Virtualization, Cloud Computing - tricks for getting around in the world of Technology


  • Category Archives vCenter
  • Tracking vCenter VM and DB

    It has been a while since I managed to do some writing on my blog, mostly because I’ve been busy with other Real Life events, and general lack of time. But now I’m here to share something that has been sitting in my drafts folder for a while. This one is about virtualization.

    2010 and 2011 were virtualization years for me, I worked on several projects in design, implementation, and I learned so much, that looking back I really get a feeling of accomplishment.
    I’ve also been a little “cutting edge”, non conservative with my designs some would say. I guess practice what you preach kind of stuck with me and I made it my mission to build reliable, self contained VMware environments, as much as possible.

    As part of the design process, you always have to think about your management software

    • Where do you put the pieces of software that help you manage the environment?
    • How do you ensure availability and SLA for these components to allow you to recover from failures?

    The answer to the first question can be:

    Option A: In a management cluster, dedicated to management software for the virtualization stack

    • The advantage is you always know where the VMs are, if you have a failure there are 2 servers they can be on.
    • The disadvantage is you dedicate two physical boxes for this purpose, which can have a maximum utilization of around 40% for failover reasons.

    Option B: Next to production machines

    • The advantage is you don’t have to setup a management cluster, and you optimize resource utilization in your datacenter.
    • The disadvantage is that you lose “determinism”, the security of “I know on what server vCenter is sitting, so i don’t have to look for it”, if i get a cluster failure or worse.

    Well I’ve come up with two “tricks” that tackle the drawbacks of the second option, not knowing where your management servers are, making it a preferred choice if your environment does not warrant a dedicated management cluster just for that.

    #1 Track the movement of vCenter and vCenter DB using vCenter Alarms

    This one is a really easy way to keep track of your vCenter components. It works best combined with the second trick you will see below, mainly because it does not cover all scenarios but the advantage of this method is that the information is provided in real time.

    What I am proposing is that you create an alarm in vCenter, that monitors for events that change the VMhost of your vCenter VM. These events are:

    1. VM is being migrated (manually)
    2. VM is being migrated by DRS
    3. VM is being restarted by HA on another host

    The third trigger will be hit and miss, it stands to reason, that if vCenter is not up to send the mail since it being restarted, you may or may not get the email, or you will get it after the fact. nevertheless it is good to have it there.

    Below are the screenshots of how the alarm would look like:

    On the advanced field put this condition in:

    Then add some notification address or whatever you prefer

    Save your alarm, and then try to migrate vCenter and see what happens. You should do this to the vCenter DB server aswell, and any components you feel you should know where they are, for troubleshooting purposes (VUM, Nexus 1000v Supervisor Modules, Management Appliances).

    #2 Check the vSphere host where vCenter is running using a scheduled script

    Another wasy to check where your vCenter components stay is using a scheduled PowerCLI script that runs once a day and sends you an email where vCenter VM and vCenter database are sitting (which vSphere host)

    This script assumes following:

    1. vCenter VM name in inventory = vCenter VM hostname
    2. vCenter is using separate database, if you don’t care about that, you can remove the references to the DB.
    3. vCenter Database name in inventory = vCenter Database hostname or at least a cNAME with this name (e.g. RO-vcenter > RO-vCenter-DB name, and alias in DNS)

    You can customize this by entering a CSV file of the names of the vcenter instances and their respective databases.

     #version 0.1
    #initial release
    
    Add-PSSnapin Vmware.VimAutomation.Core -ErrorAction:SilentlyContinue
    Set-PowerCLIConfiguration -DefaultVIServerMode multiple -Confirm:$false
    #Write-Host -ForegroundColor Yellow "This script Generates a report detailing which host has the vCenter VM and vCenter DB VM`
    #If you wish to cancel Press Ctrl+C,otherwise press Enter"
    #Read-Host
    
    #using fqdn because certificates are issued using a FQDN
    $vCenter = ('vcenter','vcenter2','vcenter3')
    
    If ($global:DefaultVIServers -ne $null) {
    	DisConnect-VIServer * -Force -Confirm:$false }
    $vCenter | % {Connect-VIServer $_ -NotDefault:$false}
    
    $Report = @()
    $vCenters = $global:DefaultVIServers | % {
    	$row = "" | select vCenterInstance,FrontendVMHost,DBVMName,DBVMHost
    	$row.vCenterInstance = $_.Name
    	$row.FrontendVMHost = (get-vm -Name $_.Name.Split(".")[0] -server $_.Name).VMHost
    	#db is hostname + db
    	$dbvm = "$($_.Name.Split(".")[0])DB"
    	$DBVMName = ([System.Net.Dns]::GetHostByName($dbvm)).HostName.Split(".")[0]
    	$row.DBVMName = $DBVMName
    	$row.DBVMHost = (get-vm -Name $DBVMName* -server $_.Name).VMHost
    	$Report += $row
    }
    
    $FileDate = get-date -Uformat "%Y%m%d-%H%M%S"
    $Path = "c:\temp\vsphere\"
    $File = "$FileDate-vCenter-InfraLocation.csv"
    $Report | Export-Csv -NoTypeInformation -UseCulture "$Path$File"
    
    $encoding = [System.Text.Encoding]::UTF8
    #I made the convoluted out-string construct because the object cannot be serialized"
    $ReportBody = $null
    $ReportBody += $Report | % { "
    `n
    `n$($_.vCenterInstance)`n$($_.FrontendVMHost)`n$($_.DBVMName)`n$($_.DBVMHost)"}$Body = "</pre>
    <div>I'm the PowerCLI Magic Script. This is the list of your vCenter instances and their locations in the Infrastructure.
    `
    If you ever lose track of them, this email is the reminder. The latest update is from $FileDate
    `
    Below is the detailed information about each Instance:
    `
    `n`n`n`n`n`n$ReportBody`n`n
    <table border="`&quot;1`&quot;">
    <tbody>
    <tr>
    <td>vCenterInstance</td>
    <td>FrontendVMHost</td>
    <td>DBVMName</td>
    <td>DBVMHost</td>
    </tr>
    </tbody>
    </table>
    </div>
    <div>"
    
    Send-MailMessage -Smtpserver smtpserver -From 'admin_vmware@foo.com' -To 'vSphereAdministrators@foo.com' -Body $Body -Bodyashtml -Encoding $encoding -Subject "vCenter Instances List" -Attachments $Path$File

    Learning points:

    Line 11: This is where you define you vCenter server names, if you have more of them. I had 3 for example.

    Line 22 & 27: This is where you perform a get-vm to find out the host where this VM is residing on

    The rest of the script is just to cycle through all vCenter instances and create an email that it sends to a given email address.

    Perhaps to some people this may seem unnecessary, as they may not have faced major outages, perhaps to some it may seem that these monitoring tricks are not enough to cover monitoring of all ‘outages’ situations, but I find it is not worse than having a separate management cluster, with the added benefit of not having to deal with another separate management cluster.

    C&C as always is welcome

    Share

  • Fix “Transaction log for database ‘VIM_VCDB’ is full” errors

    Posted on by Ionut Nica

    This is one of those “note to self posts”, in hope this may hit me again so I don’t go wandering the Internet all over again. I have a small VMware lab at home, and a few days ago I was confronted with an issue related to vCenter – the management application for VMware’s hypervisor. I tried to connect to my vCenter installation – connection refused….ok, I’ve seen this before, probably the service is not up. Initially I thought there had been a power outage at my home (they kinda happen) and the vCenter Service hanged upon starting (this also kinda happens)

    No problem I can fix it! open services snap-in remote to vCenter machine, start service, service starts, close snapin. Start vSphere Client client works, play around with it a bit, close Client.

    Time goes by, I need to log back into the system again for some work. Connection refused….now this is rich, no power outage, why is the service crashing? Ok, it’s just life treating me badly VMware is acting up (not that is usually does), open service, start service, login again to vCenter, do some work, few minutes later client disconnects…reconnect not working.

    Ok, troubleshooting mode now; open Splunk, sort by events from that host, anything that is not information from the system log. And there it was:

    Error[VdbODBCError] (-1) “ODBC error: (42000) – [Microsoft][SQL Native Client][SQL Server]The transaction log for database ‘VIM_VCDB’ is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases” is returned when executing SQL statement “UPDATE VPX_VM WITH (ROWLOCK) SET SUSPEND_TIME = ? , BOOT_TIME = ? , SUSPEND_INTERVAL = ? , QUESTION_INFO = ? , MEMORY_OVERHEAD = ? , TOOLS_MOUNTED = ? , MKS_CONNECTIONS = ? , FAULT_TOLERANCE_STATE = ? , RECORD_REPLAY_STATE = ? WHERE ID = ?”

    Ouch, something really broke, Immediately I made quick check to see if I had disk space left, which I had, so this was not going to be this easy.

    In that case: to the Internets! Found this thread on the VMware communities. I won’t bore you anymore with the storyline, I’ll just get to fixing this issue

    Note: this is probably an extremely trivial topic that does not happen on production databases, with vigilant DBA;s. However this is a homelab and I’m not a DBA :) and if you are reading this, probably so are you.

    The Fix

    To fix this you will need SQL Server Management Studio Express installed either on the server holding the databases or on a management machine (in which case you better know how to give yourself remote access to the vCenter Database Server, I couldn’t, so I installed it locally on the affected machine). You’l also need a local administrator account to run the management studio under.

    Once in the management studio, select the VIM_VCDB database, right click properties:

    On the left side of the new window select the File section:

    So, there are 2 files, database and the logs. The error we got mentioned log files. A quick look in my setup revealed I had reserved only 460MB for logs (screenshot taken after fix). Scroll down to the right, and find the “…” button, which will let you configure the maximum size of the log files.

    Now change this value to a bigger value, for a home lab 2GB is quite a lot actually, but i wanted to be safe. Close all windows by pressing OK, close the Management Studio.

    After this restart VMware VirtualCenter Server service and watch your vCenter go :) .

    Now for a little investigation why this happened. The vCenter database holds performance data, VM metadata and the likes…but how could 8VM’s gather performance data in less than 2 months that fit into 460MB which was the configured size of the log file….Well the answer lies into vCenter Server Settings, once I started browsing the menus I remembered, that just for testing I configured the statistics logging level to 4 (highest) for each retention period, and not just for testing, I Forgot to turn it off, lesson learned now.

    p.s. This my first non scripting post :)

    Share


  • dinamic_sidebar 4 none

©2012 Ionut Nica Entries (RSS) and Comments (RSS)  Raindrops Theme  
View in: Mobile | Standard