当前位置:首页 > 技术分析 > 正文内容

VMware ESXi常用命令

ruisui881个月前 (03-18)技术分析13


一、如何开启ESXi的命令行Shell和SSH服务

方法一:通过ESXi主机的终端控制台(DCUI)界面开启Shell和SSH

  1. 在ESXi主机控制台用户界面(DCUI)中,按F2 键进入“System Customization”(系统自定义)菜单,据提示输入root账户的密码,并按“Enter” (回车)键 登录。
  2. 在“System Customization”(系统自定义)界面,选择“Troubleshooting Options”(故障排除)选项,然后按 “Enter” (回车)键。
  3. 在“Troubleshooting Options”(故障排除)选项,选择“Enable ESXi Shell”(开启ESXi Shell),在右边可以看到“ESXi Shell is Disabled”可以确认当前Shell是禁用,按“Enter”(回车)键开启Shell,在右边显示“ESXi Shell is Enabled”,确认Shell已经开启。
  4. 选择“Enable SSH”(开启SSH),并按“Enter”(回车)开启SSH,在右边显示“SSH is Enabled”,认SSH已经开启(Enabled)。
  5. 访问ESXi本地命令行(Shell)
  6. 在DCUI界面,按 “ALT+F1” 组合键切换到本地命令行(Shell),输入用户名密码登录,登录成功就可以使用命令了。
  7. 在未开启Shell 服务的情况下,按“ALT+F1” 从图形页面切换到命令行后,只有一个光标闪烁,无法登录。
  8. 在Shell的命令行界面,可以按 “ALT+F2” 组合键可以切回到原来的图形界面。

方法二:登录主机客户端(VMware Host Client)开启Shell和SSH

  1. 访问ESXi主机的管理IP地址或域名,输入ESXi账户密码登录主机客户端(VMware Host Client)
  2. 在主机客户端(VMware Host Client)界面,选择“导航器”--> "管理"--> "服务",向下滚动查看服务列表,找到 TSM(ESXi Shell)和TSM-SSH(SSH)服务,点击启动。
  3. 当ESXi主机重新启动时,SSH/Shell 会自动禁用,这是默认策略。修改策SSH/Shell服务随主机启动和停止。
  4. 确认TSH/TSM-SSH服务的状态为“正在运行”,TSH/TSH-SSH开启成功。

方法三:访问vCenter Server管理地址(vSphere Client)开启Shell和SSH

vSphere Client开启Shell/SSH的方法与方法二相似


二、登录Shell/SSH

登录Shell或是SSH,即可使用ESXi命令。

  • 在DCUI界面,按 “ALT+F1” 组合键切换到本地命令行(Shell),输入用户名密码登录,登录成功使用命令行。在未开启Shell 服务的情况下,按“ALT+F1” 从图形页面切换到命令行后,只有一个光标闪烁,无法登录。
  • 在Shell的命令行界面,可以按 “ALT+F2” 组合键可以切回到原来的DCUI界面。
  • 使用SSH工具(PuTTY/SecureCRT/ssh命令)登录ESXi
  • ssh -p 22 root@10.91.xxx.xx # ESXi管理地址

三、ESXi常用命令

Shell命令

1.dcui# 在命令行下使用dcui控制台

SSH工具(PuTTY/MobaXterm)连接到ESXi,输入dcui,出现如下所示dcui界面,按F2可以整个ESXi主机进行配置,按F12键重启或关机

Note: 用ssh命令连接esxi,输入dcui无反应,需用带图形界面的SSH工具(如PuTTY/MobaXterm)

2. vmware -vl# 查看ESXi版本

[root@ESXi210:~] vmware -vl
VMware ESXi 6.7.0 build-14320388
VMware ESXi 6.7.0 Update 3
[root@ESXi210:~] 

3. uptime# 查看系统运行时间

系统总共运行时间,显示的信息依次是:现在时间、系统已经运行了多长时间、目前有多少登陆用户、系统在过去的1分钟、5分钟和15分钟内的平均负载。

