目前的Nova主要由API,Compute,Conductor,Scheduler组成

Compute:用来交互并管理虚拟机的生命周期;
Scheduler:从可用池中根据各种策略选择最合适的计算节点来创建新的虚拟机;
Conductor:为数据库的访问提供统一的接口层。

 

Compute Service Nova 是 OpenStack 最核心的服务,负责维护和管理云环境的计算资源。 
OpenStack 作为 IaaS 的云操作系统,虚拟机生命周期管理也就是通过 Nova 来实现的


在上图中可以看到,Nova 处于 Openstak 架构的中心,其他组件都为 Nova 提供支持:
Glance 为 VM 提供 image 
Cinder 和 Swift 分别为 VM 提供块存储和对象存储 
Neutron 为 VM 提供网络连接

Nova 架构如下

Nova 的架构比较复杂,包含很多组件。 
这些组件以子服务(后台 deamon 进程)的形式运行,可以分为以下几类:

 

AP部分

nova-api

其它模块的通过HTTP协议进入Nova模块的接口,api是外部访问nova的唯一途径

 

Compute Core部分

nova-scheduler
虚机调度服务,负责决定在哪个计算节点上运行虚机

Nova scheduler模块决策一个虚拟机应该调度到某个物理节点,需要两个步骤
1、过滤(Fliter):先过滤出符合条件的主机,空闲资源足够的。
2、计算权重

nova-compute
管理虚机的核心服务,通过调用 Hypervisor API 实现虚机生命周期管理

Hypervisor
计算节点上跑的虚拟化管理程序,虚机管理最底层的程序。 不同虚拟化技术提供自己的 Hypervisor。 常用的 Hypervisor 有 KVM,Xen, VMWare 等

nova-conductor
nova-compute 经常需要更新数据库,比如更新虚机的状态。 出于安全性和伸缩性的考虑,nova-compute 并不会直接访问数据库(早期版本计算节点可以直接访问数据库,计算节点一旦被入侵,整个库都危险)

而是将这个任务委托给 nova-conductor,这个我们在后面会详细讨论。

 

Console Interface部分

nova-console
用户可以通过多种方式访问虚机的控制台: nova-novncproxy,基于 Web 浏览器的 VNC 访问 nova-spicehtml5proxy,基于 HTML5 浏览器的 SPICE 访问 nova-xvpnvncproxy,基于 Java 客户端的 VNC 访问

nova-consoleauth
负责对访问虚机控制台请亲提供 Token 认证

nova-cert

cert是负责ec2 方式身份认证的,用不到的话可以不启动它

 

Database部分

Nova 会有一些数据需要存放到数据库中,一般使用 MySQL。 Nova 使用名为 "nova" 和"nova_api"的数据库。

 

 

某个主机硬件资源足够并不表示符合Nova scheduler。
可能认为会没有资源的场景:
1、网络故障,主机网络节点有问题
2、nova compute故障了

 

控制节点安装和配置Nova

1、控制节点安装软件包

[root@linux-node1 ~]# yum install openstack-nova-api openstack-nova-conductor   openstack-nova-console openstack-nova-novncproxy   openstack-nova-scheduler -y
2、配置部分---数据库连接配置

/etc/nova/nova.conf
在[api_database]和[database]部分,配置数据库的连接:

更改结果如下

[root@linux-node1 ~]# grep -n '^[a-Z]' /etc/nova/nova.conf
2161:connection = mysql+pymysql://nova:nova@192.168.1.2/nova_api
3106:connection = mysql+pymysql://nova:nova@192.168.1.2/nova
[root@linux-node1 ~]#

同步数据到mysql库,出现警告也没关系

[root@linux-node1 ~]#  su -s /bin/sh -c "nova-manage api_db sync" nova
[root@linux-node1 ~]# su -s /bin/sh -c "nova-manage db sync" nova

