跳转至

第三章 合适的虚拟化平台

3.1 虚拟化平台简介

Welcome to the core!

嗯,笔者撸了个 OpenStack 和 k8s 的部署 脚本 ,PXE 哦。

云计算目前主流实现有 SaaS(Software-as-a-service)、PaaS(Platform-as-a-service)和 IaaS(Infrastructure-as-a-service)。IaaS 和 PaaS 都算作基础件,SaaS 可以与基础件自由组合或者单独使用。

虚拟化技术已经很受重视而且被推到了一个浪尖。如今诸多开源虚拟化平台,比如 XenServer、CloudStack、OpenStack、Eucalyptus、oVirt、OpenVZ、Docker、LXC 等,我们都看花了眼,些许慌乱不知哪个适合自己了。

各平台实现方式:全虚拟化,半虚拟化,应用虚拟化。

IaaS 云计算平台,综合来说具有以下特性:

  • 虚拟化:虚拟化作为云计算平台的核心,是资源利用的主要形式之一。网络、存储、CPU 乃至 GPU 等主要通过虚拟主机进行实体化。
  • 分布式:分布式可利用共享的存储,通过网络将资源进行整合,是实现资源化的必备条件。
  • 高可用:于规模庞大的云平台,提供存储、管理节点、重要服务的高度可用性是十分必要的。笔者在写这篇文章时,oVirt 3.4 已经可以做到管理节点的高度可用。
  • 兼容性:云计算平台众多,各家有各家的特点,同一数据中心部署不同的平台的可能性极大,因此,主要服务(比如虚拟网络、存储、虚机等)要有一定兼容性,比如 oVirt 可以利用 OpenStack 的 Nouveau 提供的虚拟网络、Foreman 可以方便地在 oVirt 上部署新机器等。另外,也有 DeltaCloud、libvirt 等 API,用户可以利用它们自由地实现自己的云综合管理工具。
  • 资源池化:网络、存储、CPU 或者 GPU 可以综合或者单独划分资源池,通过配额进行分配,从而保证其合理利用。
  • 安全性:现代企业对于安全性的要求已经十分苛刻,除去传统数据加密、访问控制,甚至对于社会工程也要有一定防护能力;用户数据具有对非企业管理员具有防护性能,即使将虚拟机磁盘文件拷贝出来也不能直接获取其内容。
  • 需求导向性:在计算水平上,优质资源最先提供给重要服务;服务水平上,平台具有可定制能力。

oVirt

oVirt 目前两种部署方式:

部署方式 示例
管理独占一台物理机 .. image:: ../images/03-01.png
高可用管理引擎 .. image:: ../images/03-02.png

常见名次

管理引擎(engine):提供平台 web 管理、api,各种扩展服务,vdsm 以及 libvirt 服务的重要节点。

宿主机(node/host):为平台的的功能提供支持,主要是虚拟化能力。

数据中心(data center):以数据共享方式(Shared/Local)划分的容器,可以包含多个集群。

存储域(storage domain):平台所依赖的各种存储空间。

逻辑网络(logic network):物理网络或者虚拟网络的抽象代表。

池(pool):用于批量创建虚拟机。

集群策略(cluster policy):宿主机/虚拟机运行或者迁移时所遵循的原则。

DWH/Reports:可以查看当前状态报告(需要 ovirt-engine-reports)。

可信服务: 需要 OpenAttestation 。

电源管理: 如果没有物理电源控制器,可以直接指定某一台主机为代理机,以构建更稳健的集群。

OpenStack

OpenStack 云计算中引入的概念已经先入为主,让国内许多较晚接触云计算的人认为这就是标准概念。

更多内容请参考附录一。

CloudStack

可能也不错,我没用过。

3.2 搭建 oVirt 管理引擎

搭建 oVirt 平台的步骤:

  1. 安装 Redhat 类操作系统(Redhat、CentOS、Fedora)
  2. 从 yum 安装 oVirt,并执行 engine-setup,或者直接从 oVirt 提供的 iso 进行安装
  3. 添加宿主机
  4. 添加存储域
  5. 创建虚拟机

系统准备

所有机器的 SELINUX 都设置为 permissive。

/etc/selinux/config

1
SELINUX=permissive
1
# setenfoce permissive

如有需要,清除 iptables 规则。

1
2
# iptables -F
# service iptables save

每台机器上都要添加作为虚拟机运行的 engine 的 FQDN,此处为 ha.example.com。

1
# echo -e '192.168.10.100\tha.example.com' >> /etc/hosts

存储可以使用之前的 glusterfs,方式为 NFS_V3,注意将 brick 的权限设置为 vdsm.kvm 或者 36:36。

:::{note}

普通 NFS 服务器设置

因为考虑到 NFS4 的权限配置较为复杂,推荐 NFS 使用 V3,修改 nfsmount.conf 中的 Version 为 3。

:::

1
2
3
4
5
# gluster volume create gluster-vol1 replica 2 \
gs1.example.com:/gluster_brick0 gs2.example.com:/gluster_brick0 \
gs3.example.com:/gluster_brick0 gs4.example.com:/gluster_brick0 \
gs1.example.com:/gluster_brick1 gs2.example.com:/gluster_brick1 \
gs3.example.com:/gluster_brick1 gs4.example.com:/gluster_brick1 force

由于管理端以及节点的网络服务依赖于 network 而非 NetworkManager ,我们需要启用前者禁用后者,在每一台服务器上都进行如下类似配置修改网络。