[root@ESXi210:~] uptime
 11:27:23 up 17 days, 04:17:37, load average: 0.01, 0.01, 0.01
[root@ESXi210:

4. services.sh# ESXi服务管理

Services.sh 是 Linux服务通常使用services命令管理,管理ESXi服务是通过使用services.sh命令实现的。Services.sh命令支持的参数包括stop、start、restart,通过这三个参数可以停止、启动或重启所有的ESXi服务。

services.sh restart   # 重启所有的ESXi服务

5. /etc/init.d# 执行位于/etc/init.d目录下的脚本可以启动或停止对应的服务

ls -l /etc/init.d           # 查看/etc/init.d目录下的所有服务
cat /etc/chkconfig.db       # 查看所有ESXi服务的运行状态
/etc/init.d/vpxa stop       # 停止vCenter Server Agent(vpax服务)
/etc/init.d/vpxa restart    # 重启vCenter Server Agent(vpax服务)
/etc/init.d/vpxa start      # 启动vCenter Server Agent(vpax服务)

6.vm-support# 收集ESXi主机所有的支持及日志信息

[root@ESXi210:~] vm-support   # 收集ESXi主机所有的支持及日志信息

vim-cmd 命令

vim-cmd命令的作用:获取虚拟机状态、关闭虚拟机、重启虚拟机、打开虚拟机,主要用于控制虚拟机的注册、启动及快照等操作。

vim-cmd构建在host进程之上,允许用户调用几乎所有的vSphere API,因此它提供了对虚拟基础设施的广泛管理功能。使用vim-cmd,用户可以执行各种操作,如查看当前已有的虚拟机列表、启动或关闭虚拟机、进入或退出维护模式等。

[root@ESXi210:~] vim-cmd vmsvc    # 查看vim-cmd vmsvc/参数
Commands available under vmsvc/:  # 以下均为vim-cmd vmsvc可执行的功能
acquiremksticket                 get.snapshotinfo                 
acquireticket                    get.spaceNeededForConsolidation  
createdummyvm                    get.summary                      
destroy                          get.tasklist                     
device.connection                getallvms                        
device.connusbdev                gethostconstraints               
device.ctlradd                   message                          
device.ctlrremove                power.getstate                   
device.disconnusbdev             power.hibernate                  
device.diskadd                   power.off                        
device.diskaddexisting           power.on                         
device.diskextend                power.reboot                     
device.diskremove                power.reset                      
device.getdevices                power.shutdown                   
device.nvdimmadd                 power.suspend                    
device.nvdimmremove              power.suspendResume              
device.toolsSyncSet              queryftcompat                    
devices.createnic                reload                           
get.capability                   setscreenres                     
get.config                       snapshot.create                  
get.config.cpuidmask             snapshot.dumpoption              
get.configoption                 snapshot.get                     
get.datastores                   snapshot.remove                  
get.disabledmethods              snapshot.removeall               
get.environment                  snapshot.revert                  
get.filelayout                   snapshot.setoption               
get.filelayoutex                 tools.cancelinstall              
get.guest                        tools.install                    
get.guestheartbeatStatus         tools.upgrade                    
get.managedentitystatus          unregister                       
get.networks                     upgrade                          
get.runtime 

1. vim-cmd vmsvc/getallvms# 获取所有虚拟机信息

[root@ESXi210:~] vim-cmd vmsvc/getallvms    # 获取所有虚拟机的信息,主要是获取vmid,Vmi是虚拟机的ID号,ESXi用Vmid来标识不同的虚拟

Vmid         Name                                     File                                    Guest OS         Version           10     ipxe-bios          [datastore-hdd1-local] ipxe/ipxe.vmx                           centos7_64Guest       vmx-14           12     iPXE-Server        [datastore-hdd1-local] iPXE-Server/iPXE-Server.vmx             centos7_64Guest       vmx-15             13     ipxe-uefi          [datastore-hdd1-local] ipxe-uefi/ipxe-uefi.vmx                 windows9_64Guest      vmx-14             14     Win10-OA           [datastore-hdd1-local] Win10-OA/Win10-OA.vmx                   windows9_64Guest      vmx-14             16     WebServer-Unicom   [datastore-hdd1-local] WebServer-Unicom/WebServer-Unicom.vmx   centos7_64Guest       vmx-15      

2.vim-cmd vmsvc/power.on Vmid# 打开/启动虚拟机

vim-cmd vmsvc/power.on 14       # 打开/启动虚拟机(Win0-OA,vmid为14)

3.vim-cmd vmsvc/power.resetVmid# 重启动虚拟机

vim-cmd vmsvc/power.reset 14        # 重启虚拟机(Win0-OA,vmid为14)

4.vim-cmd vmsvc/power.off Vmid# 关闭虚拟机(vmid标识)

vim-cmd vmsvc/power.off 14    # 关闭虚拟机(Win0-OA,vmid为14)

5.vim-cmd vmsvc/power.getstate Vmid# 获取虚拟机的当前状态

vim-cmd vmsvc/power.getstate 14     # 获取虚拟机(Win0-OA,vmid为14)当前状态

6.vim-cmd vmsvc/snapshot# 虚拟机快照管理

[root@ESXi210:~]vim-cmd vmsvc/snapshot.get 14   # 查看虚拟机快照信息
Get Snapshot:
|-ROOT
--Snapshot Name        : Source
--Snapshot Id        : 1
--Snapshot Desciption  : 
--Snapshot Created On  : 11/18/2024 9:20:41
--Snapshot State       : powered off

7.vim-cmd vmsvc/snapshot.create# 创建快照

[root@ESXi210:~] vim-cmd vmsvc/snapshot.create
Insufficient arguments.
Usage: snapshot.create vmid [snapshotName] [snapshotDescription] [includeMemory] [quiesced]

Creates a snapshot for the vm.

8.vim-cmd vmsvc/snapshot.revert# 恢复快照

[root@ESXi210:~] vim-cmd vmsvc/snapshot.revert
Insufficient arguments.
Usage: snapshot.revert vmid snapshotId suppressPowerOn

Revert to a snapshot on the vm.

9. vim-cmd vmsvc/snapshot.remove# 删除快照

[root@ESXi210:~] vim-cmd vmsvc/snapshot.remove
Insufficient arguments.
Usage: snapshot.remove vmid snapshotId [removeChildren]

Remove a snapshot on the vm.

10. Vim-cmd vmsvc/snapshot.remove# 删除所有快照

[root@ESXi210:~] vim-cmd vmsvc/snapshot.removeall
Insufficient arguments.
Usage: snapshot.removeall vmid

Removes all the snapshots on the vm.

esxcli 命令

esxcli命令是VMware ESXi]主机管理的重要工具,允许管理员执行各种管理任务,包括配置网络设置、管理存储、管理虚拟机、管理系统设置、管理硬件设置以及管理软件设置等。

