Vmware: Unterschied zwischen den Versionen

Aus SchnallIchNet
Wechseln zu: Navigation, Suche
(ESXi upgrade)
 
(4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 12: Zeile 12:
 
         cd %WINDIR%\system32\sysprep; ./sysprep /generalize
 
         cd %WINDIR%\system32\sysprep; ./sysprep /generalize
 
6) Assign new workstation name / admin pw
 
6) Assign new workstation name / admin pw
7) Configure network / Connect NIC
+
7)      Run SCCM Tasks
8) Join to domain
+
8)      Run winlogbeat tasks
 +
9) Configure network / Connect NIC
 +
10)     Join to domain
 
</pre>
 
</pre>
  
Zeile 41: Zeile 43:
 
</pre>
 
</pre>
  
 +
=== SCCM Tasks ===
 +
 +
<pre>
 +
$scriptblock = {
 +
  net stop CCMEXEC
 +
  del C:\Windows\SMSCFG.INI
 +
  certutil -delstore SMS SMS
 +
  C:\Windows\ccmsetup\ccmsetup.exe /uninstall
 +
  C:\ITutils\Setup\ClientHealth\ccmsetup.exe SMSSITECODE=ARI DNSSUFFIX=Arifleet.com
 +
}
 +
</pre>
 +
And then:
 +
 +
<pre>
 +
foreach( $vm in (get-vm *dev-v0001*).name ) {
 +
  echo "Trying $vm"
 +
  Invoke-Command -ComputerName $vm -ScriptBlock $scriptblock
 +
  echo ""
 +
}
 +
</pre>
 +
 +
=== Winlogbeat Tasks ===
 +
 +
rm C:\ProgramData\winlogbeat\meta.json
 +
 +
 +
 +
== Snippets ==
 +
 +
=== Get network interface connection state ===
 +
 +
<pre>
 +
get-vm | %{
 +
    $strVMName = $_.Name; Get-NetworkAdapter -VM $_ |
 +
        select @{n="VMName"; e={$strVMName}},Name,NetworkName,ConnectionState
 +
} | ?{$_.ConnectionState.StartConnected -eq $false}
 +
 +
VMName                  Name              NetworkName    ConnectionState
 +
------                  ----              -----------    ---------------
 +
51KOBDEV-V00017_replica Network adapter 1 10.219.106.0_24 Connected, GuestControl, NoStartConnected
 +
51KOBDEV-V00027_replica Network adapter 1 10.219.106.0_24 Connected, GuestControl, NoStartConnected
 +
51KOBDEV-V00016_replica Network adapter 1 10.219.106.0_24 Connected, GuestControl, NoStartConnected
 +
</pre>
 +
 +
Set StartConnected:
 +
 +
<pre>
 +
get-vm | %{ Get-NetworkAdapter -VM $_ } | ?{$_.ConnectionState.StartConnected -eq $false} | Set-NetworkAdapter -StartConnected $true -confirm:$false
 +
</pre>
 +
 +
 +
=== Get performance counters ===
 +
 +
$allCounters = get-vm 51KOBDEV-V0* | get-stat -Stat cpu.usagemhz.average -Start 01.05.2021
 +
 +
use cpu.usage.average above to get % values
 +
 +
$allCounters | Measure-Object "Value" -Sum | %{ $($_.Sum)/$($_.Count) }
 +
2187,85404221426
  
 
== ESXi upgrade ==
 
== ESXi upgrade ==
Zeile 73: Zeile 134:
 
=== list interfaces ===
 
=== list interfaces ===
 
  esxcli network ip interface list
 
  esxcli network ip interface list
 +
 +
 +
 +
== Shrink VCenter Server Disks ==
 +
 +
Create a Clone of your running VCenter server (just in case!)
 +
 +
SSH root@vcenter-server
 +
 +
# service-control --stop --all
 +
 +
 +
List disks - We want to reduce 'seat' partition
 +
 +
<pre>
 +
# df -h
 +
Filesystem                                Size  Used Avail Use% Mounted on
 +
devtmpfs                                  4.9G    0  4.9G  0% /dev
 +
tmpfs                                    4.9G  588K  4.9G  1% /dev/shm
 +
tmpfs                                    4.9G  696K  4.9G  1% /run
 +
tmpfs                                    4.9G    0  4.9G  0% /sys/fs/cgroup
 +
/dev/sda3                                  11G  4.4G  5.7G  44% /
 +
