适用于Windows 10开发人员的Hyper-V

Microsoft Hyper-V, codenamed Viridian, is a native (type 1) hypervisor that directly runs on the hardware, compared to VMware Workstation, VirtualBox, and other type 2 or hosted hypervisors. It was first released in Windows Server 2008, and it allows you to run virtual machines on x86-64 systems.

与VMware Workstation,VirtualBox和其他类型2或托管的管理程序相比,Microsoft Hyper-V(代号为Viridian)是一种直接在硬件上运行的本机(类型1)管理程序。 它最初在Windows Server 2008中发布,它使您可以在x86-64系统上运行虚拟机。

As mentioned, with Windows 10, Microsoft optimized Hyper-V for developers. Hyper-V allows developers to quickly spin up development virtual machines on Windows 10 with excellent performance, but it is also used in a couple of other development features as a back-end technology, like the Android Emulator, the Windows Subsystem for Linux 2 or Docker Containers. In this article, we will have a quick look at what Hyper-V on Windows 10 can over for developers.

如前所述,Microsoft使用Windows 10为开发人员优化了Hyper-V。 Hyper-V允许开发人员以出色的性能在Windows 10上快速启动开发虚拟机,但它还用作后端技术的其他几个开发功能,例如Android Emulator,Windows Subsystem for Linux 2或Windows Server 2003。 Docker容器。 在本文中,我们将快速了解Windows 10上的Hyper-V可为开发人员提供哪些功能。

适用于Windows 10开发人员的Hyper-V_第1张图片

快速创建VM库 (Quick Create VM Gallery)

适用于Windows 10开发人员的Hyper-V_第2张图片

First, let’s start with one of the essential features to create virtual machines. Now you can not only create Hyper-V virtual machines by installing them with an ISO file; you can use the Hyper-V Quick Create VM Gallery, to quickly create a new Windows 10 Development environment or even an Ubuntu virtual machine. It will download a pre-configured Hyper-V virtual machine with Windows 10 and the visual studio development environment or Ubuntu 18.04 or 19.04. If you want, you can also create your own Quick Create VM images and even share them with other developers.

首先,让我们从创建虚拟机的基本功能之一开始。 现在,您不仅可以通过使用ISO文件安装Hyper-V虚拟机来创建虚拟机,还可以创建虚拟机。 您可以使用Hyper-V快速创建VM库来快速创建新的Windows 10开发环境,甚至是Ubuntu虚拟机。 它将下载具有Windows 10和Visual Studio开发环境或Ubuntu 18.04或19.04的预配置Hyper-V虚拟机。 如果需要,您还可以创建自己的快速创建VM映像 ,甚至与其他开发人员共享它们。

适用于Linux 2的Windows子系统(WSL 2) (Windows Subsystem for Linux 2 (WSL 2))

适用于Windows 10开发人员的Hyper-V_第3张图片

With the Windows Subsystem for Linux, did Microsoft bring a Linux environment to the Windows 10 desktop, and allows you to run a GNU/Linux environment — including most command-line tools, utilities, and applications — directly on Windows, unmodified, without the overhead of a full virtual machine. In the latest Windows, 10 Insider Preview builds, Microsoft released a preview of WSL 2. WSL 2 uses Hyper-V virtualization technology to isolate and virtualize WSL in the backend. This provides not just security benefits but also a huge performance boost. You can find more about the Windows Subsystem for Linux 2 on my blog.

借助适用于Linux的Windows子系统,Microsoft是否将Linux环境带入Windows 10桌面,并允许您直接在Windows上运行GNU / Linux环境-包括大多数命令行工具,实用程序和应用程序,无需修改,而无需完整虚拟机的开销。 在最新的Windows 10 Insider Preview版本中,Microsoft发布了WSL 2的预览版。WSL 2使用Hyper-V虚拟化技术在后端隔离和虚拟化WSL。 这不仅提供了安全优势,而且还极大地提高了性能。 您可以在我的博客上找到有关Linux 2的Windows子系统的更多信息。

增强的会话模式,可与虚拟机共享设备 (Enhanced Session Mode to share devices with your virtual machine)

适用于Windows 10开发人员的Hyper-V_第4张图片

One of the difficult parts in the past was the interaction between the virtual machine and the host machine. With the Enhanced Session Mode, Microsoft made it easy to copy-paste files between them and also allows you to map and share devices from the host with the virtual machine. This includes:

