Sunday, August 27, 2017

ESXi 6.5 Install Realtek NIC Drivers

esxcfg-info | less -i

Install Realtek R8168 drivers

# Lower the system's acceptance level to allow Community supported packages
esxcli software acceptance set --level=CommunitySupported
# open firewall for outgoing http requests:
esxcli network firewall ruleset set -e true -r httpClient
# Install e.g. net55-r8168 from the V-Front Online Depot
esxcli software vib install -d -n net55-r8168
# Reboot

Perl script to shutdown VM's on ESXi 6.5

I use this script to shutdown all my VM's when UPS battery is low, or when I need to do updates on my NAS'


# Get list of ALL VM's
# (\d{1,2})\s+([\w\d\-]+).*\n

$cmdvmlist = "vim-cmd vmsvc/getallvms";

# RegEX for running VM's
# ([\d]+\-[\w\d\s\.]+)\n\s+World ID:\s(\d+)

$cmdvmrunning = "esxcli vm process list";

$esxhost = "root\@";

$vmlist = `ssh $esxhost $cmdvmlist`;

#print $vmlist;

# ([\d]+\-[\w\d\s\.]+)\n\s+World ID:\s(\d+)

my @shutdownorder;


print "VM Inventory on $esxhost\n";

while ($vmlist =~ /(\d{1,2})\s+([\w\d\-]+).*\n/g)

        # Don't shutdown the VM running this script until last as it also controls APCUPSD

        if ($1 != 30)
                $shutdownorder[$count] = $1;
                $shutdownordername[$count] = $2;


print "VMID\tName\n";

my $index;
for my $order (@shutdownorder) {
  print "$order \t $shutdownordername[$index++]\n";

# If shutdown argument is present, shutdown VM's

if ($ARGV[0] eq "shutdown")
        open (my $fh, '>', "/tmp/esxhostscript");

        print "\nCreating Script for ESX Host\nUploading ";

        while (@shutdownorder)
                $vm = shift(@shutdownorder);

                print $fh "vim-cmd vmsvc/power.shutdown $vm\n";

        close $fh;

        # Copy script to ESX Host


        # Add Execute Permission

        system("ssh","root\@","chmod +x /tmp/esxhostscript");

        # Execute Script


        print "Waiting for VM's to shutdown\n";
        $timeout = 300;

        while (CheckRunning())
                print "$timeout ";
                sleep 5;
                if ($timeout<=0){exit;}
        print "\n\n";


        printf "shutdown argument not passed, no action taken\n"

sub CheckRunning

        $vmrun = `ssh $esxhost $cmdvmrunning`;

        while ($vmrun =~ /([\d]+\-[\w\d\s\.]+)\n\s+World ID:\s(\d+)/g)

                if ($1 ne "0-Control")
                        return 1;
        return 0;

To start them backup I use the autostart script on the ESXi Host:

ssh root@ /sbin/ start

LetsEncrypt for EFA

Updating EFA Cert

On efa server chown -R billw:billw certs

On Ubuntu box

letsencrypt certonly --manual --preferred-challenges dns -d

openssl x509 -outform der -in /etc/letsencrypt/live/ -out /etc/letsencrypt/live/
openssl rsa -outform der -in /etc/letsencrypt/live/ -out /etc/letsencrypt/live/
scp /etc/letsencrypt/live/ billw@