SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
sean666666@gmail.com P1
Control Hypervisor via Libvirt
Sean Chang
2011/4
sean666666@gmail.com P2
大綱
• 為什麼要用 libvirt
• Lifecycle of VM
• 順帶一提 virsh
• 順帶一提 xm
• 進入重點 libvirt
• Libvirt 使用範例
• Libvirt 使用經驗
• Libvirt 議題
• DEMO
sean666666@gmail.com P3
管理 hypervisor 的方法
• 下指令
o xm
o virsh
• 自己寫程式
o Libvirt
o A virtualization API
o Open source
o 可程式化
sean666666@gmail.com P4
飲水思源
了解VM(Guest domain)的生命週期
sean666666@gmail.com P5
Guest domain status
State Description
Undefine
d
This is the baseline state. An undefined guest domain has not been
defined or created in any way.
Defined A defined guest domain has been defined but is not running. This
state could also be described as Stopped.
Running A running guest domain is defined and being executed on a hypervisor.
Paused A paused guest domain is in a suspended state from the Running
state. Its memory image has been temporarily stored, and it can be
resumed to the Running state without the guest domain operating
system being aware it was ever suspended.
Saved A saved domain has had its memory image, as captured in the
Paused state, saved to persistent storage. It can be restored to the
Running state without the guest domain operating system being
aware it was ever suspended.
sean666666@gmail.com P6
Guest domain lifecycle
sean666666@gmail.com P7
VM(Guest domain) status
sean666666@gmail.com P8
VM Lifecycle
What does
Libvirt actully
do?
sean666666@gmail.com P9
工欲善其事
必先利其器
sean666666@gmail.com P10
xm
• Xen management user
interface
• The xm program is the main
interface for managing Xen
guest domains. The program
can be used to create, pause,
and shutdown domains. It can
also be used to list current
domains, enable or pin
VCPUs, and attach or detach
virtual block devices.
• Example
o xm create Fedora12
o xm start Fedora12
o xm help
o xm list
o xm mem-set {domain-id,
mem}
o xm migrate {domain-id,
host-ip}
o etc…沒事多玩指令,多
玩指令沒事
sean666666@gmail.com P11
virsh(1/2)
• virsh 是​個​用​來​管​理​客​座​端​和​
hypervisor(管​理​程​序​)的​指​令​
列​介​面​工​具​。
• 不過說穿了,這個指令列也是
用 libvirt 作為底層函式庫寫出
來的。
指​令​ Description
help 印​出​基​本​協​助​資​訊​。​
list 列​出​所​有​客​座​端​。​
dumpxml 輸​出​客​座​端​的​ XML 配​置​檔​案​。​
create 由​一​個​ XML 配​置​檔​案​來​建​立​客​座​端​並​啟​用​新​
的​客​座​端​。​
start 啟​用​一​個​未​啟​用​中​的​客​座​端​。​
destroy 強​制​客​座​端​停​下​。​
define 輸​出​客​座​端​的​ XML 配​置​檔​案​。​
domid 顯​示​客​座​端​的​ ID。​
domuuid 顯​示​客​座​端​的​ UUID。​
dominfo 顯​示​客​座​端​的​相​關​資​訊​。​
domname 顯​示​客​座​端​的​名​稱​。​
domstate 顯​示​客​座​端​的​狀​態​。​
quit 退​出​互​動​式​終​端​機​。​
reboot 重​新​啟​動​客​座​端​。​
restore 恢​復​之​前​已​儲​存​於​一​個​檔​案​中​的​客​座​端​。​
resume 恢​復​一​個​暫​停​中​的​客​座​端​。​
save 將​客​座​端​目​前​的​狀​態​儲​存​至​一​個​檔​案​中​。​
shutdown 正​常​地​停​用​客​座​端​。​
suspend 將​客​座​端​暫​停​。​
undefine 刪​除​與​某​個​客​座​端​有​關​聯​的​所​有​檔​案​。​
migrate 將​客​座​端​遷​移​至​另​一​部​主​機​上​。​
sean666666@gmail.com P12
virsh(2/2)
• Example
o # virsh connect {hostname
OR URL}
o # virsh create
configuration_file.xml
o # virsh suspend {domain-
id, domain-name or
domain-uuid}
o etc…沒事多玩指令,多
玩指令沒事
指​令​ Description
setmem 為​客​座​端​設​置​分​配​記​憶​體​。​
setmaxmem 設​定​ hypervisor 所​能​使​用​的​記​憶​體​最​大​限​制​。​
setvcpus 更​改​分​配​給​客​座​端​的​虛​擬​ CPU 數​量​。​
vcpuinfo 顯​示​有​關​於​客​座​端​的​虛​擬​ CPU 資​訊​。​
vcpupin 控​制​客​座​端​的​虛​擬​ CPU 相​似​性​。​
domblkstat 顯​示​正​在​執​行​中​的​客​座​端​的​區​塊​裝​置​數​據​。​
domifstat 顯​示​執​行​中​的​客​座​端​的​網​路​介​面​卡​數​據​。​
attach-device 透​過​使​用​某​個​ XML 檔​案​中​的​裝​置​定​義​來​將​裝​置​附​加​至​客​座​端​上​。​
attach-disk 附​加​新​磁​碟​裝​置​至​客​座​端​。​
attach-interface 附​加​新​網​路​介​面​卡​至​客​座​端​。​
detach-device 將​裝​置​從​客​座​端​上​分​離​,接​受​與​ attach-device 指​令​相​同​類​型​的​
XML 描​述​。​
detach-disk 將​磁​碟​裝​置​由​客​座​端​上​移​除​。​
detach-interface 將​網​路​介​面​卡​由​客​座​端​上​移​除​。​
sean666666@gmail.com P13
不是不寫程式
不過時後也已經到了
sean666666@gmail.com P14
Libvirt(http://libvirt.org/index.html)
• A toolkit to interact with the virtualization
capabilities of recent versions of Linux (and
other OSes), see our project goals for details.
• Free software available under the GNU Lesser
General Public License.(LGPL)
• A long term stable C API
• A set of bindings for common languages.(Java、
Python…etc)
• Latest release: 0.8.8: Feb 17 2011
sean666666@gmail.com P15
Terminology and goals
Xen
…
一般稱呼 Libvirt的術語 解釋
VM Domain An instance of an operating system (or
subsystem in the case of container
virtualization) running on a virtualized machine
provided by the hypervisor
Xen Hypervisor A layer of software allowing to virtualize a
node in a set of virtual machines with possibly
different configurations than the node itself
Physical
machine
Node A single physical machine
sean666666@gmail.com P16
Libvirt drivers
• Hypervisor drivers
o LXC - Linux Containers
o OpenVZ
o QEMU
o Test - Used for testing
o UML - User Mode Linux
o VirtualBox
o VMware ESX
o VMware
Workstation/Player
o Xen
o 支援Multi-Vendor(表面上…)
• Storage drivers
o Directory backend
o Local filesystem backend
o Network filesystem backend
o Logical Volume Manager
(LVM) backend
o Disk backend
o iSCSI backend
o SCSI backend
o Multipath backend
sean666666@gmail.com P17
API concepts(1/2)
Objects exposed
sean666666@gmail.com P18
API concepts(2/2)
Libvirt drivers
就是OS
或是應用程式
API呼叫
deamon
remotelocal
sean666666@gmail.com P19
Xen config V.S. XML
• VM的設定檔
o For Xen
o For libvirt
sean666666@gmail.com P20
細述 XML
unique
全虛擬
最大的實體資源分配
網路採bridge方式對外連通
這張虛擬網卡
掛在node的xenbr0
VNC port
sean666666@gmail.com P21
Python example – 基本VM操作
sean666666@gmail.com P22
Python example – 掛載/卸載磁碟
已經準備好
掛載的image空間
sean666666@gmail.com P23
我不入地獄 誰…
往下挖
sean666666@gmail.com P24
認證
• 呼叫遠端的libvirtd需要先經過認證,認證方
式如下
• ssh
o ssh username root: xen+ssh://root@node.example.com/
o 然後輸入帳號密碼,缺點,如果程式要全自動化會被卡在這裡。
• authorized key
o 製作Public / private key
o #ssh-keygen -t rsa
o 放在相對應的目錄: /root/.ssh/
sean666666@gmail.com P25
Debug / loggin
• Log message
o Generated at runtime by the libvirt code
o Timestamp, a category, a priority level, function name and line number indicating
where the message originated from, and a formatted message.
• Priority levels
o 1 (or debug) - log all messages
o 2 (or info) - log all non-debugging information
o 3 (or warn) - log only warnings and errors - this is the default
o 4 (or error) - log only errors
• Filter
o x:name
o 1:qemu
o 1:qemu 4:remote
• Log output
o 3:syslog:libvirtd 1:file:/tmp/libvirt.log
sean666666@gmail.com P26
虛擬裝置也支援熱插拔嗎?
• 半虛擬技術支援在不開機的情況下,CPU、MEM、DISK
都可以做調整。
• 全虛擬CPU、MEM要調整一定得重開機。
• 全虛擬DISK熱插拔則視VM的kernel版本而定。
• The Xen device model is more or less unchanged in the pv-ops
kernel. Converting a driver from the xen-unstable or 2.6.18-xen tree
should mostly be a matter of getting it to compile. There have been
changes in the Linux device model between 2.6.18 and 2.6.26, so
converting a driver will mostly be a matter of forward-porting to the
new kernel, rather than any Xen specific issues.
• Kernel version > 2.6.26 可能比較穩定有機會實現全虛擬的硬碟熱插
拔。
sean666666@gmail.com P27
Xen disk kinds and supporting
• Disk type
o IDE
o Virtual disk
o iSCSI
o USB Disk
• 實測熱插拔
xen 4.0 + 2.6.32.11
/ Dell
Storage
IDE Virtual SCSI USB Disk
centos5.4final
Kernel 2.6.18
× ○ × ×
RH6beta
Kernel 2.6.18
× × × ×
sean666666@gmail.com P28
API Issues
• create 跟 define 有什麼不同?
o 都是用來創建VM的API
o 差別在生命週期不完全相同
o create: 創建VM之外,順便把VM開起來,shutdown後該VM自動
從hypervisor卸除。
o define: 僅創建VM,須靠start API把VM開起來,但永遠定義在
hypervisor裡。甚至連migrate後也在。
• shutdown 跟 destroy 有什麼不同?
o 都是要把VM的狀態從running改成stop
o Shutdown:就是一般作業系統的關機。
o Destroy:以實體主機來看,就是直接把插頭拔掉。
sean666666@gmail.com P29
Development trick(1/3) - Problem
• Libvirt 在偵測 xen 上的VM實際狀態不穩定
• 連續下五十次偵測VM status的結果
[2, 665600L, 444416L, 1, 178818312669L][2, 665600L, 444416L, 1, 178818786889L][2, 665600L, 444416L, 1, 178819270686L][2
665600L, 444416L, 1, 178819782827L][2, 665600L, 444416L, 1, 178820286716L][0, 665600L, 444416L, 1, 178825799216L][2,
665600L, 444416L, 1, 178826484955L][2, 665600L, 444416L, 1, 178827054507L][2, 665600L, 444416L, 1, 178827646602L][2,
665600L, 444416L, 1, 178828162295L][2, 665600L, 444416L, 1, 178828718993L][2, 665600L, 444416L, 1, 178830313690L][2,
665600L, 444416L, 1, 178831831052L][2, 665600L, 444416L, 1, 178832305724L][2, 665600L, 444416L, 1, 178832859023L][2,
665600L, 444416L, 1, 178833339605L][2, 665600L, 444416L, 1, 178833848167L][2, 665600L, 444416L, 1, 178834372305L][2,
665600L, 444416L, 1, 178834895557L][2, 665600L, 444416L, 1, 178835386865L][2, 665600L, 444416L, 1, 178835922103L][2,
665600L, 444416L, 1, 178836494779L][2, 665600L, 444416L, 1, 178836973848L][2, 665600L, 444416L, 1, 178837452908L][2,
665600L, 444416L, 1, 178838008290L][2, 665600L, 444416L, 1, 178838553784L][2, 665600L, 444416L, 1, 178839024984L][2,
665600L, 444416L, 1, 178839462699L][2, 665600L, 444416L, 1, 178839987321L][2, 665600L, 444416L, 1, 178840510368L][2,
665600L, 444416L, 1, 178841185524L][2, 665600L, 444416L, 1, 178841873368L][2, 665600L, 444416L, 1, 178842393659L][2,
665600L, 444416L, 1, 178842910878L][2, 665600L, 444416L, 1, 178843454749L][2, 665600L, 444416L, 1, 178843947320L][2,
665600L, 444416L, 1, 178844427452L][2, 665600L, 444416L, 1, 178844942837L][2, 665600L, 444416L, 1, 178845472009L][2,
665600L, 444416L, 1, 178846036556L][2, 665600L, 444416L, 1, 178846502921L][2, 665600L, 444416L, 1, 178847082404L][2,
665600L, 444416L, 1, 178847612475L][2, 665600L, 444416L, 1, 178848158639L][2, 665600L, 444416L, 1, 178848527989L][2,
665600L, 444416L, 1, 178849177317L][2, 665600L, 444416L, 1, 178849704749L][2, 665600L, 444416L, 1, 178850274864L][2,
665600L, 444416L, 1, 178850717630L][2, 665600L, 444416L, 1, 178851307315L][2, 665600L, 444416L, 1, 178852079044L][2,
665600L, 444416L, 1, 178852861964L][2, 665600L, 444416L, 1, 178854056260L][2, 665600L, 444416L, 1, 178854907434L][2,
665600L, 444416L, 1, 178856457345L][2, 665600L, 444416L, 1, 178856918293L][2, 665600L, 444416L, 1, 178857394787L][1,
665600L, 444416L, 1, 178857716163L][2, 665600L, 444416L, 1, 178858177594L][2, 665600L, 444416L, 1, 178858773954L][2,
665600L, 444416L, 1, 178859309076L][2, 665600L, 444416L, 1, 178859897892L][2, 665600L, 444416L, 1, 178860400666L][2,
665600L, 444416L, 1, 178860937146L][2, 665600L, 444416L, 1, 178861383848L][1, 665600L, 444416L, 1, 178861889219L][2,
665600L, 444416L, 1, 178862333614L][2, 665600L, 444416L, 1, 178862848250L][2, 665600L, 444416L, 1, 178863325489L][2,
665600L, 444416L, 1, 178863674106L][2, 665600L, 444416L, 1, 178864153743L][2, 665600L, 444416L, 1, 178864647934L][2,
665600L, 444416L, 1, 178864970657L][2, 665600L, 444416L, 1, 178865558487L][2, 665600L, 444416L, 1, 178865890459L][2,
665600L, 444416L, 1, 178866309383L][2, 665600L, 444416L, 1, 178866793058L][2, 665600L, 444416L, 1, 178867306348L][2,
sean666666@gmail.com P30
Development trick(2/3) - Solution
• 如果狀態不穩,我們無法取得VM確實的狀態。
• 參考 VirtManager 的解法,利用以下API的特性
o 找出可以幫忙的 libvirt API。
o listDomainsID(): 列出所有xen上在跑的domain。
o 因為只有running的VM狀態不穩,所以利用listDomianID()這個
API把這些可能不穩的VM先抓出來,在把0,1,2等狀態都歸納為
runnung。
sean666666@gmail.com P31
Development trick(3/3) - Code
31
1
2
3
4
5
sean666666@gmail.com P32
libvirt 處理 Xen 與 KVM 的行為
• 不同的 hypervisor,libvirt的行為也會有所差異
• 以下以Xen跟KVM為例:
sean666666@gmail.com P33
開發心得
• 多用python的特有的API查詢指令help()、dir()來
幫助自己掌握libvirt的版況
• 不要太期待libvirt可以幫你做太多很強大的事情,
官網很多只定義好介面,尚未實作。舉例:
• 要熟悉XML config
• 要熟悉hypervisor的行為
sean666666@gmail.com P34
參考資料
• http://docs.fedoraproject.org/zh-
TW/Fedora/12/html/Virtualization_Guide/chap-Virtualization_Guide-
Managing_guests_with_virsh.html
• http://linux.die.net/man/1/xm
• http://libvirt.org/index.html
• http://libvirt.org/sources/virshcmdref/html/
• http://wiki.xensource.com/xenwiki/XenParavirtOps
sean666666@gmail.com P35
DEMO
• 準備 VM
o define
o create
• 操作 VM
o start
o suspend
o resume
o reboot
o shutdown
• 添加/卸載設備
o attach
o detach
• 取得 VM
o lookupByXXX
• 跨主機(下回分曉…)
o virtManager 介紹
o migration
o live migration
sean666666@gmail.com P36
Thank you
• 末記
o 這份資料的技術實作於2010~2011,如非最新資料,敬
請見諒
• End
o The technology information was implemented in 2010 ~
2011, sorry for no update on time.

Contenu connexe

Tendances

Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterSimen Li
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneDefconRussia
 
CKA Certified Kubernetes Administrator Notes
CKA Certified Kubernetes Administrator Notes CKA Certified Kubernetes Administrator Notes
CKA Certified Kubernetes Administrator Notes Adnan Rashid
 
コンテナ仮想、その裏側 〜user namespaceとrootlessコンテナ〜
コンテナ仮想、その裏側 〜user namespaceとrootlessコンテナ〜コンテナ仮想、その裏側 〜user namespaceとrootlessコンテナ〜
コンテナ仮想、その裏側 〜user namespaceとrootlessコンテナ〜Retrieva inc.
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNoSuchCon
 
2011-03 Developing Windows Exploits
2011-03 Developing Windows Exploits 2011-03 Developing Windows Exploits
2011-03 Developing Windows Exploits Raleigh ISSA
 
Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Giovanni Bechis
 
Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門
Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門
Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門tamtam180
 
Linux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium SandboxLinux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium SandboxPatricia Aas
 
Creating "Secure" PHP applications, Part 2, Server Hardening
Creating "Secure" PHP applications, Part 2, Server HardeningCreating "Secure" PHP applications, Part 2, Server Hardening
Creating "Secure" PHP applications, Part 2, Server Hardeningarchwisp
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
Threat stack aws
Threat stack awsThreat stack aws
Threat stack awsJen Andre
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.Mike Brevoort
 
Проведение криминалистической экспертизы и анализа руткит-программ на примере...
Проведение криминалистической экспертизы и анализа руткит-программ на примере...Проведение криминалистической экспертизы и анализа руткит-программ на примере...
Проведение криминалистической экспертизы и анализа руткит-программ на примере...Alex Matrosov
 
Эксплуатируем неэксплуатируемые уязвимости SAP
Эксплуатируем неэксплуатируемые уязвимости SAPЭксплуатируем неэксплуатируемые уязвимости SAP
Эксплуатируем неэксплуатируемые уязвимости SAPPositive Hack Days
 
Chromium Sandbox on Linux (NDC Security 2019)
Chromium Sandbox on Linux (NDC Security 2019)Chromium Sandbox on Linux (NDC Security 2019)
Chromium Sandbox on Linux (NDC Security 2019)Patricia Aas
 

Tendances (20)

Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitter
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
 
CKA Certified Kubernetes Administrator Notes
CKA Certified Kubernetes Administrator Notes CKA Certified Kubernetes Administrator Notes
CKA Certified Kubernetes Administrator Notes
 
コンテナ仮想、その裏側 〜user namespaceとrootlessコンテナ〜
コンテナ仮想、その裏側 〜user namespaceとrootlessコンテナ〜コンテナ仮想、その裏側 〜user namespaceとrootlessコンテナ〜
コンテナ仮想、その裏側 〜user namespaceとrootlessコンテナ〜
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge Solution
 
Testing NodeJS Security
Testing NodeJS SecurityTesting NodeJS Security
Testing NodeJS Security
 
2011-03 Developing Windows Exploits
2011-03 Developing Windows Exploits 2011-03 Developing Windows Exploits
2011-03 Developing Windows Exploits
 
Cutting out Malware
Cutting out MalwareCutting out Malware
Cutting out Malware
 
Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)
 
Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門
Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門
Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門
 
Linux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium SandboxLinux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium Sandbox
 
Creating "Secure" PHP applications, Part 2, Server Hardening
Creating "Secure" PHP applications, Part 2, Server HardeningCreating "Secure" PHP applications, Part 2, Server Hardening
Creating "Secure" PHP applications, Part 2, Server Hardening
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Threat stack aws
Threat stack awsThreat stack aws
Threat stack aws
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
iCloud keychain
iCloud keychainiCloud keychain
iCloud keychain
 
Проведение криминалистической экспертизы и анализа руткит-программ на примере...
Проведение криминалистической экспертизы и анализа руткит-программ на примере...Проведение криминалистической экспертизы и анализа руткит-программ на примере...
Проведение криминалистической экспертизы и анализа руткит-программ на примере...
 
Event loop
Event loopEvent loop
Event loop
 
Эксплуатируем неэксплуатируемые уязвимости SAP
Эксплуатируем неэксплуатируемые уязвимости SAPЭксплуатируем неэксплуатируемые уязвимости SAP
Эксплуатируем неэксплуатируемые уязвимости SAP
 
Chromium Sandbox on Linux (NDC Security 2019)
Chromium Sandbox on Linux (NDC Security 2019)Chromium Sandbox on Linux (NDC Security 2019)
Chromium Sandbox on Linux (NDC Security 2019)
 

Similaire à Control hypervisor via libvirt

NetDevOps Developer Environments with Vagrant @ SCALE16x
NetDevOps Developer Environments with Vagrant @ SCALE16xNetDevOps Developer Environments with Vagrant @ SCALE16x
NetDevOps Developer Environments with Vagrant @ SCALE16xHank Preston
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.Javier López
 
HashiCorp Vault Workshop:幫 Credentials 找個窩
HashiCorp Vault Workshop:幫 Credentials 找個窩HashiCorp Vault Workshop:幫 Credentials 找個窩
HashiCorp Vault Workshop:幫 Credentials 找個窩smalltown
 
MySQL 8.0 InnoDB Cluster demo
MySQL 8.0 InnoDB Cluster demoMySQL 8.0 InnoDB Cluster demo
MySQL 8.0 InnoDB Cluster demoKeith Hollman
 
Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Rich Bowen
 
Dockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and NovaDockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and Novaclayton_oneill
 
Issuing temporary credentials for my sql using hashicorp vault
Issuing temporary credentials for my sql using hashicorp vaultIssuing temporary credentials for my sql using hashicorp vault
Issuing temporary credentials for my sql using hashicorp vaultOlinData
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newYiwei Ma
 
Making Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixMaking Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixDiana Tkachenko
 
Your Inner Sysadmin - LonestarPHP 2015
Your Inner Sysadmin - LonestarPHP 2015Your Inner Sysadmin - LonestarPHP 2015
Your Inner Sysadmin - LonestarPHP 2015Chris Tankersley
 
Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Rich Bowen
 
Small Python Tools for Software Release Engineering
Small Python Tools for Software Release EngineeringSmall Python Tools for Software Release Engineering
Small Python Tools for Software Release Engineeringpycontw
 
Tatu: ssh as a service
Tatu: ssh as a serviceTatu: ssh as a service
Tatu: ssh as a servicePino deCandia
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP applicationJavier López
 
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context ConstraintsAlessandro Arrichiello
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...Hackito Ergo Sum
 
Orange@php conf
Orange@php confOrange@php conf
Orange@php confHash Lin
 

Similaire à Control hypervisor via libvirt (20)

NetDevOps Developer Environments with Vagrant @ SCALE16x
NetDevOps Developer Environments with Vagrant @ SCALE16xNetDevOps Developer Environments with Vagrant @ SCALE16x
NetDevOps Developer Environments with Vagrant @ SCALE16x
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.
 
HashiCorp Vault Workshop:幫 Credentials 找個窩
HashiCorp Vault Workshop:幫 Credentials 找個窩HashiCorp Vault Workshop:幫 Credentials 找個窩
HashiCorp Vault Workshop:幫 Credentials 找個窩
 
MySQL 8.0 InnoDB Cluster demo
MySQL 8.0 InnoDB Cluster demoMySQL 8.0 InnoDB Cluster demo
MySQL 8.0 InnoDB Cluster demo
 
Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011
 
Capistrano
CapistranoCapistrano
Capistrano
 
Dockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and NovaDockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and Nova
 
Issuing temporary credentials for my sql using hashicorp vault
Issuing temporary credentials for my sql using hashicorp vaultIssuing temporary credentials for my sql using hashicorp vault
Issuing temporary credentials for my sql using hashicorp vault
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
Making Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixMaking Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch Fix
 
Your Inner Sysadmin - LonestarPHP 2015
Your Inner Sysadmin - LonestarPHP 2015Your Inner Sysadmin - LonestarPHP 2015
Your Inner Sysadmin - LonestarPHP 2015
 
Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010
 
Small Python Tools for Software Release Engineering
Small Python Tools for Software Release EngineeringSmall Python Tools for Software Release Engineering
Small Python Tools for Software Release Engineering
 
Introducing Vault
Introducing VaultIntroducing Vault
Introducing Vault
 
Tatu: ssh as a service
Tatu: ssh as a serviceTatu: ssh as a service
Tatu: ssh as a service
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
 
Run Node Run
Run Node RunRun Node Run
Run Node Run
 
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
 
Orange@php conf
Orange@php confOrange@php conf
Orange@php conf
 

Dernier

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Dernier (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Control hypervisor via libvirt

  • 1. sean666666@gmail.com P1 Control Hypervisor via Libvirt Sean Chang 2011/4
  • 2. sean666666@gmail.com P2 大綱 • 為什麼要用 libvirt • Lifecycle of VM • 順帶一提 virsh • 順帶一提 xm • 進入重點 libvirt • Libvirt 使用範例 • Libvirt 使用經驗 • Libvirt 議題 • DEMO
  • 3. sean666666@gmail.com P3 管理 hypervisor 的方法 • 下指令 o xm o virsh • 自己寫程式 o Libvirt o A virtualization API o Open source o 可程式化
  • 5. sean666666@gmail.com P5 Guest domain status State Description Undefine d This is the baseline state. An undefined guest domain has not been defined or created in any way. Defined A defined guest domain has been defined but is not running. This state could also be described as Stopped. Running A running guest domain is defined and being executed on a hypervisor. Paused A paused guest domain is in a suspended state from the Running state. Its memory image has been temporarily stored, and it can be resumed to the Running state without the guest domain operating system being aware it was ever suspended. Saved A saved domain has had its memory image, as captured in the Paused state, saved to persistent storage. It can be restored to the Running state without the guest domain operating system being aware it was ever suspended.
  • 8. sean666666@gmail.com P8 VM Lifecycle What does Libvirt actully do?
  • 10. sean666666@gmail.com P10 xm • Xen management user interface • The xm program is the main interface for managing Xen guest domains. The program can be used to create, pause, and shutdown domains. It can also be used to list current domains, enable or pin VCPUs, and attach or detach virtual block devices. • Example o xm create Fedora12 o xm start Fedora12 o xm help o xm list o xm mem-set {domain-id, mem} o xm migrate {domain-id, host-ip} o etc…沒事多玩指令,多 玩指令沒事
  • 11. sean666666@gmail.com P11 virsh(1/2) • virsh 是​個​用​來​管​理​客​座​端​和​ hypervisor(管​理​程​序​)的​指​令​ 列​介​面​工​具​。 • 不過說穿了,這個指令列也是 用 libvirt 作為底層函式庫寫出 來的。 指​令​ Description help 印​出​基​本​協​助​資​訊​。​ list 列​出​所​有​客​座​端​。​ dumpxml 輸​出​客​座​端​的​ XML 配​置​檔​案​。​ create 由​一​個​ XML 配​置​檔​案​來​建​立​客​座​端​並​啟​用​新​ 的​客​座​端​。​ start 啟​用​一​個​未​啟​用​中​的​客​座​端​。​ destroy 強​制​客​座​端​停​下​。​ define 輸​出​客​座​端​的​ XML 配​置​檔​案​。​ domid 顯​示​客​座​端​的​ ID。​ domuuid 顯​示​客​座​端​的​ UUID。​ dominfo 顯​示​客​座​端​的​相​關​資​訊​。​ domname 顯​示​客​座​端​的​名​稱​。​ domstate 顯​示​客​座​端​的​狀​態​。​ quit 退​出​互​動​式​終​端​機​。​ reboot 重​新​啟​動​客​座​端​。​ restore 恢​復​之​前​已​儲​存​於​一​個​檔​案​中​的​客​座​端​。​ resume 恢​復​一​個​暫​停​中​的​客​座​端​。​ save 將​客​座​端​目​前​的​狀​態​儲​存​至​一​個​檔​案​中​。​ shutdown 正​常​地​停​用​客​座​端​。​ suspend 將​客​座​端​暫​停​。​ undefine 刪​除​與​某​個​客​座​端​有​關​聯​的​所​有​檔​案​。​ migrate 將​客​座​端​遷​移​至​另​一​部​主​機​上​。​
  • 12. sean666666@gmail.com P12 virsh(2/2) • Example o # virsh connect {hostname OR URL} o # virsh create configuration_file.xml o # virsh suspend {domain- id, domain-name or domain-uuid} o etc…沒事多玩指令,多 玩指令沒事 指​令​ Description setmem 為​客​座​端​設​置​分​配​記​憶​體​。​ setmaxmem 設​定​ hypervisor 所​能​使​用​的​記​憶​體​最​大​限​制​。​ setvcpus 更​改​分​配​給​客​座​端​的​虛​擬​ CPU 數​量​。​ vcpuinfo 顯​示​有​關​於​客​座​端​的​虛​擬​ CPU 資​訊​。​ vcpupin 控​制​客​座​端​的​虛​擬​ CPU 相​似​性​。​ domblkstat 顯​示​正​在​執​行​中​的​客​座​端​的​區​塊​裝​置​數​據​。​ domifstat 顯​示​執​行​中​的​客​座​端​的​網​路​介​面​卡​數​據​。​ attach-device 透​過​使​用​某​個​ XML 檔​案​中​的​裝​置​定​義​來​將​裝​置​附​加​至​客​座​端​上​。​ attach-disk 附​加​新​磁​碟​裝​置​至​客​座​端​。​ attach-interface 附​加​新​網​路​介​面​卡​至​客​座​端​。​ detach-device 將​裝​置​從​客​座​端​上​分​離​,接​受​與​ attach-device 指​令​相​同​類​型​的​ XML 描​述​。​ detach-disk 將​磁​碟​裝​置​由​客​座​端​上​移​除​。​ detach-interface 將​網​路​介​面​卡​由​客​座​端​上​移​除​。​
  • 14. sean666666@gmail.com P14 Libvirt(http://libvirt.org/index.html) • A toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes), see our project goals for details. • Free software available under the GNU Lesser General Public License.(LGPL) • A long term stable C API • A set of bindings for common languages.(Java、 Python…etc) • Latest release: 0.8.8: Feb 17 2011
  • 15. sean666666@gmail.com P15 Terminology and goals Xen … 一般稱呼 Libvirt的術語 解釋 VM Domain An instance of an operating system (or subsystem in the case of container virtualization) running on a virtualized machine provided by the hypervisor Xen Hypervisor A layer of software allowing to virtualize a node in a set of virtual machines with possibly different configurations than the node itself Physical machine Node A single physical machine
  • 16. sean666666@gmail.com P16 Libvirt drivers • Hypervisor drivers o LXC - Linux Containers o OpenVZ o QEMU o Test - Used for testing o UML - User Mode Linux o VirtualBox o VMware ESX o VMware Workstation/Player o Xen o 支援Multi-Vendor(表面上…) • Storage drivers o Directory backend o Local filesystem backend o Network filesystem backend o Logical Volume Manager (LVM) backend o Disk backend o iSCSI backend o SCSI backend o Multipath backend
  • 18. sean666666@gmail.com P18 API concepts(2/2) Libvirt drivers 就是OS 或是應用程式 API呼叫 deamon remotelocal
  • 19. sean666666@gmail.com P19 Xen config V.S. XML • VM的設定檔 o For Xen o For libvirt
  • 22. sean666666@gmail.com P22 Python example – 掛載/卸載磁碟 已經準備好 掛載的image空間
  • 24. sean666666@gmail.com P24 認證 • 呼叫遠端的libvirtd需要先經過認證,認證方 式如下 • ssh o ssh username root: xen+ssh://root@node.example.com/ o 然後輸入帳號密碼,缺點,如果程式要全自動化會被卡在這裡。 • authorized key o 製作Public / private key o #ssh-keygen -t rsa o 放在相對應的目錄: /root/.ssh/
  • 25. sean666666@gmail.com P25 Debug / loggin • Log message o Generated at runtime by the libvirt code o Timestamp, a category, a priority level, function name and line number indicating where the message originated from, and a formatted message. • Priority levels o 1 (or debug) - log all messages o 2 (or info) - log all non-debugging information o 3 (or warn) - log only warnings and errors - this is the default o 4 (or error) - log only errors • Filter o x:name o 1:qemu o 1:qemu 4:remote • Log output o 3:syslog:libvirtd 1:file:/tmp/libvirt.log
  • 26. sean666666@gmail.com P26 虛擬裝置也支援熱插拔嗎? • 半虛擬技術支援在不開機的情況下,CPU、MEM、DISK 都可以做調整。 • 全虛擬CPU、MEM要調整一定得重開機。 • 全虛擬DISK熱插拔則視VM的kernel版本而定。 • The Xen device model is more or less unchanged in the pv-ops kernel. Converting a driver from the xen-unstable or 2.6.18-xen tree should mostly be a matter of getting it to compile. There have been changes in the Linux device model between 2.6.18 and 2.6.26, so converting a driver will mostly be a matter of forward-porting to the new kernel, rather than any Xen specific issues. • Kernel version > 2.6.26 可能比較穩定有機會實現全虛擬的硬碟熱插 拔。
  • 27. sean666666@gmail.com P27 Xen disk kinds and supporting • Disk type o IDE o Virtual disk o iSCSI o USB Disk • 實測熱插拔 xen 4.0 + 2.6.32.11 / Dell Storage IDE Virtual SCSI USB Disk centos5.4final Kernel 2.6.18 × ○ × × RH6beta Kernel 2.6.18 × × × ×
  • 28. sean666666@gmail.com P28 API Issues • create 跟 define 有什麼不同? o 都是用來創建VM的API o 差別在生命週期不完全相同 o create: 創建VM之外,順便把VM開起來,shutdown後該VM自動 從hypervisor卸除。 o define: 僅創建VM,須靠start API把VM開起來,但永遠定義在 hypervisor裡。甚至連migrate後也在。 • shutdown 跟 destroy 有什麼不同? o 都是要把VM的狀態從running改成stop o Shutdown:就是一般作業系統的關機。 o Destroy:以實體主機來看,就是直接把插頭拔掉。
  • 29. sean666666@gmail.com P29 Development trick(1/3) - Problem • Libvirt 在偵測 xen 上的VM實際狀態不穩定 • 連續下五十次偵測VM status的結果 [2, 665600L, 444416L, 1, 178818312669L][2, 665600L, 444416L, 1, 178818786889L][2, 665600L, 444416L, 1, 178819270686L][2 665600L, 444416L, 1, 178819782827L][2, 665600L, 444416L, 1, 178820286716L][0, 665600L, 444416L, 1, 178825799216L][2, 665600L, 444416L, 1, 178826484955L][2, 665600L, 444416L, 1, 178827054507L][2, 665600L, 444416L, 1, 178827646602L][2, 665600L, 444416L, 1, 178828162295L][2, 665600L, 444416L, 1, 178828718993L][2, 665600L, 444416L, 1, 178830313690L][2, 665600L, 444416L, 1, 178831831052L][2, 665600L, 444416L, 1, 178832305724L][2, 665600L, 444416L, 1, 178832859023L][2, 665600L, 444416L, 1, 178833339605L][2, 665600L, 444416L, 1, 178833848167L][2, 665600L, 444416L, 1, 178834372305L][2, 665600L, 444416L, 1, 178834895557L][2, 665600L, 444416L, 1, 178835386865L][2, 665600L, 444416L, 1, 178835922103L][2, 665600L, 444416L, 1, 178836494779L][2, 665600L, 444416L, 1, 178836973848L][2, 665600L, 444416L, 1, 178837452908L][2, 665600L, 444416L, 1, 178838008290L][2, 665600L, 444416L, 1, 178838553784L][2, 665600L, 444416L, 1, 178839024984L][2, 665600L, 444416L, 1, 178839462699L][2, 665600L, 444416L, 1, 178839987321L][2, 665600L, 444416L, 1, 178840510368L][2, 665600L, 444416L, 1, 178841185524L][2, 665600L, 444416L, 1, 178841873368L][2, 665600L, 444416L, 1, 178842393659L][2, 665600L, 444416L, 1, 178842910878L][2, 665600L, 444416L, 1, 178843454749L][2, 665600L, 444416L, 1, 178843947320L][2, 665600L, 444416L, 1, 178844427452L][2, 665600L, 444416L, 1, 178844942837L][2, 665600L, 444416L, 1, 178845472009L][2, 665600L, 444416L, 1, 178846036556L][2, 665600L, 444416L, 1, 178846502921L][2, 665600L, 444416L, 1, 178847082404L][2, 665600L, 444416L, 1, 178847612475L][2, 665600L, 444416L, 1, 178848158639L][2, 665600L, 444416L, 1, 178848527989L][2, 665600L, 444416L, 1, 178849177317L][2, 665600L, 444416L, 1, 178849704749L][2, 665600L, 444416L, 1, 178850274864L][2, 665600L, 444416L, 1, 178850717630L][2, 665600L, 444416L, 1, 178851307315L][2, 665600L, 444416L, 1, 178852079044L][2, 665600L, 444416L, 1, 178852861964L][2, 665600L, 444416L, 1, 178854056260L][2, 665600L, 444416L, 1, 178854907434L][2, 665600L, 444416L, 1, 178856457345L][2, 665600L, 444416L, 1, 178856918293L][2, 665600L, 444416L, 1, 178857394787L][1, 665600L, 444416L, 1, 178857716163L][2, 665600L, 444416L, 1, 178858177594L][2, 665600L, 444416L, 1, 178858773954L][2, 665600L, 444416L, 1, 178859309076L][2, 665600L, 444416L, 1, 178859897892L][2, 665600L, 444416L, 1, 178860400666L][2, 665600L, 444416L, 1, 178860937146L][2, 665600L, 444416L, 1, 178861383848L][1, 665600L, 444416L, 1, 178861889219L][2, 665600L, 444416L, 1, 178862333614L][2, 665600L, 444416L, 1, 178862848250L][2, 665600L, 444416L, 1, 178863325489L][2, 665600L, 444416L, 1, 178863674106L][2, 665600L, 444416L, 1, 178864153743L][2, 665600L, 444416L, 1, 178864647934L][2, 665600L, 444416L, 1, 178864970657L][2, 665600L, 444416L, 1, 178865558487L][2, 665600L, 444416L, 1, 178865890459L][2, 665600L, 444416L, 1, 178866309383L][2, 665600L, 444416L, 1, 178866793058L][2, 665600L, 444416L, 1, 178867306348L][2,
  • 30. sean666666@gmail.com P30 Development trick(2/3) - Solution • 如果狀態不穩,我們無法取得VM確實的狀態。 • 參考 VirtManager 的解法,利用以下API的特性 o 找出可以幫忙的 libvirt API。 o listDomainsID(): 列出所有xen上在跑的domain。 o 因為只有running的VM狀態不穩,所以利用listDomianID()這個 API把這些可能不穩的VM先抓出來,在把0,1,2等狀態都歸納為 runnung。
  • 32. sean666666@gmail.com P32 libvirt 處理 Xen 與 KVM 的行為 • 不同的 hypervisor,libvirt的行為也會有所差異 • 以下以Xen跟KVM為例:
  • 33. sean666666@gmail.com P33 開發心得 • 多用python的特有的API查詢指令help()、dir()來 幫助自己掌握libvirt的版況 • 不要太期待libvirt可以幫你做太多很強大的事情, 官網很多只定義好介面,尚未實作。舉例: • 要熟悉XML config • 要熟悉hypervisor的行為
  • 34. sean666666@gmail.com P34 參考資料 • http://docs.fedoraproject.org/zh- TW/Fedora/12/html/Virtualization_Guide/chap-Virtualization_Guide- Managing_guests_with_virsh.html • http://linux.die.net/man/1/xm • http://libvirt.org/index.html • http://libvirt.org/sources/virshcmdref/html/ • http://wiki.xensource.com/xenwiki/XenParavirtOps
  • 35. sean666666@gmail.com P35 DEMO • 準備 VM o define o create • 操作 VM o start o suspend o resume o reboot o shutdown • 添加/卸載設備 o attach o detach • 取得 VM o lookupByXXX • 跨主機(下回分曉…) o virtManager 介紹 o migration o live migration
  • 36. sean666666@gmail.com P36 Thank you • 末記 o 這份資料的技術實作於2010~2011,如非最新資料,敬 請見諒 • End o The technology information was implemented in 2010 ~ 2011, sorry for no update on time.