过去最困难的部分之一是虚拟机和主机之间的交互。 借助增强的会话模式 ,Microsoft可以轻松地在文件之间复制粘贴文件,还允许您使用虚拟机映射和共享主机中的设备。 这包括:

  • Makes virtual machines resizable and high DPI aware

    使虚拟机可调整大小并了解DPI
  • Improves virtual machine integration

    改善虚拟机集成
  • Allows device sharing

    允许设备共享

Enhanced session mode is enabled by default on Windows 10 Hyper-V, in Windows Server, you will need to enable that feature in the Hyper-V Settings. If you create your own Linux virtual machine, make sure you install the latest virtualization drivers.

默认情况下,在Windows 10 Hyper-V上启用了增强会话模式,在Windows Server中,您需要在Hyper-V设置中启用该功能。 如果创建自己的Linux虚拟机,请确保安装最新的虚拟化驱动程序。

检查站 (Checkpoints)

A huge benefit of virtualization is the ability to easily save the state of a virtual machine, which allows you to go back or forward at a specific point in time. In Hyper-V, this feature is called a virtual machine checkpoint, formerly known as a virtual machine snapshot.

虚拟化的巨大好处是能够轻松保存虚拟机的状态,这使您可以在特定时间点前进或后退。 在Hyper-V中,此功能称为虚拟机检查点 ,以前称为虚拟机快照。

Hyper-V knows to types of checkpoints:

Hyper-V知道检查点的类型:

  • Standard Checkpoints: takes a snapshot of the virtual machine and virtual machine memory state at the time the checkpoint is initiated.

    标准检查点:在启动检查点时拍摄虚拟机和虚拟机内存状态的快照。
  • Production Checkpoints: uses Volume Shadow Copy Service or File System Freeze on a Linux virtual machine to create a data-consistent backup of the virtual machine. No snapshot of the virtual machine memory state is taken.

    生产检查点:在Linux虚拟机上使用“卷影复制服务”或“文件系统冻结”来创建虚拟机的数据一致性备份。 不获取虚拟机内存状态的快照。
适用于Windows 10开发人员的Hyper-V_第5张图片

The checkpoint type can be set by virtual machine. Both types of checkpoints have different advantages and disadvantages. In the latest versions of Hyper-V, production checkpoints are selected by default. However, you can easily change this using the Hyper-V Manager Settings or PowerShell. On my Windows 10 client machine, I prefer to use standard checkpoints, since it also saves the virtual machine memory state, however on production server systems I highly recommend to use production checkpoints, and even then you should be careful.

可以通过虚拟机设置检查点类型。 两种类型的检查点都有不同的优点和缺点。 在最新版本的Hyper-V中,默认情况下会选择生产检查点。 但是,您可以使用Hyper-V管理器设置或PowerShell轻松更改此设置。 在Windows 10客户端计算机上,我更喜欢使用标准检查点,因为它还会保存虚拟机的内存状态,但是,在生产服务器系统上,我强烈建议使用生产检查点,即使这样,您也应该小心。

NAT组网 (NAT Networking)

适用于Windows 10开发人员的Hyper-V_第6张图片

One of the features which were very painful in the past was networking. With the introduction of the NAT switching option in the Hyper-V virtual switch, you can now easily connect all your virtual machines to the network your host is joined. On Windows 10, you will get a default switch to connect your virtual machines. If this is not enough or you want to leverage the NAT VM Switch on a Hyper-V server, you can use the following commands to create a VM switch and NAT rule.

过去非常痛苦的功能之一是网络。 通过在Hyper-V虚拟交换机中引入NAT交换选项,您现在可以轻松地将所有虚拟机连接到主机所连接的网络。 在Windows 10上,您将获得用于连接虚拟机的默认开关。 如果这还不够,或者您想在Hyper-V服务器上利用NAT VM Switch,则可以使用以下命令来创建VM Switch和NAT规则。

You can read more about the Hyper-V NAT networking here.

您可以在此处阅读有关Hyper-V NAT网络的更多信息。

在Windows 10上运行Windows和Linux容器 (Run Windows and Linux Containers on Windows 10)

Containers are one of the hot technologies right now, with Docker Desktop for Windows you can run them on your Windows 10 machine. In the background, Windows uses Hyper-V technology to apply additional isolation between the container and the host operating system, so-called Hyper-V Containers. This feature also allows you to run Windows and Linux containers on Windows side by side, without the need of running a full Linux VM on Windows 10.