esxcli命令用途广泛,我们不能简单地将其归为单个命令。esxcli包括许多不同的命名空间,允许你控制ESXi提供的几乎所有设备。

[root@ESXi210:~] esxcli
Usage: esxcli [options] {namespace}+ {cmd} [cmd options]    # 语法格式:esxcli [命名空间] [参数]

Options:
  --formatter=FORMATTER
                        Override the formatter to use for a given command. Available formatter: keyvalue, csv, xml
  --debug               Enable debug or internal use options
  --version             Display version information for the script
  -?, --help            Display usage information for the script

Available Namespaces:
  device                Device manager commands
  esxcli                Commands that operate on the esxcli system itself allowing users to get additional information.
  fcoe                  VMware FCOE commands.
  graphics              VMware graphics commands.
  hardware              VMKernel hardware properties and commands for configuring hardware.
  iscsi                 VMware iSCSI commands.
  network               Operations that pertain to the maintenance of networking on an ESX host. This includes a wide variety
                        of commands to manipulate virtual networking components (vswitch, portgroup, etc) as well as local host
                        IP, DNS and general host networking settings.
  nvme                  VMware NVMe driver esxcli extensions
  rdma                  Operations that pertain to remote direct memory access (RDMA) protocol stack on an ESX host.
  sched                 VMKernel system properties and commands for configuring scheduling related functionality.
  software              Manage the ESXi software image and packages
  storage               VMware storage commands.
  system                VMKernel system properties and commands for configuring properties of the kernel core system and
                        related system services.
  vm                    A small number of operations that allow a user to Control Virtual Machine operations.
  vsan                  VMware vSAN commands

