如何使用OpenStack将云主机部署到特定的计算节点上

本文介绍如何利用OpenStack的nova-scheduler将实例部署到特定计算节点的方法,包括通过主机聚合和Flavor Capability的方式实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景

Openstack已经成为主流IaaS云计算平台,国内多数云计算厂商提供的云计算服务底层都是使用的OpenStack。这里我们讲的“如何将实例部署到特定的计算节点上”是基于标准的Openstack平台。

通过Openstack我们可以申请以实例为核心的各类资源。通常情况下,我们只需要指定实例配置,如多少CPU、多大内存、挂多大数据盘、连接什么样的网络即可,Openstack会帮助我们将实例部署到指定的计算节点上。但是,需求往往是多样性的,有时候我们需要将实例部署到特定的计算节点上。例如Openstack资源池中的计算节点同时存在高性能的机架服务器和刀片服务器,我们希望将运行数据库的实例部署到机架服务器上,将运行中间件的实例部署到刀片服务器上。(这里的实例指的是虚拟主机实例,而非数据库实例或中间件实例)

Openstack的nova-scheduler服务可以帮我们实现这样个性化的需求。接下来我将介绍nova-scheduler如何帮助我们实现上述需求的工作原理,并且我会以两个示例分别用两种方法来实现“如何将实例部署到特定的计算节点上”。

原理(Nova Scheduler)

Openstack通过nova-scheduler来实现将实例部署到哪台计算节点上。Filter scheduler 是 nova-scheduler 默认的调度器,调度过程分为两步:

第一步:通过过滤器(filter)选择满足条件的计算节点(运行nova-compute)

第二步:通过权重计算(weighting)选择在最优(权重值最大)的计算节点上创建 Instance。

图 0‑1过滤



图0-2分析权重

 

Filters的调度策略有以下几种:

AggregateCoreFilter

AggregateDiskFilter

AggregateImagePropertiesIsolation

AggregateInstanceExtraSpecsFilter

AggregateIoOpsFilter

AggregateMultiTenancyIsolation

AggregateNumInstancesFilter

AggregateRamFilter

AggregateTypeAffinityFilter

AllHostsFilter

AvailabilityZoneFilter

ComputeCapabilitiesFilter

ComputeFilter

CoreFilter

NUMATopologyFilter

DifferentHostFilter

DiskFilter

GroupAffinityFilter

GroupAntiAffinityFilter

ImagePropertiesFilter

IsolatedHostsFilter

IoOpsFilter

JsonFilter

MetricsFilter

NumInstancesFilter

PciPassthroughFilter

RamFilter

RetryFilter

SameHostFilter

ServerGroupAffinityFilter

ServerGroupAntiAffinityFilter

SimpleCIDRAffinityFilter

TrustedFilter

TypeAffinityFilter

计算服务Filters的策略通过配置nova.conf配置文件中的配置项scheduler_available_filters完成。默认配置的是所有filters。配置如下:

scheduler_available_filters = nova.scheduler.filters.all_filters

这个配置项可以在nova.conf中多次出现,比如你可以通过Python实现自定义的filter(myFilter.MyFilter),只需要在配置文件中增加这个filter即可。

scheduler_available_filters = nova.scheduler.filters.all_filters

scheduler_available_filters = myfilter.MyFilter

详细介绍请参见这里

下面通过两个示例来实现将Openstack的示例部署到指定的主机中。

示例一:通过主机聚合的metadata实现将云主机部署到使用ssd的主机聚合中

假设我在公司的OpenStack环境中创建了一个主机聚合fast-io,这个聚合中,所有的计算节点都连接了SSD类型的本地磁盘。我想创建一个Flavor ssd.large,通过该Flavor申请的云主机全部部署到fast-io这个主机聚合中。

要完成这个任务,我们需要做6步工作:

1.    将AggregateInstanceExtraSpecsFilter添加到nova.conf文件的scheduler_default_filters配置项中,即:

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

2.    创建一个主机聚合,命名为fast-io,可用域为nova

$ nova aggregate-create fast-io nova

+----+---------+-------------------+-------+----------+