容器是当前的热门技术之一,借助适用于Windows的Docker桌面,您可以在Windows 10计算机上运行它们。 在后台,Windows使用Hyper-V技术在容器和主机操作系统(即所谓的Hyper-V容器)之间应用其他隔离。 此功能还允许您在Windows上并排运行Windows和Linux容器 ,而无需在Windows 10上运行完整的Linux VM。

PowerShell Direct和HVC (PowerShell Direct & HVC)

If you want to interact with your virtual machine running on Windows 10, you can use the Hyper-V Manager and the console to interact with the operating system directly. However, there are also two other options that allow you to manage and access the VMs using the command line. PowerShell Direct lets you create a PowerShell remoting session to the virtual machine using the VM Bus, so no networking is required. The same applies to Linux virtual machines and the HVC tool, which allows you to create an SSH connection directly into the VM. Both options also allow you to copy files to and from virtual machines.

如果要与Windows 10上运行的虚拟机进行交互,则可以使用Hyper-V管理器和控制台直接与操作系统进行交互。 但是,还有两个其他选项可让您使用命令行来管理和访问VM。 使用PowerShell Direct ,您可以使用VM Bus创建到虚拟机的PowerShell远程会话,因此不需要联网。 同样适用于Linux虚拟机和HVC工具 ,它允许您直接在VM中创建SSH连接。 这两个选项还允许您在虚拟机之间复制文件。

适用于Windows 10开发人员的Hyper-V_第7张图片

This is extremely handy if you set up some automation, and you need to run some commands within the virtual machine.

如果您设置了一些自动化功能,并且需要在虚拟机中运行一些命令,这将非常方便。

Windows沙箱 (Windows Sandbox)

适用于Windows 10开发人员的Hyper-V_第8张图片

Windows Sandbox is a new feature in Windows 10 and was released in version 1903. Windows Sandbox uses Hyper-V technology to provide you with a Windows 10 Sandbox. The Sandbox allows you to spin up an isolated, temporary, desktop environment where you can run untrusted software. The sandbox is great for demos, development, testing, troubleshooting, or if you are dealing with malware. If you close the sandbox, all the software with all its files and state are permanently deleted. It is a Windows 10 virtual machines, with the advantage that it is built into Windows 10, so it leverages the existing OS, which gives you faster startup, less footprint, better efficiency, and easier handling, without losing security.

Windows沙箱是Windows 10中的一项新功能,已于1903版中发布。Windows沙箱使用Hyper-V技术为您提供Windows 10沙箱。 沙盒使您可以启动一个隔离的临时桌面环境,在其中可以运行不受信任的软件。 沙盒非常适合演示,开发,测试,故障排除或处理恶意软件。 如果关闭沙箱,则所有软件及其所有文件和状态将被永久删除。 它是Windows 10虚拟机,其优点是内置于Windows 10中,因此可以利用现有的OS,从而使您启动速度更快,占用空间更小,效率更高且更易于处理,而又不会丢失安全性。

The Windows Sandbox experience can also be customized with configuration files. So, you can add additional software and tools to your Windows Sandbox. You can read more about Windows Sandbox and how you create the configuration files here.

也可以使用配置文件来自定义Windows Sandbox体验。 因此,您可以将其他软件和工具添加到Windows Sandbox。 您可以在此处阅读有关Windows Sandbox以及如何创建配置文件的更多信息。

Windows Defender应用程序防护 (Windows Defender Application Guard)

适用于Windows 10开发人员的Hyper-V_第9张图片

This one might be not directly development related. However, I think we all have been here. We see a link, and we are not sure if this is a trusted site or if it is a malicious website. With Windows Defender Application Guard, we get an isolated browser, which protects us from malicious websites and software. If a user goes to an untrusted site through either Microsoft Edge or Internet Explorer, Microsoft Edge opens the site in an isolated Hyper-V-enabled container, which is separate from the host operating system.

这可能与开发没有直接关系。 但是,我认为我们所有人都曾来过这里。 我们看到了一个链接,我们不确定这是一个受信任的网站还是一个恶意网站。 使用Windows Defender Application Guard ,我们获得了一个隔离的浏览器,可以保护我们免受恶意网站和软件的侵害。 如果用户通过Microsoft Edge或Internet Explorer进入不受信任的站点,则Microsoft Edge会在独立的启用Hyper-V的容器中打开该站点,该容器与主机操作系统是分开的。

You can enable Windows Defender Application Guard on Windows 10, using the following steps.

您可以使用以下步骤在Windows 10上启用Windows Defender Application Guard 。

