在配置驱动上存储元数据

在配置驱动上存储元数据

You can configure OpenStack to write metadata to a special configuration drive that attaches to the instance when it boots. The instance can mount this drive and read files from it to get information that is normally available through the metadata service. This metadata is different from the user data.

使用配置驱动器的一个用例是不通过DHCP给实例分配IP地址的方式来配置网络。例如,通过配置驱动器传递IP地址,在配置网络之前,实例可以挂载并访问配置驱动器。

任何现代用户操作系统可以挂载使用配置驱动的ISO 9660或VFAT文件系统

要求和指南

要使用配置驱动,您必须遵循以下计算主机和镜像的要求

计算节点要求

  • 虚拟机管理程序支持以下配置驱动:libvirt,XenServer,Hyper-V和VMware。

    此外,裸金属服务支持配置驱动器。

  • 在libvirt、XenServer和VMware环境使用配置驱动器,必须首先为每个计算主机安装genisoimage包,否则实例无法正常启动。

    在你安装genisoimage程序的时候使用”mkisofs_cmd”标识设置路径,如果genisoimage的路径与”nova-compute”服务相同,你就不需要设置这个标识。

  • 在Hyper-V环境使用配置驱动器必须将``mkisofs_cmd``的值设置为``mkisofs.exe`` 的安装位置的完整路径。另外,在 ``hyperv``配置中要将``qemu_img_cmd``设置为:command:qemu-img 安装位置的完整路径。

  • 要使用裸金属服务的配置驱动器,您不需要准备任何东西,因为裸金属服务会正确处理配置驱动器。

镜像要求

向导

  • 不依靠的存在于配置驱动的EC2元数据,因为这些内容可能会在未来的版本中删除。例如,不要依赖于”EC2 “目录的文件。
  • 当你在”openstack”目录下创建可以访问配置驱动数据和多个目录的镜像时,总是选择客户支持最高的API版本的日期。例如,如果你的客户镜像支持2012-03-05,2012-08-05,和2013-04-13版本,如果2013-04-13是不存,先尝试2013-04-13并且回滚到前一个版本。

启用并访问配置驱动器。

  1. To enable the configuration drive, pass the --config-drive true parameter to the openstack server create command.

    下面的例子启用了配置驱动器,并且传递了用户数据,两个文件,两组键/值元数据,这些都可以从配置驱动器中访问。

    $ openstack server create --config-drive true --image my-image-name \
      --flavor 1 --key-name mykey --user-data ./my-user-data.txt \
      --file /etc/network/interfaces=/home/myuser/instance-interfaces \
      --file known_hosts=/home/myuser/.ssh/known_hosts \
      --property role=webservers --property essential=false MYINSTANCE
    

    在``/etc/nova/nova.conf``文件中做如下配置可以配置计算服务总是创建配置驱动器。

    force_config_drive = true
    

    注解

    如果在 nova boot`命令传递了`–config-drive true``,则管理员将不能禁用配置驱动器。

  2. 如果你的客户机操作系统支持通过标签访问卷,可以将配置驱动器挂载到``/dev/disk/by-label/configurationDriveVolumeLabel``. 下面的例子中,配置驱动器的标签为 config-2 :

    # mkdir -p /mnt/config
    # mount /dev/disk/by-label/config-2 /mnt/config
    

注解

支持配置驱动器要求CirrOS的版本为0.3.1 或更高版本。

如果你的客户机操作系统不使用``udev``, 则不存在``/dev/disk/by-label`` 目录。

可以使用:command:blkid 命令来认证配置驱动器对应的块设备。例如,使用 m1.tiny``类型启动CirrOS 镜像,设备为/dev/vdb``:

# blkid -t LABEL="config-2" -odevice
/dev/vdb

认证后即可挂载设备:

# mkdir -p /mnt/config
# mount /dev/vdb /mnt/config

配置驱动内容

在该例中,配置驱动器的内容如下:

ec2/2009-04-04/meta-data.json
ec2/2009-04-04/user-data
ec2/latest/meta-data.json
ec2/latest/user-data
openstack/2012-08-10/meta_data.json
openstack/2012-08-10/user_data
openstack/content
openstack/content/0000
openstack/content/0001
openstack/latest/meta_data.json
openstack/latest/user_data

The files that appear on the configuration drive depend on the arguments that you pass to the openstack server create command.

