实习将近一个月了,期间不断努力,终于算是把OpenStack Ironic项目实现裸机部署的过程理解了一遍,并在小规模集群上成功实践。整理一些这段时间工作的内容,就算是一个阶段性的小项目总结了。
Ironic
Ironic是OpenStack的一个子项目,用于实现在云里像管理虚拟机一样管理裸机。
Ironic在OpenStack中的概念架构图如下
其中Bare Metal就是我们要控制的物理机了,Neutron为其提供网络服务,Cinder提供块存储服务,Glance则提供裸机部署时的镜像缓存服务,在部署过程中,我们的Ironic模块要和Neutron,Nova,Glance,Keystone这些核心的OpenStack项目配合,才能完美实现裸机部署的过程。
裸机部署过程中用到的一些核心的技术
Ironic裸机部署的过程
部署实践
1 2 3 4 5 6 7 8 9 10 11 12 13 |
auto eth0 iface eth0 inet static gateway 192.168.0.253 address 192.168.0.50/24 mtu 1500 #neutron auto eth1 iface eth1 inet manual up ip link set dev eth1 promisc on up ip link set dev eth1 up down ip link set dev eth1 down down ip link set dev eth1 promisc off |
eth0 做为 API_NET 接口,提供 OpenStack 的管理网络,我们给它分配一个静态IP,这里的地址需要和你的实际网络环境一致。
eth1 做为 EXT_NET 接口,提供 OpenStack 的 neutron 网络,这里我们启动网口但是不对它进行IP配置。
更新apt源,安装依赖
1 2 3 |
sudo apt-get update sudo apt-get upgrade sudo apt-get install python-jinja2 python-pip libssl-dev -fy |
配置 pip 加速,使用阿里云 pip 源
1 2 3 4 5 6 |
mkdir ~/.pip tee ~/.pip/pip.conf <<-'EOF' [global] trusted-host = mirrors.aliyun.com index-url = https://mirrors.aliyun.com/pypi/simple EOF |
安装 kolla,kolla-ansible,python-openstackclient
1 2 3 4 |
sudo pip install --upgrade pip sudo pip install ansible sudo pip install kolla-ansible==4.0.3 sudo pip install python-openstackclient |
Kolla部署Ironic配置
1 |
sudo cp -r /usr/local/share/kolla-ansible/etc_examples/kolla /etc/kolla |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
sudo vim /etc/kolla/global.yml # 关键配置修改 # Valid options are [ centos, oraclelinux, ubuntu ] kolla_base_distro: "centos" # Valid options are [ binary, source ] kolla_install_type: "binary" # Valid option is Docker repository tag openstack_release: "4.0.0" # api_net 的地址 kolla_internal_vip_address: "192.168.0.50" network_interface: "eth0" neutron_external_interface: "eth1" neutron_plugin_agent: "openvswitch" kolla_enable_tls_external: "no" ironic_cleaning_network: "public1" ironic_dnsmasq_dhcp_range: "192.168.8.1,192.168.8.5" enable_ironic: "yes" enable_haproxy: "no" |
Ironic 相关配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 启用内核支持模块,删除open-iscsi sudo modprobe configfs sudo apt-get remove open-iscsi sudo mkdir -p /etc/kolla/config/ironic cd /etc/kolla/config/ironic # 下载和存储ironic部署时引导镜像 sudo wget http://otcloud-gateway.bj.intel.com/deployment-img/ironic-agent.kernel sudo wget http://otcloud-gateway.bj.intel.com/deployment-img/ironic-agent.initramfs sudo mv ironic.conf /etc/kolla/config/ironic.conf #ironic.conf的内容 [DEFAULT] enabled_drivers=pxe_ipmitool [conductor] automated_clean=false # pxe 寻找tftp服务器是通过这个地址找的,如果不配置,pxe将无法从tftp服务拿到镜像,从而超时失败 [pxe] tftp_server=192.168.1.50 |
kolla快速部署环境
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 生成密码 kolla-genpwd # 初始化环境,安装一些基础依赖如 docker sudo kolla-ansible \ -i /usr/local/share/kolla-ansible/ansible/inventory/all-in-one \ bootstrap-servers # 配置dockerhub加速,我们用国内的阿里云源加速 sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://ao6wb0ej.mirror.aliyuncs.com"] } EOF # 配置完后重启docker sudo systemctl daemon-reload sudo service docker restart # 拉取镜像 sudo kolla-ansible pull # 预检查 sudo kolla-ansible prechecks \ -i /usr/local/share/kolla-ansible/ansible/inventory/all-in-one # 部署 sudo kolla-ansible deploy \ -i /usr/local/share/kolla-ansible/ansible/inventory/all-in-one # 生成部署环境文件,/etc/kolla/admin-openrc.sh 里面有重要的系统初始化配置 sudo kolla-ansible post-deploy |
配置br-ex
1 2 3 4 5 6 7 8 |
# 配置 eth1 即neutron对应的网卡所在的网络环境 auto br-ex iface br-ex inet static address 192.168.1.50 netmask 255.255.255.0 gateway 192.168.1.253 dns-nameserver 192.168.1.253 # 注释掉 eth1 原来的配置 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/bin/bash # ironic 管理网段 EXT_NET_CIDR='192.168.1.0/24' EXT_NET_RANGE='start=192.168.1.20,end=192.168.1.100' EXT_NET_GATEWAY='192.168.1.253' EXT_NET_CIDR_DNS='192.168.1.253' # ironic init setup # create ironic manage network openstack network create --provider-physical-network physnet1 \ --provider-network-type flat public1 openstack subnet create \ --allocation-pool ${EXT_NET_RANGE} --network public1 \ --subnet-range ${EXT_NET_CIDR} --gateway ${EXT_NET_GATEWAY} --dns-nameserver ${EXT_NET_CIDR_DNS} -- public1-subnet # 上传部署的引导镜像 openstack image create --disk-format aki --container-format aki --public \ --file /etc/kolla/config/ironic/ironic-agent.kernel deploy-vmlinuz openstack image create --disk-format ari --container-format ari --public \ --file /etc/kolla/config/ironic/ironic-agent.initramfs deploy-initrd |
1 2 3 |
sudo pip install diskimage-builder sudo apt install -y qemu-utils disk-image-create ubuntu baremetal dhcp-all-interfaces -o my-image |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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 MY_VMLINUZ_UUID=$(glance image-list|grep my-kernel|awk -F "| " '{print $2}') MY_INITRD_UUID=$(glance image-list|grep my-image.initrd|awk -F "| " '{print $2}') 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 |
1 2 3 4 5 6 7 8 9 10 |
# 生成密钥对 if [ ! -f ~/.ssh/id_rsa.pub ]; then echo Generating ssh key. ssh-keygen -t rsa -f ~/.ssh/id_rsa fi if [ -r ~/.ssh/id_rsa.pub ]; then echo Configuring nova public key and quotas. openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey fi |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
source server_ipmi # 物理裸机的配置,可小不可大于实际值 RAM=65536 DISK=800 VCPUS=32 HOST_CPU_ARCH=x86_64 export IRONIC_API_VERSION=1.20 DEPLOY_VMLINUZ_UUID=$(glance image-list|grep deploy-vmlinuz|awk -F "| " '{print $2}') DEPLOY_INITRD_UUID=$(glance image-list|grep deploy-initrd|awk -F "| " '{print $2}') # node1 创建 flavor nova flavor-create ai-bm-node1 1 ${RAM} ${DISK} ${VCPUS} nova flavor-key ai-bm-node1 set cpu_arch=x86_64 nova flavor-key ai-bm-node1 set resources:CUSTOM_BAREMETAL_NODE1_AI=1 nova flavor-key ai-bm-node1 set resources:VCPU=0 nova flavor-key ai-bm-node1 set resources:MEMORY_MB=0 nova flavor-key ai-bm-node1 set resources:DISK_GB=0 # 创建 node ironic node-create -d pxe_ipmitool -n node1 NODE1_UUID=$(ironic node-list|grep node1|awk -F "| " '{print $2}') # 设置 node 的 ipmi信息 ironic node-update $NODE1_UUID add driver_info/ipmi_username=$s1_ipmi_username \ driver_info/ipmi_password=$s1_ipmi_password driver_info/ipmi_address=$s1_ipmi_address \ driver_info/ipmi_terminal_port=623 # 设置 node 的引导镜像信息 ironic node-update $NODE1_UUID add driver_info/deploy_kernel=$DEPLOY_VMLINUZ_UUID \ driver_info/deploy_ramdisk=$DEPLOY_INITRD_UUID # 设置 node 的基本配置信息 ironic node-update $NODE1_UUID add properties/cpus=${VCPUS} properties/memory_mb=${RAM} \ properties/local_gb=${DISK} properties/cpu_arch=${HOST_CPU_ARCH} # 设置 node 的resource-class,方面node判断部署到哪个裸机节点 openstack --os-baremetal-api-version 1.21 baremetal node set $NODE1_UUID \ --resource-class CUSTOM_BAREMETAL_NODE1_AI # 设置 启动网口的 MAC 地址,即 node 的 port ironic port-create -n $NODE1_UUID -a $s1_nic_mac_address # 设置 node状态为 provide ironic --ironic-api-version 1.20 node-set-provision-state $NODE1_UUID manage ironic --ironic-api-version 1.20 node-set-provision-state $NODE1_UUID provide # 启动部署 openstack server create --image my-image --flavor ai-bm-node1 \ --key-name mykey --network public1 node1 |
本文涉及到的所有脚本在 https://github.com/vajn/ironic_setup 中,详细部署可参考这套脚本
未完,待补部署过程中,裸机节点的控制台输出截图