nova服务详解(8774,8775)
一:简介
1:作用
1:nova是openstack最核心的服务模块,负责管理和维护云计算环境的计算资源,负责整个云环境虚拟机生命周期的管理
2:nova是openstack的计算服务,负责维护和管理的网络和存储,提供计算服务
3:创建,删除,启动,停止等操作云主机
2:概念
1:nova分为控制节点和计算节点
2:计算节点通过nova-compute进行虚拟机创建,通过libvirt调用虚拟化的程序(kvm等)创建虚拟机。nova之间通过通信通过rabbitmq队列进行通信
3:主要模块的介绍
nova-api:用于接收和响应外部的请求,管理nova的唯一入口
nova-scheduler:与placement合作,用于选择需要创建的云主机,并将信息返回给placement和nova-compute
nova-compute:负责虚拟机的创建和资源的分配,本身不提供任何的虚拟化的能力,但是可以通过工具(hypervisor)调用第三方的虚拟化工具(kvm,xen,qemu,vmware)创建和管理云主机
nova-conductor:该模块负责与数据库进行连接管理,其余组件都是通过这个与数据库交互
4:nova的单元管理模式
计算节点被分为若干个小单元进行管理,处理顶层单元cell0外,每个单元都有自己的消息队列和数据库,cell0只有数据库,cell0包含了nova-api模块,和nova-scheduler,而其余的单元cell1和cell2负责具体的云主机实例的创建和管理,随着计算节点的扩大,就会有cell3,cell4等
为nova服务的数据库有三个,nova_cell0和nova_api和nova这个三个数据库
nova_api:存放的是全局信息,单元的信息,实例类型的信息
nova_cell0:当某台云主机调度失败的时候,云主机的信息将不属于任何一个单元,就会存放到nova_cell0中,因此存放都是调度失败的信息进行管理
nova:为所有单元服务,存放了单元中所有的云主机的信息
cell0单元:只有接口模块和调度模块,没有消息队列,有数据库
cell1单元:消息队列和数据库
二:nova的基本工作流程
第1步,nova-api接收到用户通过管理界面或命令行发起的云主机创建请求,并将其发送到消息队列中。
第2步,nova-conductor从消息队列获得请求,从数据库获得如Cell单元的相关信息,再将请求和获得的数据放入消息队列。
第3步,nova-scheduler从消息队列获得请求和数据以后,与Placement组件配合选择创建云主机的物理机,选择完成后,请求转入消息队列等待nova-compute处理。
第4步,nova-compute从消息队列获得请求后,分别与Glance、Neutron和Cinder交互以获取镜像资源、网络资源和云存储资源。一切资源准备就绪后,nova-compute通过Hypervisor调用具体的虚拟化程序,如KVM、QEMU、Xen等,来创建虚拟机。
核心:placement和nova的流程
placement将数据存放到了cell数据库中,然后将数据给到了nova-scheduler来选择虚拟机
与其他组件:nova-compute分别获取镜像,存储,网络
三:nova的操作
1:对云主机进行操作
1:创建云主机
[root@controller ~]# openstack image list +--------------------------------------+---------+--------+ | ID | Name | Status | +--------------------------------------+---------+--------+ | 6b01d984-5086-46d3-9a3b-3276add0e584 | cirrors | active | +--------------------------------------+---------+--------+ [root@controller ~]# openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 5e174813-a83d-4e1d-8366-3ed0bcd10ba3 | vm-network | c4c111fe-3bf0-4e64-ba65-e38e016463e3 | +--------------------------------------+------------+--------------------------------------+ [root@controller ~]# openstack flavor list +--------------------------------------+---------+-----+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +--------------------------------------+---------+-----+------+-----------+-------+-----------+ | 99815c1d-948f-4cf9-af7d-5463f2503c15 | m1.tiny | 512 | 5 | 0 | 1 | True | +--------------------------------------+---------+-----+------+-----------+-------+-----------+ [root@controller ~]# openstack server create --image cirrors --network vm-network --flavor m1.tiny vm1 +-------------------------------------+------------------------------------------------+ | Field | Value | +-------------------------------------+------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | | | OS-EXT-SRV-ATTR:host | None | | OS-EXT-SRV-ATTR:hypervisor_hostname | None | | OS-EXT-SRV-ATTR:instance_name | | | OS-EXT-STS:power_state | NOSTATE | | OS-EXT-STS:task_state | scheduling | | OS-EXT-STS:vm_state | building | | OS-SRV-USG:launched_at | None | | OS-SRV-USG:terminated_at | None | | accessIPv4 | | | accessIPv6 | | | addresses | | | adminPass | tpAb3enZh6kK | | config_drive | | | created | 2024-02-20T07:02:01Z | | flavor | m1.tiny (99815c1d-948f-4cf9-af7d-5463f2503c15) | | hostId | | | id | d9cb6073-b05a-4bc5-ae06-69a8fe60cc32 | | image | cirrors (6b01d984-5086-46d3-9a3b-3276add0e584) | | key_name | None | | name | vm1 | | progress | 0 | | project_id | c0e095cd4ffe4567a3028105f7197e50 | | properties | | | security_groups | name='default' | | status | BUILD | | updated | 2024-02-20T07:02:01Z | | user_id | 8144eff893dd4b4b8f58cc9a9aa802b2 | | volumes_attached | | +-------------------------------------+------------------------------------------------+
2:查看云主机
[root@controller ~]# openstack server list +--------------------------------------+------+--------+---------------------------+---------+---------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------+--------+---------------------------+---------+---------+ | d9cb6073-b05a-4bc5-ae06-69a8fe60cc32 | vm1 | ACTIVE | vm-network=192.168.20.176 | cirrors | m1.tiny | +--------------------------------------+------+--------+---------------------------+---------+---------+
3:对云主机进行操作
启动,关闭,暂停,重启,重建,挂起等操作
#关闭云主机 [root@controller ~]# openstack server stop vm1 [root@controller ~]# openstack server list +--------------------------------------+------+---------+---------------------------+---------+---------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------+---------+---------------------------+---------+---------+ | d9cb6073-b05a-4bc5-ae06-69a8fe60cc32 | vm1 | SHUTOFF | vm-network=192.168.20.176 | cirrors | m1.tiny | +--------------------------------------+------+---------+---------------------------+---------+---------+
4:删除云主机
[root@controller ~]# openstack server delete vm1 [root@controller ~]# openstack server list
2:对实例类型进行管理
1:创建实例类型
#内存为512mb,cpu为1核,磁盘大小5G [root@controller ~]# openstack flavor create --id auto --ram 512 --vcpus 1 --disk 5 m1.tiny +----------------------------+--------------------------------------+ | Field | Value | +----------------------------+--------------------------------------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | disk | 5 | | id | 1598a789-28be-4cc0-adc0-42ebcbd4e7c6 | | name | m1.tiny | | os-flavor-access:is_public | True | | properties | | | ram | 512 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+--------------------------------------+ [root@controller ~]#
2:查看实例类型
[root@controller ~]# openstack flavor list +--------------------------------------+---------+-----+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +--------------------------------------+---------+-----+------+-----------+-------+-----------+ | 1598a789-28be-4cc0-adc0-42ebcbd4e7c6 | m1.tiny | 512 | 5 | 0 | 1 | True | +--------------------------------------+---------+-----+------+-----------+-------+-----------+ [root@controller ~]#
3:删除实例类型
[root@controller ~]# openstack flavor delete m1.tiny [root@controller ~]# openstack flavor list [root@controller ~]#
3:快照的管理
1:基于虚拟机创建一个快照
#基于这个vm1虚拟机拍摄了一个快照 [root@controller ~]# openstack server image create vm1 --name vm-ssss +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | checksum | None | | container_format | None | | created_at | 2024-02-20T07:20:46Z | | disk_format | None | | file | /v2/images/cd6d81a8-60cb-49f1-9c4b-786c7190812a/file | | id | cd6d81a8-60cb-49f1-9c4b-786c7190812a | | min_disk | 5 | | min_ram | 0 | | name | vm-ssss | | owner | c0e095cd4ffe4567a3028105f7197e50 | | properties | base_image_ref='6b01d984-5086-46d3-9a3b-3276add0e584', boot_roles='admin,reader,member', image_type='snapshot', instance_uuid='a4a6c7a9-8f3c-41d6-a86b-f448988eddb9', os_hash_algo=, os_hash_value=, os_hidden='False', owner_project_name='admin', owner_user_name='admin', user_id='8144eff893dd4b4b8f58cc9a9aa802b2' | | protected | False | | schema | /v2/schemas/image | | size | None | | status | queued | | tags | | | updated_at | 2024-02-20T07:20:46Z | | virtual_size | None | | visibility | private | +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ [root@controller ~]# openstack image list +--------------------------------------+---------+--------+ | ID | Name | Status | +--------------------------------------+---------+--------+ | 6b01d984-5086-46d3-9a3b-3276add0e584 | cirrors | active | | cd6d81a8-60cb-49f1-9c4b-786c7190812a | vm-ssss | active | +--------------------------------------+---------+--------+ [root@controller ~]#
这个快照就是一个镜像,可以根据这个镜像来创建一个虚拟机(就相当于,如果原来的主机受到了损坏,那就可以基于这个快照进行恢复)
2:基于卷来创建快照
前提是你要有卷,就是将卷拍摄了一个快照之后,上传到glacne服务那里,再来生成一个云主机