检查数据库表的创建情况
[root@linux-node1 ~]# mysql -h192.168.1.2 -unova -pnova -e "use nova;show tables;"
+--------------------------------------------+
| Tables_in_nova                             |
+--------------------------------------------+
| agent_builds                               |
| aggregate_hosts                            |
| aggregate_metadata                         |
| aggregates                                 |
| allocations                                |
| block_device_mapping                       |
| bw_usage_cache                             |
| cells                                      |
| certificates                               |
| compute_nodes                              |
| console_pools                              |
| consoles                                   |
| dns_domains                                |
| fixed_ips                                  |
| floating_ips                               |
| instance_actions                           |
| instance_actions_events                    |
| instance_extra                             |
| instance_faults                            |
| instance_group_member                      |
| instance_group_policy                      |
| instance_groups                            |
| instance_id_mappings                       |
| instance_info_caches                       |
| instance_metadata                          |
| instance_system_metadata                   |
| instance_type_extra_specs                  |
| instance_type_projects                     |
| instance_types                             |
| instances                                  |
| inventories                                |
| key_pairs                                  |
| migrate_version                            |
| migrations                                 |
| networks                                   |
| pci_devices                                |
| project_user_quotas                        |
| provider_fw_rules                          |
| quota_classes                              |
| quota_usages                               |
| quotas                                     |
| reservations                               |
| resource_provider_aggregates               |
| resource_providers                         |
| s3_images                                  |
| security_group_default_rules               |
| security_group_instance_association        |
| security_group_rules                       |
| security_groups                            |
| services                                   |
| shadow_agent_builds                        |
| shadow_aggregate_hosts                     |
| shadow_aggregate_metadata                  |
| shadow_aggregates                          |
| shadow_block_device_mapping                |
| shadow_bw_usage_cache                      |
| shadow_cells                               |
| shadow_certificates                        |
| shadow_compute_nodes                       |
| shadow_console_pools                       |
| shadow_consoles                            |
| shadow_dns_domains                         |
| shadow_fixed_ips                           |
| shadow_floating_ips                        |
| shadow_instance_actions                    |
| shadow_instance_actions_events             |
| shadow_instance_extra                      |
| shadow_instance_faults                     |
| shadow_instance_group_member               |
| shadow_instance_group_policy               |
| shadow_instance_groups                     |
| shadow_instance_id_mappings                |
| shadow_instance_info_caches                |
| shadow_instance_metadata                   |
| shadow_instance_system_metadata            |
| shadow_instance_type_extra_specs           |
| shadow_instance_type_projects              |
| shadow_instance_types                      |
| shadow_instances                           |
| shadow_key_pairs                           |
| shadow_migrate_version                     |
| shadow_migrations                          |
| shadow_networks                            |
| shadow_pci_devices                         |
| shadow_project_user_quotas                 |
| shadow_provider_fw_rules                   |
| shadow_quota_classes                       |
| shadow_quota_usages                        |
| shadow_quotas                              |
| shadow_reservations                        |
| shadow_s3_images                           |
| shadow_security_group_default_rules        |
| shadow_security_group_instance_association |
| shadow_security_group_rules                |
| shadow_security_groups                     |
| shadow_services                            |
| shadow_snapshot_id_mappings                |
| shadow_snapshots                           |
| shadow_task_log                            |
| shadow_virtual_interfaces                  |
| shadow_volume_id_mappings                  |
| shadow_volume_usage_cache                  |
| snapshot_id_mappings                       |
| snapshots                                  |
| tags                                       |
| task_log                                   |
| virtual_interfaces                         |
| volume_id_mappings                         |
| volume_usage_cache                         |
+--------------------------------------------+

[root@linux-node1 ~]# mysql -h192.168.1.2 -unova -pnova -e "use nova_api;show tables;"
+--------------------+
| Tables_in_nova_api |
+--------------------+
| build_requests     |
| cell_mappings      |
| flavor_extra_specs |
| flavor_projects    |
| flavors            |
| host_mappings      |
| instance_mappings  |
| migrate_version    |
| request_specs      |
+--------------------+

3、 配置部分---keystone配置

在[DEFAULT] 和 [keystone_authtoken] 部分,配置认证服务访问:

auth_strategy = keystone
 
[keystone_authtoken]
...
auth_uri = http: //192 .168.1.2:5000
auth_url = http: //192 .168.1.2:35357
memcached_servers = 192.168.1.2:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = nova
password = nova

