如何吧openstack里的镜像导出来

如何吧openstack里的镜像导出来,第1张

一、思路就4步: 1、创建镜像文件 2、用nova-compute自带的kvm,启动iso文件,用vncviewer完成OS的安装过程 3、OS安装完毕,停止虚拟机,kvm重启镜像,安装必要的软件 4、后续:上传镜像到云中 二、镜像制作指导 很多源都有为OpenStack已经编译

Swift、Keystone及Horizon(OpenStack的Web UI)服务。Server2只用来运行实例管理的nova运算工作站。由于OpenStack组件采用分布式结构,其中的任何一部分或几个部分都可以安装在任意服务器上。
Client1并不是安装所必须的,在本例中,它仅用来制作打包镜像,并使用它访问Horizon在Web上管理OpenStack设施。于是就避免了使用服务器来完成镜像打包等诸如此类的任务了,而且在制作桌面系统镜像时如果包含视窗界面的话,我们也只能相应地使用有GUI的电脑来完成。建议Client1支持虚拟化技术,以便在制作完镜像打包时可以运行KVM。
OpenStack安装需要设定主机名、IP地址等,按你实际的环境进行配置。下表是译者安装的网络参数清单:
这里写描述
二、Server1
正如上表所示,Server1包含了所有的Nova服务:nova-compute、nova-api、nova-volume、nova-network以及Glance、Swift、Keystone和Horizon。这台服务器上需要双网卡。
(一)安装底层OS
不必多想,请参照下述说明,记住相关参数,选择64位Ubuntu1204版,进行安装。
l 创建的第一个用户命名为“localadmin”
l 为eth0和eth1设定IP及其相关参数
l 在安装服务包中,仅选择“Openssh-server”作为预装项
因为Server1上也将安装nova-volume软件,而nova-volume需要一块专用分区,所以在安装Ubuntu Server时请选择手动分区,并另行创建一块合适大小的分区。从本章起,教程都将以/dev/sda6作为这块分区。你可以根据自己分区的实际情况进行修改。此外,请使用fdisk工具将该分区需要格式化为LVM(8e)格式,这一 *** 作在安装中或刚安装完毕格式化均可。进一步,如果你还计划在这台服务器上再新建一个分区配给Swift的话,那么就新建一块分区并参照本章后文“安装Swift”一节相关内容进行安装。
待1204的UbuntuOS安装完毕后 ,可以使用

