ESXI及虚拟机搭建笔记

开启ESXI-SSH

物理机界面: F2键进入系统配置页面 选择Troubleshooting Options 鼠标↓键选中Enable SSH,然后按回车键激活SSH服务,然后按Esc键退出当前页面。 启用 ESXI Shell

然后ALT+F1进入ESXI Shell,修改/etc/ssh/sshd_configPasswordAuthentication no 改为 PasswordAuthentication yes 即可远程使用密码SSH连接ESXI Shell

技巧

ESXI WEB -> 右上角用户 -> 设置 -> 控制台 -> 默认控制台 -> VMware Remote Consple,能够使用VMware Workstation连接该虚拟机。比起网页版控制台,VMware Workstation中支持粘贴等,方便安装时编辑某些内容。

ESXI WEB默认15分钟无操作自动失效,需要重新登录。

ESXI WEB -> 右上角用户 -> 设置 -> 应用程序超时 -> 关闭。

安装虚拟机

在新建时的设置页面的CD-ROM选项中选择刚刚上传的镜像

此处建议在安装时进行设置网络,同时将镜像源一并设置、开启SSH服务,免得后续设置起来麻烦,因为未正确设置网络就无法使用SSH连接该虚拟机进行管理。

比如拟分配的ipv4静态IP地址为192.168.1.212,则subnet应填写192.168.1.0/24.

设置为内网网关,比如192.168.1.254

为必填项,必须设置公共dns(114.114.114.114或8.8.8.8),不能设置内网dns(比如网关)。

新建虚拟机的硬件配置界面中的CPU数量为逻辑核心数,并非物理CPU数。

ESXI SHELL命令

1
2
3
vim-cmd vmsvc/getallvms
# Vmid     Name                    File                    Guest OS      Version   Annotation
# 3      ubuntu22   [datastore1] ubuntu22/ubuntu22.vmx   ubuntu64Guest   vmx-21

ubuntu22.vmx文件在ESXI中的详细路径/vmfs/volumes/datastore1/ubuntu22/ubuntu22.vmx 貌似该文件为虚拟机的配置文件。 虚拟机的文件系统在ESXI中的路径为/vmfs/volumes/datastore1/ubuntu22/ubuntu22.vmdk

1
esxcli network firewall ruleset set --ruleset-id=sshClient --enabled=true

执行上传命令

1
scp /vmfs/volumes/datastore1/TestVM/TestVM.vmdk root@192.168.1.120:/tmp/
1
fdisk -l

输出

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fdisk -l
Disk /dev/loop0: 63.95 MiB, 67051520 bytes, 130960 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop1: 87.04 MiB, 91267072 bytes, 178256 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop2: 38.83 MiB, 40714240 bytes, 79520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 600 GiB, 644245094400 bytes, 1258291200 sectors
Disk model: Virtual disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 2E8EF526-D132-48FE-8DF4-171BE8EB53CF

Device       Start        End    Sectors   Size Type
/dev/sda1     2048    2203647    2201600     1G EFI System
/dev/sda2  2203648    6397951    4194304     2G Linux filesystem
/dev/sda3  6397952 1258289151 1251891200 596.9G Linux filesystem

其中/dev/sda3分区为虚拟机根文件系统,也是我们虚拟挂在映射出去的分区

1
guestmount -a /vmfs/volumes/datastore1/ubuntu22/ubuntu22.vmdk -m /dev/sda3 /mnt