OpenStack组件 Nova

作者: 廖马儿 | 来源:发表于2017-05-23 17:29 被阅读55次

    都是自己的学习笔记,仅供参考。

    核心模块-Nova简介

    管理instance生命周期
    生成,调度,终止实例
    作用:处理逻辑和业务的。

    节点:
    比如:计算节点,物理机,就是一个主机。

    图片.png

    从上面的图可以看出:
    Nova可以调用KVM,Vmware, Qemu,Xen,Docker等等的API接口,从而管理,OpenStack也就能够和他们结合使用。

    Nova的架构图:

    图片.png

    Nova分为几个核心的服务:

    1)Nova-Compute
    计算,生命周期。是nova的核心服务,通过调用开发过程的api,去实现生命周期的管理。
    2)Nova-Scheduler
    做调度的,负责决定某个xx计算落在哪个计算节点上。
    完成虚拟机实例的调度分配
    schedulerdriver, scheduleravailable_filters,schedulerdefaulters
    Weight权重

    就像下面的,经过过滤,经过权重,然后抉择出质量好坏先后顺序:


    图片.png

    过滤的种类:
    a.RetryFilter:重置过滤。
    假如:Host1, Host2,Host3已经过滤删选出来了,然后Host1因为权值最高被最终选定,但是后来又因为为其他原因VM在Host1上落地失败,那么久会进行重试筛选新的host;Host1因为失败不会再入选。
    scheduler_max_attempts=3 设置重试的次数,默认就是3。根据集群的规模,环境,自己去设置。根据经验去设置,不能随意调节。
    b.AvailabilityZoneFilter:提高容灾性和隔离服务。
    计算节点可以纳入一个创建好的AZ中。
    创建VM时候可以指定AZ,这样虚拟机会落在指定的Host当中。
    c.RamFilter:内存过滤
    创建VM的时候会选择flavor,不满足flavor中内存要求的host会过滤掉
    Linux系统里的free
    超量使用设置:ram_allocation_radio = 3(如果计算节点有128G内存,那么openstack会认为有384内存)
    方便以后做监控,判断是否有资源。

    3)Nova-Api
    其实每个组件都有一个与api结合的服务。比如neutron也有,直接就和数据库打交道。
    作用:暴露REST API接口
    接受和发送跟虚拟机生命周期相关的API请求
    相关API操作直接可以在界面上看到
    4)Nova-Conductor
    最开始是没有nova-conductor的

    =====

    nova help:

    [root@ha-node1 ~]# nova help
    usage: nova [--version] [--debug] [--os-cache] [--timings]
                [--os-region-name <region-name>] [--service-type <service-type>]
                [--service-name <service-name>]
                [--os-endpoint-type <endpoint-type>]
                [--os-compute-api-version <compute-api-ver>]
                [--bypass-url <bypass-url>] [--insecure]
                [--os-cacert <ca-certificate>] [--os-cert <certificate>]
                [--os-key <key>] [--timeout <seconds>] [--os-auth-type <name>]
                [--os-auth-url OS_AUTH_URL] [--os-domain-id OS_DOMAIN_ID]
                [--os-domain-name OS_DOMAIN_NAME] [--os-project-id OS_PROJECT_ID]
                [--os-project-name OS_PROJECT_NAME]
                [--os-project-domain-id OS_PROJECT_DOMAIN_ID]
                [--os-project-domain-name OS_PROJECT_DOMAIN_NAME]
                [--os-trust-id OS_TRUST_ID]
                [--os-default-domain-id OS_DEFAULT_DOMAIN_ID]
                [--os-default-domain-name OS_DEFAULT_DOMAIN_NAME]
                [--os-user-id OS_USER_ID] [--os-username OS_USERNAME]
                [--os-user-domain-id OS_USER_DOMAIN_ID]
                [--os-user-domain-name OS_USER_DOMAIN_NAME]
                [--os-password OS_PASSWORD]
                <subcommand> ...
    
    Command-line interface to the OpenStack Nova API.
    
    Positional arguments:
      <subcommand>
        absolute-limits             DEPRECATED, use limits instead.
        add-fixed-ip                Add new IP address on a network to server.
        add-floating-ip             DEPRECATED, use floating-ip-associate instead.
        add-secgroup                Add a Security Group to a server.
        agent-create                Create new agent build.
        agent-delete                Delete existing agent build.
        agent-list                  List all builds.
        agent-modify                Modify existing agent build.
        aggregate-add-host          Add the host to the specified aggregate.
        aggregate-create            Create a new aggregate with the specified
                                    details.
        aggregate-delete            Delete the aggregate.
        aggregate-details           DEPRECATED, use aggregate-show instead.
        aggregate-list              Print a list of all aggregates.
        aggregate-remove-host       Remove the specified host from the specified
                                    aggregate.
        aggregate-set-metadata      Update the metadata associated with the
                                    aggregate.
        aggregate-show              Show details of the specified aggregate.
        aggregate-update            Update the aggregate's name and optionally
                                    availability zone.
        availability-zone-list      List all the availability zones.
        backup                      Backup a server by creating a 'backup' type
                                    snapshot.
        boot                        Boot a new server.
        clear-password              Clear the admin password for a server from the
                                    metadata server. This action does not actually
                                    change the instance server password.
        cloudpipe-configure         Update the VPN IP/port of a cloudpipe
                                    instance.
        cloudpipe-create            Create a cloudpipe instance for the given
                                    project.
        cloudpipe-list              Print a list of all cloudpipe instances.
        console-log                 Get console log output of a server.
        credentials                 Show user credentials returned from auth.
        delete                      Immediately shut down and delete specified
                                    server(s).
        diagnostics                 Retrieve server diagnostics.
        dns-create                  DEPRECATED: Create a DNS entry for domain,
                                    name, and IP.
        dns-create-private-domain   DEPRECATED: Create the specified DNS domain.
        dns-create-public-domain    DEPRECATED: Create the specified DNS domain.
        dns-delete                  DEPRECATED: Delete the specified DNS entry.
        dns-delete-domain           DEPRECATED: Delete the specified DNS domain.
        dns-domains                 DEPRECATED: Print a list of available dns
                                    domains.
        dns-list                    DEPRECATED: List current DNS entries for
                                    domain and IP or domain and name.
        endpoints                   Discover endpoints that get returned from the
                                    authenticate services.
        evacuate                    Evacuate server from failed host.
        fixed-ip-get                DEPRECATED: Retrieve info on a fixed IP.
        fixed-ip-reserve            DEPRECATED: Reserve a fixed IP.
        fixed-ip-unreserve          DEPRECATED: Unreserve a fixed IP.
        flavor-access-add           Add flavor access for the given tenant.
        flavor-access-list          Print access information about the given
                                    flavor.
        flavor-access-remove        Remove flavor access for the given tenant.
        flavor-create               Create a new flavor.
        flavor-delete               Delete a specific flavor
        flavor-key                  Set or unset extra_spec for a flavor.
        flavor-list                 Print a list of available 'flavors' (sizes of
                                    servers).
        flavor-show                 Show details about the given flavor.
        floating-ip-associate       Associate a floating IP address to a server.
        floating-ip-bulk-create     DEPRECATED: Bulk create floating IPs by range
                                    (nova-network only).
        floating-ip-bulk-delete     DEPRECATED: Bulk delete floating IPs by range
                                    (nova-network only).
        floating-ip-bulk-list       DEPRECATED: List all floating IPs (nova-
                                    network only).
        floating-ip-create          DEPRECATED: Allocate a floating IP for the
                                    current tenant.
        floating-ip-delete          DEPRECATED: De-allocate a floating IP.
        floating-ip-disassociate    Disassociate a floating IP address from a
                                    server.
        floating-ip-list            DEPRECATED: List floating IPs.
        floating-ip-pool-list       DEPRECATED: List all floating IP pools.
        get-mks-console             Get an MKS console to a server. (Supported by
                                    API versions '2.8' - '2.latest') [hint: use
                                    '--os-compute-api-version' flag to show help
                                    message for proper version]
        get-password                Get the admin password for a server. This
                                    operation calls the metadata service to query
                                    metadata information and does not read
                                    password information from the server itself.
        get-rdp-console             Get a rdp console to a server.
        get-serial-console          Get a serial console to a server.
        get-spice-console           Get a spice console to a server.
        get-vnc-console             Get a vnc console to a server.
        host-action                 Perform a power action on a host.
        host-describe               Describe a specific host.
        host-list                   List all hosts by service.
        host-update                 Update host settings.
        hypervisor-list             List hypervisors. (Supported by API versions
                                    '2.0' - '2.latest') [hint: use '--os-compute-
                                    api-version' flag to show help message for
                                    proper version]
        hypervisor-servers          List servers belonging to specific
                                    hypervisors.
        hypervisor-show             Display the details of the specified
                                    hypervisor.
        hypervisor-stats            Get hypervisor statistics over all compute
                                    nodes.
        hypervisor-uptime           Display the uptime of the specified
                                    hypervisor.
        image-create                Create a new image by taking a snapshot of a
                                    running server.
        image-delete                DEPRECATED: Delete specified image(s).
        image-list                  DEPRECATED: Print a list of available images
                                    to boot from.
        image-meta                  DEPRECATED: Set or delete metadata on an
                                    image.
        image-show                  DEPRECATED: Show details about the given
                                    image.
        interface-attach            Attach a network interface to a server.
        interface-detach            Detach a network interface from a server.
        interface-list              List interfaces attached to a server.
        keypair-add                 Create a new key pair for use with servers.
        keypair-delete              Delete keypair given by its name. (Supported
                                    by API versions '2.0' - '2.latest') [hint: use
                                    '--os-compute-api-version' flag to show help
                                    message for proper version]
        keypair-list                Print a list of keypairs for a user (Supported
                                    by API versions '2.0' - '2.latest') [hint: use
                                    '--os-compute-api-version' flag to show help
                                    message for proper version]
        keypair-show                Show details about the given keypair.
                                    (Supported by API versions '2.0' - '2.latest')
                                    [hint: use '--os-compute-api-version' flag to
                                    show help message for proper version]
        limits                      Print rate and absolute limits.
        list                        List active servers.
        list-secgroup               List Security Group(s) of a server.
        live-migration              Migrate running server to a new machine.
        live-migration-abort        Abort an on-going live migration. (Supported
                                    by API versions '2.24' - '2.latest') [hint:
                                    use '--os-compute-api-version' flag to show
                                    help message for proper version]
        live-migration-force-complete
                                    Force on-going live migration to complete.
                                    (Supported by API versions '2.22' -
                                    '2.latest') [hint: use '--os-compute-api-
                                    version' flag to show help message for proper
                                    version]
        lock                        Lock a server. A normal (non-admin) user will
                                    not be able to execute actions on a locked
                                    server.
        meta                        Set or delete metadata on a server.
        migrate                     Migrate a server. The new host will be
                                    selected by the scheduler.
        network-associate-host      DEPRECATED: Associate host with network.
        network-associate-project   DEPRECATED: Associate project with network.
        network-create              DEPRECATED: Create a network.
        network-delete              DEPRECATED: Delete network by label or id.
        network-disassociate        DEPRECATED: Disassociate host and/or project
                                    from the given network.
        network-list                DEPRECATED: Print a list of available
                                    networks.
        network-show                DEPRECATED: Show details about the given
                                    network.
        pause                       Pause a server.
        quota-class-show            List the quotas for a quota class.
        quota-class-update          Update the quotas for a quota class.
                                    (Supported by API versions '2.0' - '2.latest')
                                    [hint: use '--os-compute-api-version' flag to
                                    show help message for proper version]
        quota-defaults              List the default quotas for a tenant.
        quota-delete                Delete quota for a tenant/user so their quota
                                    will Revert back to default.
        quota-show                  List the quotas for a tenant/user.
        quota-update                Update the quotas for a tenant/user.
                                    (Supported by API versions '2.0' - '2.latest')
                                    [hint: use '--os-compute-api-version' flag to
                                    show help message for proper version]
        rate-limits                 DEPRECATED, use limits instead.
        reboot                      Reboot a server.
        rebuild                     Shutdown, re-image, and re-boot a server.
        refresh-network             Refresh server network information.
        remove-fixed-ip             Remove an IP address from a server.
        remove-floating-ip          DEPRECATED, use floating-ip-disassociate
                                    instead.
        remove-secgroup             Remove a Security Group from a server.
        rename                      DEPRECATED, use update instead.
        rescue                      Reboots a server into rescue mode, which
                                    starts the machine from either the initial
                                    image or a specified image, attaching the
                                    current boot disk as secondary.
        reset-network               Reset network of a server.
        reset-state                 Reset the state of a server.
        resize                      Resize a server.
        resize-confirm              Confirm a previous resize.
        resize-revert               Revert a previous resize (and return to the
                                    previous VM).
        resume                      Resume a server.
        root-password               DEPRECATED, use set-password instead.
        scrub                       DEPRECATED: Delete networks and security
                                    groups associated with a project.
        secgroup-add-default-rule   DEPRECATED: Add a rule to the set of rules
                                    that will be added to the 'default' security
                                    group for new tenants (nova-network only).
        secgroup-add-group-rule     DEPRECATED: Add a source group rule to a
                                    security group.
        secgroup-add-rule           DEPRECATED: Add a rule to a security group.
        secgroup-create             DEPRECATED: Create a security group.
        secgroup-delete             DEPRECATED: Delete a security group.
        secgroup-delete-default-rule
                                    DEPRECATED: Delete a rule from the set of
                                    rules that will be added to the 'default'
                                    security group for new tenants (nova-network
                                    only).
        secgroup-delete-group-rule  DEPRECATED: Delete a source group rule from a
                                    security group.
        secgroup-delete-rule        DEPRECATED: Delete a rule from a security
                                    group.
        secgroup-list               DEPRECATED: List security groups for the
                                    current tenant.
        secgroup-list-default-rules
                                    DEPRECATED: List rules that will be added to
                                    the 'default' security group for new tenants.
        secgroup-list-rules         DEPRECATED: List rules for a security group.
        secgroup-update             DEPRECATED: Update a security group.
        server-group-create         Create a new server group with the specified
                                    details.
        server-group-delete         Delete specific server group(s).
        server-group-get            Get a specific server group.
        server-group-list           Print a list of all server groups.
        server-migration-list       Get the migrations list of specified server.
                                    (Supported by API versions '2.23' -
                                    '2.latest') [hint: use '--os-compute-api-
                                    version' flag to show help message for proper
                                    version]
        server-migration-show       Get the migration of specified server.
                                    (Supported by API versions '2.23' -
                                    '2.latest') [hint: use '--os-compute-api-
                                    version' flag to show help message for proper
                                    version]
        server-tag-add              Add single tag to a server. (Supported by API
                                    versions '2.26' - '2.latest') [hint: use
                                    '--os-compute-api-version' flag to show help
                                    message for proper version]
        server-tag-delete           Delete single tag from a server. (Supported by
                                    API versions '2.26' - '2.latest') [hint: use
                                    '--os-compute-api-version' flag to show help
                                    message for proper version]
        server-tag-delete-all       Delete all tags from a server. (Supported by
                                    API versions '2.26' - '2.latest') [hint: use
                                    '--os-compute-api-version' flag to show help
                                    message for proper version]
        server-tag-list             Get list of tags from a server. (Supported by
                                    API versions '2.26' - '2.latest') [hint: use
                                    '--os-compute-api-version' flag to show help
                                    message for proper version]
        server-tag-set              Set list of tags to a server. (Supported by
                                    API versions '2.26' - '2.latest') [hint: use
                                    '--os-compute-api-version' flag to show help
                                    message for proper version]
        service-delete              Delete the service.
        service-disable             Disable the service.
        service-enable              Enable the service.
        service-force-down          Force service to down. (Supported by API
                                    versions '2.11' - '2.latest') [hint: use
                                    '--os-compute-api-version' flag to show help
                                    message for proper version]
        service-list                Show a list of all running services. Filter by
                                    host & binary.
        set-password                Change the admin password for a server.
        shelve                      Shelve a server.
        shelve-offload              Remove a shelved server from the compute node.
        show                        Show details about the given server.
        ssh                         SSH into a server.
        start                       Start the server(s).
        stop                        Stop the server(s).
        suspend                     Suspend a server.
        trigger-crash-dump          Trigger crash dump in an instance. (Supported
                                    by API versions '2.17' - '2.latest') [hint:
                                    use '--os-compute-api-version' flag to show
                                    help message for proper version]
        unlock                      Unlock a server.
        unpause                     Unpause a server.
        unrescue                    Restart the server from normal boot disk
                                    again.
        unshelve                    Unshelve a server.
        update                      Update the name or the description for a
                                    server.
        usage                       Show usage data for a single tenant.
        usage-list                  List usage data for all tenants.
        version-list                List all API versions.
        virtual-interface-list      Show virtual interface info about the given
                                    server.
        volume-attach               Attach a volume to a server.
        volume-attachments          List all the volumes attached to a server.
        volume-detach               Detach a volume from a server.
        volume-update               Update volume attachment.
        x509-create-cert            Create x509 cert for a user in tenant.
        x509-get-root-cert          Fetch the x509 root cert.
        bash-completion             Prints all of the commands and options to
                                    stdout so that the nova.bash_completion script
                                    doesn't have to hard code them.
        help                        Display help about this program or one of its
                                    subcommands.
        baremetal-interface-list    DEPRECATED: List network interfaces associated
                                    with a baremetal node.
        baremetal-node-list         DEPRECATED: Print list of available baremetal
                                    nodes.
        baremetal-node-show         DEPRECATED: Show information about a baremetal
                                    node.
        cell-capacities             Get cell capacities for all cells or a given
                                    cell.
        cell-show                   Show details of a given cell.
        force-delete                Force delete a server.
        restore                     Restore a soft-deleted server.
        host-evacuate               Evacuate all instances from failed host.
        host-evacuate-live          Live migrate all instances of the specified
                                    host to other available hosts.
        host-servers-migrate        Cold migrate all instances off the specified
                                    host to other available hosts.
        instance-action             Show an action.
        instance-action-list        List actions on a server.
        list-extensions             List all the os-api extensions that are
                                    available.
        host-meta                   Set or Delete metadata on all instances of a
                                    host.
        migration-list              Print a list of migrations.
        net                         DEPRECATED, use tenant-network-show instead.
        net-create                  DEPRECATED, use tenant-network-create instead.
        net-delete                  DEPRECATED, use tenant-network-delete instead.
        net-list                    DEPRECATED, use tenant-network-list instead.
        tenant-network-create       DEPRECATED: Create a tenant network.
        tenant-network-delete       DEPRECATED: Delete a tenant network.
        tenant-network-list         DEPRECATED: List tenant networks.
        tenant-network-show         DEPRECATED: Show a tenant network.
    
    Optional arguments:
      --version                     show program's version number and exit
      --debug                       Print debugging output.
      --os-cache                    Use the auth token cache. Defaults to False if
                                    env[OS_CACHE] is not set.
      --timings                     Print call timing info.
      --os-region-name <region-name>
                                    Defaults to env[OS_REGION_NAME].
      --service-type <service-type>
                                    Defaults to compute for most actions.
      --service-name <service-name>
                                    Defaults to env[NOVA_SERVICE_NAME].
      --os-endpoint-type <endpoint-type>
                                    Defaults to env[NOVA_ENDPOINT_TYPE],
                                    env[OS_ENDPOINT_TYPE] or publicURL.
      --os-compute-api-version <compute-api-ver>
                                    Accepts X, X.Y (where X is major and Y is
                                    minor part) or "X.latest", defaults to
                                    env[OS_COMPUTE_API_VERSION].
      --bypass-url <bypass-url>     Use this API endpoint instead of the Service
                                    Catalog. Defaults to
                                    env[NOVACLIENT_BYPASS_URL].
      --os-auth-type <name>, --os-auth-plugin <name>
                                    Authentication type to use
    
    API Connection Options:
      Options controlling the HTTP API Connections
    
      --insecure                    Explicitly allow client to perform "insecure"
                                    TLS (https) requests. The server's certificate
                                    will not be verified against any certificate
                                    authorities. This option should be used with
                                    caution.
      --os-cacert <ca-certificate>  Specify a CA bundle file to use in verifying a
                                    TLS (https) server certificate. Defaults to
                                    env[OS_CACERT].
      --os-cert <certificate>       Defaults to env[OS_CERT].
      --os-key <key>                Defaults to env[OS_KEY].
      --timeout <seconds>           Set request timeout (in seconds).
    
    Authentication Options:
      Options specific to the password plugin.
    
      --os-auth-url OS_AUTH_URL     Authentication URL
      --os-domain-id OS_DOMAIN_ID   Domain ID to scope to
      --os-domain-name OS_DOMAIN_NAME
                                    Domain name to scope to
      --os-project-id OS_PROJECT_ID, --os-tenant-id OS_PROJECT_ID
                                    Project ID to scope to
      --os-project-name OS_PROJECT_NAME, --os-tenant-name OS_PROJECT_NAME
                                    Project name to scope to
      --os-project-domain-id OS_PROJECT_DOMAIN_ID
                                    Domain ID containing project
      --os-project-domain-name OS_PROJECT_DOMAIN_NAME
                                    Domain name containing project
      --os-trust-id OS_TRUST_ID     Trust ID
      --os-default-domain-id OS_DEFAULT_DOMAIN_ID
                                    Optional domain ID to use with v3 and v2
                                    parameters. It will be used for both the user
                                    and project domain in v3 and ignored in v2
                                    authentication.
      --os-default-domain-name OS_DEFAULT_DOMAIN_NAME
                                    Optional domain name to use with v3 API and v2
                                    parameters. It will be used for both the user
                                    and project domain in v3 and ignored in v2
                                    authentication.
      --os-user-id OS_USER_ID       User id
      --os-username OS_USERNAME, --os-user-name OS_USERNAME
                                    Username
      --os-user-domain-id OS_USER_DOMAIN_ID
                                    User's domain id
      --os-user-domain-name OS_USER_DOMAIN_NAME
                                    User's domain name
      --os-password OS_PASSWORD     User's password
    
    See "nova help COMMAND" for help on a specific command.
    

    计算服务Nova是Openstack最核心的服务,负责维护和管理云环境的计算资源。 虚拟机生命周期管理也就是通过 Nova 来实现的。
    Nova处于Openstack的核心架构位置,其他组件都为 Nova 提供支持:

    Glance 为 VM 提供 image 
    Cinder 和 Swift 分别为 VM 提供块存储和对象存储 
    Neutron 为 VM 提供网络连接
    

    Nova 的架构比较复杂,包含很多组件。

    判定一个进程是否为守护进程:
    https://segmentfault.com/q/1010000000310278/a-1020000000310307

    这些组件以子服务(后台 deamon 进程)的形式运行(精灵服务,守护进程),可以分为以下几类:

    1)API

    • nova-api:
      接收和响应客户的 API 调用。
      除了提供 OpenStack 自己的API,nova-api 还支持 Amazon EC2 API。

    2)Compute Core

    • nova-scheduler
      虚拟机调度服务,负责决定在哪个计算节点上运行虚拟机。
    • nova-compute
      管理虚拟机的核心服务,通过调用Hypervisor API实现虚拟机生命周期管理。
    • Hypervisor
      计算节点上跑的虚拟化管理程序,虚拟机管理最底层的程序。
      常用的Hypervisor有:KVM,Xen,VMWare等。
    • nova-conductor
      nova-compute经常需要更新数据库,比如更新虚拟机的状态。
      处于安全性和伸缩性的考虑,nova-compute并不会直接访问数据库,而是将这个任务委托给nova-conductor

    3)Console Interface

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

    远程桌面协议浅析(VNC, SPICE, RDP)
    http://www.bubuko.com/infodetail-669896.html

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

    • nova-cert
      提供x509证书支持。

    数字证书:https://baike.baidu.com/item/数字证书

    4)Database
    Nova 会有一些数据需要存放到数据库中,一般使用 MySQL。
    数据库安装在控制节点上

    5)Message Queue
    Nova包含许多自服务,这些子服务之间需要相互协调和通信。
    为了解耦各个自服务,Nova通过Message Queue作为子服务的信息中转站。
    我们在架构图上面看到了自服务之间没有直接的连线,他们是通过Message Queue联系。


    图片.png

    OpenStack 默认使用RabbitMQ作为Message Queue。
    MQ是OpenStack的核心基础组件。


    Nova各个组件如何协同工作

    Nova物理部署方案

    Nova 由很多子服务组成,同时我们也知道 OpenStack 是一个分布式系统,可以部署到若干节点上,那么接下来大家可能就会问: Nova 的这些服务在物理上应该如何部署呢?

    对于 Nova,这些服务会部署在两类节点上:计算节点和控制节点。
    计算节点上安装了 Hypervisor,上面运行虚拟机。
    由此可知:

    1. 只有 nova-compute 需要放在计算节点上。 
    2. 其他子服务则是放在控制节点上的。 
    

    我们可以使用:

    ps -elf|grep nova*
    

    来查看运行的 nova 子服务 。
    计算节点
    只有nova-compute子服务
    控制节点
    运行了除了nova-compute之外的nova-*

    nova-novncproxy
    nova-cert
    nova-conductor
    nova-api
    nova-scheduler
    nova-consoleauth
    

    以及

    rabbitmq-server
    mysqld
    

    说明RabbitMQ和MySQL也是放在控制节点上的。

    也可以使用nova service-list查看nova-*子服务分布在哪些节点之上。

    从虚拟机创建流程看nova-*子服务如何协同工作

    图片.png
    1.客户(可以是 OpenStack 最终用户,也可以是其他程序)向 API(nova-api)发送请求:“帮我创建一个虚机”
    
    2.API 对请求做一些必要处理后,向 Messaging(RabbitMQ)发送了一条消息:“让 Scheduler 创建一个虚机”
    
    3.Scheduler(nova-scheduler)从 Messaging 获取到 API 发给它的消息,然后执行调度算法,从若干计算节点中选出节点 A
    
    4.Scheduler 向 Messaging 发送了一条消息:“在计算节点 A 上创建这个虚机”
    
    5.计算节点 A 的 Compute(nova-compute)从 Messaging 中获取到 Scheduler 发给它的消息,然后在本节点的 Hypervisor 上启动虚机。
    
    6.在虚机创建的过程中,Compute 如果需要查询或更新数据库信息,会通过 Messaging 向 Conductor(nova-conductor)发送消息,Conductor 负责数据库访问。
    

    Nova组件详解

    Nova有若干个nova-*子服务。

    1. nova-api

    Nova-api是整个Nova组件的门户,所有对Nova的请求都首先由nova-api处理。
    Nova-api 向外界暴露若干HTTP REST API 接口。
    在keystone中我们可以查询nova-api的endpoints。

    openstack endpoint show nova
    

    如果出现这个错误:

    More than one endpoint exists with the name 'nova'.
    请看:https://ask.openstack.org/en/question/113144/more-than-one-endpoint-exists-with-the-name-nova/

    客户端就可以将请求发送到endpoints指定的地址,向nova-api请求操作。
    当然作为最终用户的我们不会直接发送Rest API 请求。
    OpenStack CLI, Dashboard和其他需要跟Nova交换的组件会使用这些API。

    Nova-api 对接收到的 HTTP API 请求会做如下处理:

    1. 检查客户端传入的参数是否合法有效
    2. 调用Nova其他子服务的处理客户端HTTP请求
    3. 格式化Nova其他子服务返回的结果并返回给客户端
    

    nova-api接受哪些请求?
    简单地说,只要是跟虚拟机生命周期相关的操作,nova-api都可以相应。
    大部分操作都可以在Dashboard上找到。

    图片.png
    点击下拉箭头,列表中就是nova-api可以执行的操作。
    图片.png

    OpenStack使用Instance术语来表示虚拟机。

    2.nova-conductor

    nova-compute需要获取和更新数据库中instance的信息。
    但是nova-compute并不会直接访问数据库,而是通过nova-conductor实现数据库的访问。

    图片.png
    这样做有两个好处:
    1.更高的系统安全性
    2.更好的系统伸缩性
    

    在 OpenStack 的早期版本中,nova-compute 可以直接访问数据库,但这样存在非常大的安全隐患。
    因为 nova-compute 这个服务是部署在计算节点上的,为了能够访问控制节点上的数据库,就必须在计算节点的 /etc/nova/nova.conf 中配置访问数据库的连接信息,比如

    [database]
    connection = mysql+pymysql://root:secret@controller/nova?charset=utf8
    

    试想任意一个计算节点被黑客入侵,都会导致部署在控制节点上的数据库面临极大风险。
    为了解决这个问题,从 G 版本开始,Nova 引入了一个新服务 nova-conductor,将 nova-compute 访问数据库的全部操作都放到 nova-conductor 中,而且 nova-conductor 是部署在控制节点上的。
    这样就避免了 nova-compute 直接访问数据库,增加了系统的安全性。

    更好的伸缩性

    nova-conductor 将 nova-compute 与数据库解耦之后还带来另一个好处:提高了 nova 的伸缩性。
    nova-compute 与 conductor 是通过消息中间件交互的。

    这种松散的架构允许配置多个 nova-conductor 实例。
    在一个大规模的 OpenStack 部署环境里,管理员可以通过增加 nova-conductor 的数量来应对日益增长的计算节点对数据库的访问。

    3.nova-scheduler

    nova-scheduler 的调度机制和实现方法:即解决如何选择在哪个计算节点上启动 instance 的问题。

    创建 Instance 时,用户会提出资源需求,例如 CPU、内存、磁盘各需要多少。

    OpenStack 将这些需求定义在 flavor 中,用户只需要指定用哪个 flavor 就可以了。

    图片.png

    可用的 flavor 在 System->Flavors 中管理。

    图片.png

    Flavor 主要定义了 VCPURAMDISKMetadata 这四类。
    nova-scheduler 会按照 flavor 去选择合适的计算节点。

    Metadata是什么?

    nova-scheduler 是如何实现调度的?

    /etc/nova/nova.conf中,nova 通过:

    scheduler_driver,scheduler_available_filters 和 scheduler_default_filters 
    

    这三个参数来配置 nova-scheduler。

    Filter scheduler

    Filter scheduler 是 nova-scheduler 默认的调度器,调度过程分为两步:

    1.通过过滤器(filter)选择满足条件的计算节点(运行 nova-compute)
    2.通过权重计算(weighting)选择在最优(权重值最大)的计算节点上创建 Instance。
    
    scheduler_driver=nova.scheduler.filter_scheduler.FilterScheduler
    

    Nova 允许使用第三方 scheduler,配置 scheduler_driver 即可。 这又一次体现了OpenStack的开放性

    Scheduler 可以使用多个 filter 依次进行过滤,过滤之后的节点再通过计算权重选出最适合的节点。


    图片.png

    上图是调度过程的一个示例:

    1.最开始有 6 个计算节点 Host1-Host6
    2.通过多个 filter 层层过滤,Host2 和 Host4 没有通过,被刷掉了
    3.Host1,Host3,Host5,Host6 计算权重,结果 Host5 得分最高,最终入选
    

    Filter
    当 Filter scheduler 需要执行调度操作时,会让 filter 对计算节点进行判断,filter 返回 True 或 False。
    Nova.conf 中的 scheduler_available_filters 选项用于配置 scheduler 可用的 filter,默认是所有 nova 自带的 filter 都可以用于滤操作。

    scheduler_available_filters = nova.scheduler.filters.all_filters
    

    另外还有一个选项 scheduler_default_filters,用于指定 scheduler 真正使用的 filter,默认值如下 :

    scheduler_default_filters = RetryFilter, AvailabilityZoneFilter, RamFilter, DiskFilter, ComputeFilter, ComputeCapabilitiesFilter, ImagePropertiesFilter, ServerGroupAntiAffinityFilter, ServerGroupAffinityFilter
    

    Filter scheduler 将按照列表中的顺序依次过滤。 下面依次介绍每个 filter。

    RetryFilter

    RetryFilter 的作用是刷掉之前已经调度过的节点。

    举个例子方便大家理解: 假设 A,B,C 三个节点都通过了过滤,最终 A 因为权重值最大被选中执行操作。 但由于某个原因,操作在 A 上失败了。 默认情况下,nova-scheduler 会重新执行过滤操作(重复次数由 scheduler_max_attempts 选项指定,默认是 3)。 那么这时候 RetryFilter 就会将 A 直接刷掉,避免操作再次失败。 RetryFilter 通常作为第一个 filter。

    AvailabilityZoneFilter

    为提高容灾性和提供隔离服务,可以将计算节点划分到不同的Availability Zone中。

    例如把一个机架上的机器划分在一个 Availability Zone 中。 OpenStack 默认有一个命名为 “Nova” 的 Availability Zone,所有的计算节点初始都是放在 “Nova” 中。 用户可以根据需要创建自己的 Availability Zone。

    图片.png

    创建 Instance 时,需要指定将 Instance 部署到在哪个 Availability Zone中。

    图片.png

    nova-scheduler 在做 filtering 时,会使用 AvailabilityZoneFilter 将不属于指定 Availability Zone 的计算节点过滤掉。

    还有许多:请参考:http://www.cnblogs.com/CloudMan6/p/5441782.html

    Weight

    经过前面一堆 filter 的过滤,nova-scheduler 选出了能够部署 instance 的计算节点。
    如果有多个计算节点通过了过滤,那么最终选择哪个节点呢?

    Scheduler 会对每个计算节点打分,得分最高的获胜。
    打分的过程就是 weight,翻译过来就是计算权重值,那么 scheduler 是根据什么来计算权重值呢?

    目前 nova-scheduler 的默认实现是根据计算节点空闲的内存量计算权重值:
    空闲内存越多,权重越大,instance 将被部署到当前空闲内存最多的计算节点上。

    日志

    存放地方:/var/log/nova/nova-scheduler.log

    4.nova-compute

    nova-compute 在计算节点上运行,负责管理节点上的 instance。
    OpenStack 对 instance 的操作,最后都是交给 nova-compute 来完成的。
    nova-computeHypervisor 一起实现 OpenStack 对 instance 生命周期的管理。

    通过 Driver 架构支持多种 Hypervisor
    上面有讲到(略)。

    OpenStack 源代码中已经自带了几个 Hypervisor 的 Driver。

    nova-compute的功能可以分为两类:

    1.定时向OpenStack报告计算节点的状态
    2.实现Instance生命周期的管理
    

    定时向OpenStack报告计算节点的状态

    nova-scheduler 的很多 Filter 是根据算节点的资源使用情况进行过滤的。
    比如 RamFilter 要检查计算节点当前可以的内存量;CoreFilter 检查可用的 vCPU 数量;DiskFilter 则会检查可用的磁盘空间。

    OpenStack 是如何得知每个计算节点的这些信息呢?

    nova-compute 会定期向 OpenStack 报告。
    /var/log/nova/nova-compute.log中:

    2018-03-13 11:15:53.716 24478 INFO nova.compute.resource_tracker [req-dd17ef12-5866-4c73-beb1-641ae05ef00a - - - - -] 最终资源视图:name=controller phys_ram=7796MB used_ram=512MB phys_disk=49GB used_disk=0GB total_vcpus=8 used_vcpus=0 pci_stats=[]
    2018-03-13 11:16:53.712 24478 INFO nova.compute.resource_tracker [req-dd17ef12-5866-4c73-beb1-641ae05ef00a - - - - -] 最终资源视图:name=controller phys_ram=7796MB used_ram=512MB phys_disk=49GB used_disk=0GB total_vcpus=8 used_vcpus=0 pci_stats=[]
    

    nova-compute 是如何获得当前计算节点的资源使用信息的?

    要得到计算节点的资源使用详细情况,需要知道当前节点上所有 instance 的资源占用信息。
    这些信息谁最清楚?
    当然是 Hypervisor。

    举例来说,在我们的实验环境下 Hypervisor 是 KVM,用的 Driver 是 LibvirtDriver。
    LibvirtDriver 可以调用相关的 API 获得资源信息,这些 API 的作用相当于我们在 CLI 里执行 virsh nodeinfo、virsh dominfo 等命令。

    实现 instance 生命周期的管理

    OpenStack 对 instance 最主要的操作都是通过 nova-compute 实现的,包括 instance 的 launch、shutdown、reboot、suspend、resume、terminate、resize、migration、snapshot 等。

    nova-compute 创建 instance 的过程可以分为 4 步:

    1.为 instance 准备资源
    2.创建 instance 的镜像文件
    3.创建 instance 的 XML 定义文件
    4.创建虚拟网络并启动虚拟机
    

    为instance准备资源

    nova-compute 首先会根据指定的 flavor 依次为 instance 分配内存、磁盘空间和 vCPU。

    图片.png

    网络资源也会提前分配。

    图片.png

    创建 instance 的镜像文件

    资源准备好之后,nova-compute 会为 instance 创建镜像文件。
    OpenStack 启动一个 instance 时,会选择一个 image,这个 image 由 Glance 管理。
    nova-compute会:

    1.首先将该 image 下载到计算节点  # 注意是下载
    2.然后将其作为 **backing file** 创建 instance 的镜像文件。
    

    Glance下载image

    nova-compute 首先会检查 image 是否已经下载(比如之前已经创建过基于相同 image 的 instance)。如果没有,就从 Glance 下载 image 到本地。

    由此可知,如果计算节点上要运行多个相同 image 的 instance,只会在启动第一个 instance 的时候从 Glance 下载 image,后面的 instance 启动速度就大大加快了。

    日志:


    图片.png

    从上面可以看到:

    1.image(ID为 917d60ef-f663-4e2d-b85b-e4511bb56bc2)是 qcow2 格式,nova-compute 将其下载,然后通过 qemu-img 转换成 raw 格式。 转换的原因是下一步需要将其作为 instance 的镜像文件的 backing file,而 backing file不能是 qcow2 格式。
    2.image 的存放目录是 /opt/stack/data/nova/instances/_base,这是由 /etc/nova/nova.conf 的下面两个配置选项决定的。
    
    instances_path = /opt/stack/data/nova/instances
    base_dir_name = _base
    

    下载的 image 文件被命名为 60bba5916c6c90ed2ef7d3263de8f653111dd35f,这是 image id 的 SHA1 哈希值。

    为 instance 创建镜像文件:
    有了 image 之后,instance 的镜像文件直接通过 qemu-img 命令创建,backing file 就是下载的 image。

    图片.png

    我们可以使用qemu-info查看disk文件的属性。

    qemu-img info /xxx/xxx/xxxx/disk
    

    有两个容易搞混淆的术语:

    1. image: 指的是 Glance 上保存的镜像,作为 instance 运行的模板。 计算节点将下载的 image 存放在 /opt/stack/data/nova/instances/_base 目录下。
    2. 镜像文件,指的是 instance 启动盘所对应的文件
    

    二者的关系是:image 是镜像文件 的 backing file。image 不会变,而镜像文件会发生变化。比如安装新的软件后,镜像文件会变大。
    因为英文中两者都叫 “image”,为避免混淆,我们用 “image” 和 “镜像文件” 作区分。

    创建 instance 的 XML 定义文件

    图片.png

    创建的 XML 文件会保存到该 instance 目录 /opt/stack/data/nova/instances/f1e22596-6844-4d7a-84a3-e41e6d7618ef,命名为 libvirt.xml

    创建虚拟网络并启动 instance

    接下来便是为 instance 创建虚拟网络设备

    图片.png

    一切就绪,接下来可以启动 instance 了。

    图片.png 图片.png

    OpenStack 图形界面和 KVM CLI 都可以查看到 instance 的运行状态。

    图片.png 图片.png

    在计算节点上,instance 并不是以 OpenStack上 的名字命名,而是用 instance-xxxxx 的格式。


    详细分析 instance launch 和 shut off 操作,以及如何在日志中快速定位有用信息的技巧。

    Launch
    Launch instance 应该算 Nova 最重要的操作。
    仔细研究 lanuch 操作能够帮助我们充分理解 Nova 各个子服务的协调配合和运行机制。
    前面我们已经以 launch 操作为例详细讨论了各个 nova-* 子服务。 这里不再赘述,只是再回顾一下流程。

    图片.png
    客户(可以是 OpenStack 最终用户,也可以是其他程序)向 API(nova-api)发送请求:“帮我创建一个 Instance”
    
    API对请求做一些必要处理后,向 Messaging(RabbitMQ)发送了一条消息:“让 Scheduler 创建一个 Instance”
    
    Scheduler(nova-scheduler)从 Messaging 获取到 API 发给它的消息,然后执行调度算法,**从若干计算节点中选出节点 A **  (注意:launch也需要scheduler)
    
    Scheduler 向 Messaging 发送了一条消息:“在计算节点 A 上创建这个 Instance”
    
    计算节点 A 的 Compute(nova-compute)从 Messaging 中获取到 Scheduler 发给它的消息,然后通过本节点的 Hypervisor Driver 创建 Instance。
    
    在 Instance 创建的过程中,Compute 如果需要查询或更新数据库信息,会通过 Messaging 向 Conductor(nova-conductor)发送消息,Conductor 负责数据库访问。
    

    Shut Off

    下面是 shut off instance 的流程图

    图片.png
    向 nova-api 发送请求
    
    nova-api 发送消息
    
    nova-compute 执行操作
    

    下面我们详细讨论每一个步骤。

    1. 向 nova-api 发送请求
      客户(可以是 OpenStack 最终用户,也可以是其他程序)向 API(nova-api)发送请求:“帮我关闭这个 Instance”


      图片.png

    对于如何在日志文件中快速查找到有用的信息这里多聊几句。 对于初学者,这不是一件容易的事情,因为日志里条目和内容很多,特别是 debug 选项打开之后,容易让人眼花缭乱,无从下手。

    小窍门:

    1.先确定大的范围,比如在操作之前用 tail -f 打印日志文件,这样需要查看的日志肯定在操作之后的打印输出的这些内容里。 另外也可以通过时间戳来确定需要的日志范围。
    2.利用 “代码模块” 快速定位有用的信息。 nova-* 子服务都有自己特定的代码模块:
    nova-api 
    nova.api.openstack.compute.servers 
    nova.compute.api 
    nova.api.openstack.wsgi
    
    nova-compute
    nova.compute.manager 
    nova.virt.libvirt.*
    
    nova-scheduler
    nova.scheduler.*
    

    3.利用 Request ID 查找相关的日志信息。 在上面的日志中个,我们可以利用 “req-1758b389-a2d0-44cc-a95a-6f75e4dc07fd” 这个 Request ID 快速定位 n-api.log 中相与 shut off 操作的其他日志条目。 需要补充说明的是,Request ID 是跨日志文件的,这一个特性能帮助我们在其他子服务的日志文件中找到相关信息,我们后面马上将会看到这个技巧的应用。

    nova-api 发送消息

    nova-api 向 Messaging(RabbitMQ)发送了一条消息:“关闭这个 Instance” nova-api 没有将发送消息的操作记录到日志中,不过我们可以通过查看源代码来验证。 一提到源代码,大家可能以为要大海捞针了。其实很简单,上面日志已经清楚地告诉我们需要查看的源代码在 /opt/stack/nova/nova/compute/api.py 的 1977 行,方法是 force_stop。

    图片.png

    force_stop 方法最后调用的是对象 self.compute_rpcapistop_instance 方法。 在 OpenStack 源码中,以 xxx_rpcapi 命名的对象,表示的就是 xxx 的消息队列。 xxx_rpcapi.yyy() 方法则表示向 xxx 的消息队列发送 yyy 操作的消息。

    所以 self.compute_rpcapi.stop_instance() 的作用就是向 RabbitMQ 上 nova-compute 的消息队列里发送一条 stop instance 的消息。

    这里补充说明一下:
    关闭 instance 的前提是 instance 当前已经在某个计算节点上运行,所以这里不需要 nova-scheduler 再帮我们挑选合适的节点,这个跟 launch 操作不同。

    nova-compute 执行操作

    查看计算节点上的日志:

    图片.png

    这里我们利用了 Request ID “req-1758b389-a2d0-44cc-a95a-6f75e4dc07fd” 在 n-cpu.log 中快速定位到 nova-compute 关闭 instance 的日志条目。

    小结

    分析某个操作时,我们首先要理清该操作的内部流程,然后再到相应的节点上去查看日志。 例如shut off 的流程为:

    向 nova-api 发送请求
    
    nova-api 发送消息
    
    nova-compute 执行操作
    

    1,2 两个步骤是在控制节点上执行的,查看 nova-api 的日志。 第 3 步是在计算节点上执行的,查看 nova-compute 的日志。

    相关文章

      网友评论

        本文标题:OpenStack组件 Nova

        本文链接:https://www.haomeiwen.com/subject/depwxxtx.html