yum install qemu-kvm qemu-kvm-tools virt-manager libvirt virt-install -y

1
2
3

[root@localhost ~]# grep -E ‘(vmx|svm)’ /proc/cpuinfo 
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm arat epb pln pts dtherm tpr_shadow vnmi ept vpid fsgsbase smep
#如果沒有內容則不支援

1
2

[root@localhost ~]# qemu-img create -f raw /opt/Centos-7.3-x86_64.raw 10G
Formatting ‘/opt/Centos-7.3-x86_64.raw’, fmt=raw size=10737418240

1
2

systemctl enable libvirtd.service
service libvirtd start

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

[root@localhost ~]# service libvirtd status
Redirecting to /bin/systemctl status  libvirtd.service
● libvirtd.service – Virtualization daemon
   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
   Active: active (running) since 五 2017-05-26 14:41:33 CST; 7min ago
     Docs: man:libvirtd(8)
           http://libvirt.org
 Main PID: 912 (libvirtd)
   CGroup: /system.slice/libvirtd.service
           ├─ 912 /usr/sbin/libvirtd
           ├─2441 /sbin/dnsmasq –conf-file=/var/lib/libvirt/dnsmasq/default.conf –leasefile-ro –dhcp-script=/usr…
           └─2449 /sbin/dnsmasq –conf-file=/var/lib/libvirt/dnsmasq/default.conf –leasefile-ro –dhcp-script=/usr…

5 月 26 14:41:24 localhost.localdomain systemd[1]: Starting Virtualization daemon…
5 月 26 14:41:33 localhost.localdomain systemd[1]: Started Virtualization daemon.
5 月 26 14:41:38 localhost.localdomain dnsmasq[2441]: started, version 2.66 cachesize 150
5 月 26 14:41:38 localhost.localdomain dnsmasq[2441]: compile time options: IPv6 GNU-getopt DBus no-i18n IDN DH…auth
5 月 26 14:41:38 localhost.localdomain dnsmasq-dhcp[2441]: DHCP, IP range 192.168.122.2 — 192.168.122.254, leas… 1h
5 月 26 14:41:38 localhost.localdomain dnsmasq[2441]: reading /etc/resolv.conf
5 月 26 14:41:38 localhost.localdomain dnsmasq[2441]: using nameserver 192.168.106.2#53
5 月 26 14:41:38 localhost.localdomain dnsmasq[2441]: read /etc/hosts – 2 addresses
5 月 26 14:41:38 localhost.localdomain dnsmasq[2441]: read /var/lib/libvirt/dnsmasq/default.addnhosts – 0 addresses
5 月 26 14:41:38 localhost.localdomain dnsmasq-dhcp[2441]: read /var/lib/libvirt/dnsmasq/default.hostsfile
Hint: Some lines were ellipsized, use -l to show in full.

1
2
3
4

[root@localhost ~]# dd if=/dev/cdrom of=/opt/CentOs-7.3.iso
記錄了 8554496+0 的讀入
記錄了 8554496+0 的寫出
4379901952 位元組 (4.4 GB) 已複製,137.034 秒,32.0 MB/秒

1
2
3
4
5
6
7

[root@localhost ~]# virt-install –name CentOS-7.3-x86_64 –virt-type kvm –ram 1024 –cdrom=/opt/CentOs-7.3.iso –disk path=/opt/Centos-7.3-x86_64.raw –network network=default –graphics vnc,listen=0.0.0.0 –noautoconsole

開始安裝……
建立域……                                                                                |    0 B  00:00:01     
域安裝仍在進行。您可以重新連線
到控制檯以便完成安裝程式。
[root@localhost ~]#

VNC 連線:

CentOS-7 安裝的時候讓網路卡名稱預設變成 eth0 的方法:
按 TAB 鍵,後面加入:
net.ifnames=0 biosdevname=0

1
2
3
4
5

[root@localhost qemu]# virsh list –all                   
 Id    名稱                         狀態
—————————————————-
 –     CentOS-7.3-x86_64              關閉
 –     CentOS-7.3-x86_64_1            關閉

1
2

[root@localhost qemu]# virsh start CentOS-7.3-x86_64_1
域 CentOS-7.3-x86_64_1 已開始

1
2
3
4
5
6
7
8
9
10
11

改 CPU:

[root@localhost qemu]# pwd
/etc/libvirt/qemu
[root@localhost qemu]# virsh edit CentOS-7.3-x86_64_1 
4
重啟:
[root@localhost qemu]# virsh shutdown CentOS-7.3-x86_64_1
[root@localhost qemu]# virsh start CentOS-7.3-x86_64_1

[root@localhost qemu]# virsh setvcpus CentOS-7.3-x86_64_1 2 –live  #熱新增或熱減少

1
2
3
4
5
6
7
8
9

改記憶體:

virsh edit CentOS-7.3-x86_64_1 
4048576
重啟:
[root@localhost qemu]# virsh shutdown CentOS-7.3-x86_64_1
[root@localhost qemu]# virsh start CentOS-7.3-x86_64_1

virsh qemu-monitor-command  CentOS-7.3-x86_64_1 –hmp –cmd balloon 500  #熱新增或熱減少