1,在根目录下创建p_w_picpaths目录,然后依次创建iso和test。其中ISO目录是存放ISO镜像的,test是存放虚拟机的主机名的,然后把Linux安装镜像的iso文件,上传到iso文件夹里
[root@KVM ~]# mkdir -p /p_w_picpaths/iso [root@KVM ~]# mkdir -p /p_w_picpaths/test
[root@KVM ~]# ll /data/iso/ total 407556 -rw-r--r-- 1 qemu qemu 417333248 Aug 5 09:11 CentOS-6.5-x86_64-minimal.iso
2,安装Linux虚拟主机:
a)安装raw磁盘格式的虚拟机:
[root@KVM p_w_picpaths]#virt-install --name hadoop2 --ram 1024 --vcpus 1 --disk path=/p_w_picpaths/test/hadoop2.img,size=10 --network bridge=br0,model=virtio --noautoconsole --accelerate --vnc --vncport=5912 --vnclisten=0.0.0.0 --cdrom /p_w_picpaths/iso/CentOS-6.5-x86_64-minimal.iso -d
b)安装qcow2格式的磁盘(空间动态增长),首先要先创建qcow2格式的磁盘。
[root@KVM test]# qemu-img create -f qcow2 hadoop3.img 10G Formatting 'hadoop3.img', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 [root@KVM test]# virt-install --name=hadoop3 --ram 512 --vcpus=1 --disk path=/p_w_picpaths/test/hadoop3.img,format=qcow2,size=7,bus=virtio --accelerate --cdrom /p_w_picpaths/iso/CentOS-6.5-x86_64-minimal.iso -d --vnc --vncport=5913 --network network:default --noautoconsole
具体的安装信息,如下:
[root@KVM test]# qemu-img create -f qcow2 hadoop3.img 10G Formatting 'hadoop3.img', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 [root@KVM test]# virt-install --name=hadoop3 --ram 512 --vcpus=1 --disk path=/p_w_picpaths/test/hadoop3.img,format=qcow2,size=7,bus=virtio --accelerate --cdrom /p_w_picpaths/iso/CentOS-6.5-x86_64-minimal.iso -d --vnc --vncport=5913 --network network:default --noautoconsole Tue, 02 Feb 2016 14:12:36 DEBUG Launched with command line: /usr/sbin/virt-install --name=hadoop3 --ram 512 --vcpus=1 --disk path=/p_w_picpaths/test/hadoop3.img,format=qcow2,size=7,bus=virtio --accelerate --cdrom /p_w_picpaths/iso/CentOS-6.5-x86_64-minimal.iso -d --vnc --vncport=5913 --network network:default --noautoconsole Tue, 02 Feb 2016 14:12:36 DEBUG Requesting libvirt URI default Tue, 02 Feb 2016 14:12:36 DEBUG Received libvirt URI qemu:///system Tue, 02 Feb 2016 14:12:36 DEBUG Requesting virt method 'default', hv type 'default'. Tue, 02 Feb 2016 14:12:36 WARNING KVM acceleration not available, using 'qemu' Tue, 02 Feb 2016 14:12:36 DEBUG Received virt method 'hvm' Tue, 02 Feb 2016 14:12:36 DEBUG Hypervisor name is 'qemu' Tue, 02 Feb 2016 14:12:36 DEBUG --graphics compat generated: vnc,port=5913 Tue, 02 Feb 2016 14:12:36 DEBUG DistroInstaller location is a local file/path: /p_w_picpaths/iso/CentOS-6.5-x86_64-minimal.iso Tue, 02 Feb 2016 14:12:36 DEBUG Guest.has_install_phase: True Starting install... Tue, 02 Feb 2016 14:12:36 DEBUG Generated install XML: <domain type='qemu'> <name>hadoop3</name> <uuid>ae9def17-b45b-f9ea-4ff9-ece22c95503e</uuid> <memory>524288</memory> <currentMemory>524288</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64'>hvm</type> <boot dev='cdrom'/> <boot dev='hd'/> </os> <features> <acpi/><apic/><pae/> </features> <clock offset="utc"/> <on_poweroff>destroy</on_poweroff> <on_reboot>destroy</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/p_w_picpaths/test/hadoop3.img'/> <target dev='vda' bus='virtio'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu'/> <source file='/p_w_picpaths/iso/CentOS-6.5-x86_64-minimal.iso'/> <target dev='hdc' bus='ide'/> <readonly/> </disk> <controller type='usb' index='0' model='ich9-ehci1'> </controller> <controller type='usb' index='0' model='ich9-uhci1'> <master startport='0'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> </controller> <interface type='network'> <source network='default'/> <mac address='52:54:00:87:5b:c0'/> </interface> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='5913'/> <console type='pty'/> <video> <model type='cirrus'/> </video> </devices> </domain> Tue, 02 Feb 2016 14:12:36 DEBUG Generated boot XML: <domain type='qemu'> <name>hadoop3</name> <uuid>ae9def17-b45b-f9ea-4ff9-ece22c95503e</uuid> <memory>524288</memory> <currentMemory>524288</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/><apic/><pae/> </features> <clock offset="utc"/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/p_w_picpaths/test/hadoop3.img'/> <target dev='vda' bus='virtio'/> </disk> <disk type='block' device='cdrom'> <target dev='hdc' bus='ide'/> <readonly/> </disk> <controller type='usb' index='0' model='ich9-ehci1'> </controller> <controller type='usb' index='0' model='ich9-uhci1'> <master startport='0'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> </controller> <interface type='network'> <source network='default'/> <mac address='52:54:00:87:5b:c0'/> </interface> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='5913'/> <console type='pty'/> <video> <model type='cirrus'/> </video> </devices> </domain> Creating domain... | 0 B 00:00 Tue, 02 Feb 2016 14:12:36 DEBUG Started guest, connecting to console if requested Tue, 02 Feb 2016 14:12:36 DEBUG XML fetched from libvirt object: <domain type='qemu' id='15'> <name>hadoop3</name> <uuid>ae9def17-b45b-f9ea-4ff9-ece22c95503e</uuid> <memory unit='KiB'>524288</memory> <currentMemory unit='KiB'>524288</currentMemory> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='rhel6.6.0'>hvm</type> <boot dev='cdrom'/> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>destroy</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/p_w_picpaths/test/hadoop3.img'/> <target dev='vda' bus='virtio'/> <alias name='virtio-disk0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/p_w_picpaths/iso/CentOS-6.5-x86_64-minimal.iso'/> <target dev='hdc' bus='ide'/> <readonly/> <alias name='ide0-1-0'/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> <controller type='usb' index='0' model='ich9-ehci1'> <alias name='usb0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/> </controller> <controller type='usb' index='0' model='ich9-uhci1'> <alias name='usb0'/> <master startport='0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <alias name='usb0'/> <master startport='2'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <alias name='usb0'/> <master startport='4'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/> </controller> <controller type='ide' index='0'> <alias name='ide0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='network'> <mac address='52:54:00:87:5b:c0'/> <source network='default'/> <target dev='vnet3'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <serial type='pty'> <source path='/dev/pts/8'/> <target port='0'/> <alias name='serial0'/> </serial> <console type='pty' tty='/dev/pts/8'> <source path='/dev/pts/8'/> <target type='serial' port='0'/> <alias name='serial0'/> </console> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='5913' autoport='no' listen='127.0.0.1'> <listen type='address' address='127.0.0.1'/> </graphics> <video> <model type='cirrus' vram='9216' heads='1'/> <alias name='video0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <alias name='balloon0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </memballoon> </devices> </domain>
然后按照提示安装步骤一步步来安装,操作系统的安装省略。
也可以通过VNC使用virt-manager远程进行安装管理
[参数说明]
--name 虚拟机名称
--hvm 使用全虚拟化(与para-irtualization向对),不支持xen hypervisor
--ram 虚拟机内存大小
--vcpus 虚拟机虚拟CPU个数
--disk 虚拟机使用的磁盘(文件)的路径,本例中文件放置在/p_w_picpaths/test目录下
--network 网络设置,使用默认设置即可
--vnc 设置连接桌面环境的vnc端口,本例是5911
--cdrom 设置光驱获取虚拟光驱文件的路径 -d 指示从光驱启动( -c 指示从硬盘启动)我们这里是/p_w_picpaths/iso
安装时建议一个来安装,否则会出现报错信息