修改后如下:

[root@linux-node1 ~]# grep -n '^[a-Z]' /etc/nova/nova.conf
382:auth_strategy = keystone
2161:connection = mysql+pymysql://nova:nova@192.168.1.2/nova_api
3106:connection = mysql+pymysql://nova:nova@192.168.1.2/nova
3523:auth_uri = http://192.168.1.2:5000
3524:auth_url = http://192.168.1.2:35357
3525:memcached_servers = 192.168.1.2:11211
3526:auth_type = password
3527:project_domain_name = default
3528:user_domain_name = default
3529:project_name = service
3530:username = nova
3531:password = nova

4、配置部分---RabbitMQ配置

修改rabbitmq的配置,nova它们各个组件之间要用到 

在 [DEFAULT] 和 [oslo_messaging_rabbit]部分,配置 RabbitMQ 消息队列访问,
[DEFAULT]
...
rpc_backend = rabbit
 
[oslo_messaging_rabbit]
...
rabbit_host=192.168.1.2
rabbit_userid = openstack
rabbit_password = openstack

配置好如下:

[root@linux-node1 ~]# grep -n '^[a-Z]' /etc/nova/nova.conf
382:auth_strategy = keystone
2119:rpc_backend=rabbit
2161:connection = mysql+pymysql://nova:nova@192.168.1.2/nova_api
3106:connection = mysql+pymysql://nova:nova@192.168.1.2/nova
3523:auth_uri = http://192.168.1.2:5000
3524:auth_url = http://192.168.1.2:35357
3525:memcached_servers = 192.168.1.2:11211
3526:auth_type = password
3527:project_domain_name = default
3528:user_domain_name = default
3529:project_name = service
3530:username = nova
3531:password = nova
4403:rabbit_host=192.168.1.2
4404:rabbit_userid = openstack
4405:rabbit_password = openstack

4465:rabbit_port=5672

5、配置部分---nova自身功能模块的配置

在[DEFAULT]部分,只启用计算和元数据API:

[DEFAULT]
...
enabled_apis = osapi_compute,metadata


配置好如下:

[root@linux-node1 ~]# grep -n '^[a-Z]' /etc/nova/nova.conf
267:enabled_apis=osapi_compute,metadata
382:auth_strategy = keystone
2119:rpc_backend=rabbit
2161:connection = mysql+pymysql://nova:nova@192.168.1.2/nova_api
3106:connection = mysql+pymysql://nova:nova@192.168.1.2/nova
3523:auth_uri = http://192.168.1.2:5000
3524:auth_url = http://192.168.1.2:35357
3525:memcached_servers = 192.168.1.2:11211
3526:auth_type = password
3527:project_domain_name = default
3528:user_domain_name = default
3529:project_name = service
3530:username = nova
3531:password = nova
4403:rabbit_host=192.168.1.2
4404:rabbit_userid = openstack
4405:rabbit_password = openstack
4465:rabbit_port=5672

文档里说设置my_ip ,这里我们不设置它,因为有后面配置调用my_ip这个变量。我们可以直接配置,虽然麻烦点,但是知道哪些地方使用了这个IP
所以下面my_ip就不配置了

在 [DEFAULT] 部分,使能 Networking 服务:
默认情况下,计算服务使用内置的防火墙服务。由于网络服务包含了防火墙服务
你必须使用nova.virt.firewall.NoopFirewallDriver防火墙服务来禁用掉计算服务内置的防火墙服务

[DEFAULT]
...
use_neutron = True
firewall_driver=nova.virt.libvirt.firewall.IptablesFirewallDriver

在[vnc]部分,配置VNC代理使用控制节点的管理接口IP地址 (这里原来是$my_ip):

[vnc]
...
vncserver_listen =192.168.1.2
vncserver_proxyclient_address =192.168.1.2

在 [glance] 区域,配置镜像服务 API 的位置:

[glance]
...
api_servers = http://192.168.1.2:9292

在 [oslo_concurrency] 部分,配置锁路径:

