在部署openstack云平台环境的时候,需要上传镜像到glance。

首先下载iso镜像,这里下载了centos6.5镜像,放到/usr/local/src目录下
然后用OZ工具制作openstack的镜像

*******************************安装libvirt虚拟机软件****************************************
[root@openstack-server src]# yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install
[root@openstack-server src]# systemctl enable libvirtd && systemctl start libvirtd
************************************************************************************

[root@openstack-server src]#yum install -y oz libguestfs-tools

[root@openstack-server src]# pwd
/usr/local/src
[root@openstack-server src]# ll CentOS-6.5-x86_64-bin-DVD1.iso #下载的iso镜像
-rw-r--r--. 1 root root 4467982336 Nov 29 2013 CentOS-6.5-x86_64-bin-DVD1.iso
[root@openstack-server src]# cat CentOS6u5-x86_64.tdl #创建tdl 文件
<template>
<name>CentOS6u5-x86_64</name>
<description>CentOS6u5-x86_64 template</description>
<os>
<name>CentOS-6</name>
<version>5</version>
<arch>x86_64</arch>
<rootpw>PASSWORD</rootpw>             #这个是虚拟机创建好后,root的登陆密码,密码是在这个镜像里定义的!
<install type='iso'>
<iso>file:///usr/local/src/CentOS-6.5-x86_64-bin-DVD1.iso</iso>
</install>
</os>
<commands>                  #centos7系统里没有/boot/grub/grub.conf文件,这块可以不用写,但写了也无妨。这里我是centos7,也写了
<command name='console'>
sed -i 's/ rhgb//g' /boot/grub/grub.conf
sed -i 's/ quiet//g' /boot/grub/grub.conf
sed -i 's/ console=tty0 / serial=tty0 console=ttyS0,115200n8 /g' /boot/grub/grub.conf
</command>
</commands>
</template>

在用OZ工具制作openstack镜像,有报错:
[root@openstack-server src]# oz-install -u -d3 CentOS6u5-x86_64.tdl #报错如下:
..................
raise oz.OzException.OzException("Could not find a libvirt bridge. Please run 'virsh net-start default' to start the default libvirt network, or see http://github.com/clalancette/oz/wiki/Oz-Network-Configuration for more information")
oz.OzException.OzException: Could not find a libvirt bridge. Please run 'virsh net-start default' to start the default libvirt network, or see http://github.com/clalancette/oz/wiki/Oz-Network-Configuration for more information

[root@openstack-server src]# virsh net-start default
error: failed to get network 'default'
error: Network not found: no network with matching name 'default'

查阅资料,说是因为 default 网络不存在
回想了一下,我开始在捣鼓openstack 的时候,可能用命令删除了default,也或许没有启动default网络
因为在不同的环境下,default.xml 的存放路径不同,这里笔者以自己的 centos7 为例

[root@openstack-server src]# find / -name "default.xml"
/etc/libvirt/qemu/networks/autostart/default.xml
/etc/libvirt/qemu/networks/default.xml
/usr/share/backgrounds/default.xml
/usr/share/libvirt/networks/default.xml
[root@openstack-server src]# virsh net-define /usr/share/libvirt/networks/default.xml
Network default defined from /usr/share/libvirt/networks/default.xml

[root@openstack-server src]# virsh net-start default
Network default started

[root@openstack-server src]# virsh net-list
Name State Autostart Persistent
----------------------------------------------------------
default active no yes

[root@openstack-server src]#

