diff --git "a/docs/zh/docs/Virtualization/\345\207\206\345\244\207\344\275\277\347\224\250\347\216\257\345\242\203.md" "b/docs/zh/docs/Virtualization/\345\207\206\345\244\207\344\275\277\347\224\250\347\216\257\345\242\203.md" index bb05c54bfbb483023f205d6bb60545122c3209c4..f58d189a56bd63a869a96931f7e89ee039afbe82 100644 --- "a/docs/zh/docs/Virtualization/\345\207\206\345\244\207\344\275\277\347\224\250\347\216\257\345\242\203.md" +++ "b/docs/zh/docs/Virtualization/\345\207\206\345\244\207\344\275\277\347\224\250\347\216\257\345\242\203.md" @@ -1,52 +1,66 @@ -# 准备使用环境 +# Preparing the environment for use -## 准备虚拟机镜像 +## Prepare VM image -### 概述 +### Overview -虚拟机镜像是一个文件,包含了已经完成安装并且可启动操作系统的虚拟磁盘。虚拟机镜像具有不同格式,常见的有raw格式和qcow2格式。与raw格式镜像相比,qcow2格式镜像占用更小的空间,支持快照、Copy-On-Write、AES加密、zlib压缩等特性,但性能略逊于raw格式镜像。镜像文件的制作借助于qemu-img工具,本节以qcow2格式镜像文件为例,介绍虚拟机镜像制作过程。 +The virtual machine image is a file that contains the virtual disks that +have been installed and can start the operating system. Virtual machine +images have different formats. The common formats are raw format and qcow2 +format. Compared with raw format image, The qcow2 format image occupies +less space and supports snapshots Copy On Write, AES encryption Zlib +compression and other features, but its performance is slightly inferior +to the raw format image. The creation of the image file uses the qemu img +tool. This section takes the qcow2 format image file as an example to +introduce the creation process of the virtual machine image. -### 制作镜像 +### Make a mirror image -制作qcow2格式镜像文件的操作步骤如下: +The operation steps for creating a qcow2 format image file are as follows: -1. 使用root用户安装qemu-img软件包。 +1. Use the root user to install the qemu img software package. ```sh # yum install -y qemu-img ``` -2. 使用qemu-img工具的create命令,创建镜像文件,命令格式为: +2. Use the create command of the qemu img tool to create an image file. +The command format is: ```sh qemu-img create -f -o ``` - 其中,各参数含义如下: + where the meaning of each parameter is as follows. - - _imgFormat_:镜像格式,取值为raw, qcow2等。 - - _fileOption_:文件选项,用于设置镜像文件的特性,如指定后端镜像文件,压缩,加密等特性。 - - _fileName_:文件名称。 - - _diskSize_:磁盘大小,用于指定块磁盘设备的大小,支持的单位有K、M、G、T,分别代表KiB、MiB、GiB、TiB。 + - _imgFormat_:image format, the value is raw, Qcow2, etc. + - _fileOption_: File option, used to set the characteristics of the image file, such as specifying the back-end image file,compression,encryption and other characteristics. + - _fileName_:File name. + - _diskSize_:disk size, used to specify the size of a disk device.The supported units are K M、G、T, KiB MiB、GiB、TiB。 + + For example, create an image file openEuler-image. qcow2 with a disk device size of 4GB and a format of qcow2. The command and echo are as +follows: - 例如,创建一个磁盘设备大小为4GB、格式为qcow2的镜像文件openEuler-image.qcow2,命令和回显如下: ```sh $ qemu-img create -f qcow2 openEuler-image.qcow2 4G Formatting 'openEuler-image.qcow2', fmt=qcow2 size=4294967296 cluster_size=65536 lazy_refcounts=off refcount_bits=16 ``` -### 修改镜像磁盘空间大小 +### Modify the size of the mirrored disk space -当虚拟机需要更大的磁盘空间时,可以使用qemu-img工具,修改虚拟机镜像磁盘空间的大小,修改方法如下。 +When the virtual machine needs more disk space, you can use the qemu img +tool to modify the size of the virtual machine image disk space. The +modification method is as follows. -1. 查询当前虚拟机镜像磁盘空间大小,命令如下: +1. Query the current virtual machine image disk space size, the command +is as follows. ```sh qemu-img info ``` - 例如,查询openEuler-image.qcow2镜像磁盘空间大小的命令和回显如下,说明该镜像磁盘空间大小为4GiB。 + For example, the command to query the space size of the openEuler-image. qcow2 image disk is echoed as follows, indicating that the space size of the image disk is 4GiB. ```sh $ qemu-img info openEuler-image.qcow2 @@ -62,26 +76,28 @@ corrupt: false ``` -2. 修改镜像磁盘空间大小,命令如下,其中_imgFiLeName_为镜像名称,“+”和“-”分别表示需要增加或减小的镜像磁盘空间大小,单位为K、M、G、T,代表KiB、MiB、GiB、TiB。 +2. Modify the size of the image disk space. The command is as follows, where _imgFiLeName_ is the image name, and "+" and "-" respectively indicate the size of the image disk space that needs to be increased or decreased. The units are K M、G、T, On behalf of KiB MiB、GiB、TiB。 + ```sh qemu-img resize [+|-] ``` - 例如,将上述openEuler-image.qcow2镜像磁盘空间大小扩展到24GiB,即在原来4GiB基础上增加20GiB,命令和回显如下: + For example, expand the size of the above openEuler-image. qcow2 image disk space to 24GiB, that is, add 20GiB to the original 4GiB. The command and echo are as follows: ```sh $ qemu-img resize openEuler-image.qcow2 +20G Image resized. ``` -3. 查询修改后的镜像磁盘空间大小,确认是否修改成功,命令如下: +3. Query the size of the mirrored disk space after modification to confirm whether the modification is successful, the command is as follows. ```sh qemu-img info ``` - 例如,上述openEuler-image.qcow2镜像磁盘空间已扩展到24GiB,命令和回显如下: + For example, the above openEuler-image. qcow2 image disk space has been expanded to 24GiB. The command and echo are as follows: + ```sh $ qemu-img info openEuler-image.qcow2 @@ -97,86 +113,92 @@ corrupt: false ``` -## 准备虚拟机网络 +## Prepare the VM network -### 概述 +### Overview +In order to enable the virtual machine to communicate with the external network, the network environment needs to be configured for the virtual machine.KVM virtualization supports Linux bridge、Open vSwitch bridge and other types of bridges.As shown in [Figure 1](#fig1785384714917).the +data transmission path is "virtual machine ->virtual network interface device ->Linux bridge or Open vSwitch bridge->physical network interface". To create a bridge, in addition to configuring virtual network card devices for virtual machines, creating a bridge for hosts is the key to connecting virtual machine networks. -为了使虚拟机可以与外部进行网络通信,需要为虚拟机配置网络环境。KVM虚拟化支持Linux网桥、Open vSwitch网桥等多种类型的网桥。如[图1](#fig1785384714917)所示,数据传输路径为“虚拟机 -\> 虚拟网卡设备 -\> Linux网桥或Open vSwitch网桥 -\> 物理网卡”。创建网桥,除了为虚拟机配置虚拟网卡设备外,为主机创建网桥是连接虚拟化网络的关键。 +This section gives the method of building Linux bridge and Open vSwitch bridge, so that the virtual machine can be connected to the network. The user can choose the type of bridge to build according to the situation. -本节给出搭建Linux网桥和Open vSwitch网桥的方法,使虚拟机连接到网络,用户可以根据情况选择搭建网桥的类型。 -**图 1** 虚拟网络结构图 +**Figure 1 ** Virtual Network Structure Diagram ![](./figures/virtual-network-structure.png) -### 搭建Linux网桥 +### Build Linux bridge -以物理网卡eth0绑定到Linux网桥br0的操作为例,使用root用户执行如下命令搭建Linux网桥: +Taking the operation of physical network card eth0 binding to Linux bridge br0 as an example, use the root user to execute the following command to +build a Linux bridge: -1. 安装bridge-utils软件包。 +1. Install the bridge utils software package. - Linux网桥通常通过brctl工具管理,其对应的安装包为bridge-utils,安装命令如下: + The Linux bridge is usually managed through the brctl tool. The corresponding installation package is bridge utils. The installation command is as follows: ```sh # yum install -y bridge-utils ``` -2. 创建网桥br0。 +2. Create the bridge br0. ```sh # brctl addbr br0 ``` -3. 将物理网卡eth0绑定到Linux网桥。 +3. Bind the physical network card eth0 to the Linux bridge. ```sh # brctl addif br0 eth0 ``` -4. eth0与网桥连接后,不再需要IP地址,将eth0的IP设置为0.0.0.0。 +4. After eth0 is connected to the bridge, the IP address is no longer needed. Install the net tools software package and set the IP address of eth0 to +0.0.0.0. ```sh # yum install -y net-tools # ifconfig eth0 0.0.0.0 ``` -5. 设置br0的IP地址。 - - 如果有DHCP服务器,可以通过dhclient设置动态IP地址。 +5. Set the IP address of br0. + -If you have a DHCP server, you can set a dynamic IP address through dhclient. + ```sh # dhclient br0 ``` - - 如果没有DHCP服务器,给br0配置静态IP,例如设置静态IP为192.168.1.2,子网掩码为255.255.255.0。 + -If there is no DHCP server, configure a static IP for br0. For example, set the static IP to 192.168. 1.2 and the subnet mask to 255.255.255.0. + ```sh # ifconfig br0 192.168.1.2 netmask 255.255.255.0 ``` -### 搭建Open vSwitch网桥 +### Build an Open vSwitch bridge -Open vSwitch网桥,具有更便捷的自动化编排能力。搭建Open vSwitch网桥需要安装网络虚拟化组件,这里介绍总体操作。 +Open vSwitch bridge, with more convenient automatic editing capability. To build an Open vSwitch bridge, you need to install network virtualization components. Here is the overall operation. -#### 一、安装Open vSwitch组件 +#### I.Install the Open vSwitch component. -使用Open vSwitch提供虚拟网络,需要安装Open vSwitch网络虚拟化组件,使用root用户执行如下命令: +If you use Open vSwitch to provide virtual network, you need to install the Open vSwitch network virtualization component, and use the root user to execute the following command: -1. 安装Open vSwitch组件。 +1. Install the Open vSwitch component. ```sh # yum install -y openvswitch ``` -2. 启动Open vSwitch服务。 +2. Load the Open vSwitch module into the kernel. ```sh # systemctl start openvswitch ``` -#### 二、确认安装是否成功 +#### II.Confirmation of successful installation + +Confirm whether the Open vSwitch component is successfully installed. -确认Open vSwitch组件是否安装成功。 +1. Confirm whether the openvswitch component is successfully installed. If the installation is successful, you can see the information about the software package. The commands and echoes are as follows: -1. 确认openvswitch组件是否安装成功。若安装成功,可以看到软件包相关信息,命令和回显如下: ```sh $ rpm -qi openvswitch @@ -202,7 +224,8 @@ Open vSwitch网桥,具有更便捷的自动化编排能力。搭建Open vSwitc traffic. ``` -2. 查看Open vSwitch服务是否启动成功。若服务处于“Active”状态,说明服务启动成功,可以正常使用Open vSwitch提供的命令行工具,命令和回显如下: +2. Check whether the Open vSwitch service is started successfully. If the service is in "Active" status, it indicates that the service is successfully started. You can normally use the command line tool provided by Open vSwitch. The command and echo are as follows: + ```sh $ systemctl status openvswitch @@ -220,76 +243,76 @@ Open vSwitch网桥,具有更便捷的自动化编排能力。搭建Open vSwitc └─54603 ovs-vswitchd unix:/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/var/log/openvswitch/ovs-vswitchd.log --pidfile=/var/run/open> ``` -#### 三、搭建Open vSwitch网桥 +#### III.Build an Open vSwitch bridge -以创建Open vSwitch一层网桥br0为例,介绍搭建方法,使用root用户执行如下命令: +Taking the creation of the Open vSwitch Layer 1 bridge br0 as an example, this paper introduces the building method, and uses the root user to execute the following commands: -1. 创建Open vSwitch网桥br0。 +1. Create an Open vSwitch bridgebr0. ```sh # ovs-vsctl add-br br0 ``` -2. 将物理网卡eth0添加到br0。 +2. Create an Open vSwitch bridgebr0. ```sh # ovs-vsctl add-port br0 eth0 ``` -3. eth0与网桥连接后,不再需要IP地址,将eth0的IP设置为0.0.0.0。 +3. After eth0 is connected to the bridge, the IP address is no longer needed.Set the IP address of eth0 to 0.0.0.0. ```sh # ifconfig eth0 0.0.0.0 ``` -4. 为OVS网桥br0分配IP。 - - 如果有DHCP服务器,可以通过dhclient设置动态IP地址。 +4. Assign an IP address to the OVS bridge br0. + -If you have a DHCP server, you can set a dynamic IP address through dhclient. ```sh # dhclient br0 ``` - - 如果没有DHCP服务器,给br0配置静态IP,例如192.168.1.2。 + -If there is no DHCP server, configure a static IP address for br0, such as 192.168.1.2. ```sh # ifconfig br0 192.168.1.2 ``` -## 准备引导固件 +## Preparing to boot the firmware -### 概述 +### Preparing to boot the firmware -针对不同的架构,引导的方式有所差异。x86支持UEFI(Unified Extensible Firmware Interface)和BIOS方式启动,AArch64仅支持UEFI方式启动。openEuler默认已安装BIOS启动对应的引导文件,不需要用户额外操作。所以这里仅介绍UEFI启动方式的安装方法。 +The guidance methods are different for different architectures. X86 supports UEFI (Unified Extensible Firmware Interface) and BIOS mode startup, AArch64 only supports UEFI mode startup. By default, openEuler has installed the boot file corresponding to BIOS startup, and no additional user operation is required. Therefore, only the installation method of UEFI startup mode is introduced here. -统一的可扩展固件接口UEFI是一种全新类型的接口标准,用于开机自检、引导操作系统的启动,是传统BIOS的一种替代方案。EDK II是一套实现了UEFI标准的开源代码,在虚拟化场景中,通常利用EDK II工具集,通过UEFI的方式启动虚拟机。使用EDK II工具需要在虚拟机启动之前安装对应的软件包 ,本节介绍EDK II的安装方法。 +The unified extensible firmware interface (UEFI) is a new type of interface standard, which is used for POST and booting the operating system. It is an alternative to the traditional BIOS. EDK II is a set of open source code that implements the UEFI standard. In virtualization scenarios, the virtual machine is usually started through UEFI using the EDK II toolset. To use the EDK II tool, you need to install the corresponding software package before starting the virtual machine. This section describes the installation method of EDK II. -### 安装方法 +### Installation method -如果使用UEFI方式引导,需要安装工具集EDK II,AArch64架构对应的安装包为edk2-aarch64,x86架构对应的安装包为edk2-ovmf。这里以AArch64架构为例,给出具体的安装方法,x86架构仅需将edk2-aarch64替换为edk2-ovmf。 +If you use UEFI mode to boot, you need to install the tool set EDK II, The installation package corresponding to AArch64 architecture is edk2-aarch64, The installation package corresponding to x86 architecture is edk2-ovmf. Taking the AArch64 architecture as an example, the specific installation method is given here, The x86 architecture only needs to replace edk2-aarch64 with edk2-ovmf. -1. 安装edk软件包,使用root用户执行如下命令: +1. Install the edk software package, and use the root user to execute the following commands: - 在AArch64架构下edk2的包名为edk2-aarch64 + The package name of edk2 under AArch64 architecture is edk2-aarch64 ```sh # yum install -y edk2-aarch64 ``` - 在x86\_64架构下edk2的包名为edk2-ovmf + The package name of edk2 under x86\_64 architecture is edk2-ovmf ```sh # yum install -y edk2-ovmf ``` -2. 查询edk软件是否安装成功,命令如下: +2. Query whether the edk software is successfully installed. The command is as follows: - 在AArch64架构下查询如下 + Query under AArch64 architecture as follows ```sh rpm -qi edk2-aarch64 ``` - 若edk软件安装成功,回显类似如下: + If the edk software is successfully installed, the echo is similar to the following: ```text Name : edk2-aarch64 @@ -300,13 +323,13 @@ Open vSwitch网桥,具有更便捷的自动化编排能力。搭建Open vSwitc Group : Applications/Emulators ``` - 在x86\_64架构下查询如下 + uery under x86\_64 architecture as follows ```sh # rpm -qi edk2-ovmf ``` - 若edk软件安装成功,回显类似如下: + If the edk software is successfully installed, the echo is similar to the following: ```text Name : edk2-ovmf @@ -316,49 +339,49 @@ Open vSwitch网桥,具有更便捷的自动化编排能力。搭建Open vSwitc Install Date: Thu 19 Mar 2020 09:09:06 AM CST ``` -## 非root用户配置 +## Non root user configuration -### 概述 +### Overview -openEuler虚拟化使用virsh管理虚拟机。如果希望在非root用户使用virsh命令管理虚拟机,在使用之前需要进行相关配置,这里给出配置指导。 +OpenEuler virtualization uses virsh to manage virtual machines. If you want to use the virsh command to manage the virtual machine for non root users, you need to configure it before using it. Here are the configuration instructions. -### 操作指导 +### Operating instructions -允许非root用户使用virsh命令管理虚拟机的配置操作如下,以下命令中的userName请改为实际的非root用户名称: +The configuration operations for allowing non root users to use the virsh command to manage virtual machines are as follows. Please change the userName in the following commands to the actual non root user name: -1. 使用root用户登录主机。 +1. Log in to the host as root. -2. 将非root用户添加到libvirt用户组。 +2. Add the non root user to the libvirt user group. ```sh # usermod -a -G libvirt userName ``` -3. 切换到非root用户。 +3. Switch to a non root user. ```sh # su userName ``` -4. 配置非root用户的环境变量。使用vim打开~/.bashrc文件: +4. Configure environment variables for non root users. Use vim to open the~/.bashrc file: ```sh vim ~/.bashrc ``` - 并在末尾加上如下内容后保存。 + and save it after adding the following at the end. ```sh export LIBVIRT_DEFAULT_URI="qemu:///system" ``` - 执行如下命令,使配置生效。 + Execute the following command to make the configuration effective. ```sh source ~/.bashrc ``` -5. 在虚拟机XML配置文件中的domain根元素中添加如下内容,使qemu-kvm进程可以访问磁盘镜像文件。 +5. Add the following content to the domain root element in the XML configuration file of the virtual machine, so that the qemu_kvm process can access the disk image file. ```xml