1.esxcli system version get# 获取系统版本包括patch等信息

[root@ESXi210:~] esxcli system version get
   Product: VMware ESXi
   Version: 6.7.0
   Build: Releasebuild-14320388
   Update: 3
   Patch: 73

2.esxcli hardware cpu global get# 获取CPU信息

[root@ESXi210:~] esxcli hardware cpu global get
   CPU Packages: 2
   CPU Cores: 12
   CPU Threads: 24
   Hyperthreading Active: true
   Hyperthreading Supported: true
   Hyperthreading Enabled: true
   HV Support: 3
   HV Replay Capable: false
   HV Replay Disabled Reasons: incompatible CPU

3.esxcli hardware platform get# 获取硬件平台信息

[root@ESXi210:~]  esxcli hardware platform get
Platform Information
   UUID: 0x49 0x43 0x4d 0x53 0x2 0x0 0x90 0x6b 0x25 0x0 0x6b 0x90 0x25 0x0 0x3b 0xb9
   Product Name: X8DTL
   Vendor Name: Supermicro
   Serial Number: 1234567890
   Enclosure Serial Number: 1234567890
   BIOS Asset Tag: To Be Filled By O.E.M.
   IPMI Supported: false

4.esxcli hardware memory get# 获取内存信息

[root@ESXi210:~]  esxcli hardware memory get
   Physical Memory: 51530223616 Bytes
   Reliable Memory: 0 Bytes
   NUMA Node Count: 2

5.esxcli network ip interface ipv4 get# 查看ESXi管理地址

[root@ESXi210:~] esxcli network ip interface ipv4 get
Name  IPv4 Address  IPv4 Netmask   IPv4 Broadcast  Address Type  Gateway       DHCP DNS
----  ------------  -------------  --------------  ------------  ------------  --------
vmk0  10.91.19.210  255.255.255.0  10.91.19.255    STATIC        10.91.19.254     false

6. esxcli network nic list# 列出所的网卡信息

esxcli network nic list
Name    PCI Device    Driver  Admin Status  Link Status  Speed  Duplex  MAC Address         MTU  Description
------  ------------  ------  ------------  -----------  -----  ------  -----------------  ----  ---------------------------------------------------
vmnic0  0000:06:00.0  ne1000  Up            Up            1000  Full    00:25:90:6b:b9:3a  1500  Intel Corporation 82574L Gigabit Network Connection
vmnic1  0000:07:00.0  ne1000  Up            Up             100  Full    00:25:90:6b:b9:3b  1500  Intel Corporation 82574L Gigabit Network Connection
vmnic2  0000:01:00.0  igbn    Up            Up            1000  Full    a0:36:9f:0a:1f:d4  1500  Intel Corporation Ethernet Server Adapter I350-T4
vmnic3  0000:01:00.1  igbn    Up            Up            1000  Full    a0:36:9f:0a:1f:d5  1500  Intel Corporation Ethernet Server Adapter I350-T4
vmnic4  0000:01:00.2  igbn    Up            Up            1000  Full    a0:36:9f:0a:1f:d6  1500  Intel Corporation Ethernet Server Adapter I350-T4
vmnic5  0000:01:00.3  igbn    Up            Up            1000  Full    a0:36:9f:0a:1f:d7  1500  Intel Corporation Ethernet Server Adapter I350-T4

7.esxcli network vm list # 列出有一个活动网络端口的虚拟机的网络信息。(列出所有活动虚拟机网络信息)