然后接着再进行openstack镜像的制作:
[root@openstack-server src]# oz-install -u -d3 CentOS6u5-x86_64.tdl
libvirt bridge name is virbr0
Libvirt type is kvm
Name: CentOS6u5-x86_64, UUID: 0a9b1d18-f517-40ae-9de9-1fd6101878e2
MAC: 52:54:00:fb:0b:c9, distro: CentOS-6
update: 5, arch: x86_64, diskimage: /var/lib/libvirt/images/CentOS6u5-x86_64.dsk
nicmodel: virtio, clockoffset: utc
mousetype: ps2, disk_bus: virtio, disk_dev: vda
icicletmp: /var/lib/oz/icicletmp/CentOS6u5-x86_64, listen_port: 36050
Original ISO path: /var/lib/oz/isos/CentOS-65x86_64-iso.iso
Modified ISO cache: /var/lib/oz/isos/CentOS-65x86_64-iso-oz.iso
Output ISO path: /var/lib/libvirt/images/CentOS6u5-x86_64-iso-oz.iso
ISO content path: /var/lib/oz/isocontent/CentOS6u5-x86_64-iso
Checking for guest conflicts with CentOS6u5-x86_64
Generating install media
Attempting to get the lock for /var/lib/oz/isos/CentOS-65x86_64-iso.iso
Got the lock for /var/lib/oz/isos/CentOS-65x86_64-iso.iso
Fetching the original media
Fetching the original install media from file:///usr/local/src/CentOS-6.5-x86_64-bin-DVD1.iso
15kB of 4363264kB
10255kB of 4363264kB
20494kB of 4363264kB
30734kB of 4363264kB
40973kB of 4363264kB
51212kB of 4363264kB
....................
....................
....................
Cleaning up guestfs handle for CentOS6u5-x86_64
Syncing
Unmounting all
Libvirt XML was written to CentOS6u5-x86_64Aug_30_2016-13:47:18

注意:
镜像制作完默认会存放到/var/lib/libvirt/images/ 目录下,可以在/etc/oz/oz.cfg 配置文件中进行修改路径。

[root@openstack-server src]# cd /var/lib/libvirt/images/
[root@openstack-server images]# pwd
/var/lib/libvirt/images
[root@openstack-server images]# ll
total 1087336
-rw-rw-rw-. 1 root root 10737418240 Aug 30 13:47 CentOS6u5-x86_64.dsk
[root@openstack-server images]# virt-sysprep --add CentOS6u5-x86_64.dsk
[ 0.0] Examining the guest ...
[ 5.0] Performing "abrt-data" ...
...........
[ 5.0] Setting a random seed
[ 5.0] Performing "lvm-uuids" ...

查看文件信息
[root@openstack-server images]# qemu-img info CentOS6u5-x86_64.dsk
image: CentOS6u5-x86_64.dsk
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 1.0G

上传镜像到 Glance
[root@openstack-server images]# glance image-create --name "CentOS-6.5" --file /var/lib/libvirt/images/CentOS6u5-x86_64.dsk --disk-format qcow2 --container-format bare --visibility public --progress
[=============================>] 100%

+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | 2d16e5ef687fead34fa801aafe37f058 |
| container_format | bare |
| created_at | 2016-08-30T06:03:22Z |
| disk_format | qcow2 |
| id | 508db9d4-6c9f-459d-8782-065ee8b6f2c2 |
| min_disk | 0 |
| min_ram | 0 |
| name | CentOS-6.5 |
| owner | 65a0c00638c247a0a274837aa6eb165f |
| protected | False |
| size | 10737418240 |
| status | active |
| tags | [] |
| updated_at | 2016-08-30T06:04:26Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------+

查看镜像
[root@openstack-server images]# glance image-list
+--------------------------------------+------------+
| ID | Name |
+--------------------------------------+------------+
| 508db9d4-6c9f-459d-8782-065ee8b6f2c2 | CentOS-6.5 |
+--------------------------------------+------------+

登陆openstack界面,发现可以查看到上面已经上传到glance里面的镜像。上面使用OZ工具制作的openstack所需要的Centos6/Centos7镜像的默认大小是10G(如下图)。

----------------------------------------------------------------------------------------------------------
注意:

如果不想用OZ工具制作,可以直接下载centos的qcow2格式镜像

下载地址:http://cloud.centos.org/centos 【有centos6/7的镜像】

比如:下载centos7的qcow2格式镜像
#wget http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2

上传到 galnce
#glance image-create --name "CentOS-7-x86_64" --disk-format qcow2 --container-format bare --file
CentOS-7-x86_64-GenericCloud.qcow2 --visibility public --progress

-------------------------------------------------------------------------------------------------------------

