使用vCenter Orchestrator實現VMware vSphere的自動化任務

配置過程主要有如下幾步:

1.啓動vCenter Orchestrator Configuration服務

2.配置vCenter Orchestrator 網絡連接

3.創建一個LDAP 服務器,本環境使用活動目錄

4.配置後臺數據庫,本環境使用Sql2008R2

5.爲vCenter Orchestrator創建SSL證書

6.輸入vCenter Server的許可證

7.配置缺省插件

 

1. 啓動vCenter Orchestrator Configuration服務

缺省該服務啓動狀態爲手動,修改爲自動,並啓動它。

sc config vCOConfiguration start= auto

sc start vCOConfiguration

服務啓動之後,通過http://vcenter Server的IP:8282來訪問,缺省的用戶名及密碼是vmware/vmware

clip_image002

clip_image004

紅色部分提示,配置未完成,配置完成之後,狀態將改爲綠色

2. 配置vCenter Orchestrator 網絡連接

點擊上圖的Network,在右側的IP Address欄,選擇vCenter Orchestrator使用的IP,然後點擊Apply Changes。可以看到,狀態變綠。

clip_image006

3. 配置LDAP

點擊LDAP,

在右側LDAP Client選擇Active Directory,

Primary LDAP Host輸入域控的FQDN,

Root文本框裏面輸入活動目錄的root DN,形如DC=xyz,DC=com,

在Username文本框,輸入用戶名,該用戶名爲Orchestrator登錄活動目錄的憑據,用戶名的格式要麼是DN 格式 (cn=username,cn=Users,dc=domain,dc=com) 要麼是UPN格式 ([email protected]),此處是[email protected]

User Lookup Base 文本框,提供Orchestrator用來搜索用戶帳戶的base DN,可配置成與root DN一致,DC=xyz,DC=com

Group Lookup Base 文本框,可配置成與root DN一致,DC=xyz,DC=com

vCO Admin Group文本框,指定具有vCenter Orchestrator管理員權限的DN,可以使用域管理員組cn=Administrators,cn=Builtin,dc=domain,dc=com,本實驗指定CN=vmadmin,OU=vmwareOU,DC=xyz,DC=com,將域管理員及xyz\vcadmin用戶添加到該組,

點擊Apply Changes,然後狀態變爲綠色。

clip_image008

clip_image010

用ldap方式訪問AD域的的錯誤一般會如下格式:

LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece

其中紅字部分的意思如下:

525 - 用戶沒有找到

52e - 證書不正確,或者憑據不正確

530 - not permitted to logon at this time

532 - 密碼期滿

533 - 帳戶不可用

701 - 賬戶期滿

773 - 用戶必須重設密碼

4. 配置後臺數據庫

先在Sql2008R2 服務器上新建一空的數據庫vcodb,Db_owner爲xyz\vcadmin

點擊Database,選擇SqlServer

信息輸入完成之後,點Apply Changes,然後點上方的Install the database

clip_image012

點擊Instal the database之後,Database標籤狀態變綠

5. 配置服務器證書

即可使用自簽名的證書,也可使用第三方證書

clip_image014

創建自簽名證書

clip_image016

使用vCenter Server的FQDN

clip_image018

6. 輸入vCenter Server的許可證

clip_image020

導入vCenter Server的證書

clip_image022

此處應該使用IP地址,不能使用FQDN

clip_image024

C:\Documents and Settings\All Users\Application Data\VMware\VMware VirtualCenter\SSL\rui.crt

clip_image026

7. 配置插件

vCenter Orchestrator使用插件連接工作流引擎。缺省情況下,vCenter Orchestrator提供了一一套插件,但需要使用具有vCenter Orchestrator管理員權限的用戶來執行。

單擊Plug-Ins

指定屬於vCO Administration組的用戶

Apply Changes

clip_image028

此步驟完成之後,Startup Options標籤隨之變綠

8. 添加vCenter Server主機

與vCenter Orchestrator通訊的vCenter Server

不配置vCenter Server,vCenter Orchestrator同樣能工作,但將失去在vCenter Server內自動化任務的能力

clip_image030

clip_image032

9. 安裝和啓動vCenter Orchestrator Server服務

單擊Startup Options標籤

單擊Install vCO Server As A Service鏈接,當狀態再次變綠,單擊啓動服務鏈接

clip_image034

clip_image036

clip_image038

10. 使用Orchestrator工作流

vCenter Orchestrator Client是配置工作的工具軟件

