1,在根目录下创建images目录,然后依次创建iso和test。其中ISO目录是存放ISO镜像的,test是存放虚拟机的主机名的,然后把Linux安装镜像的iso文件,上传到iso文件夹里
1
2
|
[root@KVM ~]
# mkdir -p /images/iso
[root@KVM ~]
# mkdir -p /images/test
|
1
2
3
|
[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磁盘格式的虚拟机:
1
|
[root@KVM images]
#virt-install --name hadoop2 --ram 1024 --vcpus 1 --disk path=/images/test/hadoop2.img,size=10 --network bridge=br0,model=virtio --noautoconsole --accelerate --vnc --vncport=5912 --vnclisten=0.0.0.0 --cdrom /images/iso/CentOS-6.5-x86_64-minimal.iso -d
|
b)安装qcow2格式的磁盘(空间动态增长),首先要先创建qcow2格式的磁盘。
1
2
3
|
[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=/images/test/hadoop3.img,format=qcow2,size=7,bus=virtio --accelerate --cdrom /images/iso/CentOS-6.5-x86_64-minimal.iso -d --vnc --vncport=5913 --network network:default --noautoconsole
|
具体的安装信息,如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
[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=/images/test/hadoop3.img,format=qcow2,size=7,bus=virtio --accelerate --cdrom /images/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=
/images/test/hadoop3
.img,
format
=qcow2,size=7,bus=virtio --accelerate --cdrom
/images/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
:
/images/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
=
'/images/test/hadoop3.img'
/>
<target dev=
'vda'
bus=
'virtio'
/>
<
/disk
>
<disk
type
=
'file'
device=
'cdrom'
>
<driver name=
'qemu'
/>
<
source
file
=
'/images/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
=
'/images/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
=
'/images/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
=
'/images/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 虚拟机使用的磁盘(文件)的路径,本例中文件放置在/images/test目录下
--network 网络设置,使用默认设置即可
--vnc 设置连接桌面环境的vnc端口,本例是5911
--cdrom 设置光驱获取虚拟光驱文件的路径 -d 指示从光驱启动( -c 指示从硬盘启动)我们这里是/images/iso
安装时建议一个来安装,否则会出现报错信息
本文转自 lqbyz 51CTO博客,原文链接:http://blog.51cto.com/liqingbiao/1740672