当然,也可以使用OZ工具制作openstack需要的qcow2的Centos7镜像
[root@openstack-server src]# pwd
/usr/local/src
[root@openstack-server src]# ls CentOS-7-x86_64-DVD-1511.iso
CentOS-7-x86_64-DVD-1511.iso
[root@openstack-server src]# ls CentOS-7-x86_64.tdl
CentOS-7-x86_64.tdl
[root@openstack-server src]# cat CentOS-7-x86_64.tdl
<template>
<name>CentOS-7-x86_64</name>
<description>CentOS-7-x86_64 template</description>
<os>
<name>CentOS-7</name>
<version>2</version>
<arch>x86_64</arch>
<rootpw>PASSWORD</rootpw>
<install type='iso'>
<iso>file:///usr/local/src/CentOS-7-x86_64-DVD-1511.iso</iso>
</install>
</os>
<commands>
<command name='console'>
sed -i 's/ rhgb//g' /boot/grub/grub.conf
sed -i 's/ quiet//g' /boot/grub/grub.conf
sed -i 's/ console=tty0 / serial=tty0 console=ttyS0,115200n8 /g' /boot/grub/grub.conf
</command>
</commands>
</template>

[root@openstack-server src]# oz-install -u -d3 CentOS-7-x86_64.tdl

后面的步骤跟上面制作Centos6.5版本的操作一样

----------------------------------------------------------------------------------------------------------

下面是centos6.8版本镜像制作的tdl文件模板:
[root@openstack-server src]# pwd
/usr/local/src
[root@openstack-server src]# ls CentOS-6.8-x86_64-bin-DVD1.iso
CentOS-6.8-x86_64-bin-DVD1.iso

[root@openstack-server src]# cat CentOS6u8-x86_64.tdl
<template>
<name>CentOS6u8-x86_64</name>
<description>CentOS6u8-x86_64 template</description>
<os>
<name>CentOS-6</name>
<version>8</version>
<arch>x86_64</arch>
<rootpw>PASSWORD</rootpw>
<install type='iso'>
<iso>file:///usr/local/src/CentOS-6.8-x86_64-bin-DVD1.iso</iso>
</install>
</os>
<commands>
<command name='console'>
sed -i 's/ rhgb//g' /boot/grub/grub.conf
sed -i 's/ quiet//g' /boot/grub/grub.conf
sed -i 's/ console=tty0 / serial=tty0 console=ttyS0,115200n8 /g' /boot/grub/grub.conf
</command>
</commands>
</template>

[root@openstack-server src]# oz-install -u -d3 CentOS6u8-x86_64.tdl

后面的步骤跟上面制作Centos6.5版本的操作一样

------------------------------------------------------------------------------------------------------------

下面说下使用OZ工具制作openstack虚拟化环境下的ubuntu版本镜像的过程记录:

下面以ubuntu12.04版本为例,tdl内容参考OZ在github上的模板样式。
https://github.com/rcbops/oz-image-build/tree/master/templates

[root@openstack-server src]# pwd
/usr/local/src
[root@openstack-server src]# ls ubuntu-12.04-server-amd64.iso
ubuntu-12.04-server-amd64.iso

下面ubuntu的tdl模板可直接使用~
[root@openstack-server src]# cat ubuntu-12.04_x86_64.tdl 
<template>
<name>ubuntu-12.04_x86_64</name>
<description>Ubuntu 12.04 15GB template</description>
<disk>
<size>15</size>                                                  #镜像大小为15G
</disk>
<os>
<name>Ubuntu</name>
<version>12.04</version>
<arch>x86_64</arch>
<rootpw>ROOT-PW_CHANGE-ME!!!</rootpw>                  #root账号登录密码
<install type='iso'>
<iso>file:///usr/local/src/ubuntu-12.04-server-amd64.iso</iso>
</install>
</os>
<commands>
<command name='console'>
sed -i 's/splash//g' /etc/default/grub
sed -i 's/quiet/console=ttyS0/g' /etc/default/grub
/usr/sbin/update-grub
</command>
<command name='update'>
apt-get update
apt-get -y upgrade
echo "cloud-init cloud-init/datasources string NoCloud, OVF, Ec2" > /tmp/debconf-selections
/usr/bin/debconf-set-selections /tmp/debconf-selections
rm -f /tmp/debconf-selections
apt-get -y install cloud-init
apt-get clean
/usr/sbin/useradd -m stack
echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
sed -i 's/^user: ubuntu/user: stack/g' /etc/cloud/cloud.cfg
echo -n > /etc/udev/rules.d/70-persistent-net.rules
echo -n > /lib/udev/rules.d/75-persistent-net-generator.rules
</command>
</commands>
</template>