OpenStack元数据格式

以下的示例展示了文件``openstack/2012-08-10/meta_data.json``和``openstack/latest/meta_data.json``的内容。这些文件都是相同的。文件内容已格式化以提高可读性。

{
    "availability_zone": "nova",
    "files": [
        {
            "content_path": "/content/0000",
            "path": "/etc/network/interfaces"
        },
        {
            "content_path": "/content/0001",
            "path": "known_hosts"
        }
    ],
    "hostname": "test.novalocal",
    "launch_index": 0,
    "name": "test",
    "meta": {
        "role": "webservers",
        "essential": "false"
    },
    "public_keys": {
        "mykey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDBqUfVvCSez0/Wfpd8dLLgZXV9GtXQ7hnMN+Z0OWQUyebVEHey1CXuin0uY1cAJMhUq8j98SiW+cU0sU4J3x5l2+xi1bodDm1BtFWVeLIOQINpfV1n8fKjHB+ynPpe1F6tMDvrFGUlJs44t30BrujMXBe8Rq44cCk6wqyjATA3rQ== Generated by Nova\n"
    },
    "uuid": "83679162-1378-4288-a2d4-70e13ec132aa"
}

Note the effect of the --file /etc/network/interfaces=/home/myuser/instance-interfaces argument that was passed to the openstack server create command. The contents of this file are contained in the openstack/content/0000 file on the configuration drive, and the path is specified as /etc/network/interfaces in the meta_data.json file.

EC2元数据格式

以下的示例展示了文件“ec2/2009-04-04/meta-data.json”和“ec2/latest/meta-data.json”的内容。这些文件都是同样的。文件的内容被格式化以提高文件的可读性。

{
    "ami-id": "ami-00000001",
    "ami-launch-index": 0,
    "ami-manifest-path": "FIXME",
    "block-device-mapping": {
        "ami": "sda1",
        "ephemeral0": "sda2",
        "root": "/dev/sda1",
        "swap": "sda3"
    },
    "hostname": "test.novalocal",
    "instance-action": "none",
    "instance-id": "i-00000001",
    "instance-type": "m1.tiny",
    "kernel-id": "aki-00000002",
    "local-hostname": "test.novalocal",
    "local-ipv4": null,
    "placement": {
        "availability-zone": "nova"
    },
    "public-hostname": "test.novalocal",
    "public-ipv4": "",
    "public-keys": {
        "0": {
            "openssh-key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDBqUfVvCSez0/Wfpd8dLLgZXV9GtXQ7hnMN+Z0OWQUyebVEHey1CXuin0uY1cAJMhUq8j98SiW+cU0sU4J3x5l2+xi1bodDm1BtFWVeLIOQINpfV1n8fKjHB+ynPpe1F6tMDvrFGUlJs44t30BrujMXBe8Rq44cCk6wqyjATA3rQ== Generated by Nova\n"
        }
    },
    "ramdisk-id": "ari-00000003",
    "reservation-id": "r-7lfps8wj",
    "security-groups": [
        "default"
    ]
}

用户数据

The openstack/2012-08-10/user_data, openstack/latest/user_data, ec2/2009-04-04/user-data, and ec2/latest/user-data file are present only if the --user-data flag and the contents of the user data file are passed to the openstack server create command.

配置驱动格式

配置驱动器的默认文件系统格式为ISO 9660. 如需显式设置为ISO 9660格式,在``/etc/nova/nova.conf`` 添加以下内容:

config_drive_format=iso9660

默认情况下,配置驱动器镜像只能作为磁盘驱动加载,而不能作为CD驱动器加载。如需作为CD驱动器加载,在``/etc/nova/nova.conf``中添加以下内容:

config_drive_cdrom=true

由于历史原因,可以将配置驱动器配置为使用VFAT格式,而不使用ISO 9660格式。ISO 9660在多操作系统支持方面优于VFAT. 如需显式配置为VFAT, 在``/etc/nova/nova.conf``加入如下内容:

config_drive_format=vfat

如果你选择了VFAT,配置驱动大小为64MB

注解

OpenStack Compute的Liberty版本,由于libvirt拷贝只读磁盘存在bug,无法在本地磁盘通过``config_drive``执行实时迁移。配置``config_drive``为VFAT时,实时迁移可正常执行。

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.