CloudStack 默認情況下 KVM實例的CPU模型可能是QEMU虛擬CPU版本x.x.x,其CPU特性暴露最少。
如果需要設置CPU。在大多數情況下,主機管理員在每個主機配置文件(/etc/CloudStack/agent/agent.properties)中指定客戶CPU配置就足夠了
- custom: you can explicitly specify one of the supported named model in /usr/share/libvirt/cpu_map.xml
- host-model: libvirt will identify the CPU model in /usr/share/libvirt/cpu_map.xml which most closely matches the host, and then request additional CPU flags to complete the match. This should give close to maximum functionality/performance, which maintaining good reliability/compatibility if the guest is migrated to another host with slightly different host CPUs.
- host-passthrough: libvirt will tell KVM to passthrough the host CPU with no modifications. The difference to host-model, instead of just matching feature flags, every last detail of the host CPU is matched. This gives absolutely best performance, and can be important to some apps which check low level CPU details, but it comes at a cost with respect to migration: the guest can only be migrated to an exactly matching host CPU.
custom:可以在/usr/share/libvirt/cpu_map.xml中顯式指定受支持的命名模型之一。
host-model:libvirt將識別/usr/share/libvirt/cpu_map.xml中與主機最接近的CPU模型,然後請求額外的CPU標誌來完成匹配。這將提供接近最大功能/性能的功能/性能,如果將來賓遷移到具有稍微不同的主機CPU的另一個主機,則該功能/性能將保持良好的可靠性/兼容性。
host-passthrough:libvirt將告訴KVM在沒有修改的情況下通過主機CPU。主機模型的不同,而不僅僅是匹配特徵標誌,主機CPU的每一個細節都是匹配的。這提供了絕對最好的性能,對於一些檢查低級別CPU細節的應用程序來說也是很重要的,但這是以遷移爲代價的:客戶只能遷移到完全匹配的主機CPU上。
有時候 需求不同虛擬主機擁有不同型號的CPU,爲什麼會有這樣的需求咱也不懂。。。這時候參考KVM和qumu的使用。最終我也沒實現 如何讓cloudstack管理的虛擬機如何在同一個宿主機上有不同CPU型號。。。
在 VMwareWorkstation 創建兩個虛擬機 一個作爲計算節點 一個作爲 管理節點時。。。發現在設置custom 時。。。有些 模型不支持設置。。。
本來以爲 是因爲 qemu 版本問題。。。因爲cloudstack4.11.0 版本安裝kvm 主機建議 qemu版本 2.0 或以上,但是CentOS7 版本的附帶的qemu-kvm 安裝包是1.5.3 版本。。。於是源碼安裝了 qemu 最後 發現 只有 2.6 和 2.7 版本。。。可以正常安裝後使用,但是,依然是有些 CPU模型無法設置。。。
這裏 附上 qemu的源碼安裝
安裝依賴包
yum -y install gcc gcc-c++ automake libtool zlib-devel glib2-devel bzip2-devel libuuid-devel spice-protocol spice-server-devel usbredir-devel libaio-devel
下載壓縮包。。。https://download.qemu.org/
解壓
tar xf qemu-XXX.tar.bz2
進入該解壓後的包
cd qemu-XXX
配置安裝。。可以先查看一下幫助
./configure --help
./configure --prefix=/usr/local/qemu --target-list="x86_64-softmmu x86_64-linux-user" --enable-debug
這裏一定要說。target-list 表示要安裝的 模擬架構 x86_64-softmmu 表示安裝X86_64 位架構的模擬架構命令所需 x86_64-linux-user 安裝該架構的虛擬機所需。 注,一般 我們只用安裝 這兩個就行了。。。因爲target list 中安裝的是獨立的命令。並不是包含在一個指令中。
編譯 這裏 qemu2.1-2.5 版本 編譯都會 報錯。。。不知爲何
make
執行安裝
make install
安裝路徑在 配置安裝時指定了 /usr/local/qemu 。可以將這裏面的 /bin 目錄下命令 添加到環境變量。。。
vim ~/.bashrc
將路徑添加到末尾
export PATH=/usr/local/qemu/bin:$PATH
重新激活該文件
source ~/.bashrc
如此做 即使之前安裝了 CentOS7自帶的qemu1.5.3 版本。 相應的 qemu-img qemu-io 等命令也會執行/usr/local/qemu/bin/ 中的。。。
然後。。。爲了使cloudstack使用新安裝的qemu(這裏說一句。cloudstack是使用qemu + kvm + libvirt 來管理KVM主機的。使用的也是這些個開源軟件 但是做了一些封裝和端口處理。)
執行 virsh capabilities 可以看到 一大堆內容。。。但是大多內容先忽視。。。
可以看到 一個 host 大標籤 和 兩個 guest 大標籤。。。host大概是對計算節點主機的一個大概描述。guest表示在該計算節點上創建虛擬機的一個描述。一個是32位,一個是64位。。。 先看guest 可以看到一行。不管是64位還是32位 都有 /usr/libexec/qemu-kvm 大約是創建的虛擬機和 這個指令有關。。。
安裝完新版 qemu 後,我們要把這個指定替換掉。。。可以先備份。然後
ln -s /usr/local/qemu/bin/qemu-system-x86_64 /usr/libexec/qemu-kvm
ln -s /usr/local/qemu/libexec/qemu-bridge-helper /usr/libexec/qemu-bridge-helper
然後根據該指令查詢可 設置的CPU型號
/usr/libexec/qemu-kvm -cpu ?
[root@agent ~]# /usr/libexec/qemu-kvm -cpu ?
x86 qemu64 QEMU Virtual CPU version 2.5+ X
x86 phenom AMD Phenom(tm) 9550 Quad-Core Processor X
x86 core2duo Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz X
x86 kvm64 Common KVM processor Y
x86 qemu32 QEMU Virtual CPU version 2.5+
x86 kvm32 Common 32-bit KVM processor
x86 coreduo Genuine Intel(R) CPU T2600 @ 2.16GHz X
x86 486
x86 pentium
x86 pentium2
x86 pentium3
x86 athlon QEMU Virtual CPU version 2.5+ X
x86 n270 Intel(R) Atom(TM) CPU N270 @ 1.60GHz X
x86 Conroe Intel Celeron_4x0 (Conroe/Merom Class Core 2) Y
x86 Penryn Intel Core 2 Duo P9xxx (Penryn Class Core 2) Y
x86 Nehalem Intel Core i7 9xx (Nehalem Class Core i7) Y
x86 Westmere Westmere E56xx/L56xx/X56xx (Nehalem-C) X
x86 SandyBridge Intel Xeon E312xx (Sandy Bridge)
x86 IvyBridge Intel Xeon E3-12xx v2 (Ivy Bridge) X
x86 Haswell-noTSX Intel Core Processor (Haswell, no TSX)
x86 Haswell Intel Core Processor (Haswell)
x86 Broadwell-noTSX Intel Core Processor (Broadwell, no TSX)
x86 Broadwell Intel Core Processor (Broadwell)
x86 Opteron_G1 AMD Opteron 240 (Gen 1 Class Opteron) Y
x86 Opteron_G2 AMD Opteron 22xx (Gen 2 Class Opteron) X
x86 Opteron_G3 AMD Opteron 23xx (Gen 3 Class Opteron) X
x86 Opteron_G4 AMD Opteron 62xx class CPU X
x86 Opteron_G5 AMD Opteron 63xx class CPU X
x86 host KVM processor with all supported host features (only available in KVM mode)
後面的XY是我自己加的。。。沒什麼意義 懶得刪除了。。。看上去可以選擇的CPU不少啊
設置 /etc/cloudstack/agent/agent.properties 然後發現其中幾個CPU模型設置後 系統VM 還是啓動失敗。。。所以和qemu版本應該無關。即使1.5.3 版本 ,cloudstack也能正常運行。。。
看日誌文件 看了好久 也沒發現到底爲什麼 系統VM會啓動失敗。。。
ERROR 信息倒是有
com.cloud.exception.InsufficientServerCapacityException: Unable to create a deployment for VM[ConsoleProxy|v-6-VM]Scope=interface com.cloud.dc.DataCenter; id=1
什麼資源 不夠之類的。。。沒什麼用
嘗試了好多次。。。發現錯誤信息在 info 中,不是 error
2020-05-06 14:11:35,518 INFO [c.c.v.VirtualMachineManagerImpl] (Work-Job-Executor-45:ctx-335ce82b job-1/job-54 ctx-2f92e5f7) (logid:56d5ba67) Unable to start VM on Host[-1-Routing] due to the CPU is incompatible with host CPU: Host CPU does not provide required features: monitor
大抵意思是 創建該CPU模型需要 HOST 就是宿主機 的CPU具有 monitor 特性。。。我TM。找了快兩天原因。竟然是這個。。。查看當前host 的 CPU是不是沒有 該特性
cat /proc/cpuinfo
flags 裏面就是 host 的CPU的特性。。。要是覺得過多不好看 直接查詢 沒結果就是沒有。。。
egrep "monitor" /proc/cpuinfo
果然沒有,可能是因爲這個HOST本身就是VMWare Worksations 創建的一個虛擬機的緣故吧。。。正常的主機應該是有的。。。。
另外 virsh capabilities host 大標籤中 feature name 也是該宿主機 的CPU特性 可以看到 並沒有。。。
<host>
<uuid>a28c4d56-acc8-5031-6d1f-1e77095a16cf</uuid>
<cpu>
<arch>x86_64</arch>
<model>Nehalem</model>
<vendor>Intel</vendor>
<microcode version='5'/>
<counter name='tsc' frequency='2793049000' scaling='no'/>
<topology sockets='2' cores='2' threads='1'/>
<feature name='vme'/>
<feature name='ds'/>
<feature name='ss'/>
<feature name='ht'/>
<feature name='vmx'/>
<feature name='x2apic'/>
<feature name='tsc-deadline'/>
<feature name='hypervisor'/>
<feature name='tsc_adjust'/>
<feature name='rdtscp'/>
<feature name='invtsc'/>
<pages unit='KiB' size='4'/>
<pages unit='KiB' size='2048'/>
</cpu>
<power_management>
<suspend_mem/>
<suspend_disk/>
<suspend_hybrid/>
</power_management>
<iommu support='no'/>
<migration_features>
<live/>
<uri_transports>
<uri_transport>tcp</uri_transport>
<uri_transport>rdma</uri_transport>
</uri_transports>
</migration_features>
<topology>
<cells num='1'>
<cell id='0'>
<memory unit='KiB'>4193716</memory>
<pages unit='KiB' size='4'>1048429</pages>
<pages unit='KiB' size='2048'>0</pages>
<distances>
<sibling id='0' value='10'/>
</distances>
<cpus num='4'>
<cpu id='0' socket_id='0' core_id='0' siblings='0'/>
<cpu id='1' socket_id='0' core_id='1' siblings='1'/>
<cpu id='2' socket_id='1' core_id='0' siblings='2'/>
<cpu id='3' socket_id='1' core_id='1' siblings='3'/>
</cpus>
</cell>
</cells>
</topology>
<cache>
<bank id='0' level='3' type='both' size='8' unit='MiB' cpus='0-1'/>
<bank id='1' level='3' type='both' size='8' unit='MiB' cpus='2-3'/>
</cache>
<secmodel>
<model>selinux</model>
<doi>0</doi>
<baselabel type='kvm'>system_u:system_r:svirt_t:s0</baselabel>
<baselabel type='qemu'>system_u:system_r:svirt_tcg_t:s0</baselabel>
</secmodel>
<secmodel>
<model>dac</model>
<doi>0</doi>
<baselabel type='kvm'>+107:+107</baselabel>
<baselabel type='qemu'>+107:+107</baselabel>
</secmodel>
</host>
所以 最後並未能實現 cloudstack 的一個宿主機上不同虛擬機擁有不同的CPU型號。。。只是發現qemu源碼安裝方式然後,發現 高版本qemu 在和cloudstack結合使用穩定性還不如 qemu1.5.3
另 源碼安裝的 qemu 並沒有 make uninstall 命令。需要卸載可以直接刪除 /usr/local/qemu 然後在 source 就是解壓後的文件夾裏執行 make clean 即可。。。當然
要把在 /usr/libexec/ 裏qemu-kvm 備份恢復過來。。。