tmpfs                                    4.9G  1.6M  4.9G  1% /tmp
 +
/dev/sda1                                120M  34M  78M  31% /boot
 +
/dev/mapper/core_vg-core                  25G  44M  24G  1% /storage/core
 +
/dev/mapper/log_vg-log                    9.8G  72M  9.2G  1% /storage/log
 +
/dev/mapper/db_vg-db                      9.8G  101M  9.1G  2% /storage/db
 +
/dev/mapper/dblog_vg-dblog                15G  86M  14G  1% /storage/dblog
 +
/dev/mapper/seat_vg-seat                  296G  67M  283G  1% /storage/seat
 +
[...]
 +
</pre>
 +
 +
 +
UnMount the disk
 +
 +
# umount /storage/seat
 +
 +
 +
Check Filesystem
 +
 +
# e2fsck -f /dev/mapper/seat_vg-seat
 +
 +
 +
Resize the filesystem - We want 20GB disk as result.<br/>
 +
(resize filesystem to <disk size>-2GB = 18GB)
 +
 +
# resize2fs /dev/mapper/seat_vg-seat 18G
 +
 +
 +
Resize logical volume to <disk size>-1GB = 19GB
 +
 +
# lvreduce -L 19G /dev/seat_vg/seat
 +
 +
 +
At this point login to the VMHost (were vcenter is located on)<br/>
 +
and add a new 20GB disk to VCenter server.
 +
 +
Trigger SCSI rescan:
 +
 +
# echo "- - -" > /sys/class/scsi_host/host<X>/scan
 +
 +
If you want to figure out the host adapter that is in use for virtual disks, run "lsscsi".
 +
 +
 +
Get name of new disk:
 +
 +
# dmesg | grep -i scsi
 +
...
 +
[58915.572852] scsi 3:0:2:0: Direct-Access    VMware  Virtual disk    1.0  PQ: 0 ANSI: 2
 +
[58915.573970] sd 3:0:1:0: [sdn] Attached SCSI disk
 +
...
 +
 +
 +
Put new disk to VG and remove the old (big) disk:
 +
 +
# pvcreate /dev/sdn
 +
 +
# vgextend seat_vg /dev/sdn
 +
 +
 +
Now check both disks belong to the VG:
 +
 +
<pre>
 +
# pvs |grep seat_vg
 +
/dev/sdh seat_vg lvm2 a-- 299.99g 279.99g
 +
/dev/sdn seat_vg lvm2 a-- 24.99g 24.99g
 +
</pre>
 +
 +
 +
Move physical allocation from old (big) disk to new disk:
 +
 +
# pvmove /dev/sdh /dev/sdn
 +
 +
 +
Verify /dev/sdh is empty:
 +
 +
<pre>
 +
# pvdisplay -m /dev/sdh
 +
  --- Physical volume ---
 +
  PV Name              /dev/sdh
 +
  VG Name              seat_vg
 +
  PV Size              300.00 GiB / not usable 7.00 MiB
 +
  Allocatable          yes
 +
  PE Size              8.00 MiB
 +
  Total PE              38399
 +
  Free PE              38399
 +
  Allocated PE          0                                          <---- Alloc needs to be '0'
 +
  PV UUID              V7lkDg-Fxyr-qX4x-d3oi-KhNO-XZyT-EHgibI
 +
 +
  --- Physical Segments ---
 +
  Physical extent 0 to 38398:
 +
    FREE
 +
</pre>
 +
 +
 +
Remove old big disk now:
 +
 +
<pre>
 +
# vgreduce seat_vg /dev/sdh
 +
 +
# pvremove /dev/sdh
 +
</pre>
 +
 +
 +
Resize all volumes to virtual disk size:
 +
 +
# /usr/lib/applmgmt/support/scripts/autogrow.sh
 +
 +
 +
Delete Disk from vcenter (make sure you delete the correct disk!!!)
 +
 +
# lsscsi |grep sdh
 +
[2:0:8:0] disk VMware Virtual disk 1.0 /dev/sdh
 +
 +
Controller0-Disk8: [2:'''0:8''':0]<br/>
 +
Delete SCSI Disk 0:8 from VMWare - Reboot VCenter
 +
 +
Delete the VCenter clone

Aktuelle Version vom 11. Juni 2021, 09:07 Uhr


Clone System

