准备工做:html
安装好kvm,可以使用kvm建立虚拟机,此处安装步骤略过。linux
# virsh vol-create-as lv3 Centos7.img 50G --format qcow2
Vol Centos7.img createdcentos
此处选择qcow2格式,建立出来的img会较小,成功配置完成后大概在1.2G左右;若是是raw格式,建立完成img大概在51G左右。bash
# virt-install --connect qemu:///system -n Centos7 -r 4096 -f /vg0_lv3/Centos7.img --vnc --vcpus=2 --network bridge=br0 -c /vg0_lv1/openstack-image/CentOS-7-x86_64-Everything-1511.iso
Starting install...dom
Creating domain... | 0 B 00:00 ide
Cannot open display: 学习
Run 'virt-viewer --help' to see a full list of available command line optionsui
Domain installation still in progress. You can reconnect to centos7
the console to complete the installation process.spa
链接vnc,图形化界面安装centos7.2的系统,选择最小化安装,系统安装完再继续如下步骤。
# yum install acpid # systemctl enable acpid
# yum install http://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-7.noarch.rpm # yum install cloud-init
修改配置
# vi /etc/cloud/cloud.cfg
users: root
# echo "NOZEROCONF=yes" >> /etc/sysconfig/network
删除rhgb quiet
添加 console=tty0console=ttyS0,115200n8
# vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root console=tty0 console=ttyS0,115200n8"
GRUB_DISABLE_RECOVERY="true"
让配置生效
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-8ad37cd5879289675a6517371665929a
Found initrd image: /boot/initramfs-0-rescue-8ad37cd5879289675a6517371665929a.img
done
八、删除网卡配置信息
删除mac信息和 UUID
# cd /etc/sysconfig/network-scripts/ # vi ifcfg-ens3
BOOTPROTO=dhcp
ONBOOT=yes
# shutdown -h now
# source ~/admin-openrc.sh # openstack image create "Centos-7.2-init" \ --file /data/Centos-7.2-init.img \ --disk-format qcow2 --container-format bare \ --public
十一、建立云主机,查看日志
注意:
# virsh vol-create-as lv3 Centos6.6.img 50G --format qcow2
二、建立虚拟机
# virt-install --connect qemu:///system -n Centos6.6 -r 4096 -f Centos6.6.img --vnc --vcpus=2 --network bridge=br0 -c /vg0_lv1/CentOS-6.6-x86_64-bin-DVD1.iso
Starting install...
Creating domain... | 0 B 00:00
Cannot open display:
Run 'virt-viewer --help' to see a full list of available command line options
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
链接vnc,图形化界面安装centos6.6的系统,系统安装完再继续如下步骤。
四、安装 ACPI 服务
为了让虚拟化层能重启和关闭虚拟机,必须在虚拟机内安装并运行 acpid
服务。
在 CentOS虚拟机内运行如下命令安装 ACPI 服务并配置为系统启动时自动启动。
# yum install acpid # chkconfig acpid on
安装完cloud-init可能会致使没法链接进虚拟机的状况,因此,此步骤最好不作,有待继续学习研究……
cloud-init
包自动从元数据服务获取公钥并保存到帐户,你能够在 CentOS虚拟机添加 EPEL 安装源来安装 cloud-init
包,我发现其余自带的yum源就能够安装了,并不必定要安装epel源。
# yum install http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # yum install cloud-init
修改配置,添加root用户
# vi /etc/cloud/cloud.cfg
users: root
要让虚拟机访问元数据服务,必须禁用 zeroconf 路由:
# echo "NOZEROCONF=yes" >> /etc/sysconfig/network
要使 nova console-log 命令在 CentOS 6.x
生效 ,你须要添加如下文字到 /boot/grub/menu.lst
文件:
在kernel最后面加上 console=tty0 console=ttyS0,115200n8
# vi /boot/grub/menu.lst
八、清理mac地址信息,最后的网卡配置信息以下
# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=dhcp
删除记录网卡MAC地址的文件
# cd /etc/udev/rules.d/ # rm -f 70-persistent-net.rules
九、关闭虚拟机
# shutdown -h now
十、上传镜像
# source ~/admin-openrc.sh # openstack image create "Centos-6.6-init-cloud" \ --file /data/Centos-6.6-init-cloud.img \ --disk-format qcow2 --container-format bare \ --public
十一、建立云主机,检查日志
参考连接:
http://docs.openstack.org/zh_CN/image-guide/content/centos-image.html
http://docs.openstack.org/image-guide/centos-image.html