为openstack 制作CentOS镜像
[*]首先下载CentOS安装文件:http://mirrors.tuna.tsinghua.edu.cn/centos/6.4/isos/x86_64/
[*]
创建空的硬盘:kvm-image create -f raw centos6.4.img 5G
[*]
用安装文件进行引导:
kvm -m 1024 -cdrom CentOS-6.4-x86_64-minimal.iso -drive file=centos6.4.img -boot d -net nic -net tap -nographic -vnc :11
[*]
用vnc连接,最好用UltraVNC,不用vncviewer,否则也许会出现一闪而过的情况。
连接后进行安装,安装时有config network的按钮,我将ipv4和ipv6都设置成了auto connection。
[*]
安装后再次启动镜像,这时不用安装镜像来驱动了:
kvm -m 1024 -drive file=centos6.4.img -boot c -net nic -net tap -nographic -vnc :11
[*]
启动ssh:chkconfig sshd on
[*]
在网络接口配置里注释掉#HWADDR这一行,启用dhcp。
[*]注射sshKey。在rc.local文件(自动加载)中加入注射的脚本,放到touch一行前:
# vi /etc/rc.local
...
mkdir -p /root/.ssh
echo >> /root/.ssh/authorized_keys
curl -m 10 -s http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key
| grep 'ssh-rsa' >> /root/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
echo "AUTHORIZED_KEYS:"
echo "--------------------"
cat /root/.ssh/authorized_keys
echo "--------------------"
...
touch ...
[*]配置ssh无密码登录:
# vi /etc/ssh/sshd_config
...
RSAAuthentication yes
PubkeyAuthentication yes
PermitRootLogin without-password
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
[*]
关闭防火墙和selinux:
service iptables stop && chkconfig iptables off
service ip6tables stop && chkconfig ip6tables off
[*]
删除已经生成的网络规则,并关机:
rm -rf /etc/udev/rules.d/70-persistent-net.rules
shutdown -h now
注意:不能重启,因为重启后那个规则文件又会生成了
[*]上传镜像:
glance add name=”centos6.4” is_public=true container_format=ovf disk_format=raw < centos6.4.img
[*]
上传成功之后,使用nova list查看镜像,记住id号,然后创建虚拟机
# nova boot --flavor 1 --key_name key1 --image e180b9a7-32a6-47b0-8f33-d557b5e54937 centos6.4A
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///C:UsersADMINI~1AppDataLocalTempksohtmlwps_clip_image-18767.png
[*]设置floating ip:
nova floating-ip-create
nova add-floating-ip centos6.4A 10.109.254.41
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///C:UsersADMINI~1AppDataLocalTempksohtmlwps_clip_image-18659.png
参考资料:
http://www.vpsee.com/2012/02/create-centos-kvm-image-for-openstack-nova/
http://docs.openstack.org/trunk/openstack-compute/admin/content/manually-creating-qcow2-images.html
http://bbs.chinaunix.net/thread-3729514-1-1.html
页:
[1]