[oslo_concurrency]
...
lock_path =/var/lib/nova/tmp
6、检查配置
配置完毕,过滤一下
[root@linux-node1 ~]# grep -n '^[a-Z]' /etc/nova/nova.conf
267:enabled_apis=osapi_compute,metadata
382:auth_strategy = keystone
1561:firewall_driver=nova.virt.libvirt.firewall.IptablesFirewallDriver
1684:use_neutron=True
2119:rpc_backend=rabbit
2161:connection = mysql+pymysql://nova:nova@192.168.1.2/nova_api
3106:connection = mysql+pymysql://nova:nova@192.168.1.2/nova
3323:api_servers = http://192.168.1.2:9292
3523:auth_uri = http://192.168.1.2:5000
3524:auth_url = http://192.168.1.2:35357
3525:memcached_servers = 192.168.1.2:11211
3526:auth_type = password
3527:project_domain_name = default
3528:user_domain_name = default
3529:project_name = service
3530:username = nova
3531:password = nova
4292:lock_path = /var/lib/nova/tmp
4403:rabbit_host=192.168.1.2
4404:rabbit_userid = openstack
4405:rabbit_password = openstack
4465:rabbit_port=5672
5359:vncserver_listen = 192.168.1.2
5360:vncserver_proxyclient_address = 192.168.1.2

7、启动nova服务

启动 nova 服务并将其设置为随系统启动

[root@linux-node1 ~]# systemctl enable openstack-nova-api.service  openstack-nova-consoleauth.service  openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-nova-api.service to /usr/lib/systemd/system/openstack-nova-api.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-nova-consoleauth.service to /usr/lib/systemd/system/openstack-nova-consoleauth.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-nova-scheduler.service to /usr/lib/systemd/system/openstack-nova-scheduler.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-nova-conductor.service to /usr/lib/systemd/system/openstack-nova-conductor.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-nova-novncproxy.service to /usr/lib/systemd/system/openstack-nova-novncproxy.service.


[root@linux-node1 ~]# systemctl start openstack-nova-api.service  openstack-nova-consoleauth.service  openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
启动后,它要去keystone上注册
8、创建 nova 服务实体和端点

下面步骤之前已经操作了,这里就不做了,以删除线标识
1、获得 admin 凭证来获取只有管理员能执行的命令的访问权限
source admin-openrc

2、 要创建服务证书,完成这些步骤
创建 nova 用户
openstack user create --domain default \
--password-prompt nova

3、给 nova 用户添加 admin 角色
$ openstack role add --project service --user nova admin

创建 nova 服务实体:
[root@linux-node1 ~]# source admin-openstack.sh
[root@linux-node1 ~]#  openstack service create --name nova --description "OpenStack Compute" compute
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Compute                |
| enabled     | True                             |
| id          | 4cb4bef311a3452b9584cd284ce19ded |
| name        | nova                             |
| type        | compute                          |
+-------------+----------------------------------+


创建 Compute 服务 API 端点 
nova_api端口是8774
创建public端点
[root@linux-node1 ~]# openstack endpoint create --region RegionOne compute public http://192.168.1.2:8774/v2.1/%\(tenant_id\)s
+--------------+--------------------------------------------+
| Field        | Value                                      |
+--------------+--------------------------------------------+
| enabled      | True                                       |
| id           | 7b12e9461fe0477a8be6e5cd3b75745f           |
| interface    | public                                     |
| region       | RegionOne                                  |
| region_id    | RegionOne                                  |
| service_id   | 4cb4bef311a3452b9584cd284ce19ded           |
| service_name | nova                                       |
| service_type | compute                                    |
| url          | http://192.168.1.2:8774/v2.1/%(tenant_id)s |
+--------------+--------------------------------------------+


创建internal端点

[root@linux-node1 ~]#  openstack endpoint create --region RegionOne compute internal http://192.168.1.2:8774/v2.1/%\(tenant_id\)s
+--------------+--------------------------------------------+
| Field        | Value                                      |
+--------------+--------------------------------------------+
| enabled      | True                                       |
| id           | f2e25fc624bd42999c943b91f24ca54e           |
| interface    | internal                                   |
| region       | RegionOne                                  |
| region_id    | RegionOne                                  |
| service_id   | 4cb4bef311a3452b9584cd284ce19ded           |
| service_name | nova                                       |
| service_type | compute                                    |
| url          | http://192.168.1.2:8774/v2.1/%(tenant_id)s |
+--------------+--------------------------------------------+