[root@openstack-server src]# oz-install -u -d3 ubuntu-12.04_x86_64.tdl
............
............

Waiting for ubuntu-12.04_x86_64 to finish installing, 1200/1200
Waiting for ubuntu-12.04_x86_64 to finish installing, 1190/1200
Waiting for ubuntu-12.04_x86_64 to finish installing, 1180/1200
Waiting for ubuntu-12.04_x86_64 to finish installing, 1170/1200

............
............
Unmounting all
Libvirt XML was written to ubuntu-12.04_x86_64Oct_31_2016-23:01:36

[root@openstack-server src]# cd /var/lib/oz/isos/
[root@openstack-server isos]# pwd
/var/lib/oz/isos
[root@openstack-server isos]# ls                    #发现oz下已经有了ubuntu12.04镜像
Ubuntu12.04x86_64-iso.iso

[root@openstack-server src]# cd /var/lib/libvirt/images/
[root@openstack-server images]# ls
ubuntu-12.04_x86_64.dsk
[root@openstack-server images]# virt-sysprep --add ubuntu-12.04_x86_64.dsk 
[ 0.0] Examining the guest ...
...........
[ 5.0] Performing "lvm-uuids" .

[root@openstack-server images]# qemu-img info ubuntu-12.04_x86_64.dsk 
image: ubuntu-12.04_x86_64.dsk
file format: raw
virtual size: 15G (16106127360 bytes)
disk size: 1.3G

[root@openstack-server images]# glance image-create --name "ubuntu-12.04" --file /var/lib/libvirt/images/ubuntu-12.04_x86_64.dsk --disk-format qcow2 --container-format bare --visibility public --progress
[=============================>] 100%
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | 15d25f4da354d8fbd5a248fc01894ceb |
| container_format | bare |
| created_at | 2016-10-31T15:25:29Z |
| disk_format | qcow2 |
| id | 042073da-e6cb-4b0b-97dd-1d5ef5be236a |
| min_disk | 0 |
| min_ram | 0 |
| name | ubuntu-12.04 |
| owner | 0cd3632df93d48d6b2c24c67f70e56b8 |
| protected | False |
| size | 64424509440 |
| status | active |
| tags | [] |
| updated_at | 2016-10-31T15:38:09Z |
| virtual_size | None |
| visibility | public |
+------------------+-----------------------------------------+

[root@linux-node2 images]# glance image-list
+--------------------------------------+---------------------+
| ID | Name |
+--------------------------------------+---------------------+
| 042073da-e6cb-4b0b-97dd-1d5ef5be236a | ubuntu-12.04 |
+--------------------------------------+---------------------+

登录openstack界面,发现上面上传到openstack的ubuntu12.04镜像已经有了,镜像大小为15G。

ubuntu各历史版本镜像下载地址:http://releases.ubuntu.com/

ubuntu版本升级记录,详情参考:http://www.cnblogs.com/kevingrace/p/6084118.html