[root@ESXi210:~] esxcli network vm list
World ID  Name              Num Ports  Networks
--------  ----------------  ---------  -----------------------------
 2100680  WebServer-Unicom          2  VM Network Wan, VM Network OA
 2100534  Win10-OA                  2  VM Network Wan, VM Network OA

8.esxcli system maintenanceMode set --enable true/false# ESXi主机进入/退出维护模式

[root@ESXi210:~] esxcli system maintenanceMode get                  # 查看ESXi主机维护模式状态
Disabled                                                            # 正常模式
[root@ESXi210:~] esxcli system maintenanceMode set --enable true    # 进入维护模式
[root@ESXi210:~] esxcli system maintenanceMode get                  # 查看ESXi主机维护模式状态
Enabled                                                             # 维护模式
[root@ESXi210:~] esxcli system maintenanceMode set --enable false   # 退出维护模式
[root@ESXi210:~] esxcli system maintenanceMode get                  # 查看ESXi主机维护模式状态
Disabled

9. esxcli system shutdown reboot/poweroff# 重启/关闭ESXi主机

ESXi必须处于维护模式,否则该命令不生效

10.esxcli network ip route ipv4 list# 查看路由表

[root@ESXi210:~] esxcli network ip route ipv4 list
Network   Netmask    Gateway    Interface Source
---------- ------------- ------------ --------- ------
default   0.0.0.0    10.91.19.254 vmk0    MANUAL
10.91.19.0 255.255.255.0 0.0.0.0    vmk0    MANUAL



扫描二维码推送至手机访问。

版权声明:本文由ruisui88发布,如需转载请注明出处。

本文链接:http://www.ruisui88.com/post/2850.html

分享给朋友:

“VMware ESXi常用命令” 的相关文章

医疗养老收费管理系统

医疗养老收费管理系统headerfooter《医疗养老收费管理系统》是最新开发的适用于养老保险收费行业的管理系统。主要功能:1.基本信息:单位设置、缴费基数、缴费比例和队别设置;2.医疗保险管理:医疗保险人员信息、医疗保险收费、医疗保险信息查询、医疗保险收费查询、医疗保险收费情况;3.养老保险信息:...

Beta版Linux Mint“Xia”发行版22.1发布

IT之家 12 月 13 日消息,Beta 版 Linux Mint“Xia” 22.1 昨日(12 月 12 日)发布,新版本基于 Ubuntu 24.04,内核版本为 Linux 6.8,长期支持将持续到 2029 年,为用户提供可靠稳定的使用体验。新版本在软件包管理方面,主要弃用了传统的 ap...

如何在GitLab上回退指定版本的代码?GitLab回退指定版本问题分析

在Git中,回退到指定版本并不是删除或撤销之前的提交,而是创建一个新的提交,该提交包含指定版本的内容。这意味着您需要将当前代码更改与指定版本之间的差异进行比较,并将其合并到一个新的提交中。如果您没有更新本地代码,并且您希望将 GitLab 仓库回退到指定版本,您可以使用以下命令:git fetchg...

Vue2的16种传参通信方式

前言先直入主题列出有哪些传参方式,下面再通过事例一一讲解。props(父传子)$emit与v-on (子传父)EventBus (兄弟传参).sync与update: (父子双向)v-model (父子双向)ref$children与$parent$attrs与$listeners (爷孙双向)pr...

VUE-router

七.Vue-router1、什么是vue-routervue-router是vue.js官方路由管理器。vue的单页应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来。传统页面切换是用超链接a标签进行切换。但vue里是用路由,因为我们用Vue做的都是单页应用,就相当于只有一个主的i...

快来看看重构了 365 天的 vue3.5 这次到底更新了啥

新人求关注?,点击右上角 ↗? 关注,博主日更,全年无休,您的关注是我的最大的更新的动力~ 感谢大家了 就在 9 月 1 号,迭代了一年多的 Vue 3.5 终于发布了,这次发布的代号是 "天元突破 红莲螺岩"。这是一个机器人动画片的名字,相信喜欢看动漫的小伙伴应该很熟悉从更新的 C...