/etc/sysconfig/network-scripts/ifcfg-eth0

1
2
3
4
5
6
7
8
9
NAME=eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
# 注意修改此处的IP
IPADDR=192.168.10.101
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
DNS1=192.168.10.1
1
2
3
# chkconfig NetworkManager off
# chkconfig network on
# service NetworkManager stop; service network restart

添加 repo

:::{note}

oVirt3.4.2 特别说明

2014 年六七月的初次安装 oVirt 的用户可能会遇到添加宿主机失败的问题,暂时解决办法为卸载 python-pthreading-0.1.3-1 及以后的版本,安装老版本,比如 ftp://ftp.icm.edu.pl/vol/rzm2/linux-fedora/linux/epel/6/i386/python-pthreading-0.1.3-0.el6.noarch.rpm ,再尝试安装 vdsm 并添加宿主机。

:::

使用 rpm:

1
2
# yum localinstall http://plain.resources.ovirt.org/releases/ovirt-release/ovirt-release34.rpm
# yum install ovirt-hosted-engine-setup

或者手动添加:

 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
32
33
34
35
[ovirt-stable]
name=Latest oVirt Releases
baseurl=http://resources.ovirt.org/releases/stable/rpm/EL/$releasever/
enabled=1
skip_if_unavailable=1
gpgcheck=0

[ovirt-3.4-stable]
name=Latest oVirt 3.4.z Releases
baseurl=http://resources.ovirt.org/releases/3.4/rpm/EL/$releasever/
enabled=1
skip_if_unavailable=1
gpgcheck=0

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0

[ovirt-glusterfs-epel]
name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
baseurl=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/epel-$releasever/$basearch/
enabled=1
skip_if_unavailable=1
gpgcheck=0

[ovirt-glusterfs-noarch-epel]
name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
baseurl=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/epel-$releasever/noarch
enabled=1
skip_if_unavailable=1
gpgcheck=0

从下面两种方式中选择之一进行搭建

{ref}label2

{ref}label3

(label2)=

搭建普通 oVirt 虚拟化平台

笔者写此文时 oVirt 已经更新到 3.4。

在此,我们会用到之前创建的 distributed-replicated 存储,这样可用保证系统服务的高度可用性有所提高。

对于初次使用 oVirt 的用户,建议使用此种搭建方式,太折腾的话就吓走好多目标读者了

使用之前的四台机器,分别为 gs1.example.com,gs2.example.com,gs3.example.com 和 gs4.example.com,其中,将 gs1 作为管理机安装 ovirt-engine,其余三台作为节点(node),存储使用已经创建好的 glusterfs。

```{image} ../images/03-03.png :align: center

  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
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
在 gs1 上运行如下命令。

```{code}

# yum install ovirt-engine
# engine-setup --offline
[ INFO  ] Stage: Initializing
[ INFO  ] Stage: Environment setup
          Configuration files: ['/etc/ovirt-engine-setup.conf.d/10-packaging.conf']
          Log file: /var/log/ovirt-engine/setup/ovirt-engine-setup-20140508054649.log
          Version: otopi-1.2.0 (otopi-1.2.0-1.el6)
[ INFO  ] Stage: Environment packages setup
[ INFO  ] Stage: Programs detection
[ INFO  ] Stage: Environment setup
[ INFO  ] Stage: Environment customization

          --== PRODUCT OPTIONS ==--


          --== PACKAGES ==--


          --== NETWORK CONFIGURATION ==--

          Host fully qualified DNS name of this server [gs1.example.com]:
          Setup can automatically configure the firewall on this system.
          Note: automatic configuration of the firewall may overwrite current settings.
          Do you want Setup to configure the firewall? (Yes, No) [Yes]:
          The following firewall managers were detected on this system: iptables
          Firewall manager to configure (iptables): iptables
[ INFO  ] iptables will be configured as firewall manager.

          --== DATABASE CONFIGURATION ==--

          Where is the Engine database located? (Local, Remote) [Local]:
          Setup can configure the local postgresql server automatically for the engine to run. This may conflict with existing applications.
          Would you like Setup to automatically configure postgresql and create Engine database, or prefer to perform that manually? (Automatic, Manual) [Automatic]:

          --== OVIRT ENGINE CONFIGURATION ==--

          Application mode (Both, Virt, Gluster) [Both]:
          Default storage type: (NFS, FC, ISCSI, POSIXFS) [NFS]:
          Engine admin password:
          Confirm engine admin password:

          --== PKI CONFIGURATION ==--

          Organization name for certificate [example.com]:

          --== APACHE CONFIGURATION ==--

          Setup can configure apache to use SSL using a certificate issued from the internal CA.
          Do you wish Setup to configure that, or prefer to perform that manually? (Automatic, Manual) [Automatic]:
          Setup can configure the default page of the web server to present the application home page. This may conflict with existing applications.
          Do you wish to set the application as the default page of the web server? (Yes, No) [Yes]:

          --== SYSTEM CONFIGURATION ==--

          Configure WebSocket Proxy on this machine? (Yes, No) [Yes]:
          Configure an NFS share on this server to be used as an ISO Domain? (Yes, No) [Yes]: no

          --== MISC CONFIGURATION ==--


          --== END OF CONFIGURATION ==--

