OpenStack 安装和使用(七)
建立一个raw格式的10GB大小的image文件:
# qemu-img create -f raw server.img 4G
运行一个虚拟机,内存256MB,从虚拟的cdrom启动,cdrom的文件为CentOS-6.0-x86_64-bin-DVD1.iso,有个虚拟硬盘设备为host刚建立的server.img文件,有一块用户模式网卡,没有图形设备,支持VNC:
优先从光驱启动,安装时把SWAP设置成1GB就可以了:
# qemu-kvm -M pc-1.0 -enable-kvm -m 2048 -drive file=CentOS-6.0-x86_64-bin-DVD1.iso,media=cdrom,if=none,id=cd -device ide-cd,drive=cd,bootindex=1 -drive file=server.img,if=none,id=hd1,format=raw,cache=none -device virtio-blk-pci,bus=pci.0,addr=0x5,drive=hd1,id=vhd1 -net none -nographic -vnc :10
优先从硬盘启动:
# qemu-kvm -M pc-1.0 -enable-kvm -m 2048 -drive file=CentOS-6.0-x86_64-bin-DVD1.iso,media=cdrom,if=none,id=cd -device ide-cd,drive=cd,bootindex=1 -drive file=server.img,if=none,id=hd1,format=raw,cache=none -device virtio-blk-pci,bus=pci.0,addr=0x5,drive=hd1,id=vhd1,bootindex=0 -net none -nographic -vnc :10
去掉cdrom试试能否启动刚才安装的系统:
# qemu-kvm -M pc-1.0 -enable-kvm -m 2048 -drive file=server.img,if=none,id=hd1,format=raw,cache=none -device virtio-blk-pci,bus=pci.0,addr=0x5,drive=hd1,id=vhd1,bootindex=0 -net nic -net user -nographic -vnc :10
openstack需要ext4格式的文件系统,因为fedora 17或centos6以上默认为ext4,所以不用处理,否则需要处理。
修改一些配置文件:
首先mount虚拟机设备到host机器,这里/dev/sda3为vm的根目录:
# guestmount –rw -a server.img -m /dev/vg_test/lv_root /mnt/tmp
修改网卡配置:
# vi /mnt/tmp/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=on
BOOTPROTO=dhcp
# vi /mnt/tmp/etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
这里不要配置HOSTNAME,在nova boot的时候会把vm的name作为hostname传进来,会把(_)下划线变成(-)中划线。
修改rc.local,以便登录时可以不输入密码:
# vi /mnt/tmp/etc/rc.local
#!/bin/sh
depmod -a
modprobe acpiphp
# simple attempt to get the user ssh key using the meta-data service
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
echo “AUTHORIZED_KEYS:”
echo “************************”
cat /root/.ssh/authorized_keys
echo “************************”
touch /var/lock/subsys/local
最后umount掉:
# umount /mnt/tmp
增加到glance:
# glance add name=”centos6″ is_public=true container_format=ovf disk_format=raw < server.img
# glance index
ID Name Disk Format Container Format Size
———————————— —————————— ——————– ——————– ————–
7d2a591b-cb13-4bfd-acef-aafee18f86be centos6 raw ovf 10737418240
起个虚拟机测试是否可用:
# nova boot –flavor 2 –image 7d2a591b-cb13-4bfd-acef-aafee18f86be –key_name f16jeos –security_group default centos_vm
# nova show centos_vm
+————————————-+———————————————————-+
| Property | Value |
+————————————-+———————————————————-+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-SRV-ATTR:host | compute1 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None |
| OS-EXT-SRV-ATTR:instance_name | instance-00000020 |
| OS-EXT-STS:power_state | 1 |
| OS-EXT-STS:task_state | None |
| OS-EXT-STS:vm_state | active |
| accessIPv4 | |
| accessIPv6 | |
| config_drive | |
| created | 2012-07-26T06:32:02Z |
| flavor | m1.small |
| hanborq network | 10.25.1.4 |
| hostId | ba210c21c18c8c89c1848c6fb140ac5936c5d539ea17737a2921b7e2 |
| id | 6ae439ed-b7c6-4580-aaee-07bb3ad141a2 |
| image | centos6 |
| key_name | f16jeos |
| metadata | {} |
| name | centos_vm |
| progress | 0 |
| status | ACTIVE |
| tenant_id | 94d38db32a7d4107beeed36d9e98bf06 |
| updated | 2012-07-26T06:37:37Z |
| user_id | cd5e2e764fc7420dad016f9af7be7123 |
+————————————-+———————————————————-+
使用VNC登录该VM。
# ssh -i f16jeos 10.25.1.4