镜像制作方法一:
centos65镜像制作:(首先将CentOS-65-x86_64-minimaliso镜像拷贝到/home下面)
1:
qemu-img create -f qcow2 /home/ttxImg/ttx_centos65img 28G
2:
virt-install --connect qemu:///system -n ttx_centos65 -r 1024 --vcpus=2 --disk path=/home/ttxImg/ttx_centos65img -c /home/ttxImg/CentOS-65-x86_64-minimaliso --vnc --vncport=5914 --vnclisten=0000 --noautoconsole --os-type linux --network=bridge:br100 --hvm --noautoconsole
windows7镜像制作:
qemu-img create -f qcow2 /home/ttxImg/ttx_win7qcow2 40000M
virt-install --connect qemu:///system -n ttx_win7 -r 2048 --vcpus=2 --disk path=/home/ttxImg/ttx_win7qcow2,bus=virtio,format=qcow2,cache=writeback --disk path=/home/ttxImg/virtio-win-01-81iso,device=cdrom,perms=ro --force -c /home/ttxImg/win7_x86_64iso --vnc --vncport=5914 --vnclisten=0000 --noautoconsole --os-type windows --os-variant=win7 --network=bridge:virbr0 --hvm --noautoconsole
注:假若安装系统时,磁盘损坏,则可以将上述bus=virtio修改为bus=ide
若是还找不到,使用如下命令
virt-install --connect qemu:///system -n neokylin_lst -r 1024 --vcpus=2 --disk path=/neokylinlstqcow2,bus=virtio,format=qcow2,cache=writeback --force -c /home/neokyliniso --vnc --vncport=5914 --vnclisten=0000 --noautoconsole --os-type linux --network=bridge:virbr0 --hvm --noautoconsole
使用virtio网卡驱动:
virt-install --connect qemu:///system -n ttx_win7 -r 2048 --vcpus=2 --disk path=/home/ttxImg/ttx_win7qcow2,bus=virtio,format=qcow2,cache=writeback --disk path=/home/ttxImg/virtio-win-01-81iso,device=cdrom,perms=ro --force -c /home/ttxImg/win7_x86_64iso --vnc --vncport=5914 --vnclisten=0000 --noautoconsole --os-type windows --os-variant=win7 --network=bridge:virbr0,model=virtio --hvm --noautoconsole
<interface type='bridge'>
<mac address='52:54:00:ac:9c:4c'/>
<source bridge='br1'/>
<target dev='vnet3'/>
<model type='virtio'/>
<alias name='net3'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</interface>
windows镜像上传命令:
glance add name="windows" is_public=true container_format=ovf disk_format=qcow2 < windowsxpimg
centos镜像上传命令:
glance image-create --name centos --is-public true --container-format ovf --disk-format qcow2 < /home/agen/centos63img
centos镜像上传命令:
glance add name=centos_62_ramdisk disk_format=ari container_format=ari is_public=True < initrd-2632-220el6x86_64img
输出:Added new image with ID: 9
以上命令是先上传镜像的ramdisk文件,注意类型必须是ari
glance add name=centos_62_kernel disk_format=aki container_format=aki is_public=True < vmlinuz-2632-220el6x86_64
输出:Added new image with ID: 10
以上命令是上传镜像的kernel文件,格式必须是aki
glance add name=centos_62_final disk_format=ami container_format=ami is_public=True ramdisk_id=9 kernel_id=10 < centos_62_finalimg
以上命令是上传主要镜像文件,格式必须是ami,ramdisk_id是刚上传的ramdisk的id,kernel_id同理。
镜像制作方法二:
1、将iso镜像文件转换为img镜像
qemu-img convert -f raw CentOS_62_Final64bitiso /home/createvm/testimg
2、创建配置文件setupxml
<domain type='kvm' id='21'>
<name>test_mini_centos</name>
<uuid>7e7f54d0-4b62-7c5e-d385-ed72473a5785</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='pc-014'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/var/lib/libvirt/images/test_mini_centosimg'/>
<target dev='vda' bus='virtio'/>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<alias name='ide0-1-0'/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'>
<alias name='ide0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='bridge'>
<mac address='52:54:00:7a:d2:93'/>
<source bridge='br0'/>
<target dev='vnet1'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/0'/>
<target port='0'/>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/0'>
<source path='/dev/pts/0'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
<input type='tablet' bus='usb'>
<alias name='input0'/>
</input>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='5901' autoport='yes'/>
<sound model='ich6'>
<alias name='sound0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<alias name='video0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</memballoon>
</devices>
</domain>
3、virsh define setupxml //创建虚拟机 查看当前系统所有的虚拟机信息:virsh list --all
4、virsh start vm_name //启动你创建的相应名字的虚拟机
注意:假若出现br0 没有此设备则使用sudo /usr/sbin/brctl addbr br0命令
qemu-img create -f raw /home/ttxImg/centos65_openstack_ttximg 3000M
virt-install -n CentOS65-openstack-ttx -r 2048 --cpu host -c /home/ttxImg/CentOS-65-i386-minimaliso --disk path=/home/ttxImg/centos65_openstack_ttximg,device=disk,bus=virtio,size=10,format=qcow2 --vnc --vncport=5908 --vnclisten=0000 -v --network bridge=br0
用 vncviewer 登录后按照屏幕提示完成 CentOS 安装。需要注意的是在分区阶段把 10GB 硬盘全部划分成一个 ext4 root 分区,不要创建多个分区也不要创建 swap 区:
$ vncviewer 1721639111:5900
安装完后会自动重启,如果没有重启的话按照下面的命令启动刚刚安装好的虚拟机镜像 centosimg,如果出现 failed to find romfile “pxe-rtf8139bin” 的错误提示可以通过安装 kvm-pxe 解决:
$ sudo qemu-kvm -m 512 -drive file=centosimg -boot c -net nic -net user -nographic -vnc :10
kvm: pci_add_option_rom: failed to find romfile "pxe-rtl8139bin"
$ sudo apt-get install kvm-pxe
再次用 vnc 登录虚拟机镜像,安装一些必要工具(因为这个镜像将会是模板,所以最好保持最简最小化):
$ vncviewer 1721639111:5900
# yum update
# yum upgrade
# yum install openssh-server
# chkconfig sshd on
修改分区加载表(/etc/fstab),注释或删除以前的,加上 LABEL=cec-rootfs 一行:
# vi /etc/fstab
#UUID=47a90bea-2d88-4c82-a335-09c1533b1538 / ext4 defaults 1 1
LABEL=cec-rootfs / ext4 defaults 0 0
在网络接口配置里面注释或删除这行 #HWADDR= 一行,启用 DHCP:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
#HWADDR="00:11:22:12:34:56"
#NM_CONTROLLED="yes"
BOOTPROTO=dhcp
ONBOOT="yes"
注射 ssh key 以便外界可以用 ssh -i mykeypriv root@host 的形式无密码登录到虚拟机实例,在 /etc/rclocal 文件中加入下面这些:
# vi /etc/rclocal

mkdir -p /root/ssh
echo >> /root/ssh/authorized_keys
curl -m 10 -s >转换条件。
1、在openstack的镜像服务中,镜像的状态跟人的状态一样,也存在着很多状态和状态发生转换的条件,镜像文件状态为svaing时是可用的,因为符合软件的设定。
2、在制作好镜像后,通过dashboard上传到openstack系统或者通过CLI命令查看镜像信息的时候,会发现镜像标识的状态,准确来说,镜像的状态包括queue排队,active有效,pendingdelete等待删除,saving保存中,deactivated无效的。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13488498.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-17
下一篇 2023-08-17

发表评论

登录后才能评论

评论列表(0条)

保存