本文介绍如果使用devstack搭建Ironic环境,以及在安装的过程中可能遇到的问题。
Ubuntu14.04虚拟机一台,建议选择高配的机器,因为会在上面创建三个虚拟机模拟bare metal机器
cp /etc/apt/sources.list /etc/apt/sources.list.bak vim /etc/apt/sources.list
网易源:
deb http://mirrors.163.com/ubuntu/ precise-updates main restricted deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted deb http://mirrors.163.com/ubuntu/ precise universe deb-src http://mirrors.163.com/ubuntu/ precise universe deb http://mirrors.163.com/ubuntu/ precise-updates universe deb-src http://mirrors.163.com/ubuntu/ precise-updates universe deb http://mirrors.163.com/ubuntu/ precise multiverse deb-src http://mirrors.163.com/ubuntu/ precise multiverse deb http://mirrors.163.com/ubuntu/ precise-updates multiverse deb-src http://mirrors.163.com/ubuntu/ precise-updates multiverse deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
[[local|localrc]] # Credentials ADMIN_PASSWORD=12345 DATABASE_PASSWORD=12345 RABBIT_PASSWORD=12345 SERVICE_PASSWORD=12345 SERVICE_TOKEN=12345
# Enable Ironic API and Ironic Conductor enable_service ironic enable_service ir-api enable_service ir-cond
# Enable Neutron which is required by Ironic and disable nova-network. disable_service n-net disable_service n-novnc enable_service q-svc enable_service q-agt enable_service q-dhcp enable_service q-l3 enable_service q-meta enable_service neutron
# Disable Horizon disable_service horizon
# Disable Heat disable_service heat h-api h-api-cfn h-api-cw h-eng
# Disable Cinder disable_service cinder c-sch c-api c-vol
# Create 3 virtual machines to pose as Ironic's baremetal nodes. IRONIC_VM_COUNT=3 IRONIC_VM_SSH_PORT=22 IRONIC_BAREMETAL_BASIC_OPS=True
# The parameters below represent the minimum possible values to create # functional nodes. IRONIC_VM_SPECS_RAM=1024 IRONIC_VM_SPECS_DISK=10
# Size of the ephemeral partition in GB. Use 0 for no ephemeral partition. IRONIC_VM_EPHEMERAL_DISK=0
VIRT_DRIVER=ironic
# By default, DevStack creates a 10.0.0.0/24 network for instances. # If this overlaps with the hosts network, you may adjust with the # following. NETWORK_GATEWAY=10.1.0.1 FIXED_RANGE=10.1.0.0/24 FIXED_NETWORK_SIZE=256
# Log all output to files LOGFILE=$HOME/devstack.log LOGDIR=$HOME/logs IRONIC_VM_LOG_DIR=$HOME/ironic-bm-logs IRONIC_SSH_TIMEOUT=10
IRONIC_SSH_TIMEOUT=10即可
由于安装过程中需要下载大量镜像文件,所以时间比较漫长
安装Ironic结束后,根据local.conf中的配置,会通过libvirt创建三个虚拟机作为bare metal机器,通过
stack@devstack:~/ironic/ironic/drivers$ sudo virsh list --all
Id Name State ---------------------------------------------------- - baremetalbrbm_0 shut off - baremetalbrbm_1 shut off - baremetalbrbm_2 shut off
查看这三个bare metal虚拟机
在Ironic中,有node的概念,每个node代表着一个物理机(devstack中代表一个虚拟机),通过
stack@devstack:~/ironic/ironic/drivers$ ironic node-list +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ | UUID | Name | Instance UUID | Power State | Provisioning State | Maintenance | +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ | 9d35b836-4ffd-408c-816f-ff912192adaf | node-0 | e2b36cc9-3e41-418e-9531-3357fca1d2ff | power on | active | False | | b66839b1-4dfc-4791-8285-71ad0964c433 | node-1 | e2ce2efd-6aa1-4c5c-8702-1bd9dd0a0b1a | power on | active | False | | 926364e1-b35d-4a58-8ed1-6333ff6be8cc | node-2 | None | power off | available | False | +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+
查看当前注册在Ironic里的node信息,当通过nova boot创建虚拟机时,会自动分配一个node和nova匹配,当虚拟机创建成功后,就会出现上述输出了。
(由于没有baremetal机器,本示例中没有配置TFTP和DHCP Server)
部署的全部文档都在这里这里
需要指出的是,部署完Ironic后,nova相应的配置已经修改成了Ironic的相关资源了,比如:
/etc/nova/nova.conf
scheduler_host_manager = nova.scheduler.ironic_host_manager.IronicHostManager compute_driver = nova.virt.ironic.IronicDriver
首先,根据上面对于Ironic的描述,如果新部署一个物理机,首先要在Ironic里创建一个node。使用命令:
ironic node-create -d pxe_ipmitool
通过命令:
ironic driver-properties pxe_ipmitool
来查看pxe_ipmitool可能使用到的哪些参数。
使用命令:
ironic node-update $NODE_UUID add \ driver_info/ipmi_username=$USER \ driver_info/ipmi_password=$PASS \ driver_info/ipmi_address=$IP_ADDRESS
通过设置node的IPMI信息来匹配对应物理设备,IPMI信息是由厂商预设的,可通过物理设备进行查询。
在部署物理机时,使用的Ironic的driver是pxe_ipmitool。
需要说明的是,在Ironic中,有两种常用的driver,一个是pxe_ssh,一个是pxe_ipmitool,关于这两种driver的比较,详细说明在这里,摘要如下:
Ironic pxe_ssh driver vs. agent_ipmi driver
The Juno version of Ironic has eight drivers. These driver classes are inherited from a base class that
defines six types of interfaces: power, deploy, console, management, rescue, and vendor.
These interfaces are assigned with a module class instance that has the extension points
that define the vendor-specific implementations of each Ironic driver. For example,
the pxe_ssh driver uses the PXE implementation module for deploy and vendor interfaces
while the SSH implementation module is used for power and management interfaces.
The rationale for this is a VM’s boot device can be configured to use PXE, but the power
state of VMs is only manageable through the CLI of the hypervisor it is running on.
However, when provisioning physical machines, there is no hypervisor involved in the process;
therefore, a different Ironic driver should be used in this case to do the task.
The agent_ipmitool driver is a widely used Ironic driver for physical machine provisioning.
It uses the agent modules for deploy and vendor interfaces and leverages the IPMI tool module
for the power and management interfaces. DevStack will register a custom ramdisk to the image
repository when the agent_ipmitool driver is set as the deploy driver for Ironic. This custom
ramdisk has an Ironic Python Agent, known as IPA, included that will execute disk partitioning,
OS image installation, etc. The IPMI tool module uses the ipmitool utility to set boot devices
and change power states of physical machines. Figures 1 and 2 show how each driver interacts
with other services and the provision target. The DevStack patch from Intel enables the use of
the agent_ipmitool driver through DevStack, which makes Ironic capable of sending IPMI requests
to physical machines.
大体说来,pxe_ssh适用于虚拟环境(在devstack中一般用这种driver),pxe_ipmitool适用于物理环境。
下一步,制作镜像。
详细说明在这里。
首先下载OpenStack制作镜像使用的工具:
sudo pip install diskimage-builder
然后下载部署镜像和用户镜像,关于这两种镜像,部署镜像用来给裸机使用,来引导最终的OS;用户镜像是用户最终会使用到的镜像
准备镜像:
关于glance image-create中使用到的disk format 和 container format,请参考 这里
Partition images: disk-image-create ubuntu baremetal dhcp-all-interfaces grub2 -o my-image Whole disk images: disk-image-create ubuntu vm dhcp-all-interfaces grub2 -o my-image
命令1会生成3个文件和一个文件夹:
my-image.d my-image.initrd my-image.qcow2 my-image.vmlinuz
my-image.initrd:initrd是initial ramdisk的缩写,是Linux系统引导过程中使用到的一个临时的根文件系统,ramdisk里包括一些基本的Linux命令,比如ls,cd,tftp等,用于将真正的文件系统加载到本地
my-image.vmlinuz:vmlinuz是“Virtual Memory”的缩写, vmlinuz是可引导的、压缩的内核
my-image.qcow2:qcow2是qemu支持的一种格式,是最终用户会使用到的镜像
创建用户镜像:
glance image-create --name my-kernel --visibility public \ --disk-format aki --container-format aki < my-image.vmlinuz
glance image-create --name my-image.initrd --visibility public \ --disk-format ari --container-format ari < my-image.initrd
glance image-create --name my-image --visibility public \ --disk-format qcow2 --container-format bare --property \ kernel_id=$MY_VMLINUZ_UUID --property \ ramdisk_id=$MY_INITRD_UUID < my-image.qcow2
disk-image-create ironic-agent fedora -o ironic-deploy
创建部署镜像:
glance image-create --name deploy-vmlinuz --visibility public \ --disk-format aki --container-format aki < my-deploy-ramdisk.kernel
glance image-create --name deploy-initrd --visibility public \ --disk-format ari --container-format ari < my-deploy-ramdisk.initramfs
通过命令
ironic node-update $NODE_UUID add \ properties/cpus=$CPU \ properties/memory_mb=$RAM_MB \ properties/local_gb=$DISK_GB \ properties/cpu_arch=$ARCH
修改node的flavor信息。注:当部署完成Ironic后,会创建一个baremetal的flavor,该flavor中会有上述需要填写的参数。
通过命令:
ironic node-update $NODE_UUID add \ driver_info/deploy_kernel=$DEPLOY_VMLINUZ_UUID \ driver_info/deploy_ramdisk=$DEPLOY_INITRD_UUID
其中
DEPLOY_VMLINUZ_UUID
DEPLOY_INITRD_UUID
是『创建部署镜像』中上传到glance中的镜像id号
neutron net-create ironic-network
neutron subnet-create $IRONIC_NETWORK $NETWORK_CIDR --name $SUBNET_NAME \ --ip-version=4 --gateway=$GATEWAY_IP --allocation-pool \ start=$START_IP,end=$END_IP --enable-dhcp
创建路由器和上面的子网想连
neutron router-create ironic-router
neutron router-interface-add [router_id] [subnet_id]
通过命令:
ironic node-validate $NODE_UUID
输出的结果一般都会错误信息,根据错误信息进行相应操作。
比如:该node缺少网卡,使用命令创建网卡:
ironic port-create -n $NODE_UUID -a 00:a0:d1:ed:06:14
或者报错说没有instance_info相关信息,缺少image_source,disk等等
使用命令修改相关信息:
ironic node-update $NODE_UUID add instance_info/ramdisk=$USER_IMAGE_RAMDISK_UUID \
instance_info/kernel=$USER_IMAGE_KERNEL_UUID \
instance_info/image_source=$USER_IMAGE_QCOW2_UUID
创建port时候需要注意MAC地址的填写,这个MAC要写上物理网卡的真实MAC,这个MAC会记录在dnsmasq的配置文件中(/opt/stack/data/neutron/dhcp/xxx/host),如:
00:a0:d1:ed:06:14,host-10-0-0-103.openstacklocal.,10.0.0.103
当MAC为00:a0:d1:ed:06:14的物理机DHCP的时候,当该dnsmasq进程接受到MAC为00:a0:d1:ed:06:14的DHCP请求,它就会读取host文件,并将
相应的IP地址(10.0.0.103)回复给物理机作为DHCP的Offer
使用nova boot命令启动:
nova boot --flavor baremetal --image my-image --nic net-id=$IRONIC_NETWORK instance-1
由于在创建Ironic服务时已经对nova boot进行设定,所以此时的nova boot并不是传统意义上的虚拟机创建,而是通过Ironic服务在裸机节点上创建系统。
需要特别指出的是,如果虚拟机创建失败,报错『No valid host was found』
参考文档这里
一般都是由于node中的flavor信息和nova所期待的flavor信息不匹配导致的,修改相应的node的flavor信息即可。
现在的问题是:不知道如何设置fedora的root密码,导致登陆不进去
PS:视频链接
这是在执行完nova boot后,物理服务器的IPMI界面看到的:
http://youtube.com/watch?v=BbSK8kUc4nk
Q:物理机在DHCP获取到IP地址后如何链接到TFTP服务器上?
A:首先我们要明确的是,物理机的IP地址是Neutron里的Dnsmasq服务提供的,大致过程如下,当nova boot(指定network)一个虚拟机时,Neutron Server会在Dnsmasq的配置
文件中写入一条数据,大致如下:
00:a0:d1:ed:06:14,host-10-0-0-202.openstacklocal.,10.0.0.202,set:167f1d69-fe3b-4e4b-bc2f-f2196e149dd8
这是什么意思呢?前面几位的意思是,要提供给MAC为00:a0:d1:ed:06:14的物理网卡IP地址,FQDN是host-10-0-0-202.openstacklocal.,要提供的IP地址是10.0.0.202,设置tag为
167f1d69-fe3b-4e4b-bc2f-f2196e149dd8,这是Neutron里的一个port,详细信息:
[stack@localhost pxelinux.cfg]$ neutron port-show 167f1d69-fe3b-4e4b-bc2f-f2196e149dd8 +-----------------------+--------------------------------------------------------------------------------------------------------+ | Field | Value | +-----------------------+--------------------------------------------------------------------------------------------------------+ ... ... | extra_dhcp_opts | {"opt_value": "pxelinux.0", "ip_version": 4, "opt_name": "bootfile-name"} | | | {"opt_value": "10.0.0.103", "ip_version": 4, "opt_name": "server-ip-address"} | | | {"opt_value": "10.0.0.103", "ip_version": 4, "opt_name": "tftp-server"} | ... ... +-----------------------+--------------------------------------------------------------------------------------------------------+
可以观察到这个port指定了一些DHCP时的信息,对应到配置文件中是(/opt/stack/data/neutron/dhcp/cf9e60fa-1e62-4af7-af58-b9407c209824/opts):
tag:167f1d69-fe3b-4e4b-bc2f-f2196e149dd8,option:bootfile-name,pxelinux.0 tag:167f1d69-fe3b-4e4b-bc2f-f2196e149dd8,option:server-ip-address,10.0.0.103 tag:167f1d69-fe3b-4e4b-bc2f-f2196e149dd8,option:tftp-server,10.0.0.103
关于TFTP服务器的配置在Ironic的配置文件中(/etc/ironic/ironic.conf):
[pxe] pxe_append_params = nofb nomodeset vga=normal console=ttyS0 rootfstype=ramfs tftp_master_path = /opt/stack/data/ironic/tftpboot/master_images tftp_root = /opt/stack/data/ironic/tftpboot tftp_server = 10.0.0.103