[ INFO  ] Stage: Setup validation

          --== CONFIGURATION PREVIEW ==--

          Engine database name                    : engine
          Engine database secured connection      : False
          Engine database host                    : localhost
          Engine database user name               : engine
          Engine database host name validation    : False
          Engine database port                    : 5432
          PKI organization                        : example.com
          Application mode                        : both
          Firewall manager                        : iptables
          Update Firewall                         : True
          Configure WebSocket Proxy               : True
          Host FQDN                               : gs1.example.com
          Datacenter storage type                 : nfs
          Configure local Engine database         : True
          Set application as default page         : True
          Configure Apache SSL                    : True

          Please confirm installation settings (OK, Cancel) [OK]: ok
[ INFO  ] Stage: Transaction setup
[ INFO  ] Stopping engine service
[ INFO  ] Stopping websocket-proxy service
[ INFO  ] Stage: Misc configuration
[ INFO  ] Stage: Package installation
[ INFO  ] Stage: Misc configuration
[ INFO  ] Initializing PostgreSQL
[ INFO  ] Creating PostgreSQL 'engine' database
[ INFO  ] Configuring PostgreSQL
[ INFO  ] Creating Engine database schema
[ INFO  ] Creating CA
[ INFO  ] Configuring WebSocket Proxy
[ INFO  ] Generating post install configuration file '/etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf'
[ INFO  ] Stage: Transaction commit
[ INFO  ] Stage: Closing up

          --== SUMMARY ==--

          SSH fingerprint: 1B:FD:08:A2:FD:83:20:8A:65:F5:0D:F6:CB:BF:46:C7
          Internal CA 28:7E:D6:6B:F7:F2:6C:B5:60:27:44:C3:7F:3C:22:63:E5:68:DD:F4
          Web access is enabled at:
              http://gs1.example.com:80/ovirt-engine
              https://gs1.example.com:443/ovirt-engine
          Please use the user "admin" and password specified in order to login into oVirt Engine

          --== END OF SUMMARY ==--

[ INFO  ] Starting engine service
[ INFO  ] Restarting httpd
[ INFO  ] Generating answer file '/var/lib/ovirt-engine/setup/answers/20140508054842-setup.conf'
[ INFO  ] Stage: Clean up
          Log file is located at /var/log/ovirt-engine/setup/ovirt-engine-setup-20140508054649.log
[ INFO  ] Stage: Pre-termination
[ INFO  ] Stage: Termination
[ INFO  ] Execution of setup completed successfully

至此,管理节点安装结束,参考 {ref}label1 加入节点以及存储域。

(label3)=

搭建管理端高可用 oVirt(hosted engine)

高可用,我们可以这么划分:

  • 存储的高可用:传统存储使用 DRBD/Heartbeat 或者独立的存储设备保证高可用,在灵活性、可扩展性、成本上都有一定局限。在与主机同台使用 Ceph 或者 Glusterfs 可以较好地保证资源充分利用地同时,又满足了高度可用的要求。
  • 管理高可用:因为比如 oVirt、OpenStack 这种拥有大型数据库的设施不像存储设施那样高效的同步,需要独立的管理运行在集群中的某一台机器上来同步集群消息,所以,管理端的高可用也是十分必要的。
  • 虚拟机/服务高可用:虚拟机在宕机时可自动重启,在主机资源紧张时可用迁移到其他负载较低的主机上,从而保证服务的质量以及连续性。

```{image} ../images/03-03.png :align: center

1
2
3
4
5
6
7
8
9
```{eval-rst}
.. epigraph::

    1. 宿主机的CPU架构建议选择Westmere(Westmere E56xx/L56xx/X56xx)、Nehalem(Intel Core i7 9xx)、Penryn(Intel Core 2 Duo P9xxx)或者Conroe(Intel Celeron_4x0)中的之一。

    CPU Family table 参阅
        `Intel Architecture and Processor Identification With CPUID Model and Family Numbers <https://software.intel.com/en-us/articles/intel-architecture-and-processor-identification-with-cpuid-model-and-family-numbers>`_

    2. 建议参考第11节提前安装含有oVirt管理的虚拟机,硬盘格式为RAW,从而在安装管理机时作为OVF导入或者覆盖虚拟磁盘,减少失败风险时间。

安装 ovirt-hosted-engine-setup,并回答一些问题,注意高亮部分:

