VMware vSphere Replication은 VMware vCenter Server의 확장이며 스토리지 기반 복제의 대안으로 사용할 수 있습니다. VMware vSphere Replication을 사용하면 둘 이사의 사이트 간에 또는 동일한 사이트 내에서 가상 시스템을 복제하는 방식으로 부분 또는 전체 사이트 장애로부터 가상 시스템을 보호할 수 있습니다.
vRealize Orchestrator용 vSphere Replication 플러그인을 사용하여 vSphere 환경에서 복제 및 구성 작업을 자동화하려는 경우 vSphere Replication 플러그인 사용에서 정보를 찾을 수 있습니다.
vRealize Orchestrator는 강력한 워크플로우 생성 기능을 제공하여, 자동화 프로세스 구현을 보다 쉽게 구현 하도록 지원합니다.
운영자는 vRealize Orchestrator를 이용한 워크플로를 생성하고, 프로세스화하는 방법을 알고 있어야 하며, vReplication의 동작 방식에 대한 이해를 하고 있어야 합니다.
이러한 vReplication의 기능은 DR 솔루션 혹은 Backup 솔루션의 핵심적인 복제 기능만을 대체하여, 비용을 줄이는 효과를 나타낼 수 있습니다. 그러나, DR 솔루션인 SRM(Site Recovery Manager)이나 3rd party 솔루션인 백업 도구에는 이러한 오케스트레이션을 위한 자동화 프로세스에 대한 고급 기능을 포함하고 있기에 대규모 인프라에서는 여전히 필요로 하는 필수 도구가 될 것입니다.
vSphere Replication은 스토리지 기반 복제 대신 사용됩니다. vSphere Replication을 통해 다음 사이트 간에 가상 시스템을 복제하여 부분 또는 전체 사이트 장애로부터 가상 시스템을 보호할 수 있습니다.
- 소스 사이트에서 대상 사이트로 복제
- 단일 사이트 내의 한 클러스터에서 다른 클러스터로 복제
- 여러 소스 사이트에서 공유 원격 대상 사이트로 복제
vSphere Replication은 스토리지 기반 복제와 비교하여 여러 가지 이점을 제공합니다.
- 가상 시스템당 더 낮은 비용으로 데이터 보호
- 소스 사이트와 대상 사이트에서 스토리지 벤더를 유연하게 선택할 수 있는 복제 솔루션
- 복제당 전반적으로 낮은 비용
이 기사에서는 vSpere Replication을 이용 시, 복구 과정에서의 손쉬운 VM 등록을 위한 프로세스를 위한 VMware PowerCLI 도구(Windows Powershell 기반)를 이용한 powershell script를 다루는 과정을 다룹니다.
vSphere Replication은 vSphere 하이퍼바이저에 포함된 free 기능으로 자유롭게 이용할 수 있으나, 많은 수의 VM을 복제 후 복제 대상 사이트에서 동시에 기동하기가 어렵습니다.
첫째, 단일 가상 시스템만 작업이 가능
둘째, 가상 시스템의 vNIC에 대한 port group 변경 작업을 필요
이러한 2가지 이유만으로도 가상 시스템이 3~4개가 넘어가게 되면 각각 가상 시스템마다 설정 작업을 vCenter UI에서 진행하는데 있어서 불편함이 발생할 것입니다.
이런 이유로 아래와 같이 Powershell script를 이용하여, 기존 원본 사이트에서 기존 가상 시스템의 네트워크 구성 정보, 포트 그룹 구성 정보를 수집하였습니다. 이후, 대상 사이트에서는 수집된 정보를 기반으로 vReplication 작업을 중지 이후, VM을 인벤토리에 등록하는 작업과 해당 VM의 vNIC별 포트 그룹을 대상 사이트가 지닌 속성 값으로 다시 설정하는 작업을 수행하도록 함으로서 다수의 가상 시스템에 대한 복제 작업 중단 및 대상 사이트에서 복구 작업을 진행 시 원활한 작업을 진행할 수 있습니다.
* vSphere Replication 구성 후, VM 정보 수집
VM Source site에 대한 VM 및 Network adapter, DVS portgroup 정보를 수집 필요, 해당 정보를 기반으로 복구 사이트의 VM에 대한 Network Portgroup name을 다시 재 구성을 함으로 복구 원본 사이트(Source Site)와 복구 대상 사이트(Target Site)에 대한 동일한 DVS Portgroup Name이 구성되어야 합니다.
1) GetNetworkNames.ps1 파일 실행(원본 사이트 vCenter 접속)
- "Network_Portgroup.csv" 파일을 동일 폴더에 자동 생성
- 주기적인 파일 실행을 통한, .csv 파일의 update 필요, 예약 실행을 통한 반복 작업 권장
Login 계정 및 Password 정보를 입력을 필요로 함으로, 읽기 권한으로 한정된 계정을 구성하여, script 파일내 계정 정보 변수에 대한 사
전 정보 정의
GetNetworkNames.ps1
#$VerbosePreference = "Continue"
function GetNetworkAdapters{
#This provides the function with Debug/Verbose/WhatIf parameters.
Begin
{
Write-Verbose "Retrieving VMs' Network Port Group Info . . ."
}#Begin
Process
{
try
{
$GetVMs = Get-VM
$VMsCount = $GetVMs.count
$i=1
foreach($VM_Name in $GetVMs) {
$j=$i/$VMsCount*100
$j="{0:f2}" -f $j
Write-Progress -Activity "Search in Progress" -Status "$j% Complete:" -PercentComplete $j;
Get-VM -name $VM_Name | Get-NetworkAdapter | Select @{N="VM";E={$_.Parent.Name}},Name,NetworkName,Type | export-csv -Path "c:\Temp\Network_Portgroup.csv" -Append -NoTypeInformation
$i++
Write-Verbose "Search $VM_Name to get a port group name"
}
}#try
catch
{
"Error: You must connect to vCenter first." | Out-host
}#Catch
}#Process
End
{
}#End
}
function vCenterLogin {
# vCenter Server on Source Site
$vCenter = 'vmk-vcs01.vmk.local'
# vCenter Username
$username = "ichoi@vsphere.local"
$password = "Rhksflwk123!"
Disconnect-VIServer -Force -confirm:$false -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null
Write-Host "Connecting to $vCenter..." -Foregroundcolor "Yellow" -NoNewLine
$connection = Connect-VIServer -Server $vCenter -username $username -password $password -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null
}
function vCenterlogout {
Disconnect-VIServer -Force -confirm:$false -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null
}
Clear-Host
Date
vCenterLogin
GetNetworkAdapters
vCenterlogout
* VM 복구를 위한 Task
1) 복구 사이트의 vSphere Replication 프로세스 전체 중지
2) VMRun.ps1 파일 실행(복구 사이트 vCenter 접속)
3) 복구 대상 Datastore name, VM folder name, resourcePool name 혹은 Cluster name 입력
4) 자동으로 인벤토리 등록되지 않은 VM을 검색을 위해서 Datastore를 Client에서 접근하도록 Client 집적 연결함으로, Powershell New-PSdrive 명령어 수행 시, NFS통한 연결 포트가 막혀있지 않아야합니다.
5) Excel .csv 파일로 등록되지 않은 VM 리스트를 출력하여 사용하며, 앞서 검색한 원본 사이트의 Network 정보를 불러와서 VM 이름으로 비교하여 복구 VM에 대한 인벤토리 등록, 포트그룹 재설정, 전원 켜짐, 네트워크 어덥터 연결됨 변경 등을 수행합니다.
VMRun.ps1
#$VerbosePreference = "Continue"
$ErrorActionPreference = "SilentlyContinue"
$ActionPreference = "SilentlyContinue"
Clear-Host
##############################
# Check the required modules #
##############################
function vmware-check-Module ($m) {
# If module is imported say that and do nothing
if (Get-Module | Where-Object {$_.Name -eq $m}) {
write-host "Module $m " -f Magenta -NoNewLine
write-host "is already imported." -f Green
} else {
# If module is not imported, but available on disk then import
Write-Warning "Module $m is NOT imported (must be installed before starting)."
if (Get-Module -ListAvailable | Where-Object {$_.Name -eq $m}) {
Import-Module 'VMware.PowerCLI' -Verbose
} else {
# If module is not imported, not available on disk, but is in online gallery then install and import
if (Find-Module -Name 'VMware.PowerCLI' | Where-Object {$_.Name -eq 'VMware.PowerCLI'}) {
Install-Module -Name 'VMware.PowerCLI' -Force -Verbose -Scope CurrentUser
Import-Module 'VMware.PowerCLI' -Verbose
} else {
# If module is not imported, not available and not in online gallery then abort
Write-Warning "Module $m not imported, not available and not in online gallery, exiting."
EXIT 1
}
}
}
}
function Check_PS_Version
{
$version = (Get-Host).Version.Major
if($version -lt 3)
{
#--- Windows Form to alert user the detected powershell version is not sufficient ---#
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$ans = [System.Windows.Forms.MessageBox]::Show(
"This script requires Windows Management Framework 3.0 or higher`n`nClick Yes to be directed to the download page", `
"Attention", `
[System.Windows.Forms.MessageBoxButtons]::YesNo, `
[System.Windows.Forms.MessageBoxIcon]::Exclamation)
if($ans -eq "Yes")
{
start 'http://www.microsoft.com/en-us/download/details.aspx?id=34595'
}
exit
}
}
function vCenter_connect {
#################################
# vSphere Targeting Variables #
#################################
write-host;
write-host;
$vCenter = Read-Host 'Enter the vCenter domain or IP Address'
#$vCenter = 'vCenter domain URL or IP Address'
write-host;
$username = Read-Host 'Enter The your vCenter Username administrator@vsphere.local'
#$username = 'administrator@vsphere.local'
write-host;
$password = Read-Host 'Enter The vCenter Password' -AsSecureString
$vccredential = New-Object System.Management.Automation.PSCredential ($username, $password)
Disconnect-VIServer -Force -confirm:$false -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null
Write-Host "Connecting to $vCenter..." -Foregroundcolor "Yellow" -NoNewLine
$connection = Connect-VIServer -Server $vCenter -Cred $vccredential -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null
If($? -Eq $True){
Write-Host "Connected" -Foregroundcolor "Green"
}
Else{
Write-Host "`nError in Connecting to $vCenter; Try Again with correct user name & password!" -Foregroundcolor "Red"
sleep 5
break
}
}
Function Connect_Portgroup {
Begin{
}
Process{
try{
#Set Variables to point to the csv with your import data
$csvpath = '.\Network_Portgroup.csv'
$drlistpath = '.\drlists.csv'
#change the network (portgroup) for each network adapter in each vm in the csv
$vmniclist = import-csv $csvpath
$drlists = import-csv $drlistpath
$dritem = $null
ForEach ($dritem in $drlists){
ForEach ($vmpg in $vmniclist){
$vmname = $($vmpg.vm)
$nwadapter = $($vmpg.name)
$nwname = $($vmpg.networkname)
if ($vmname -eq $dritem.vmname){
$checkitem="1"
$mynewpg = Get-VDPortGroup $nwname
Get-VM -Name $dritem.vmname | Get-NetworkAdapter -Name $nwadapter | Set-NetworkAdapter -PortGroup $mynewpg -confirm:$False
}
}
if ($checkitem -ne "1"){
Write-host "$dritem.name is not found."
}
else{
$power_vm=$dritem.vmname
get-vm $power_vm | start-vm -Confirm:$False -RunAsync
Write-Host "Messages: Power ON $power_vm"
sleep 3
# Confirm VM Moved or copied
$VMquestion=Get-VMQuestion
if ($VMquestion = $null) {
Get-VMQuestion | Set-VMQuestion –Option "I copied it"
}
# Check box - Conntected Network Adapter
Get-VM -Name $dritem.vmname | Get-NetworkAdapter -Name $nwadapter | Set-NetworkAdapter -Connected:$true -Confirm:$False
$checkitem = "0"
}
}
}#try
catch{
"Connect portgroup error" | out-host
break
} #catch
}#Process
End{
}
}
function Import-VMX-from-datastore{
#This provides the function with Debug/Verbose/WhatIf parameters.
[CmdletBinding(SupportsShouldProcess=$True)]
#Defined input parameters.
Param(
[parameter(Mandatory=$true)]
[string]$Cluster,
[parameter(Mandatory=$true)]
[string]$Datastores,
[parameter(Mandatory=$true)]
[string]$VMFolder
)
Begin
{
Get-Variable true | Out-Default; Clear-Host;
Write-Host "Retrieving VMX Path Info . . ."
}#Begin
Process
{
try
{
#Actual import code.
foreach($Datastore in Get-Datastore $Datastores) {
# Collect .vmx paths of registered VMs on the datastore
Write-host "`nWait registering process in few minute . . .`n"
$registered = @{}
$unregistered = @{}
Get-VM -Datastore $Datastore | %{$registered.Add($_.ExtensionData.Summary.Config.VmPathName.Split('/')[-1],$true)}
# Set PSDrive for the search.
New-PSDrive -Name TgtDS -Location $Datastore -PSProvider VimDatastore -Root '\' | Out-Null
$unregistered = @(Get-ChildItem -Path TgtDS: -Filter *.vmx -Recurse | where {$_.FolderPath -notmatch ".snapshot" -and !$registered.ContainsKey($_.Name)})
Remove-PSDrive -Name TgtDS
#Check-completed
If ($unregistered -ne $null ) {
#$UnRegvmscnt = $unregistered.count
#$j=1
#$unregistered | Select Name | Get-Unique -AsString
$vmgroup = @{}
$unregistered | %{$vmgroup.Add($_.name.Split('.')[0], $ture)}
$vmgroup.GetEnumerator() | Select-Object -Property @{N='VMName';E={$_.Key}} | Export-Csv -NoTypeInformation -Path '.\drlists.csv'
foreach ($unregisteredvm in $unregistered){
#$i=$j/$UnRegvmscnt*100
#Progress Bar
#Write-Progress -Activity "Registering in Progress" -Status "$i% Complete:" -PercentComplete $i
#Register all .vmx Files as VMs on the datastore.
New-VM -VMFilePath $unregisteredvm.datastorefullpath -ResourcePool $Cluster -Location $VMFolder -RunAsync
#$j++
}
} # if
} #foreach
}#Try
catch
{
"Error: You must input corrected data.`n" | Out-host
sleep 5
break
}
}#Process
End
{
}#End
}#Import-VMX-from-datastore
function Exit_Program {
Disconnect-VIServer -Force -confirm:$false -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null
Write-Host "Exiting Program . . .`n"
sleep 5
} # exit
# Check Powershell version
Check_PS_Version
# Check PowerCLI Module
vmware-check-Module 'VMware.Vim'
# Connect vCenter Server
vCenter_connect
Get-Variable true | Out-Default; Clear-Host;
#Searching Virtual Machine on Target Site
Write-host "Searching Unregistered Virtual machine`n"
#$targetcluster='Cluster name or ResourcePool name'
$targetcluster=Read-Host "Target clsuter or resource pool name "
#$targetdatastore='Datastore Name'
$targetdatastore=Read-Host "Target Datasotre "
#$targetvmfolder='VM folder Name'
$targetvmfolder=Read-Host "Target VM folder name "
Import-VMX-from-datastore -Cluster $targetcluster -Datastores $targetdatastore -VMFolder $targetvmfolder
# Change Network Port group and Power ON
Connect_Portgroup
#--- Cleanly exit program ---#
Exit_Program
sleep 10
exit
* PowerShell Windows 창으로 독립 실행하여, 명령어로 수행 시에는 수행 완료 이후, 해당 Windows를 닫아주셔야 합니다.
* 윈도우 폴더에서는 마우스 우클릭 Powershell 실행을 클릭하면 됩니다.
'VMware Cloud Foundation > vSphere' 카테고리의 다른 글
vSphere+, vSAN+ 로 전환 (0) | 2023.05.25 |
---|---|
vmware vm tools upgrade (0) | 2022.09.30 |