| Id | Name    | Availability Zone | Hosts | Metadata |

+----+---------+-------------------+-------+----------+

| 1  | fast-io | nova              |       |          |

+----+---------+-------------------+-------+----------+

3.    设置集群元数据ssd=true

$ nova aggregate-set-metadata 1 ssd=true

+----+---------+-------------------+-------+-------------------+

| Id | Name    | Availability Zone | Hosts | Metadata          |

+----+---------+-------------------+-------+-------------------+

| 1  | fast-io | nova              | []    | {u'ssd': u'true'} |

+----+---------+-------------------+-------+-------------------+

 

4.    在主机聚合fast-io中增加两台主机node1和node2

$ nova aggregate-add-host 1 node1

+----+---------+-------------------+-----------+-------------------+

| Id | Name    | Availability Zone | Hosts      | Metadata          |

+----+---------+-------------------+------------+-------------------+

| 1  | fast-io | nova              | [u'node1'] | {u'ssd': u'true'} |

+----+---------+-------------------+------------+-------------------+

 

$ nova aggregate-add-host 1 node2

+----+---------+-------------------+---------------------+-------------------+

| Id | Name    | Availability Zone | Hosts                | Metadata          |

+----+---------+-------------------+----------------------+-------------------+

| 1  | fast-io | nova              | [u'node1', u'node2'] | {u'ssd': u'true'} |

+----+---------+-------------------+----------------------+-------------------+

5.    使用novaflavor-create命令创建flavor ssd.large,配置为4个vCPU、8GB内存和80GB root盘。

$ nova flavor-create ssd.large68192804

+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

| ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |

+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

| 6  | ssd.large | 8192      | 80   | 0         |      | 4     | 1.0         | True      |

+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

 

6.    设置flavor ssd.large的元数据为ssd=true

$ nova flavor-key ssd.large set  aggregate_instance_extra_specs:ssd=true

完成以上6步工作后,当用户通过ssd.large这个flavor创建云主机时,nova-scheduler将会把这个云主机调度到元数据为ssd=true这个主机聚合的主机上。

示例二:通过配置flavor的Capability实现将云主机部署到厂商为intel的主机上

某些情况下,我们希望将申请的云主机与某些厂商的主机绑定。例如我想把使用flavor为vendor.intel的云主机全部部署到intel生产的主机上。

首先我们把compute-host-capabilities.json这个文件导入到元数据信息中。

其次我们创建一个flavor vendor.intel,并把元数据指定为cpu.info:vendor=intel。

此时申请flavor为vendor.intel的云主机会自动部署到intel生产的主机上。

compute-host-capabilities.json文件内容:

{

    "namespace":"OS::Compute::HostCapabilities",

    "display_name": "ComputeHost Capabilities",

    "description": "Hardwarecapabilities provided by the compute host. This provides the ability to finetune the hardware specification required when an instance is requested. TheComputeCapabilitiesFilter should be enabled in the Nova scheduler to use theseproperties. When enabled, this filter checks that the capabilities provided bythe compute host satisfy any extra specifications requested. Only hosts thatcan provide the requested capabilities will be eligible for hosting theinstance.",

    "visibility": "public",

    "protected": true,

    "resource_type_associations": [

        {

            "name":"OS::Nova::Flavor",

            "prefix":"capabilities:"

        },

        {

            "name":"OS::Nova::Aggregate",

            "prefix":"aggregate_instance_extra_specs:"

        }

    ],

    "properties": {

        "cpu_info:vendor": {

            "title":"Vendor",

            "description":"Specifies the CPU manufacturer.",

            "operators":["<or>"],

            "type":"string",

            "enum": [

                "Intel",

                "AMD"

            ]

        },

        "cpu_info:model": {

            "title":"Model",

            "description":"Specifies the CPU model. Use this property to ensure that your vm runs ona a specific cpu model.",

            "operators":["<or>"],

            "type":"string",

            "enum": [

                "Conroe",

                "Core2Duo",

                "Penryn",

                "Nehalem",

                "Westmere",

                "SandyBridge",

                "IvyBridge",

                "Haswell",

                "Broadwell",

                "Delhi",

                "Seoul",

                "Abu Dhabi",

                "Interlagos",

                "Kabini",

                "Valencia",

                "Zurich",

                "Budapest",

                "Barcelona",

                "Suzuka",

                "Shanghai",

                "Istanbul",

                "Lisbon",

                "Magny-Cours",

                "Valencia",

                "Cortex-A57",

                "Cortex-A53",

                "Cortex-A12",

                "Cortex-A17",

                "Cortex-A15",

                "Coretx-A7",

                "X-Gene"

            ]

        },

        "cpu_info:arch": {

            "title": "Architecture",

            "description":"Specifies the CPU architecture. Use this property to specify thearchitecture supported by the hypervisor.",

            "operators":["<or>"],

            "type":"string",

            "enum": [

                "x86",

                "x86_64",

                "i686",

                "ia64",

                "ARMv8-A",

                "ARMv7-A"

            ]

        },

        "cpu_info:topology:cores": {

            "title":"cores",

            "description":"Number of cores.",

            "type":"integer",

            "readonly": false,

            "default": 1

        },

        "cpu_info:topology:threads":{

            "title":"threads",

            "description":"Number of threads.",

            "type":"integer",

            "readonly": false,

            "default": 1

        },

        "cpu_info:topology:sockets":{

            "title":"sockets",

            "description":"Number of sockets.",

            "type":"integer",

            "readonly": false,

            "default": 1

        },

        "cpu_info:features": {

            "title":"Features",

            "description":"Specifies CPU flags/features. Using this property you can specify therequired set of instructions supported by a vm.",

            "operators":["<or>", "<all-in>"],

            "type":"array",

            "items": {

                "type":"string",

                "enum": [

                    "fpu",

                    "vme",

                    "de",

                    "pse",

                    "tsc",

                    "msr",

                    "pae",

                    "mce",

                    "cx8",

                    "apic",

                    "sep",

                    "mtrr",

                    "pge",

                    "mca",

                    "cmov",

                    "pat",

                    "pse36",

                    "pn",

                    "clflush",

                    "dts",

                    "acpi",

                    "mmx",

                    "fxsr",

                    "sse",

                    "sse2",

                    "ss",

                    "ht",

                    "tm",

                    "ia64",

                    "pbe",

                    "syscall",

                    "mp",

                    "nx",

                    "mmxext",

                    "fxsr_opt",

                    "pdpe1gb",

                    "rdtscp",

                    "lm",

                    "3dnowext",

                    "3dnow",

                    "arch_perfmon",

                    "pebs",

                    "bts",

                    "rep_good",

                    "nopl",

                    "xtopology",

                    "tsc_reliable",

                    "nonstop_tsc",

                    "extd_apicid",

                    "amd_dcm",

                    "aperfmperf",

                    "eagerfpu",

                    "nonstop_tsc_s3",

                    "pni",

                    "pclmulqdq",

                    "dtes64",

                    "monitor",

                    "ds_cpl",

                    "vmx",

                    "smx",

                    "est",

                    "tm2",

                    "ssse3",

                    "cid",

                    "fma",

                    "cx16",

                    "xtpr",

                    "pdcm",

                    "pcid",

                    "dca",

                    "sse4_1",

                    "sse4_2",

                    "x2apic",

                    "movbe",

                    "popcnt",

                   "tsc_deadline_timer",

                    "aes",

                    "xsave",

                    "avx",

                    "f16c",

                    "rdrand",

                    "hypervisor",

                    "rng",

                    "rng_en",

                    "ace",

                    "ace_en",

                    "ace2",

                    "ace2_en",

                    "phe",

                    "phe_en",

                    "pmm",

                    "pmm_en",

                    "lahf_lm",

                    "cmp_legacy",

                    "svm",

                    "extapic",

                    "cr8_legacy",

                    "abm",

                    "sse4a",

                    "misalignsse",

                    "3dnowprefetch",

                    "osvw",

                    "ibs",

                    "xop",

                    "skinit",

                    "wdt",

                    "lwp",

                    "fma4",

                    "tce",

                    "nodeid_msr",

                    "tbm",

                    "topoext",

                    "perfctr_core",

                    "perfctr_nb",

                    "bpext",

                    "perfctr_l2",

                    "mwaitx",

                    "ida",

                    "arat",

                    "cpb",

                    "epb",

                    "pln",

                    "pts",

                    "dtherm",

                    "hw_pstate",

                    "proc_feedback",

                    "hwp",

                    "hwp_notify",

                    "hwp_act_window",

                    "hwp_epp",

                    "hwp_pkg_req",

                    "intel_pt",

                    "tpr_shadow",

                    "vnmi",

                    "flexpriority",

                    "ept",

                    "vpid",

                    "npt",

                    "lbrv",

                    "svm_lock",

                    "nrip_save",

                    "tsc_scale",

                    "vmcb_clean",

                    "flushbyasid",

                    "decodeassists",

                    "pausefilter",

                    "pfthreshold",

                    "vmmcall",

                    "fsgsbase",

                    "tsc_adjust",

                    "bmi1",

                    "hle",

                    "avx2",

                    "smep",

                    "bmi2",

                    "erms",

                    "invpcid",

                    "rtm",

                    "cqm",

                    "mpx",

                    "avx512f",

                    "rdseed",

                    "adx",

                    "smap",

                    "pcommit",

                    "clflushopt",

                    "clwb",

                    "avx512pf",

                    "avx512er",

                    "avx512cd",

                    "sha_ni",

                    "xsaveopt",

                    "xsavec",

                    "xgetbv1",

                    "xsaves",

                    "cqm_llc",

                    "cqm_occup_llc",

                    "clzero"

                ]

            }

        }

    },

    "objects": []

}