```{code-block} bash :emphasize-lines: 21,36,123,138-144,150,166,173

hosted-engine --deploy

[ INFO ] Stage: Initializing Continuing will configure this host for serving as hypervisor and create a VM where you have to install oVirt Engine afterwards. Are you sure you want to continue? (Yes, No)[Yes]: yes [ INFO ] Generating a temporary VNC password. [ INFO ] Stage: Environment setup Configuration files: [] Log file: /var/log/ovirt-hosted-engine-setup/ovirt-hosted-engine-setup-20140508182241.log Version: otopi-1.2.0 (otopi-1.2.0-1.el6) [ INFO ] Hardware supports virtualization [ INFO ] Bridge ovirtmgmt already created [ INFO ] Stage: Environment packages setup [ INFO ] Stage: Programs detection [ INFO ] Stage: Environment setup [ INFO ] Stage: Environment customization

1
2
3
4
      --== STORAGE CONFIGURATION ==--

      During customization use CTRL-D to abort.
      Please specify the storage you would like to use (nfs3, nfs4)[nfs3]:

此处的存储域只存储hosted-engine的相关文件,不作为主数据域

建议挂载gluster的nfs时使用localhost:data形式

1
      Please specify the full shared storage connection path to use (example: host:/path): 192.168.10.101:/gluster-vol1/ovirt_data/hosted_engine

[ INFO ] Installing on first host Please provide storage domain name. [hosted_storage]: Local storage datacenter name is an internal name and currently will not be shown in engine's admin UI.Please enter local datacenter name [hosted_datacenter]:

1
2
3
4
5
6
7
8
9
      --== SYSTEM CONFIGURATION ==--


      --== NETWORK CONFIGURATION ==--

      iptables was detected on your computer, do you wish setup to configure it? (Yes, No)[Yes]: no
      Please indicate a pingable gateway IP address [192.168.10.1]:

      --== VM CONFIGURATION ==--

虚拟engine的安装方式

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
      Please specify the device to boot the VM from (cdrom, disk, pxe) [cdrom]:
      The following CPU types are supported by this host:
              - model_Conroe: Intel Conroe Family
      Please specify the CPU type to be used by the VM [model_Conroe]:
      Please specify path to installation media you would like to use [None]: /tmp/centos.iso
      Please specify the number of virtual CPUs for the VM [Defaults to minimum requirement: 2]:
      Please specify the disk size of the VM in GB [Defaults to minimum requirement: 25]:
      You may specify a MAC address for the VM or accept a randomly generated default [00:16:3e:59:9b:e2]:
      Please specify the memory size of the VM in MB [Defaults to minimum requirement: 4096]: 4096
      Please specify the console type you would like to use to connect to the VM (vnc, spice) [vnc]:

      --== HOSTED ENGINE CONFIGURATION ==--

      Enter the name which will be used to identify this host inside the Administrator Portal [hosted_engine_1]:
      Enter 'admin@internal' user password that will be used for accessing the Administrator Portal:
      Confirm 'admin@internal' user password:
      Please provide the FQDN for the engine you would like to use.
      This needs to match the FQDN that you will use for the engine installation within the VM.
      Note: This will be the FQDN of the VM you are now going to create,
      it should not point to the base host or to any other existing machine.
      Engine FQDN: ha.example.com

[WARNING] Failed to resolve ha.example.com using DNS, it can be resolved only locally Please provide the name of the SMTP server through which we will send notifications [localhost]: Please provide the TCP port number of the SMTP server [25]: Please provide the email address from which notifications will be sent [root@localhost]: Please provide a comma-separated list of email addresses which will get notifications [root@localhost]: [ INFO ] Stage: Setup validation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
      --== CONFIGURATION PREVIEW ==--

      Engine FQDN                        : ha.example.com
      Bridge name                        : ovirtmgmt
      SSH daemon port                    : 22
      Gateway address                    : 192.168.10.1
      Host name for web application      : hosted_engine_1
      Host ID                            : 1
      Image size GB                      : 25
      Storage connection                 : 192.168.10.101:/gluster-vol1/ovirt_data/hosted_data/
      Console type                       : vnc
      Memory size MB                     : 4096
      MAC address                        : 00:16:3e:59:9b:e2
      Boot type                          : cdrom
      Number of CPUs                     : 2
      ISO image (for cdrom boot)         : /tmp/centos.iso
      CPU Type                           : model_Conroe

      Please confirm installation settings (Yes, No)[No]: yes

[ INFO ] Generating answer file '/etc/ovirt-hosted-engine/answers.conf' [ INFO ] Stage: Transaction setup [ INFO ] Stage: Misc configuration [ INFO ] Stage: Package installation [ INFO ] Stage: Misc configuration [ INFO ] Configuring libvirt [ INFO ] Configuring VDSM [ INFO ] Starting vdsmd [ INFO ] Waiting for VDSM hardware info [ INFO ] Waiting for VDSM hardware info [ INFO ] Waiting for VDSM hardware info [ INFO ] Waiting for VDSM hardware info [ INFO ] Creating Storage Domain [ INFO ] Creating Storage Pool [ INFO ] Connecting Storage Pool [ INFO ] Verifying sanlock lockspace initialization [ INFO ] Initializing sanlock lockspace [ INFO ] Initializing sanlock metadata [ INFO ] Creating VM Image [ INFO ] Disconnecting Storage Pool [ INFO ] Start monitoring domain [ INFO ] Configuring VM [ INFO ] Updating hosted-engine configuration [ INFO ] Stage: Transaction commit [ INFO ] Stage: Closing up The following network ports should be opened: tcp:5900 tcp:5901 udp:5900 udp:5901 An example of the required configuration for iptables can be found at: /etc/ovirt-hosted-engine/iptables.example In order to configure firewalld, copy the files from /etc/ovirt-hosted-engine/firewalld to /etc/firewalld/services and execute the following commands: firewall-cmd -service hosted-console [ INFO ] Creating VM You can now connect to the VM with the following command: /usr/bin/remote-viewer vnc://localhost:5900 Use temporary password "2067OGHU" to connect to vnc console. Please note that in order to use remote-viewer you need to be able to run graphical applications. This means that if you are using ssh you have to supply the -Y flag (enables trusted X11 forwarding). Otherwise you can run the command from a terminal in your preferred desktop environment. If you cannot run graphical applications you can connect to the graphic console from another host or connect to the console using the following command: virsh -c qemu+tls://192.168.1.150/system console HostedEngine If you need to reboot the VM you will need to start it manually using the command: hosted-engine --vm-start You can then set a temporary password using the command: hosted-engine --add-console-password The VM has been started. Install the OS and shut down or reboot it. To continue please make a selection:

1
2
3
      (1) Continue setup - VM installation is complete
      (2) Reboot the VM and restart installation
      (3) Abort setup

需要在另外一个有图形能力的terminal中运行

"remote-viewer vnc://192.168.10.101:5900"连接虚拟机。

完成engine-setup后关闭虚拟机;可以在虚拟机运行状态下执行

"hosted-engine --add-console-password"更换控制台密码。

如果之前选择cdrom进行安装的话,此处可以在gs1上用已经安装好engine的

虚拟磁盘进行覆盖,类似

"mount -t nfs 192.168.10.101:192.168.10.101:/gluster-vol1/ovirt_data/hosted_data/ /mnt; mv engine-disk.raw /mnt/ovirt_data/hosted_data/.../vm_UUID"

1
2
      (1, 2, 3)[1]: 1
      Waiting for VM to shut down...

[ INFO ] Creating VM You can now connect to the VM with the following command: /usr/bin/remote-viewer vnc://localhost:5900 Use temporary password "2067OGHU" to connect to vnc console. Please note that in order to use remote-viewer you need to be able to run graphical applications. This means that if you are using ssh you have to supply the -Y flag (enables trusted X11 forwarding). Otherwise you can run the command from a terminal in your preferred desktop environment. If you cannot run graphical applications you can connect to the graphic console from another host or connect to the console using the following command: virsh -c qemu+tls://192.168.1.150/system console HostedEngine If you need to reboot the VM you will need to start it manually using the command: hosted-engine --vm-start You can then set a temporary password using the command: hosted-engine --add-console-password Please install and setup the engine in the VM. You may also be interested in installing ovirt-guest-agent-common package in the VM. To continue make a selection from the options below: (1) Continue setup - engine installation is complete (2) Power off and restart the VM (3) Abort setup

此处参考第一次操作,连接虚拟机控制台后进行"engine-setup --offline"以安装engine

1
      (1, 2, 3)[1]: 1

[ INFO ] Engine replied: DB Up!Welcome to Health Status! [ INFO ] Waiting for the host to become operational in the engine. This may take several minutes... [ INFO ] Still waiting for VDSM host to become operational... [ INFO ] The VDSM Host is now operational Please shutdown the VM allowing the system to launch it as a monitored service.

到此,需要连接虚拟机控制台关闭虚拟机

1
      The system will wait until the VM is down.

[ INFO ] Enabling and starting HA services Hosted Engine successfully set up [ INFO ] Stage: Clean up [ INFO ] Stage: Pre-termination [ INFO ] Stage: Termination

 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
32
33
34
35
36
37
38
39
此时,运行”hosted-engine –vm-start”以启动虚拟管理机。

:::{note}

1. 若要重新部署

# vdsClient -s 0 list

# vdsClient -s 0 destroy <ID of the vm you get from the first command>

2. 若要添加第二台机器

# yum install ovirt-hosted-engine-setup

# hosted-engine --deploy

然后指定存储路径即可自动判断此为第 2+台机器。

:::

(label1)=

## 3.3 添加节点以及存储域

你看到这的话应该已经有了一个数据中心、几个宿主机,也可能有一个虚拟机(engine),还差一个存储虚拟机镜像的地方就可以拥有基本的 oVirt 平台了。

### 添加节点(宿主机)

对于第 11 节的普通 oVirt、第 12 节的 ha 平台,你可能需要添加更多节点以支持更好的 SLA(service level agreement)。
添加节点目前有三种方式:

- 通过 oVirt 的节点 ISO 安装系统后加入。
- 直接将现有 CentOS 或者 Fedora 转化为节点(可以为当前管理机)。
- 指定使用外部提供者(Foreman)。

在此我们使用第二种方法。

```{image} ../images/03-05.png
:align: center

