openstack镜像制作

openstack镜像制作上传镜像至glance中,然后启动虚拟机。 最后一步:安装完 windows 后可以进行一些必要的定制, 关闭防火墙,打开 RDP 访问等,可以安装一些必要软件。

一:制作centos镜像

准备工作:

需要先安装qemu-common qemu-img 和qemu-kvm qemu-system

yum install qemu-common qemu-img qemu-kvm qemu-system -y

1、dd一个镜像文件:

qemu-img create -f raw centos63_server.img 30G

2、安装Centos

用 -vnc 参数打开 vnc 访问,这样可以从其他机器登录到这个界面安装系统:

/usr/libexec/qemu-kvm -m 16024 -cdrom centos6.3_x86_64.iso -drive file=centos63_server.img,index=0 -boot d -net nic -net user -nographic -vnc  :2  

3、VNC连接安装

/usr/libexec/qemu-kvm -m 16024 -drive file=centos63_server.img,index=0,boot=on -boot c -net nic -net user -nographic -vnc :3
#vnc连接:
vncveiwers 10.28.1.96:3
# 安装完后会自动重启,如果没有重启的话按照下面的命令启动刚刚安装好的虚拟机镜像 centos.img
# 如果出现 failed to find romfile pxe-rtf8139.bin 的错误提示可以通过安装 kvm-pxe解决:
yum install kvm-pxe

4、转化镜像并安装包

挂载镜像文件,并安装所需软件并生成ext4格式文件系统:

losetup -f centos63_server.img
losetup -a
fdisk -cul /dev/loop0
# 记住start开始 2048× 512 = 1048576
losetup -d /dev/loop0
mkdir hh && mount -o loop,offset=1048576  centos63_server.img  hh
# 或者
losetup -f -o 1048576 centos63_server.img


# 将其转换为ext4格式
losetup -a #查看挂载的是那个/dev/loop:实现以下操作
dd  if=/dev/loop0 of=cenos63_x86.img
losetup -d /dev/loop0
mount -o loop centos63_x86.img hh

5、安装软件并做必要配置

    1. 安装软件:
cd hh. && chroot .
yum install gcc gcc-c   gcc-c++ make automake autoconfig libgcc gcc* glibc* rpmbuild unzip bunzip2 qpid openssh-server cloud-init rsync tree kde
    1. 删除网络规则文件,否则centos虚拟机不能创建虚拟网卡eth0 在这个/etc/udev/rules.d 下只保存一下文件:
-rw-r--r--. 1 root root 316 Dec  8 04:56 60-raw.rules
-rw-r--r--. 1 root root  53 Dec  8 07:38 91-drm-modeset.rules

其他的全部删除

查看/etc/fstab根节点挂载是否是用uuid,如果是则改变为LABEL=/

    1. 配置ifcfg-eth0 在网络接口配置里面注释或删除这行 #HWADDR= 一行,启用 DHCP:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
    1. 注入ssh key,以便登录时不需要输入密码(可以不做这一步) 注入ssh key 以便外界可以用 ssh -i mykey.priv root@host 的形式无密码登录到虚拟机实例,在 /etc/rc.local 文件中加入下面这些:
# vi /etc/rc.local
mkdir -p /root/.ssh
echo >> /root/.ssh/known_hosts
curl -m 10 -s http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key | grep 'ssh-rsa' >> /root/.ssh/known_hosts
curl -m 10 -s http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key | grep ssh-rsa >> /root/.ssh/known_hosts

chmod 700 ~/.ssh
chmod 600 ~/.ssh/known_hosts
echo "AUTHORIZED_KEYS:"
echo "--------------------"
cat /root/.ssh/authorized_keys
echo "--------------------"
    1. 打开selinux 和iptables 需要打开 SELINUX,否则即使上面 ssh 设定允许 root 无密码登录也无效:
# vi /etc/selinux/config
SELINUX=enabled
SELINUXTYPE=targeted

打开iptables服务:chkconfig iptables on

    1. 制作启动文件: 将virtio的包打入到镜像中,以提高instances的性能
mkinitrd --with virtio_pci --with virtio_ring --with virtio_blk --with virtio_net --with virtio_balloon --with virtio -f /boot/initrd-$(uname -r).img $(uname -r)

解挂并推出chroot

exit
cp boot/initrd-2.6.32-504.el6.x86_64.img  /opt/centos_img/ centos6.7_img /
cp boot/vmlinuz-2.6.32-504.el6.x86_64  /opt/centos_img/ centos6.7_img / 
cd ..
umount  hh 或者losetup -d /dev/loop0
    1. 检查镜像是否合格 校验镜像文件的根Label是否符合
tune2fs  -L  cenos67_x86.img
    1. 上传镜像并启动虚拟机 上传镜像至glance中,然后启动虚拟机。 进入到 /opt/centos_img/ centos6.7_img /
[root@node54 centos6.7_img]# glance image-create --name centos6_7_ramdisk --disk-format ari --container-format ari --image-type VM --is-public True < initrd-2.6.32-504.el6.x86_64.img
Added new image with ID: 7

[root@node54 centos6.7_img]# glance image-create --name centos6_7_kernel --disk-format aki --container-format aki --image-type VM --is-public True < vmlinuz-2.6.32-504.el6.x86_64
Added new image with ID: 8

[root@node54 centos6.7_img]# glance image-create --name Centos6_7 --disk-format ami --container-format ami --is-public True --property ramdisk-id=7 --property kernel-id=8 < cenos67_x86.img

二:Windows镜像:

Windows2008

这里windows2008采用qcow2格式来制作镜像,流程和centos类似用qemu-img创建一个10G大小的镜像文件:

qemu-img create -f qcow2 win2008.img 10G

因为Windows没有默认的virtio驱动,所以先下载:

wget http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/virtio-win-0.1-22.iso

用vnc访问安装,在安装的时候需要选择一下硬盘驱动,安装好以后,停掉虚拟机,重新用以下命令启动:

qemu-kvm -m 1024 -drive file=/home/win7/win2008_server.qcow2,if=virtio,boot=on -drive file=/home/win7/virtio-win-0.1-22.iso,index=1,media=cdrom --drive file=/home/CN_WIN7_SP1_X86_33in1_V1.2.iso,index=2,media=cdrom -net nic,model=virtio -net user -boot c -nographic -vnc :9

Window 2003的制作:

/usr/libexec/qemu-kvm -m 512 -boot d -drive file=/xxx/win2k3.qcow2,cache=writeback,if=virtio,boot=on -drive file=/home/win7/virtio-win-0.1-22.iso,-fda /xxx/virtio-win-1.1.16.vfd -cdrom /xxx/cn_win_srv_2003_r2_standard_with_sp2_cd1_X13-13927.iso --drive file  -vnc :1

加cache=yes比较快

qemu-kvm -m 4096 -drive file=windows2008.qcow2,if=virtio,cache=none,boot=on -drive file=/home/virtio-win-0.1-22.iso,index=1,media=cdrom --drive file=/home/windows_2008.iso,index=2,media=cdrom -net nic,model=virtio -net user -boot c -nographic -vnc :9

发布 Windows 镜像 再用vnc访问,应该会提示自动安装好了virtio的网卡驱动,用glance添加这个镜像,指定格式为qcow2

glance add  name="win2008" is_public=true container_format=ovf  disk_format=qcow2 < win2008.img

最后一步:安装完 windows 后可以进行一些必要的定制, 关闭防火墙,打开 RDP 访问等,可以安装一些必要软件。

今天的文章openstack镜像制作分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/21885.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注