Traitement par lots de la découverte d'invités et la collecte de données
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Ce tutoriel vous guide tout au long du processus de découverte et de collecte de données sur un lot d'instances de machines virtuelles (VM) VMware à l'aide de la découverte d'invités de la CLI du centre de migration. La surveillance et la résolution des problèmes liés aux lots de VM volumineux peuvent être difficiles. Nous vous recommandons de les regrouper par groupes plus petits, de moins de 1 000 VM.
Objectifs
Dans ce tutoriel, vous allez apprendre à effectuer les opérations suivantes :
Télécharger la CLI mcdc.
Exécuter une découverte d'inventaire VMWare.
Générer un fichier CSV contenant toutes les VM détectées.
Diviser le fichier CSV en plusieurs fichiers CSV contenant un sous-ensemble de VM.
Exécuter la détection d'invités sur toutes les VM dans un fichier CSV.
Générer un rapport d'évaluation hors connexion.
Coûts
Ce tutoriel utilise des ressources sur site et n'entraîne aucun coût Google Cloud.
Avant de commencer
Préparez une machine Linux pour installer et exécuter la CLI mcdc. La machine Linux doit répondre aux exigences minimales suivantes :
glibc version 2.25 ou ultérieure
4 Go de RAM et 10 Go d'espace disque
Connectivité réseau aux hôtes vCenter et ESX
Assurez-vous de disposer d'un utilisateur vSphere disposant des autorisations nécessaires :
Droits de lecture sur les VM
Droits de lecture sur tous les hôtes ESX
Modifications d'opération d'invité
Exécution du programme d'opération d'invité
Requêtes concernant les opérations d'invités
Télécharger la CLI mcdc
Connectez-vous à la machine Linux :
sshMACHINE_IP
Remplacez MACHINE_IP par l'adresse IP de votre machine Linux.
Téléchargez la dernière version de la CLI mcdc et rendez-la exécutable :
CSV_FILES_PREFIX : le préfixe des fichiers CSV générés
LINES_PER_FILE : le nombre de lignes par fichier CSV généré. La valeur par défaut est 10.
Le script génère divers fichiers CSV.
Affichez la liste des fichiers CSV générés :
ls-lrtCSV_FILES_PREFIX*
Exécuter la détection d'invités sur toutes les VM dans un fichier CSV
Pour exécuter la découverte d'invités pour les VM dans un fichier CSV, utilisez le script collection du dépôt GitHub de Migrate to Containers.
Répétez cette opération pour chaque fichier CSV généré à l'étape précédente.
url_regex='^https?://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]\.[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$'read-r-p"CSV file name: "CSV_FILE
if[[!-r"$CSV_FILE"]];thenecho"The file $CSV_FILE does not exist or can not be accessed."exit1firead-r-p"vSphere URL: "VSPHERE_URL
if![[$VSPHERE_URL=~$url_regex]];thenecho"vSphere URL $VSPHERE_URL IS not a valid URL"exit1firead-r-p"vSphere username: "VSPHERE_USER
read-r-s-p"vSphere password: "VSPHERE_PASSWORD
echo""read-r-p"Default username: "DEFAULT_USER
read-r-s-p"Default password: "DEFAULT_PASSWORD
echo""# CSV fields#NAME;PLATFORM VM ID;OS;IP;USERNAME;PASSWORDwhileIFS=";"read-rvm_namevm_idosipusernamepassword
doif[-z"$username"]thenusername=$DEFAULT_USERfiif[-z"$password"]thenpassword=$DEFAULT_PASSWORDfiif[!-z"$vm_id"]then# Note that the below only works for VMWare VMs# vm_id after the last slash if prefixed by vSphere IPmod_vm_id=$(echo"$vm_id"|sed's/.*\///')mcdcdiscovervsphereguest--url$VSPHERE_URL-u$VSPHERE_USER-p$VSPHERE_PASSWORD--vm-user$username--vm-password$password$mod_vm_idelseecho"Skipping VM: $vm_name because it has no VM ID"fidone < <(tail-n+1$CSV_FILE)
Le script utilise la commande discover vsphere guest pour importer et exécuter le script de collecte d'invités sur la VM.
Il est préférable d'exécuter ce script en arrière-plan et de diriger la sortie vers un fichier journal. Pour ce faire, vous devez créer un fichier texte qui sera transmis en entrée au script.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["# Batching guest discovery and data collection\n\n*** ** * ** ***\n\nThis tutorial walks you through the process of discovering and collecting data\non a batch of VMware virtual machine (VM) instances using the\nMigration Center discovery client CLI guest discovery. Large batches of VMs may be difficult\nto monitor and troubleshoot. We recommend batching into smaller groups of less\nthan 1,000.\n\nObjectives\n----------\n\nIn this tutorial, you will learn how to:\n\n- Download the `mcdc` CLI.\n- Run a VMWare inventory discovery.\n- Generate a CSV file with all the discovered VMs.\n- Split the CSV file into multiple CSV files containing a subset of the VMs.\n- Run guest discovery on all the VMs in a CSV file.\n- Generate an offline assessment report.\n\nCosts\n-----\n\nThis tutorial uses on-premises resources and incurs no Google Cloud\ncosts.\n\nBefore you begin\n----------------\n\n1. Prepare a Linux machine to install and run the\n `mcdc` CLI. The Linux machine must have the\n following minimum requirements:\n\n - `glibc` version 2.25 or later\n - 4 GB RAM and 10 GB disk space\n - Network connectivity to vCenter and ESX hosts\n2. Ensure that you have a vSphere user with the necessary permissions:\n\n - Read privileges to VMs\n - Read privileges to all the ESX hosts\n - Guest operation modifications\n - Guest operation program execution\n- Guest operation queries \n\nDownload the `mcdc` CLI\n-----------------------\n\n1. Connect to the Linux machine: \n\n ```bash\n ssh MACHINE_IP\n ```\n\n Replace \u003cvar translate=\"no\"\u003eMACHINE_IP\u003c/var\u003e with the IP address of your Linux machine.\n2. Download the latest version of the `mcdc` CLI and make it executable: \n\n ```bash\n curl -O \"https://mcdc-release.storage.googleapis.com/$(curl -s https://mcdc-release.storage.googleapis.com/latest)/mcdc\"\n chmod +x mcdc\n ```\n3. Add the `mcdc` CLI to your shell path: \n\n ```bash\n PATH=$PATH:`pwd`\n ```\n\nPerform a VMware inventory discovery\n------------------------------------\n\n- Run the inventory discovery:\n\n ./mcdc discover vsphere -u \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e --url https://\u003cvar translate=\"no\"\u003eVSPHERE_URL\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: your vCenter username\n - \u003cvar translate=\"no\"\u003eVSPHERE_URL\u003c/var\u003e: the URL for your vCenter Server instance or the vSphere Client\n\n The output of the `discover` command looks like the following: \n\n ```\n [+] Found 528 VMs\n Collecting data...\n 528 / 528 [---------------------------------------------------] 100.00% 5 p/s\n [✓] Collection completed.\n ```\n\nGenerate a CSV file with all the discovered VMs\n-----------------------------------------------\n\nTo generate a CSV file, use the `export` script from the Migrate to Containers\nrepository on GitHub. \n\n\n vms=$(mcdc report --format csv | tail -n +2 | awk -F ',' '{; print $2\";\"$3\";\"$4\";;;\"}')\n printf \"%s\\n\" \"Name;Platform VM ID;OS Family;IP;USERNAME;PASSWORD\"\n printf \"%s\\n\" \"$vms\"\n\nThe script uses the `report` command to generate a CSV file containing all the\nVMs that were discovered in the previous step.\n\n1. Download the script:\n\n curl -O https://raw.githubusercontent.com/GoogleCloudPlatform/migrate-to-containers/main/scripts/mcdc/mcdc_discovery_export_guest_tools.sh\n chmod +x mcdc_discovery_export_guest_tools.sh\n\n2. Run the script and save the output to a file:\n\n ./mcdc_discovery_export_guest_tools.sh \u003e \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e with the name you want for the CSV file.\n\nSplit the CSV file into multiple CSV files with a subset of the VMs\n-------------------------------------------------------------------\n\nTo split the large CSV file into smaller CSV files, use the `splitter` script\nfrom the Migrate to Containers repository on GitHub. \n\n tail -n +2 $1 | split -d -l $num_of_lines - $2\n for file in $2*\n do\n head -n 1 $1 \u003e tmp_file\n cat \"$file\" \u003e\u003e tmp_file\n mv -f tmp_file \"$file\"\n done\n\n1. Download the script:\n\n curl -O https://raw.githubusercontent.com/GoogleCloudPlatform/migrate-to-containers/main/scripts/mcdc/csv_splitter.sh\n chmod +x csv_splitter.sh\n\n2. Run the script:\n\n ./csv_splitter.sh \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e \u003cvar translate=\"no\"\u003eLINES_PER_FILE\u003c/var\u003e \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e: the input CSV file to split.\n - \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e: the prefix for the generated CSV files.\n - \u003cvar translate=\"no\"\u003eLINES_PER_FILE\u003c/var\u003e: the number of lines per generated CSV file. The default value is `10`.\n\n The script generates various CSV files.\n3. View the list of generated CSV files:\n\n ls -lrt \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e*\n\nRun guest discovery on all the VMs in a CSV files\n-------------------------------------------------\n\nTo run the guest discovery for the VMs in a CSV file, use the\n`collection` script from the Migrate to Containers GitHub repository.\n\nRepeat this step for each CSV file generated in the previous step. \n\n\n url_regex='^https?://[-A-Za-z0-9\\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\\+&@#/%=~_|]\\.[-A-Za-z0-9\\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\\+&@#/%=~_|]$'\n\n read -r -p \"CSV file name: \" CSV_FILE\n if [[ ! -r \"$CSV_FILE\" ]]; then\n echo \"The file $CSV_FILE does not exist or can not be accessed.\"\n exit 1\n fi\n\n read -r -p \"vSphere URL: \" VSPHERE_URL\n if ! [[ $VSPHERE_URL =~ $url_regex ]]; then\n echo \"vSphere URL $VSPHERE_URL IS not a valid URL\"\n exit 1\n fi\n read -r -p \"vSphere username: \" VSPHERE_USER\n read -r -s -p \"vSphere password: \" VSPHERE_PASSWORD\n echo \"\"\n read -r -p \"Default username: \" DEFAULT_USER\n read -r -s -p \"Default password: \" DEFAULT_PASSWORD\n\n echo \"\"\n\n # CSV fields\n #NAME;PLATFORM VM ID;OS;IP;USERNAME;PASSWORD\n while IFS=\";\" read -r vm_name vm_id os ip username password\n do\n if [ -z \"$username\" ]\n then\n username=$DEFAULT_USER\n fi\n if [ -z \"$password\" ]\n then\n password=$DEFAULT_PASSWORD\n fi\n\n if [ ! -z \"$vm_id\" ]\n then\n # Note that the below only works for VMWare VMs\n # vm_id after the last slash if prefixed by vSphere IP\n mod_vm_id=$(echo \"$vm_id\" | sed 's/.*\\///')\n mcdc discover vsphere guest --url $VSPHERE_URL -u $VSPHERE_USER -p $VSPHERE_PASSWORD --vm-user $username --vm-password $password $mod_vm_id\n else\n echo \"Skipping VM: $vm_name because it has no VM ID\"\n fi\n done \u003c \u003c(tail -n +1 $CSV_FILE)\n\nThe script uses the `discover vsphere guest` command to upload and execute the\nguest collection script on the VM.\n\nIt's best to execute this script in the background and direct the output to a\nlog file. To do so, you need to create a text file which is passed as input to\nthe script.\n\n1. Create the text file:\n\n cat \u003c\u003cEOF \u003e\u003e \u003cvar translate=\"no\"\u003eINPUT_FILE\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e\u003cvar translate=\"no\"\u003eCSV_FILE_SUFFIX\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVSPHERE_URL\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVSPHERE_USER\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVSPHERE_PASSWORD\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVM_USER\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVM_PASSWORD\u003c/var\u003e\n EOF\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eINPUT_FILE\u003c/var\u003e: input filename\n - \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e: CSV filename prefix\n - \u003cvar translate=\"no\"\u003eCSV_FILE_SUFFIX\u003c/var\u003e: CSV filename suffix\n - \u003cvar translate=\"no\"\u003eVSPHERE_URL\u003c/var\u003e: the URL for your vCenter Server instance or the vSphere Client\n - \u003cvar translate=\"no\"\u003eVSPHERE_USER\u003c/var\u003e: vCenter username\n - \u003cvar translate=\"no\"\u003eVSPHERE_PASSWORD\u003c/var\u003e: vCenter password\n - \u003cvar translate=\"no\"\u003eVM_USER\u003c/var\u003e: VM username\n - \u003cvar translate=\"no\"\u003eVM_PASSWORD\u003c/var\u003e: VM password\n2. Run the guest collection script:\n\n nohup ./mcdc_collect_vms_guest_tools.sh \u003c\u003cvar translate=\"no\"\u003eINPUT_FILE\u003c/var\u003e \u003e /tmp/mcdc.out 2\u003e&1 &\n\n3. Repeat steps 1 and 2 for each CSV file generated in the previous step.\n\nGenerate an offline assessment report\n-------------------------------------\n\n- After all the data is collected, you can produce a detailed HTML report:\n\n ```bash\n ./mcdc report --format html --full \u003e REPORT_NAME.html\n \n ```\n\nWhat's next\n-----------\n\n- Learn how to [collect guest data from EC2 instances](/migrate/containers/docs/mcdc-aws-collection-tutorial).\n- Learn more about the [`mcdc` CLI](/migration-center/docs/discovery-client-cli-overview).\n- Look [through scripts samples](https://github.com/GoogleCloudPlatform/migrate-to-containers/tree/main/scripts/mcdc)."]]