创建admin端点

[root@linux-node1 ~]# openstack endpoint create --region RegionOne  compute admin http://192.168.1.2:8774/v2.1/%\(tenant_id\)s
+--------------+--------------------------------------------+
| Field        | Value                                      |
+--------------+--------------------------------------------+
| enabled      | True                                       |
| id           | 1c845f930ccb4360be7cfb5215b6206d           |
| interface    | admin                                      |
| region       | RegionOne                                  |
| region_id    | RegionOne                                  |
| service_id   | 4cb4bef311a3452b9584cd284ce19ded           |
| service_name | nova                                       |
| service_type | compute                                    |
| url          | http://192.168.1.2:8774/v2.1/%(tenant_id)s |
+--------------+--------------------------------------------+


检查创建结果

[root@linux-node1 ~]# openstack host list
+----------------------+-------------+----------+
| Host Name            | Service     | Zone     |
+----------------------+-------------+----------+
| linux-node1.shi.com | consoleauth | internal |
| linux-node1.shi.com | conductor   | internal |
| linux-node1.shi.com | scheduler   | internal |



计算节点安装和配置nova

nova compute通过libvirt管理kvm,计算节点是真正运行虚拟机的

vmware支持嵌套虚拟机,其它虚拟机软件不支持

 计算节点机器必须打开vt-x



1、安装软件包

[root@linux-node2 ~]# yum install openstack-nova-compute -y

关于novncproxy

novncproxy的端口是6080 ,登录控制节点查看下

[root@linux-node1 ~]# netstat -lntp|grep 6080
tcp        0      0 0.0.0.0:6080            0.0.0.0:*               LISTEN      931/python2 

2、计算节点配置文件修改

计算节点的配置文件更改的地方和控制节点几乎一致,因此可以把控制节点的配置文件拷贝过来使用,还需要修改个别地方
1、计算节点没有配置连接数据库。(其实拷贝过来不删数据库的配置也能运行正常,但是不规范)
2、计算节点vnc多配置一行

拷贝之前先查看控制节点的权限

[root@linux-node1 ~]# ls /etc/nova/ -l
total 224
-rw-r----- 1 root nova   3673 Mar 22 18:14 api-paste.ini
-rw-r----- 1 root nova 184584 Jul 30 20:13 nova.conf
-rw-r----- 1 root nova  27914 Mar 22 18:14 policy.json
-rw-r--r-- 1 root root     72 May 24 06:43 release
-rw-r----- 1 root nova    966 Mar 22 18:13 rootwrap.conf

拷贝文件过去

[root@linux-node1 ~]# scp -r /etc/nova/nova.conf 192.168.1.3:/etc/nova/


查看推送过来的文件权限是否正确
[root@linux-node2 ~]# ll /etc/nova/
total 224
-rw-r----- 1 root nova   3673 Jul 31 08:36 api-paste.ini
-rw-r----- 1 root nova 184584 Jul 31 08:36 nova.conf
-rw-r----- 1 root nova  27914 Jul 31 08:36 policy.json
-rw-r--r-- 1 root root     72 Jul 31 08:36 release
-rw-r----- 1 root nova    966 Jul 31 08:36 rootwrap.conf
更改配置,把mysql的部分删除了。然后注释掉这行
涉及到[api_database]和[database]模块两个地方
[api_database]
#connection = mysql+pymysql://nova:nova@192.168.1.2/nova_api

[database]
#connection = mysql+pymysql://nova:nova@192.168.1.2/nova

在[vnc]部分,启用并配置远程控制台访问:

[vnc]
enabled=true
vncserver_listen = 0.0.0.0
vncserver_proxyclient_address = 192.168.1.3
novncproxy_base_url = http://192.168.1.2:6080/vnc_auto.html

