Learning KVM - part8 如何添加/刪除vCPU到VM

KVM是否支持vCPU熱插拔苛预? Linux KVM客戶端能否識別出新添加的vCPU? 答案是“當然”笋熬。 像KVM內(nèi)存管理一樣热某,您可以使用“virsh”命令將vCPU添加到活動VM。 但是必須已使用Maximum vCPUs參數(shù)配置KVM guest虛擬機胳螟,則此功能將起作用苫拍。 所以在部署新的虛擬機時,您應該始終將此參數(shù)視為先決條件旺隙。如果已使用已分配的vCPU“”vcpu placement ='static' current ='N'”,所以無需為KVM guest虛擬機指定最大vCPU骏令。


了解VM的vCPU配置:

[root@test-kvm ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     generic                        running
 -     centos7                        shut off

[root@test-kvm ~]# virsh start centos7
Domain centos7 started

[root@test-kvm ~]# virsh console centos7
Connected to domain centos7

localhost login: root
Password: 
Last login: Tue Jun 13 14:03:04 on ttyS0
[root@localhost ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 61
Model name:            Intel Core Processor (Broadwell)
Stepping:              2
CPU MHz:               2400.010
BogoMIPS:              4800.02
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
NUMA node0 CPU(s):     0

為運行的VM增加vCPU:

接下來我們來講vCPU數(shù)量增加到2:

[root@test-kvm ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     generic                        running
 9     centos7                        running

[root@test-kvm ~]# virsh setvcpus centos7
error: command 'setvcpus' requires --count option
[root@test-kvm ~]# virsh setvcpus centos7 2

[root@test-kvm ~]# virsh dominfo centos7
Id:             9
Name:           centos7
UUID:           6693189b-0a29-4225-b822-724001270bc0
OS Type:        hvm
State:          running
CPU(s):         2
CPU time:       30.0s
Max memory:     4194304 KiB
Used memory:    2048576 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: none
Security DOI:   0

我們登錄到VM驗證一下:

[root@test-kvm ~]# virsh console centos7
Connected to domain centos7
Escape character is ^]  

CentOS Linux 7 (Core)
Kernel 3.10.0-514.el7.x86_64 on an x86_64

localhost login: root
Password: 
Last login: Wed Jun 14 15:01:05 on ttyS0
[root@localhost ~]# tail -f /var/log/messages 
Jun 14 15:10:52 localhost kernel: CPU1 has been hot-added
Jun 14 15:10:52 localhost kernel: SMP alternatives: switching to SMP code
Jun 14 15:10:52 localhost kernel: smpboot: Booting Node 0 Processor 1 APIC 0x1
Jun 14 15:10:52 localhost kernel: kvm-clock: cpu 1, msr 1:3ff86041, secondary cpu clock
Jun 14 15:10:52 localhost kernel: TSC synchronization [CPU#0 -> CPU#1]:
Jun 14 15:10:52 localhost kernel: Measured 1467576033050 cycles TSC warp between CPUs, turning off TSC clock.
Jun 14 15:10:52 localhost kernel: tsc: Marking TSC unstable due to check_tsc_sync_source failed
Jun 14 15:10:52 localhost kernel: KVM setup async PF for cpu 1
Jun 14 15:10:52 localhost kernel: kvm-stealtime: cpu 1, msr 13fd0f3c0
Jun 14 15:10:52 localhost kernel: Will online and init hotplugged CPU: 1
[root@localhost ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             2
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 61
Model name:            Intel Core Processor (Broadwell)
Stepping:              2
CPU MHz:               2400.010
BogoMIPS:              4800.02
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
NUMA node0 CPU(s):     0,1

為運行的VM刪除VCPU

無法直接從VM中刪除vCPU蔬捷, 但您可以通過關(guān)閉VM后再刪除vCPU;

[root@test-kvm ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     generic                        running
 10    centos7                        running
[root@test-kvm ~]# virsh setvcpus centos7 1
error: unsupported configuration: failed to find appropriate hotpluggable vcpus to reach the desired target vcpu count
[root@test-kvm log]# virsh setvcpus --config centos7 1
  
[root@test-kvm log]# virsh destroy centos7
Domain centos7 destroyed

[root@test-kvm log]# virsh start centos7
Domain centos7 started

[root@test-kvm log]# virsh dominfo centos7
Id:             11
Name:           centos7
UUID:           6693189b-0a29-4225-b822-724001270bc0
OS Type:        hvm
State:          running
CPU(s):         1
CPU time:       3.3s
Max memory:     4194304 KiB
Used memory:    4194304 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: none
Security DOI:   0
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市周拐,隨后出現(xiàn)的幾起案子铡俐,更是在濱河造成了極大的恐慌,老刑警劉巖妥粟,帶你破解...
    沈念sama閱讀 218,546評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件审丘,死亡現(xiàn)場離奇詭異,居然都是意外死亡勾给,警方通過查閱死者的電腦和手機滩报,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來播急,“玉大人脓钾,你說我怎么就攤上這事∽” “怎么了可训?”我有些...
    開封第一講書人閱讀 164,911評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長捶枢。 經(jīng)常有香客問我握截,道長,這世上最難降的妖魔是什么烂叔? 我笑而不...
    開封第一講書人閱讀 58,737評論 1 294
  • 正文 為了忘掉前任谨胞,我火速辦了婚禮,結(jié)果婚禮上长已,老公的妹妹穿的比我還像新娘畜眨。我一直安慰自己,他們只是感情好术瓮,可當我...
    茶點故事閱讀 67,753評論 6 392
  • 文/花漫 我一把揭開白布康聂。 她就那樣靜靜地躺著,像睡著了一般胞四。 火紅的嫁衣襯著肌膚如雪恬汁。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,598評論 1 305
  • 那天辜伟,我揣著相機與錄音氓侧,去河邊找鬼。 笑死导狡,一個胖子當著我的面吹牛约巷,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播旱捧,決...
    沈念sama閱讀 40,338評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼独郎,長吁一口氣:“原來是場噩夢啊……” “哼踩麦!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起氓癌,我...
    開封第一講書人閱讀 39,249評論 0 276
  • 序言:老撾萬榮一對情侶失蹤谓谦,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后贪婉,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體反粥,經(jīng)...
    沈念sama閱讀 45,696評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,888評論 3 336
  • 正文 我和宋清朗相戀三年疲迂,在試婚紗的時候發(fā)現(xiàn)自己被綠了才顿。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,013評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡鬼譬,死狀恐怖娜膘,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情优质,我是刑警寧澤竣贪,帶...
    沈念sama閱讀 35,731評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站巩螃,受9級特大地震影響演怎,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜避乏,卻給世界環(huán)境...
    茶點故事閱讀 41,348評論 3 330
  • 文/蒙蒙 一爷耀、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧拍皮,春花似錦歹叮、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至爹橱,卻和暖如春萨螺,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背愧驱。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評論 1 270
  • 我被黑心中介騙來泰國打工慰技, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人组砚。 一個月前我還...
    沈念sama閱讀 48,203評論 3 370
  • 正文 我出身青樓吻商,卻偏偏與公主長得像,于是被迫代替她去往敵國和親糟红。 傳聞我的和親對象是個殘疾皇子手报,可洞房花燭夜當晚...
    茶點故事閱讀 44,960評論 2 355

推薦閱讀更多精彩內(nèi)容