添加存储域

存储域有 3 种,Data(数据域)、ISO(ISO 域)、Export(导出域)。

其中,数据域是为必需,在创建任何虚拟机之前需要有一个可用的数据域用于存储虚拟磁盘以及快照文件;ISO 域中可以存放 ISO 和 VFD 格式的系统镜像或者驱动文件,可在多个数据中心间共享;导出域用于导出或导入 OVF 格式的虚机。

而根据数据域的存储类型,我们有 5 种(NFS、POSIX 兼容、Glusterfs、iSCSI、光纤)可选,在此,选择 glusterfs 导出的 NFS。

```{image} ../images/03-06.png :align: center

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
:::{note}

确保存储域目录被 vdsm.kvm 可读,即所有者为 36:36,或者 vdsm.kvm。
导出域在已加入数据中心后不可共享,如果它意外损坏,请参考 <http://blog.lofyer.org/blog/2014/05/11/cloud-6-5-advanced-ovirt/> 手动修复,或者删除 dom_md/metadata 中的 POOL_UUID 的值以及\_SHA_CKSUM 行。
若要使用 oVirt 的 gluster 支持,请安装 vdsm-gluster 包。

:::

## 3.4 连接虚拟机

虚拟机运行后,通过 web 界面,你可用使用以下几种方式连接虚拟机(可通过控制台选项进行修改):

```{image} ../images/03-08.png
:align: center

Spice-Html5

首先在服务器端打开 spice 代理:

1
2
3
4
5
# engine-setup --otopi-environment="OVESETUP_CONFIG/websocketProxyConfig=bool:True" # 如果未setup或者要在其他机器setup,可做此步
# yum install -y numpy # 安装numpy以加速转换。
# engine-config -s WebSocketProxy="192.168.10.100:6100"
# service ovirt-websocket-proxy restart
# service ovirt-engine restart