参考资料

http://www.codexiu.cn/openstack/blog/14729/#OSC_h2_9

http://docs.openstack.org/kilo/config-reference/content/section_compute-scheduler.html

 

### 如何在OpenStack部署CentOS云主机 #### 准备工作 为了成功部署CentOS云主机,在开始之前需确认已具备如下条件: - 已经安装并配置好OpenStack平台。 - OpenStack环境中已经创建了必要的网络资源,例如外部网络和内部网络。其中`eth0`作为管理网络接口用于各组件间的通信[^2]。 #### 创建镜像 要启动一个新的虚拟机实例,首先需要上传一个可用的操作系统映像到Glance服务中。对于CentOS而言,可以通过命令行工具完成此操作: ```bash openstack image create "CentOS7" \ --file ~/images/CentOS-7-x86_64-GenericCloud.qcow2 \ --disk-format qcow2 --container-format bare \ --public ``` 这里假设操作系统映像文件名为`CentOS-7-x86_64-GenericCloud.qcow2`并且位于用户的home目录下的`~/images/`路径下。 #### 配置安全组规则 为了让新创建的VM能够访问互联网以及允许SSH登录,应该适当调整默认的安全组策略来开放相应的端口和服务协议: ```bash openstack security group rule create --proto tcp --dst-port 22 default openstack security group rule create --proto icmp default ``` 上述两条指令分别打开了TCP 22号端口供远程shell连接使用,并启用了ICMP回显请求功能以便测试连通性。 #### 启动实例 当所有的前置准备工作完成后就可以正式发起创建实例的动作了。下面是一条完整的命令用来定义新的计算节点参数: ```bash openstack server create --flavor m1.small --image CentOS7 \ --nic net-id=private_network_uuid \ --security-group default \ --key-name mykey centos-instance ``` 这条命令指定了所使用的硬件规格(`m1.small`)、基础镜像(CentOS7),所属私有子网UUID(private_network_uuid), 应用的安全组(default) 和 SSH密钥(mykey),最后给出了这个实例的名字(centos-instance). #### SELinux设置 如果目标服务器运行的是基于Red Hat的企业级Linux发行版,则可能还需要考虑SELinux的影响因素。建议暂时禁用它以减少不必要的麻烦: 编辑 `/etc/selinux/config` 文件并将 `SELINUX=enforcing` 修改为 `SELINUX=disabled`[^3]: ```vim # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled ... ``` 保存更改后重启机器使改动生效即可。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值