1)	Shut down the VM
2)	Clone the VM
3)	Disconnect the NIC
4)	Bring up the VM
Win10)  Run uninstall.ps1 script below, to uninstall unprovisioned AppStore Apps
5)	Run sysprep /generalize
        cd %WINDIR%\system32\sysprep; ./sysprep /generalize
6)	Assign new workstation name / admin pw
7)      Run SCCM Tasks
8)      Run winlogbeat tasks
9)	Configure network / Connect NIC
10)     Join to domain

Uninstall.ps1

# Get the list of provisioned packages
$provisioned = Get-AppxProvisionedPackage -online

# Check each installed app
$count = 0

for ($i=1; $i -ile 2; $i++) {
  # Check each app (two loops just in case there are dependencies that can't be removed until the
  # main app is removed)
  Get-AppxPackage | ? {$_.SignatureKind -ne 'System'} | ForEach-Object {
    $current = $_
    $found = $provisioned | ? {$_.DisplayName -eq $current.Name -and $_.Version -eq $current.Version}
    if ($found.Count -eq 0)
    {
      Write-Host "$($current.Name) version $($current.Version) is not provisioned, removing."
      Remove-AppxPackage -Package $current.PackageFullName
      $count++
    }
  }
}

SCCM Tasks

$scriptblock = {
   net stop CCMEXEC
   del C:\Windows\SMSCFG.INI
   certutil -delstore SMS SMS
   C:\Windows\ccmsetup\ccmsetup.exe /uninstall
   C:\ITutils\Setup\ClientHealth\ccmsetup.exe SMSSITECODE=ARI DNSSUFFIX=Arifleet.com
}

And then:

foreach( $vm in (get-vm *dev-v0001*).name ) {
   echo "Trying $vm"
   Invoke-Command -ComputerName $vm -ScriptBlock $scriptblock
   echo ""
}

Winlogbeat Tasks

rm C:\ProgramData\winlogbeat\meta.json


Snippets

Get network interface connection state

get-vm | %{
    $strVMName = $_.Name; Get-NetworkAdapter -VM $_ |
        select @{n="VMName"; e={$strVMName}},Name,NetworkName,ConnectionState
} | ?{$_.ConnectionState.StartConnected -eq $false}

VMName                  Name              NetworkName     ConnectionState
------                  ----              -----------     ---------------
51KOBDEV-V00017_replica Network adapter 1 10.219.106.0_24 Connected, GuestControl, NoStartConnected
51KOBDEV-V00027_replica Network adapter 1 10.219.106.0_24 Connected, GuestControl, NoStartConnected
51KOBDEV-V00016_replica Network adapter 1 10.219.106.0_24 Connected, GuestControl, NoStartConnected

Set StartConnected:

get-vm | %{ Get-NetworkAdapter -VM $_ } | ?{$_.ConnectionState.StartConnected -eq $false} | Set-NetworkAdapter -StartConnected $true -confirm:$false


Get performance counters

$allCounters = get-vm 51KOBDEV-V0* | get-stat -Stat cpu.usagemhz.average -Start 01.05.2021

use cpu.usage.average above to get % values

$allCounters | Measure-Object "Value" -Sum | %{ $($_.Sum)/$($_.Count) }
2187,85404221426

ESXi upgrade

Get list of storage adapters

esxcli storage core adapter list

HBA Name  Driver      Link State  UID                                     Capabilities      
--------  ----------  ----------  --------------------------------------  ------------------
vmhba0    nhpsa       link-n/a    sas.50014380361bab70                                      
vmhba1    qlnativefc  link-up     fc.500143802318ab7b:500143802318ab7a    Data Integrity, Se
vmhba2    qlnativefc  link-up     fc.500143802318a82f:500143802318a82e    Data Integrity, Se
vmhba32   bnx2i       unbound     iscsi.vmhba32                           Second Level Lun I
vmhba33   bnx2i       unbound     iscsi.vmhba33                           Second Level Lun I
vmhba34   bnx2fc      link-down   fcoe.10003ca82a244d11:20003ca82a244d11  Second Level Lun I
vmhba35   bnx2fc      link-down   fcoe.10003ca82a244d15:20003ca82a244d15  Second Level Lun I

cat /proc/scsi/bnx2fc/7 | grep 'Host Device Name'
 Host Device Name vmhba34


Run this script in ESXi 6.x to obtain the driver version and Firmware for all HBAs in the system:

for name in `vmkchdev -l | grep vmhba | awk '{print$5}'`;do echo $name ; echo "VID :DID  SVID:SDID"; vmkchdev -l | grep $name | awk '{print $2 , $3}';printf "Driver: ";echo `esxcfg-scsidevs -a | grep $name |awk '{print $2}'`;vmkload_mod -s `esxcfg-scsidevs -a | grep $name|awk '{print $2}'` |grep -i version;echo `lspci -vvv | grep $name | awk '{print $1=$NF="",$0}'`;printf "\n";done


list interfaces

esxcli network ip interface list


Shrink VCenter Server Disks

Create a Clone of your running VCenter server (just in case!)

SSH root@vcenter-server

# service-control --stop --all


List disks - We want to reduce 'seat' partition

# df -h
Filesystem                                Size  Used Avail Use% Mounted on
devtmpfs                                  4.9G     0  4.9G   0% /dev
tmpfs                                     4.9G  588K  4.9G   1% /dev/shm
tmpfs                                     4.9G  696K  4.9G   1% /run
tmpfs                                     4.9G     0  4.9G   0% /sys/fs/cgroup
/dev/sda3                                  11G  4.4G  5.7G  44% /
tmpfs                                     4.9G  1.6M  4.9G   1% /tmp
/dev/sda1                                 120M   34M   78M  31% /boot
/dev/mapper/core_vg-core                   25G   44M   24G   1% /storage/core
/dev/mapper/log_vg-log                    9.8G   72M  9.2G   1% /storage/log
/dev/mapper/db_vg-db                      9.8G  101M  9.1G   2% /storage/db
/dev/mapper/dblog_vg-dblog                 15G   86M   14G   1% /storage/dblog
/dev/mapper/seat_vg-seat                  296G   67M  283G   1% /storage/seat 
[...]


UnMount the disk

# umount /storage/seat


Check Filesystem

# e2fsck -f /dev/mapper/seat_vg-seat


Resize the filesystem - We want 20GB disk as result.
(resize filesystem to <disk size>-2GB = 18GB)

# resize2fs /dev/mapper/seat_vg-seat 18G


Resize logical volume to <disk size>-1GB = 19GB

# lvreduce -L 19G /dev/seat_vg/seat


At this point login to the VMHost (were vcenter is located on)
and add a new 20GB disk to VCenter server.

Trigger SCSI rescan:

# echo "- - -" > /sys/class/scsi_host/host<X>/scan

If you want to figure out the host adapter that is in use for virtual disks, run "lsscsi".


Get name of new disk:

# dmesg | grep -i scsi
...
[58915.572852] scsi 3:0:2:0: Direct-Access     VMware   Virtual disk     1.0  PQ: 0 ANSI: 2
[58915.573970] sd 3:0:1:0: [sdn] Attached SCSI disk
...


Put new disk to VG and remove the old (big) disk:

# pvcreate /dev/sdn
# vgextend seat_vg /dev/sdn


Now check both disks belong to the VG:

# pvs |grep seat_vg
/dev/sdh seat_vg lvm2 a-- 299.99g 279.99g
/dev/sdn seat_vg lvm2 a-- 24.99g 24.99g


Move physical allocation from old (big) disk to new disk:

# pvmove /dev/sdh /dev/sdn


Verify /dev/sdh is empty:

# pvdisplay -m /dev/sdh
  --- Physical volume ---
  PV Name               /dev/sdh
  VG Name               seat_vg
  PV Size               300.00 GiB / not usable 7.00 MiB
  Allocatable           yes
  PE Size               8.00 MiB
  Total PE              38399
  Free PE               38399
  Allocated PE          0                                          <---- Alloc needs to be '0'
  PV UUID               V7lkDg-Fxyr-qX4x-d3oi-KhNO-XZyT-EHgibI

  --- Physical Segments ---
  Physical extent 0 to 38398:
    FREE


Remove old big disk now:

# vgreduce seat_vg /dev/sdh

# pvremove /dev/sdh


Resize all volumes to virtual disk size:

# /usr/lib/applmgmt/support/scripts/autogrow.sh


Delete Disk from vcenter (make sure you delete the correct disk!!!)

# lsscsi |grep sdh
[2:0:8:0] disk VMware Virtual disk 1.0 /dev/sdh

Controller0-Disk8: [2:0:8:0]
Delete SCSI Disk 0:8 from VMWare - Reboot VCenter

Delete the VCenter clone