修改[libvirt]模块
修改之前,确定您的计算节点是否支持虚拟机的硬件加速。
[root@linux-node2 ~]# egrep -c '(vmx|svm)' /proc/cpuinfo
1

如果这个命令返回了 one or greater 的值,那么你的计算节点支持硬件加速且不需要额外的配置。
如果这个命令返回了 zero 值,那么你的计算节点不支持硬件加速。你必须配置 libvirt 来使用 QEMU 去代替 KVM在
/etc/nova/nova.conf 文件的 [libvirt] 区域做出如下的编辑:
[libvirt]
virt_type=kvm

查看下所有修改的地方
[root@linux-node2 ~]# grep -n '^[a-Z]'  /etc/nova/nova.conf
267:enabled_apis=osapi_compute,metadata
382:auth_strategy=keystone
1561:firewall_driver=nova.virt.libvirt.firewall.IptablesFirewallDriver
1684:use_neutron=true
2119:rpc_backend=rabbit
3323:api_servers=http://192.168.1.2:9292
3523:auth_uri=http://192.168.1.2:5000
3524:auth_url=http://192.168.1.2:35357
3525:memcached_servers=192.168.1.2:11211
3526:auth_type = password
3527:project_domain_name = default
3528:user_domain_name = default
3529:project_name = service
3530:username = nova
3531:password = nova
3682:virt_type=kvm
4292:lock_path=/var/lib/nova/tmp
4403:rabbit_host=192.168.1.2
4404:rabbit_userid = openstack
4405:rabbit_password = openstack
4465:rabbit_port=5672
5359:enabled=true
5360:vncserver_listen=0.0.0.0
5361:vncserver_proxyclient_address=192.168.1.3
5362:novncproxy_base_url = http://192.168.1.2:6080/vnc_auto.html


3、启动服务和检查状态

[root@linux-node2 ~]# systemctl enable libvirtd.service openstack-nova-compute.service
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-nova-compute.service to /usr/lib/systemd/system/openstack-nova-compute.service.
[root@linux-node2 ~]# systemctl start libvirtd.service openstack-nova-compute.service

控制节点查看,有了计算节点。说明计算节点的服务正常启动了,而且配置没问题
[root@linux-node1 ~]# openstack host list
+----------------------+-------------+----------+
| Host Name            | Service     | Zone     |
+----------------------+-------------+----------+
| linux-node1.shi.com | consoleauth | internal |
| linux-node1.shi.com | conductor   | internal |
| linux-node1.shi.com | scheduler   | internal |
| linux-node2.shi.com | compute     | nova     |
+----------------------+-------------+----------+

控制节点列出nova的服务,后面的update时间都几乎一致,如果差距过大,可能造成无法创建虚拟机

[root@linux-node1 ~]# nova service-list
+----+------------------+---------------------+----------+---------+-------+----------------------------+-----------------+
| Id | Binary           | Host                | Zone     | Status  | State | Updated_at                 | Disabled Reason |
+----+------------------+---------------------+----------+---------+-------+----------------------------+-----------------+
| 1  | nova-scheduler   | linux-node1.shi.com | internal | enabled | up    | 2017-08-02T07:00:53.000000 | -               |
| 2  | nova-conductor   | linux-node1.shi.com | internal | enabled | up    | 2017-08-02T07:00:54.000000 | -               |
| 3  | nova-consoleauth | linux-node1.shi.com | internal | enabled | up    | 2017-08-02T07:00:54.000000 | -               |
| 6  | nova-compute     | linux-node2.shi.com | nova     | enabled | up    | 2017-08-02T07:00:54.000000 | -               |
+----+------------------+---------------------+----------+---------+-------+----------------------------+-----------------+


下面命令测试nova连接glance是否正常

[root@linux-node1 ~]# nova image-list
+--------------------------------------+--------+--------+--------+
| ID                                   | Name   | Status | Server |
+--------------------------------------+--------+--------+--------+
| b7fb24c1-b6d5-42bf-af36-20fbd9a66239 | cirros | ACTIVE |        |
+--------------------------------------+--------+--------+--------+













Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