完整部署CentOS7.2+OpenStack+kvm 云平台环境(4)--用OZ工具制作openstack镜像的更多相关文章

  1. 完整部署CentOS7.2+OpenStack+kvm 云平台环境(3)--为虚拟机指定固定ip

    之前在测试环境(centos7.2)上部署了openstack云平台(完整部署CentOS7.2+OpenStack+kvm 云平台环境(1)--基础环境搭建),openstack在neutron组网 ...

  2. 完整部署CentOS7.2+OpenStack+kvm 云平台环境(2)--云硬盘等后续配置

    继上一篇博客介绍了完整部署CentOS7.2+OpenStack+kvm 云平台环境(1)--基础环境搭建,本篇继续讲述后续部分的内容 1 虚拟机相关1.1 虚拟机位置介绍 openstack上创建的 ...

  3. 完整部署CentOS7.2+OpenStack+kvm 云平台环境(1)--基础环境搭建

    公司在IDC机房有两台很高配置的服务器,计划在上面部署openstack云平台虚拟化环境,用于承载后期开发测试和其他的一些对内业务.以下对openstack的部署过程及其使用做一详细介绍,仅仅依据本人 ...

  4. 完整部署CentOS7.2+OpenStack+kvm 云平台环境(6)--在线调整虚拟机的大小

    前面提到过openstack环境部署及创建虚拟机的完整过程,然后有时候会发现创建的虚拟机规格太小,满足不了业务需求:亦或是虚拟机规格太大,容易造成资源浪费.于是就有了在线拉伸虚拟机规格的需求.所以,今 ...

  5. 完整部署CentOS7.2+OpenStack+kvm 云平台环境(5)--问题解决

    一.[root@openstack-server ~]# nova listERROR (CommandError): You must provide a username or user id v ...

  6. 用OZ工具制作openstack镜像

    在部署openstack云平台环境的时候,需要上传镜像到glance. 首先下载iso镜像,这里下载了centos7.2镜像,放到/iso目录下 然后用OZ工具制作openstack的镜像 1.安装l ...

  7. 《4》CentOS7.0+OpenStack+kvm云平台部署—配置Nova

    感谢朋友支持本博客,欢迎共同探讨交流,因为能力和时间有限,错误之处在所难免,欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  8. 《5》CentOS7.0+OpenStack+kvm云平台的部署—组态Horizon

    感谢朋友支持本博客,欢迎共同探讨交流,因为能力和时间有限,错误之处在所难免,欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  9. 《3》CentOS7.0+OpenStack+kvm云平台部署—配置Glance

    感谢朋友支持本博客,欢迎共同探讨交流.因为能力和时间有限,错误之处在所难免,欢迎指正. 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

随机推荐

  1. git 版本回退

    由于操作失误,需要将代码进行版本回退,首先在本地仓库执行了“git reset --hard HEAD^”命令,这样只会回退本地仓库的代码,但是我的代码之前已经push到了远程库中,查看远程仓库,发现 ...

  2. Linux网络相关配置

    一.修改网卡相关配置 Linux网络参数是在/etc/sysconfig/network-scripts/ifcfg-eth0中设置,其中ifcfg-eth0表示是第一个网卡,如果还有另外一块网卡,则 ...

  3. 分布式文件系统 - FastDFS 配置 Nginx 模块及上传测试

    也不说废话,直接干 上一篇 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署 中安装了 FastDFS 后,并配置启动了 Tracker 和 Storage 服务,已经可以上传文件 ...

  4. 【特种兵系列】String中的==和equals()

    1. 小样示例 public static void main(String[] args) { String a = "a" + "b" + 123; Str ...

  5. 高性能 TCP & UDP 通信框架 HP-Socket v3.5.3

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

  6. 高性能 TCP & UDP 通信框架 HP-Socket v3.3.1

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

  7. 关于input标签和placeholder在IE8,9下的兼容问题

    一. input常用在表单的输入,包括text,password,H5后又新增了许多type属性值,如url, email, member等等,考虑到非现代浏览器的兼容性问题,这些新的type常用在移 ...

  8. 应用Apache Axis进行Web Service开发

    转自(http://tscjsj.blog.51cto.com/412451/84813) 一.概述 SOAP原意为Simple Object Access Protocol(简单对象访问协议),是一 ...

  9. 深入理解javascript闭包(二)

    在上次的分享中javascript--函数参数与闭包--详解,对闭包的解释不够深入.本人经过一段时间的学习,对闭包的概念又有了新的理解.于是便把学习的过程整理成文章,一是为了加深自己闭包的理解,二是给 ...

  10. GO 1.5 代码编译安装 [centos7 64位]

    2015年8月,Go 1.5 正式发布,这是 Go 的第六个重要版本. 此版本包括大量重大改进,编译工具链从 C 转换到 Go,从 Go 代码库中完全移除 C 代码.完完全全重新设计了垃圾收集器,减少 ...