连接之前,要信任以下两处 https 证书:

https://192.168.10.100

https://192.168.10.100:6100

然后点击控制台按钮即可在浏览器的新标签中打开 spice-html5 桌面。

浏览器插件

对于 Redhat 系列系统,可安装 spice-xpi 插件;Windows 系统可以安装 SpiceX 的控件。

本地客户端

访问 virt-manager 官网 下载 virt-viewer 客户端,使用它打开下载到本地的 console.vv 文件。

spice proxy/gateway - squid 代理

设置 squid 代理,将所有 spice 端口代理至 3128 端口。

1

yum install squid

1
修改/etc/squid/squid.conf。
1

第 5 行

acl localhost src 192.168.0.150

第 41 行修改为

http_access allow CONNECT Safe_ports

acl spice_servers dst 192.168.10.0/24

http_access allow spice_servers

1
启用squid服务。
1

chkconfig squid on

service squid restart

1
设置engine的SpiceProxy
1

engine-config -s SpiceProxyDefault="http://FQDNor外网 IP:3128"

service ovirt-engine restart

1
可通过集群设置中设置所有宿主机的Spice代理,或者在虚拟机设置中单一设置某台虚拟机通过代理访问。

RDP 插件(仅适用于 Windows 虚机及 IE 浏览器)

如果虚拟机的操作系统选择为 Windows,并且内部启动了远程桌面服务,使用 IE 浏览器访问用户或者管理员入口时,可以启用 RDP 控件。

3.5 oVirt 使用进阶

数据库修改非同步数据

如果出现网络错误,很有可能导致数据不同步,从而导致界面上虚拟机状态一直处于异常状态,这点 OpenStack 也有一样的缺点。连接引擎数据库,修改其中的 vm_dynamic, image, vm_static 等数据表即可。

engine-config 参数配置

平台安装完以后,可用通过 engine-config 命令进行详细参数配置。

1
2
3
4
# 查看设置说明
# engine-config -l
# 查看当前设置
# engine-config -a

示例:重设管理员密码

1

engine-config -s AdminPassword=interactive

Please enter a password: # 密码 Please reenter password: # 密码

1

ovirt-shell 与 API

Restful API(Application User Interface)是 oVirt 的一大特点,用户可以通过它将其与第三方的界面或者应用进行集成。访问 http://192.168.10.100/api?rsdl 以获取其用法。

:::{note}

访问 API 使用 GET、POST、PUT、DELETE 方法

获取内容时使用 GET; 添加新内容或者执行动作使用 POST; 更新内容使用 PUT; 删除内容使用 DELETE;

详细用法参考 http://www.ovirt.org/Api,SDK 示例参考 http://www.ovirt.org/Testing/PythonApi

:::

ovirt-shell 则是全部使用 Restful API 写成的 shell,通过它可以完成图形界面所不能提供的功能。

1
2
3
4
5
6
7
8
9
# ovirt-shell -I -u admin@internal -l https://192.168.10.100/api
============================================================================
                        >>> connected to oVirt manager 3.4.0.0 <<<
============================================================================

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                              Welcome to oVirt shell
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[oVirt shell (connected)]#

示例:使用 ovirt-shell 或者 API 来连接虚拟机。

  1. 获取虚拟机列表及其所在宿主机
  • ovirtshell
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# ovirt-shell -I -u admin@internal -l https://192.168.10.100/api -E "list vms"
id         : 124e8020-c9d7-4e86-81e1-0d4e28ff1cd4
name       : aaa
# ovirt-shell -I -u admin@internal -l https://192.168.10.100/api -E "show vm aaa"
id                                : 124e8020-c9d7-4e86-81e1-0d4e28ff1cd4
name                              : aaa
...
display-address                   : 192.168.10.100
...
display-port                      : 5912
display-secure_port               : 5913
...
  • restapi
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# curl -u admin@internal:admin https://192.168.10.100/api/vms | less
<name>aaa</name>
<description></description>
...
<display>
    <type>spice</type>
    <address>192.168.10.100</address>
    <port>5912</port>
    <secure_port>5913</secure_port>
    <monitors>1</monitors>
    <single_qxl_pci>false</single_qxl_pci>
    <allow_override>false</allow_override>
    <smartcard_enabled>false</smartcard_enabled>
</display>
...
  1. 获取/设置控制台密码

  2. ovirtshell

1
2
3
4
5
6
7
# ovirt-shell -I -u admin@internal -l https://192.168.10.100/api -E     "action vm aaa ticket"
# [oVirt shell (connected)]# action vm aaa ticket

status-state : complete
ticket-expiry: 7200
ticket-value : MfY9P5kpmNpw
vm-id        : 124e8020-c9d7-4e86-81e1-0d4e28ff1cd4
  • restapi
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# curl -k -u admin@internal:admin https://192.168.10.100/api/vms/124e8020-c9d7-4e86-81e1-0d4e28ff1cd4/ticket -X POST -H "Content-type: application/xml" -d '<action><ticket><expiry>120</expiry></ticket></action>'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<action>
    <ticket>
        <value>jRUqhrks6JiT</value>
        <expiry>120</expiry>
    </ticket>
    ...
    <status>
        <state>complete</state>
    </status>
</action>
  1. 连接虚拟机

除了以上获取的显示端口、宿主机 IP,我们需要额外获取一个根证书。

