39,59 €
If you are a virtualization professional who wants to unleash the power of automation and combat the complexity of sprawling virtual environments, this book is ideal for you. This book will enhance your skills of administering VMware vSphere and vCloud Director with PowerCLI.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 442
Veröffentlichungsjahr: 2015
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: March 2015
Production reference: 1200315
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-372-4
www.packtpub.com
Author
Philip Sellers
Reviewers
Dustin Lenz
Ajeet Singh Raina
Earl Waud
Commissioning Editor
Ashwin Nair
Acquisition Editor
Sonali Vernekar
Content Development Editor
Arwa Manasawala
Technical Editor
Menza Mathew
Copy Editor
Rashmi Sawant
Project Coordinator
Danuta Jones
Proofreaders
Simran Bhogal
Joel T. Johnson
Indexer
Rekha Nair
Graphics
Abhinash Sahu
Production Coordinator
Melwyn D'sa
Cover Work
Melwyn D'sa
Philip Sellers is an IT enthusiast residing in Myrtle Beach, South Carolina. Philip has more than 16 years of industry experience in consulting and systems administration. Currently, he is a senior-level systems administrator with Horry Telephone Cooperative, America's largest telecommunications cooperative. Philip focuses on Microsoft and VMware software solutions along with server and SAN infrastructure. He spends a lot of time wrangling unwieldy systems and tries to tame as much as he can with automation using tools such as PowerCLI.
Philip has a bachelor of science degree in interdisciplinary studies with a minor in computer science from Coastal Carolina University and holds certifications as a VMware VCAP5-DCA and VCP5-DCV and is a Microsoft Certified IT Professional.
He maintains a technology blog at http://www.techazine.com that provides explanations and reviews of enterprise IT solutions, and he is a leader with the Myrtle Beach VMware Users Group. You may also follow him on Twitter @pbsellers.
Philip is married to his college sweetheart, Jennifer, and has two kids who keep him busy when he's not working.
I would like to thank my wonderful wife, Jennifer, for her support and patience during the project and for all of her enthusiasm and encouragement. I enjoy every day of our adventure together. I would also like to thank my children, Peyton and Jake. No dream is too big for you to dream and if you put your mind to it, step by step (or chapter by chapter) you can achieve anything you set your mind to. You three are the reasons why I do what I do and I love you all.
To my mom and dad, thank you for always supporting me, listening, and encouraging me, no matter how crazy the idea was. Thank you dad for teaching me to troubleshoot; you prepared me in ways you'll never know because you taught me to solve problems.
A special thanks to my technical reviewers; I appreciate the valuable work you did. All of your notes and suggestions helped make this book the best possible resource it could be. Thank you to the Packt Publishing team who worked on this book. Thank you to my managers and executive staff at Horry Telephone Cooperative for allowing me to pursue this opportunity.
Dustin Lenz is currently an MTS IT systems engineer with a large semiconductor manufacturer. Dustin earned a bachelor of science degree in computer technology from Ball State University, Muncie, Indiana, and has earned his certification, VCP, from VMware for datacenter technologies.
Ajeet Singh Raina is a senior systems engineer at Dell R&D. He has received a certification in VMware Certified Professional (VCP 4.1) and has more than 7 years of experience working on open source and virtualization platforms. He was a part of the VMQA GOS Validation Team at VMware India and validated all flavors of operating systems on ESXi 4.1 and 5.0. He is currently working with Enterprise Solutions Group at Dell and has a solid understanding of a diverse range of IT infrastructure, systems management, systems integration, and quality assurance.
Ajeet has a great passion for open source technologies (Linux, Hadoop, and OpenStack). He likes providing tech-talks and technical consultations on the latest open source software and has a habit of sharing it through blogs and wikis. He can be reached at http://collabnix.com
This book would not have been a success without the direct and indirect help from many people. Thanks to my wife and my 5-year-old kid for putting up with me for all the missing family time and for providing me with love and encouragement throughout the writing period. Thanks to my parents and family members for all the love, guidance, and encouragement during the tough times.
Thanks to all my past and present colleagues and mentors at VMware and Dell for the insightful discussions and the knowledge they shared with me.
Earl Waud is a virtualization development professional with more than 7 years of focused industry experience in creating innovative solutions for hypervisor provisioning, management, and automation. He is an expert in aligning engineering strategy with organizational vision and goals, and delivering highly scalable and user friendly virtualization environments.
With more than 18 years of experience in developing customer facing and corporate IT software solutions, he has a proven track record of delivering high-caliber and on-time technology solutions that have a significant impact on business results.
Earl currently lives in San Diego, California. He is blessed with a beautiful wife, Patti, and three amazing daughters, Madison, Daniella, and Alexis.
Currently, Earl is a senior systems engineer with Intuit Inc., a company that creates business and financial management solutions that simplify the business of life for small businesses, consumers, and accounting professionals.
Earl can be reached online at http://sandiegoearl.com.
I would like to thank my wonderful family for allowing me to spend some of my precious family time to review this book. I love and appreciate you all, and I know I am truly blessed to be part of this family.
For support files and downloads related to your book, please visit http://www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at http://www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At http://www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at http://www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Get notified! Find out when new books are published by following @PacktEnterprise on Twitter or the Packt Enterprise Facebook page.
VMware PowerCLI offers a compelling command-line alternative to the point-and-click administration of vSphere and vCloud Director. As virtualization has become mainstream and deployments begin to sprawl, the simple commands of PowerCLI allows faster administration by executing tasks on groups of objects in the virtual environment.
Since PowerCLI follows a very logical pattern, it can be quickly adopted, making it the first choice for many vSphere administrators. However, with simplicity, it also combines extensibility to allow users to build their own functions and modules to solve specific problems not addressed by out-of-box functionalities.
Chapter 1, Configuring the Basic Settings of an ESXi Host with PowerCLI, covers the configuration of a fresh installation of VMware ESXi on a host system.
Chapter 2, Configuring vCenter and Computing Clusters, teaches you how to perform a basic vCenter configuration and add multiple ESXi hosts into a cluster with vSphere features, such as Dynamic Resource Scheduler (DRS) and High Availability (HA).
Chapter 3, Managing Virtual Machines, provides you with many of the common tasks needed to manage virtual machines from PowerCLI, including deploying and cloning virtual machines, changing hardware settings on virtual machines, and reloading inaccessible virtual machines in vCenter.
Chapter 4, Working with Datastores and Datastore Clusters, introduces the PowerCLI cmdlets needed to create and manage datastores and datastore clusters for individual ESXi hosts or vSphere clusters.
Chapter 5, Creating and Managing Snapshots, covers cmdlets and routines to work with snapshots on virtual machines, how to manage and report on snapshots before they become problems, and uses the topic to teach you how to write your own function in PowerCLI that can be reused easily. This chapter also covers how to take your code and schedule it to run with defined triggers using native PowerShell commands.
Chapter 6, Managing Resource Pools, Reservations, and Limits for Virtual Machines, covers the topic of creating and managing resource pools and their associated settings that include reservations and limits both at a pool and virtual machine level.
Chapter 7, Creating Custom Reports and Notifications for vSphere, teaches you how to use many of the native PowerShell features for reporting and leveraging those with PowerCLI cmdlets to create custom reports and notifications.
Chapter 8, Performing ESXCLI and in-guest Commands from PowerCLI, works with the advanced topics of using ESXCLI, an alternative command-line administration tool, from within PowerCLI to access and manage settings that are not natively accessible from PowerCLI. This chapter also covers some of the basics of performing in-guest commands invoked from PowerCLI.
Chapter 9, Managing DRS and Affinity Groups PowerCLI, is built on everything covered in the previous chapters to discuss managing the vSphere DRS features from PowerCLI by building your own functions and modules to alter the group memberships of DRS groups and keep the membership updated per defined rules.
Chapter 10, Working with vCloud Director from PowerCLI, changes gears and covers managing vCloud Director and vCloud deployments in multi-tenanted environments.
Appendix, Setting up and Configuring vCloud Director, covers certain installation tips and techniques.
To create and perform the commands created in the recipes of this cookbook, you will need:
This book was written and tested against PowerCLI versions 5.5, 5.8, and 6.0, and utilizes PowerShell 3.0.
Windows PowerShell 2.0 or 3.0 are distributed as part of the Windows Management Framework and are available for free from http://www.microsoft.com. VMware vSphere PowerCLI and the VMware Hypervisor (ESXi) are available for free from http://www.vmware.com. You can obtain a 60-day trial license for vSphere that cover ESXi and vCenter Server in order to enable advanced features and management. vCloud Director is available as a trial with a streamlined virtual appliance for evaluation purposes from http://www.vmware.com.
This book is written for readers with a basic, working knowledge of PowerCLI, a command-line tool for managing vSphere and vCloud environments that is based on PowerShell. The book is written in a recipe format, which means that each chapter approaches a topic of vSphere or vCloud administration and walks you through step-by-step commands to handle the common tasks. Each recipe is built on the previous recipes that allow you to learn how to take basic commands and combine them into functions and modules in order to automate tasks for your environment, making your job easier.
It is assumed that you have a working understanding of VMware vSphere, both ESXi and vCenter Server, and the experience with vCloud Director might help you with the chapter focused on this topic. The book is written so that you can go beyond simple commands in PowerCLI and unleash the potential of more complex series of commands that handle real work problems. It is impossible to cover every possible use for PowerCLI, but the book covers some topics in representative ways and gives you techniques to apply to any other need you might encounter.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To check the version you are running, open a PowerCLI prompt and run Get-PowerCLIVersion."
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Open the Organizations section under Manage & Monitor and select an organization."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
In this chapter, you will cover the following recipes:
Initially, automation doesn't save time. To get the benefits of automation, you must invest the time upfront to create scripts that you'll use time and again. In this chapter, you'll take your first ESXi host that has been installed with an IP address configured on it, and you will configure the server continually from there. This chapter will take an administrator through the basic configuration tasks needed to perform the initial configuration, join them to vCenter, and get it into an operational state. At the end of this chapter, all of these steps will build into a scripted configuration that can be executed against new hosts in the future.
To begin working with PowerCLI, you must first have PowerShell installed and available on the system on which you will run PowerCLI. PowerShell is a part of the Windows Management Framework and it ships with Windows client and server versions. PowerCLI extends PowerShell with commands to administer VMware environments. With PowerShell installed, you will need to obtain PowerCLI from http://www.vmware.com. The specific link is listed in the See also section of this recipe.
Once you have installed PowerCLI, you will need to build an ESXi host for this recipe. All that is required is a fresh ESXi installation from the ISO or DVD image distributed by VMware. Once installed, set an IP address on an accessible network using the console screens of the new ESXi host. The network address should be accessible from your PowerCLI workstation.
With the assumption that your ESXi host is built, the first step to administer VMware environments in PowerCLI is to connect to the ESXi host or to a vCenter server. In this chapter, you will focus on how to configure a single ESXi host. In the next chapter, you will focus on how to configure a vCenter Server and a vSphere cluster of ESXi hosts.
To begin, you only need to launch PowerCLI from its shortcut on the desktop or from the Start Menu. If you already had PowerCLI previously installed, you will want to check the version number to ensure that the cmdlet references throughout the book are available to you. Each version of PowerCLI builds additional native cmdlets and functionalities. To check the version you are running, open a PowerCLI prompt and run Get-PowerCLIVersion.
The recipes in this book are built and tested using VMware PowerCLI 5.5 Release 1 and have also been tested with VMware PowerCLI 5.8 Release 1, which accompanies vCloud Suite 5.8. The recipes also work on vSphere and PowerCLI 6.0 with any differences noted.
The Connect-VIServer cmdlet is the simplest kind of cmdlet in PowerCLI. This cmdlet initiates a connection to the vCenter or ESXi web services to allow additional commands to be passed to the server and be executed.
The Connect-VIServer cmdlet requires only the name of the host to which you want to connect. There are additional parameters that you might pass to the cmdlet, such as the protocol (HTTP or HTTPS), the username, and the password. If you prefer not to keep your password in plain text, you can also pass a PSCredentials object. The PSCredentials object contains login data to authenticate. For more information about the PSCredentials objects, type get-help about_server_authentication.
Once you execute the cmdlet, a warning will be displayed in yellow, similar to the following one:
The warning is displayed because the certificate installed on the ESXi host is self-signed and untrusted by the computer you are connecting from. Changing an SSL certificate on ESXi hosts will be covered later in the book, but the warning can be ignored this time. The cmdlet will continue to execute even though the warning is displayed.
You can also prevent the invalid certificate errors by running the following PowerCLI cmdlet that changes the action when an invalid certificate is encountered:
If you choose to join the ESXi host to Active Directory, your PowerCLI session performs a single sign-in. PowerCLI uses the credentials of your current Windows session to log in against the ESXi host or vCenter server if your account has access to the server. If your account does not have access to the server that it is attempting to connect to, a login box will be presented like our example, shown in the preceding screenshot, in this recipe.
One of the first things to be completed against a new ESXi installation is network configuration. Network configuration consists of several things on an ESXi host—first would be to configure the additional management interfaces of the host for VMotion, Fault Tolerance logging, vSphere Replication, and VSAN traffic.
To begin this recipe, you will need to open a PowerCLI window, connect to an ESXi host, and load a VMHost object into a variable. The example uses $esxihost as the variable for the VMHost object.
On installation, ESXi has a single Network Interface Card (NIC) labeled eth0 that is connected to a VMware Standard—vSwitch. The vSwitch has two port groups created: one labeled Management Networkfor management traffic and the other is labeled VM Network. The Management Network is a vmkernel port with the IP defined on the console attached to it.
In this example, our host contains six 10 Gigabit NICs that will connect the host to the network. You will define two additional vSwitches with two physical ports attached to each for redundancy. The additional vSwitches will handle storage and replication traffic on one and VM traffic on the other.
Best practices of vSphere networking are far beyond the scope of this book. The network layout shown in the preceding diagram is not an endorsement of a particular layout and is for illustration purposes to show the PowerCLI cmdlets used to configure networking on ESXi.
While this is outside the scope of this book, there are many different ideas for the best design of VMware networking. Most administrators agree that Management traffic and vMotion traffic should be separated, but with increasing speeds and capabilities of NICs today, it's common to see them sharing the same virtual switch. Administrators will set the Management traffic to be active on the first NIC and vMotion to be active on the second NIC. The two traffic streams will only be on the same NIC in a failover situation.
The Get-VMHostNetworkAdapter cmdlet displays all of the vmkernel ports along with all of the physical NICs present on the host.
After confirming the NIC, you will run the New-VirtualSwitch cmdlet to provision the new virtual switch. This cmdlet provisions the vSwitch with its uplinks, but it's currently an island with no connectivity for Management or virtual servers:In this example, you will work with the VMHost