vagrant box list 查看镜像 PS C:VPCvagrant> vagrant box list debian (virtualbox, 0) 4.使用 vagrant up 建立虚拟机和启动虚拟机 先建立一个目录 C:VPCvagrant,在这个目录 init 这个目录到时会自动挂载到虚拟机中,命令行进入这个目录 vagrant init debian vagrant up # 虚拟机磁盘保存硬盘位置 C:UsersvipVirtualBox VMsvagrant_default_1632921757898_12141 运行 vagrant up 前先编辑 Vagrantfile,开启 config.vm.network "public_network" 创建一个公共网络,它通常与桥接网络相匹配。 桥接网络使机器显示为网络上的另一个物理设备。 # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. config.vm.network "public_network"
vagrant status 查看虚拟机运行状态; vagrant halt 停止; vagrant up 重启 vagrant2.PNG
PS C:VPCvagrant> vagrant status Current machine states:
default running (virtualbox)
The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`. PS C:VPCvagrant> vagrant halt ==> default: Attempting graceful shutdown of VM… vagrant ssh 登陆虚拟机,ip addr 查看IP地址 vagrant3.PNG
vagrant ssh ip addr sudo -i # 切换到root 5.添加证书方便使用 Xshell 登陆 [email protected]:~# df -h Filesystem Size Used Avail Use% Mounted on