1
# wget http://192.168.10.100/ca.crt
  • ovirt-shell
1
2
# ovirt-shell -I -u admin@internal -l https://192.168.10.100/api \
-E "console aaa"
  • virt-viewer
1
# remote-viewer --spice-ca-file=ca.crt spice://192.168.10.100?port=5912&tls-port=5913&password=jRUqhrks6JiT

主机 hooks

主机 hooks 位于各个宿主机上,用于扩展 oVirt 的平台功能,比如网络、USB 设备、SRIOV 等。原理是在某一事件触发时(比如虚拟机启动之前),修改 libvirt 启动 XML 文件、环境变量或者主机配置,从而改变 qemu 的启动参数。

更多 hooks 内容请参考 vdsm-hooks

示例:使用 libvirt 内部网络

  1. 准备所需文件。

拷贝 extnet_vnic.py 至/usr/libexec/vdsm/hooks/before_vm_start/,不要忘记添加可执行权限。

  1. 查看,添加 libvirt 网络。
1
# virsh net-list

extnet_vnic.py 文件中 newnet = os.environ.get('extnet') 前一行添加如下代码,替换其中的 default 为要使用的 libvirt 网络, 其他的 hooks 脚本多数可以这样修改,也可以在 engine-config 的 CustomProperty 中指定

1
2
3
4
# 注意此处使用双引号
params = "default"
# 同上部分粗体字,因为大部分hooks检查engine-config中的环境变量,简便起见,我直接在hooks脚本中设置了环境变量
os.environ.__setitem__("extnet",params)
  1. 虚拟机一定要添加网络配置,否则会启动失败,在虚拟机启动时,第一个网络配置文件会被替换为 default 网络。

::::{note}

如果忘记了 libvirt 密码,可以用以下命令重置。

1
# saslpasswd2 -a libvirt root

::::

第三方界面

oVirt 现在自带的 gwt 界面对浏览器和客户的要求较高,有一些人由于这个原因抛弃它使用第三方的 web 界面,参考 oVirt Dashovirt sample-portals

主机策略

参考这个 PDF 。(没记错的话,里面那个显卡透穿的问题,是当初我问的。。)

示例:

使用 virt-install 安装系统

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# virt-install \
--name centos7 \
--ram 2048 \
--disk path=/var/kvm/images/centos7.img,format=qcow2 \
--vcpus 2 \
--os-type linux \
--os-variant rhel7 \
--graphics none \
--console pty,target_type=serial \
--location 'http://mirrors.aliyun.com/centos/7/os/x86_64/' \
--extra-args 'console=ttyS0,115200n8 serial'

虚拟机文件系统扩容

oVirt 3.4 磁盘可以进行在线扩容,但是对于磁盘内的文件系统需要单独支持,在此列出常用 Linux 以及 Windows 扩容方法。

Linux 文件系统扩容(镜像扩容后操作)

在镜像扩容后进行如下操作。

  1. 重写分区表
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# fdisk /dev/sda
> d
> 3
> n
> 3
> w
然后
# kpartprobe
或者
# reboot
  1. 在线扩容文件系统
1
# resize2fs /dev/sda3

Linux 文件系统扩容(lvm)

在创建好一个新的分区或者一个新的磁盘后,将新空间(比如 10G)添加到 PV,VG,扩容 LV,然后扩容文件系统。

1
2
3
# vgextend vg_livecd /dev/sdb
# lvextend /dev/vg_livecd/lv_root -L +10G
# resize2fs /dev/vg_livecd/lv_root

Linux 文件系统扩容(libguestfs)

具体内容请参考 libguestfs site

  1. 检视磁盘
1
# virt-filesystem --all --long -h -a hda.img
  1. 创建待扩容磁盘副本,同时扩容 10G(假设原磁盘大小为 10G)

对于 RAW 格式:

1
2
# truncate -r hda.img hda-new.img
# truncate -s +10G hda-new.img

对于 QCOW2 等有压缩格式:

1
# qemu-img create -f qcow2 -o preallocation=metadata hda-new.img 20G
  1. 扩展分区尺寸

普通分区扩展,/boot 分区扩容 200M,其余全部给/分区:

1
# virt-resize --resize /dev/sda1=+200M --expand /dev/sda2 hda.img hda-new.img

LVM 分区扩展,扩容 lv_root 逻辑卷:

1
# virt-resize --expand /dev/sda2 --LV-expand /dev/vg_livecd/lv_root hda.qcow2 hda-new.qcow2

FAT/NTFS 扩容

XP 使用 Paragon Partion Manager;Windows 7 在磁盘管理中即可扩容。

P2V/V2P

V2V

在此以 ESXi 迁移至 oVirt 为例。

  1. 在 oVirt 上创建一个 NFS 导出域
  2. 安装 libguestfs,并创建.netrc 文件,文件内容为 ESXi 的登陆信息:

~/.netrc

1
machine 192.168.1.135 login root password 1234567
  1. 开始迁移,确保 ESXi 的虚拟机已正常关闭:
1
2
3
# virt-v2v -ic esx://192.168.1.135/?no_verify=1 -o rhev -os 192.168.1.111:/export --network mgmtnet myvm
myvm_myvm: 100% [====================================================]D 0h04m48s
virt-v2v: myvm configured with virtio drivers.
  1. 从导出域导入虚拟机并运行:

导入虚拟机:

