1. 程式人生 > >CentOS-7 安裝KVM

CentOS-7 安裝KVM

kvm

yum install qemu-kvm qemu-kvm-tools virt-manager libvirt virt-install -y
[[email protected] ~]# 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
#如果沒有內容則不支持
[[email protected] ~]# 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
systemctl enable libvirtd.service
service libvirtd start
[[email protected] ~]# 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.
[[email protected] ~]# dd if=/dev/cdrom of=/opt/CentOs-7.3.iso
記錄了8554496+0 的讀入
記錄了8554496+0 的寫出
4379901952字節(4.4 GB)已復制,137.034 秒,32.0 MB/秒
[[email protected] ~]# 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     
域安裝仍在進行。您可以重新連接
到控制臺以便完成安裝進程。
[[email protected]
/* */ ~]#

VNC連接:

技術分享

技術分享


CentOS-7安裝的時候讓網卡名稱默認變成eth0的方法:

按TAB鍵,後面加入:

net.ifnames=0 biosdevname=0

技術分享

[[email protected] qemu]# virsh list --all                   
 Id    名稱                         狀態
----------------------------------------------------
 -     CentOS-7.3-x86_64              關閉
 -     CentOS-7.3-x86_64_1            關閉
[[email protected] qemu]# virsh start CentOS-7.3-x86_64_1
域 CentOS-7.3-x86_64_1 已開始
改CPU:

[[email protected] qemu]# pwd
/etc/libvirt/qemu
[[email protected] qemu]# virsh edit CentOS-7.3-x86_64_1 
<vcpu placement=‘auto‘ current="1">4</vcpu>
重啟:
[[email protected] qemu]# virsh shutdown CentOS-7.3-x86_64_1
[[email protected] qemu]# virsh start CentOS-7.3-x86_64_1

[[email protected] qemu]# virsh setvcpus CentOS-7.3-x86_64_1 2 --live  #熱添加或熱減少
改內存:

virsh edit CentOS-7.3-x86_64_1 
<memory unit=‘KiB‘>4048576</memory>
重啟:
[[email protected] qemu]# virsh shutdown CentOS-7.3-x86_64_1
[[email protected] qemu]# virsh start CentOS-7.3-x86_64_1

virsh qemu-monitor-command  CentOS-7.3-x86_64_1 --hmp --cmd balloon 500  #熱添加或熱減少


CentOS-7 安裝KVM