準備工做: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