```{image} ../images/03-11.png :align: center

1
2
3
4
运行虚拟机:

```{image} ../images/03-12.png
:align: center

P2V

oVirt 的 P2V 方式我所知的有三种,一是使用 VMWare 的 P2V 工具转化为 VM 以后,再通过 virt-v2v 转化为 oVirt 的 VM,二是使用 clonezilla 或者 ghost 制作系统后,再将其安装到 oVirt 中,三则是使用 virt-p2v 工具。笔者在此使用 virt-p2v 工具示例,成文时只在 CentOS 6.5 以上版本测试,CentOS 7 未测试,RHEL 7.1 以上有此工具。

  1. 在服务器端安装所需包:
1
yum install -y virt-p2v virt-v2v
  1. 将/usr/share/virt-v2v/中的 ISO 文件 dd 到 U 盘或者烧录到光盘,然后在要转化的机器上启动。
  2. 修改服务器端/etc/virt-v2v.conf,修改 rhevm 的配置,形如:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<virt-v2v>
  <profile name="rhev-sparse">
    <method>rhev</method>
    <storage format='qcow2' allocation='sparse'>
      nfs.example.com:/ovirt-export
    </storage>
    <network type="default">
      <network type="network" name="ovirtmgmt"/>
    </network>
  </profile>
</virt-v2v>
  1. 开始转换(我是使用 libvirt 的 profile 示例)

```{image} ../images/03-13.png :align: center

```

  1. 转换完成后关闭计算机,并修改虚拟机的配置以完全适应 OS。

UI 插件

详细内容请参考 oVirt 官网关于 UI 插件的介绍 以及附录部分内容,在此我仅使用 ShellInABox 举例,你可以考虑将上面的 libguestfs 扩容加进来,更多 UI Plugin 请 git clone git://gerrit.ovirt.org/samples-uiplugins.git

ShellInABox oVirt UI plugin

  1. 在宿主机上安装 ShellInABox。
1
2
# yum install shellinabox
# chkconfig shellinaboxd on

修改 shellinabox 配置 OPTS

/etc/sysconfig/shellinaboxd

1
OPTS="--disable-ssl --service /:SSH"
  1. 拷贝 uiplugin 文件并启动服务。
1
2
3
4
# git clone git://gerrit.ovirt.org/samples-uiplugins.git
# cp -r samples-uiplugins/shellinabox-plugin/* /usr/share/ovirt-engine/ui-plugins/
# service shellinaboxd start
# service ovirt-engine restart

```{image} ../images/03-09.png :align: center

```

:::{note}

shellinabox 插件链接问题

由于 3.3 到 3.4 之后链接的变化,shellinabox.json 中的 /webadmin/webadmin/plugin/ShellBoxPlugin/start.html 需要替换为 plugin/ShellBoxPlugin/start.html

:::

:::{note}

shellinabox 的 root 登陆问题

echo -e "pts0npts1npts2" >> /etc/securetty

:::

使用 SysPrep/Cloud-Init 重置虚拟机信息

参考 https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Virtualization/3.4/html/Administration_Guide/sect-Sealing_Templates_in_Preparation_for_Deployment.html .

初始化 Redhat 系列 Linux

1

touch /.unconfigured

rm -i /etc/ssh/sshhost*

echo "HOSTNAME=localhost.localdomain" >> /etc/sysconfig/network

rm -i /etc/udev/rules.d/70-persistent*

1
2
3
4
5
6
7
删除 */etc/sysconfig/network-scripts/ifcfg-** 文件中的 **HWADDR=** 字段,删除 */var/log/** 、 */root/*.log* ,然后关机即可。

修改密码

```{code}

# virt-sysprep --root-password password:123456 -a os.img

初始化 Windows 7

  1. 使用http://www.drbl-winroll.org工具批量修改。
  2. 使用位于 C:\Windows\system32\sysprep 目录下的工具。

```{image} ../images/03-10.jpg :align: center

```

与其他平台集成、与认证服务器集成

oVirt 平台目前可以使用 Foreman,OpenStack Network,OpenStack Image 的部分功能,具体实施请参阅附录一内容。

与认证服务器集成时很有可能遇到各种问题,比如与 AD 集成时不能使用 Administrator 用户进行 engine-manage-domains,与 IPA 集成时需要修改 minss 之类的参数,与 LDAP 集成时需要 Kerberos 或者使用 3.5 版本中的 aaa 认证插件。

后端(libvirt/qemu/kernel)优化

如果你觉得现有平台的性能达不到预期,或者有其他的需求,可以从以下几方面进行调节或优化。

  • qemu : 我写了 一系列 qemu 的脚本 ,你可以调节里面的参数直接启动虚拟机进行调试或者优化。
  • libvirt : libvirt 的目的是统一各种虚拟化后端的调用方式(kvm/xen/lxc/OpenVZ//VirtualBox/VMWare/Hyper-V 等等),主要一个特性是用统一的描述文件来定义虚拟机配置(xml 文件),在 Linux 下你可以使用 Virt Manager 进行调试,相关文档参考 libvirt ref
  • kernel : 基本上大部分的内核相关配置都可以通过 /sys 或者 /proc 进行调节,而针对内核所谓的“优化”,在非大规模部署的情况下,其优势很难体现出来,还有一方面,目前的 KVM 效率,CPU、内存管理、网络等方面都比较优秀,在 I/O 方面还有部分不足,可以在 VIRTIO 上进行相关的优化,还有开启 HugePage 等操作。