運行vCenter Orchestrator Client,會看到vCenter Orchestrator已經提供了預安裝的工作流。

clip_image040

如果系統內存低於4GB,VMware vCenter Orchestrator Server有可能無法啓動

clip_image042

11. 使用PowerShell和PowerCLI實現自動化任務

Windows 2008 R2已經內置PowerShell2

安裝PowerCLI,首先提示安裝VIX

clip_image044

 

clip_image046

clip_image048

clip_image050

clip_image052

在使用PowerCLI之前,需要設置PowerShell執行策略允許運行PowerCLI的組件

clip_image054

Set-ExecutionPolicy RemoteSigned

Get-ExecutionPolicy

運行PowerCLI

Everything is object.Esx主機、虛擬機、快照等等均爲對象。

首先需要連接到vCenter Server或者Esx/Esxi主機

Connect-VIServer -Server <vCenter Server hostname> -User <Username> -Password <password>

Get-VMHost

Get-VMHost <Hostname> | Get-VM

Get-VMHost <Hostname> | Get-VM | Get-NetworkAdapter

Get-VMHost <Hostname> | Get-VM | Get-NetworkAdapter | Select NetworkName, Type

Get-Datacenter Datacenter

Get-Datastore Datastore

Get-Folder Folder

Get-HardDisk Virtual hard disk

Get-NetworkAdapter Virtual network adapter

Get-ResourcePool Resource pool

Get-Snapshot Virtual machine snapshot

Get-Template Virtual machine template

Get-VirtualPortGroup Port group

Get-VirtualSwitch Virtual switch

Get-VM Virtual machine

Get-VMGuest Virtual machine guest operating system

Get-VMHost ESX/ESXi host

Move-VM Moves a VM to a new host, cluster, or datastore

Move-ResourcePool Moves a resource pool

New-Cluster Creates a new cluster of ESX/ESXi hosts

New-HardDisk Creates a new hard disk on a VM

New-NetworkAdapter Creates a new network adapter on a VM

New-ResourcePool Creates a new resource pool

New-Snapshot Creates a new snapshot on a VM

New-VM Creates a new VM

Remove-Snapshot Removes a VM snapshot or snapshots

Restart-VMGuest Restarts a VM guest operating system

Set-CDDrive Changes VM’s virtual CD configuration

Set-Datacenter Changes the name of the datacenter

Set-Datastore Changes the name of the datastore

Set-FloppyDrive Updates a VM’s virtual floppy configuration

Set-HardDisk Changes VM’s hard disk configuration

Set-NetworkAdapter Modifies VM’s network adapter configuration

Set-ResourcePool Updates resource pool configuration

Set-VirtualPortGroup Updates virtual port group configuration

Set-VirtualSwitch Changes virtual switch configuration

Set-VM Changes virtual machine configuration

Set-VMHost Updates ESX/ESXi host configuration

Set-VMResourceConfiguration Changes resource allocation for a VM

Shutdown-VMGuest Shuts down a VM guest operating system

Suspend-VMGuest Suspends a VM guest operating system

一些示例:

Get-VMHost <FirstHost> | Get-VM | Move-VM –destination (Get-VMHost <SecondHost>)
利用vmotion移動主機1上的虛擬機到主機2
Get-VMHost <Hostname> | Get-VM | New-Snapshot -Name "Target-Snapsht"
主機上所有的虛擬機都創建一份快照
Get-VMHost <Hostname> | Get-VM | Get-Snapshot -Name "Target-Snapsht" | Remove-Snapshot
刪除快照
Get-VMHost <Hostname> | Get-VM | Get-Snapshot
列出快照
Get-VM | Get-NetworkAdapter | Where-Object { $_.NetworkName -like "OldPortGroupName" } | Set-NetworkAdapter –NetworkName "NewPortGroupName" –Confirm:$false
將某個端口組的虛擬機移動到另外一個端口組
Get-ResourcePool <ResourcePoolName> | Get-VM | Get-VMGuest
Get-ResourcePool <ResourcePoolName> | Get-VM | Get-VMGuest | Where-Object { $_.OSFullName –match " ? Microsoft Windows.*" }
列出資源池中操作系統爲windows的虛擬機
\MoveWindowsVMs.ps1
$VMs = Get-VM -Location (Get-ResourcePool Infrastructure)
foreach ($vm in $VMs) {
$vmguest = Get-VMGuest -VM $vm
if ($vmguest.OSFullName -match " ^ Microsoft Windows.*") {
Move-VM -VM $vm -Destination (Get-ResourcePool "Windows VMs") } }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章