Hyper-V电池直通 (Hyper-V Battery Pass-through)

适用于Windows 10开发人员的Hyper-V_第10张图片

This feature is more about convenience. If you are working and develop inside a virtual machine and you are running this virtual machine console in full-screen mode, you might not notice when your notebook runs out of battery. With the Battery Pass-through feature, the guest operating system inside the virtual machine knows about the battery status. The Hyper-V Virtual Battery feature is enabled by default and works with Windows and Linux virtual machines.

此功能更多关于便利性。 如果您在虚拟机中进行工作和开发,并且正在全屏模式下运行此虚拟机控制台,则笔记本电池没电时可能不会注意到。 通过电池直通功能,虚拟机内部的来宾操作系统可以了解电池状态。 Hyper-V虚拟电池功能默认情况下处于启用状态,并且可与Windows和Linux虚拟机一起使用。

嵌套虚拟化 (Nested Virtualization)

适用于Windows 10开发人员的Hyper-V_第11张图片

Nested Virtualization lets you run virtualization in a virtual machine, basically like inception for virtual machines. With Hyper-V, you can run Hyper-V within a Hyper-V virtual machine. This is interesting for a couple of different scenarios. First, you can create a virtual Hyper-V host for testing and labs, or you even more important, you can run Hyper-V Containers or Windows Sandbox within a virtual machine. And another great thing about Nested Virtualization, it also works with virtual machines in Microsoft Azure.

嵌套虚拟化使您可以在虚拟机中运行虚拟化,基本上就像虚拟机的启动一样。 使用Hyper-V,您可以在Hyper-V虚拟机中运行Hyper-V。 对于几个不同的场景,这很有趣。 首先,您可以创建用于测试和实验室的虚拟Hyper-V主机,或者更重要的是,可以在虚拟机中运行Hyper-V容器或Windows沙箱。 嵌套虚拟化的另一个优点是,它还可以与Microsoft Azure中的虚拟机一起使用。

To enable nested virtualization within a Hyper-V, you basically can follow this guide.

要在Hyper-V中启用嵌套虚拟化,您基本上可以遵循本指南 。

适用于Android的Visual Studio模拟器 (Visual Studio Emulator for Android)

If you are using Visual Studio to build Android applications, I am sure you already used the Visual Studio Emulator for Android. This enables developers to use a hardware accelerated Android emulator, without needing to switch to Intel’s HAXM hypervisor, which gives them even more performance and speed.

如果您使用Visual Studio来构建Android应用程序,那么我确定您已经使用了适用于Android的Visual Studio模拟器 。 这使开发人员可以使用硬件加速的Android仿真器,而无需切换到英特尔的HAXM虚拟机管理程序,从而为他们提供了更高的性能和速度。

如何在Windows 10上设置Hyper-V (How to set up Hyper-V on Windows 10)

Now, as you can see, Hyper-V is a great developer tool and used for many different features. To Install Hyper-V, you have to check for the following requirements on your machine:

现在,如您所见,Hyper-V是一款出色的开发人员工具,可用于许多不同功能。 要安装Hyper-V,必须在计算机上检查以下要求:

  • Windows 10 Enterprise, Pro, or Education

    Windows 10企业版,专业版或教育版
  • 64-bit processor with Second Level Address Translation (SLAT).

    具有二级地址转换(SLAT)的64位处理器。
  • CPU support for VM Monitor Mode Extension (VT-c on Intel CPUs).

    VM监视器模式扩展(Intel CPU上的VT-c)的CPU支持。
  • Minimum of 4 GB memory.

    至少4 GB的内存。

For more information and troubleshooting, see Windows 10 Hyper-V System Requirements.

有关更多信息和故障排除,请参阅Windows 10 Hyper-V系统要求 。

If you want to enable and install Hyper-V on Windows 10, you can run the following PowerShell command.

如果要在Windows 10上启用和安装Hyper-V,可以运行以下PowerShell命令。

For more information on how you can install Hyper-V on Windows 10, you can check the following Microsoft Docs.

有关如何在Windows 10上安装Hyper-V的更多信息,可以查看以下Microsoft Docs 。

I hope this gives you an overview of why Hyper-V is great for developers and enables a lot of different features. If you have any questions, please leave a comment.

我希望这能概述为什么Hyper-V非常适合开发人员并启用许多不同的功能。 如有任何疑问,请发表评论。

翻译自: https://habr.com/en/company/microsoft/blog/481224/

你可能感兴趣的:(docker,linux,java,大数据,数据库)