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 安装位置的完整路径。
要使用裸金属服务的配置驱动器,您不需要准备任何东西,因为裸金属服务会正确处理配置驱动器。
镜像要求
An image built with a recent version of the cloud-init package can automatically access metadata passed through the configuration drive. The following table lists the references for cloud-init versions mapped to a particular operating system:
Operating system | Reference for cloud-init version |
---|---|
Ubuntu | http://packages.ubuntu.com/search?keywords=cloud-init |
Fedora (RHEL) | https://www.rpmfind.net/linux/rpm2html/search.php?query=cloud-init |
openSUSE (SLE) | http://software.opensuse.org/download.html?project=Cloud%3ATools&package=cloud-init |
如果镜像没有安装云初始化包,您必须自定义镜像运行一个在启动时安装配置驱动的脚本,读取驱动器的数据,并采取适当的行动,如添加一个帐户的公钥。您可以读取有关如何在配置驱动器上的数据的详细信息。
在Xen环境下使用配置驱动器,使用``xenapi_disable_agent`` 配置参数来关闭代理。
向导
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``,则管理员将不能禁用配置驱动器。
如果你的客户机操作系统支持通过标签访问卷,可以将配置驱动器挂载到``/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/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/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时,实时迁移可正常执行。
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.