Product SiteDocumentation Site

Red Hat Enterprise Linux 5

虛​擬​化​指​南​

Virtualization Documentation

版 5.8

Red Hat Engineering Content Services

法律聲明

Copyright © 2008, 2009, 2010, 2011, 2012 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–​​​Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the Infinity Logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
All other trademarks are the property of their respective owners.


1801 Varsity Drive
 RaleighNC 27606-2072 USA
 Phone: +1 919 754 3700
 Phone: 888 733 4281
 Fax: +1 919 754 3701

摘要
The Red Hat Enterprise Linux Virtualization Guide contains information on installation, configuring, administering, and troubleshooting virtualization technologies included with Red Hat Enterprise Linux.

序​言​
1. 關​於​本​指​南​
2. 文​​​件​​​常​​​規​​​
2.1. 排​​​字​​​上​​​的​​​常​​​規​​​
2.2. 引​​​述​​​常​​​規​​​
2.3. 註​​​解​​​和​​​警​​​告​​​
3. We need your feedback
3.1. Technical review requests
4. What is Virtualization?
5. Types of Virtualization
5.1. Full Virtualization
5.2. Para-Virtualization
5.3. Para-virtualized drivers
6. How CIOs should think about virtualization
I. Red Hat Enterprise Linux 虛​擬​化​方​案​的​需​求​與​限​制​
1. 系​統​需​求​
2. Xen 的​限​制​與​支​援​
3. KVM 的​限​制​與​支​援​
4. Hyper-V restrictions and support
5. 虛​擬​化​的​限​制​
5.1. 虛​擬​化​的​一​般​限​制​
5.2. KVM 的​限​制​
5.3. Xen 的​限​制​
5.4. 應​用​程​式​的​限​制​
II. 安​裝​
6. 安​裝​虛​擬​化​套​件​
6.1. 在​ Red Hat Enterprise Linux 安​裝​程​序​進​行​時​安​裝​ Xen
6.2. 在​一​部​現​有​的​ Red Hat Enterprise Linux 系​統​上​安​裝​ Xen 套​件​
6.3. 安​裝​ Red Hat Enterprise Linux 時​安​裝​ KVM
6.4. 在​一​部​現​有​的​ Red Hat Enterprise Linux 系​統​上​安​裝​ KVM
7. 虛​擬​化​客​座​端​安​裝​總​覽​
7.1. 透​過​ virt-install 來​建​立​客​座​端​
7.2. 透​過​ virt-manager 來​建​立​客​座​端​
7.3. 使​用​ PXE 來​安​裝​客​座​端​
8. 客​座​端​作​業​系​統​的​安​裝​程​序​
8.1. 將​ Red Hat Enterprise Linux 5 安​裝​為​半​虛​擬​化​的​客​座​端​
8.2. 將​ Red Hat Enterprise Linux 5 安​裝​為​完​整​虛​擬​化​的​客​座​端​
8.3. 安​裝​ Windows XP 客​座​端​為​完​整​的​虛​擬​化​客​座​端​
8.4. 安​裝​ Windows Server 2003 為​完​整​的​虛​擬​化​客​座​端​
8.5. 安​裝​ Windows Server 2008 為​完​整​的​虛​擬​化​客​座​端​
III. 配​置​
9. Virtualized storage devices
9.1. 建​立​虛​擬​化​軟​碟​控​制​器​
9.2. 在​客​座​端​上​新​增​儲​存​裝​置​
9.3. 在​ Red Hat Enterprise Linux 5 環​境​下​設​定​持​續​性​儲​存​裝​置​
9.4. 新​增​虛​擬​化​的​ CD-ROM 或​ DVD 裝​置​至​客​座​端​上​
10. 網​路​設​定​
10.1. 使​用​ libvirt 來​進​行​網​路​位​址​轉​譯​
10.2. 透​過​ libvirt 來​進​行​橋​接​網​路​作​業​
11. Red Hat Enterprise Linux 5.4 Xen 網​路​作​業​
11.1. 設​定​多​重​客​座​端​網​路​橋​接​來​使​用​多​重​乙​太​網​路​卡​
11.2. Red Hat Enterprise Linux 5.0 手​提​電​腦​網​路​配​置​
12. Xen 半​虛​擬​化​驅​動​程​式​
12.1. 系​統​需​求​
12.2. 半​虛​擬​化​的​限​制​與​支​援​
12.3. 安​裝​半​虛​擬​化​驅​動​程​式​
12.3.1. 一​般​安​裝​步​驟​
12.3.2. Red Hat Enterprise Linux 3 上​的​半​虛​擬​化​驅​動​程​式​安​裝​與​設​定​
12.3.3. Red Hat Enterprise Linux 4 上​的​半​虛​擬​化​驅​動​程​式​的​安​裝​和​配​置​
12.3.4. Xen Para-virtualized Drivers on Red Hat Enterprise Linux 5
12.3.5. Xen Para-virtualized Drivers on Red Hat Enterprise Linux 6
12.4. 半​虛​擬​化​的​網​路​驅​動​程​式​設​定​
12.5. 額​外​的​半​虛​擬​化​硬​體​設​定​
12.5.1. 虛​擬​網​路​介​面​卡​
12.5.2. 虛​擬​儲​存​裝​置​
13. KVM 半​虛​擬​化​驅​動​程​式​
13.1. 安​裝​ KVM Windows 半​虛​擬​化​驅​動​程​式​
13.2. Installing drivers with a virtualized floppy disk
13.3. 將​ KVM 半​虛​擬​化​驅​動​程​式​使​用​於​現​有​的​裝​置​上​
13.4. 使​用​ KVM 半​虛​擬​化​驅​動​程​式​於​新​裝​置​上​
14. PCI 的​通​透​性​
14.1. Adding a PCI device with virsh
14.2. Adding a PCI device with virt-manager
14.3. PCI passthrough with virt-install
14.4. PCI passthrough for para-virtualized Xen guests on Red Hat Enterprise Linux
15. SR-IOV
15.1. Introduction
15.2. Using SR-IOV
15.3. Troubleshooting SR-IOV
16. KVM 客​座​端​時​間​管​理​
IV. 管​理​
17. 良​好​的​伺​服​器​使​用​習​慣​
18. 虛​擬​化​的​安​全​性​
18.1. Storage security issues
18.2. SELinux 和​虛​擬​化​
18.3. SELinux
18.4. Virtualization firewall information
19. 使​用​ xend 來​管​理​客​座​端​
20. Xen 即​時​遷​移​
20.1. 即​時​遷​移​的​範​例​
20.2. 配​置​客​座​端​即​時​遷​移​
21. KVM 即​時​遷​移​
21.1. 即​時​遷​移​需​求​
21.2. 共​享​儲​存​裝​置​範​例​:用​來​進​行​基​本​遷​移​的​ NFS
21.3. 以​ virsh 來​進​行​即​時​ KVM 遷​移​
21.4. 以​ virt-manager 來​進​行​遷​移​
22. 虛​擬​化​客​座​端​的​遠​端​管​理​
22.1. 透​過​使​用​ SSH 來​進​行​遠​端​管​理​
22.2. 透​過​使​用​ TLS 與​ SSL 來​進​行​遠​端​管​理​
22.3. 傳​輸​模​式​
V. Virtualization Storage Topics
23. Using shared storage with virtual disk images
23.1. Using iSCSI for storing virtual disk images
23.1.1. How to set up an iSCSI target on Red Hat Enterprise Linux
23.1.2. How to configure iSCSI on a libvirt KVM host and provision a guest using virt-install
VI. 虛​擬​化​參​考​指​南​
24. 虛​擬​化​工​具​
25. 透​過​ virsh 來​管​理​客​座​端​
26. 使​用​虛​擬​主​機​管​理​程​式​(Virtual Machine Manager,virt-manager)來​管​理​客​座​端​
26.1. The Add Connection window
26.2. 虛​擬​主​機​管​理​程​式​的​主​視​窗​
26.3. The guest Overview tab
26.4. 虛​擬​主​機​圖​形​主​控​台​
26.5. 啟​動​ virt-manager
26.6. 復​原​已​儲​存​的​機​器​
26.7. 顯​示​客​座​端​詳​細​資​訊​
26.8. 狀​態​監​控​
26.9. 顯​示​客​座​端​的​標​識​符​號​
26.10. Displaying a guest's status
26.11. 顯​示​虛​擬​ CPU
26.12. 顯​示​ CPU 使​用​率​
26.13. 顯​示​記​憶​體​使​用​率​
26.14. 管​理​虛​擬​網​路​
26.15. 建​立​一​個​虛​擬​網​路​
27. xm 指​令​快​速​參​照​指​南​
28. 設​定​ Xen 核​心​的​開​機​參​數​
29. 配​置​ ELILO
30. libvirt configuration reference
31. Xen 配​置​檔​案​
VII. 提​示​與​技​巧​
32. 提​示​和​技​巧​
32.1. 自​動​啟​動​客​座​端​
32.2. 在​ KVM 與​ Xen hypervisor 之​間​互​換​
32.2.1. 從​ Xen 到​ KVM
32.2.2. 從​ KVM 到​ Xen
32.3. 使​用​ qemu-img
32.4. Overcommitting Resources
32.5. 修​改​ /etc/grub.conf
32.6. 驗​證​虛​擬​化​延​伸​
32.7. Accessing data from a guest disk image
32.8. Setting KVM processor affinities
32.9. 產​生​一​個​新​的​獨​特​ MAC 位​址​
32.10. 限​制​ Xen 客​座​端​的​網​路​頻​寬​
32.11. 配​置​ Xen 處​理​器​的​關​係​
32.12. 修​改​ Xen hypervisor
32.13. 非​常​安​全​的​ ftpd
32.14. 配​置​ LUN 的​持​續​性​
32.15. 停​用​客​座​端​的​ SMART 磁​碟​監​控​
32.16. 清​除​舊​的​ Xen 配​置​檔​案​
32.17. 配​置​ VNC 伺​服​器​
32.18. 複​製​客​座​端​配​置​檔​案​
32.19. 複​製​一​個​現​有​的​客​座​端​以​及​它​的​配​置​檔​案​
33. 建​立​自​訂​化​的​ libvirt script
33.1. 搭​配​使​用​ virsh 與​ XML 配​置​檔​案​
VIII. 疑​難​排​解​
34. Xen 疑​難​排​解​
34.1. 針​對​於​ Xen 進​行​除​錯​和​疑​難​排​解​
34.2. 日​誌​檔​案​概​述​
34.3. 日​誌​檔​案​描​述​
34.4. 重​要​的​目​錄​位​置​
34.5. 透​過​使​用​日​誌​來​進​行​疑​難​排​解​
34.6. 透​過​使​用​序​列​主​控​台​來​進​行​疑​難​排​解​
34.7. 半​虛​擬​化​客​座​端​的​主​控​台​存​取​
34.8. 完​整​虛​擬​化​客​座​端​的​主​控​台​存​取​
34.9. Xen 的​一​般​問​題​
34.10. 建​立​客​座​端​上​的​錯​誤​
34.11. 透​過​使​用​序​列​主​控​台​來​進​行​疑​難​排​解​
34.11.1. Xen 的​序​列​主​控​台​
34.11.2. 從​半​虛​擬​化​客​座​端​的​ Xen 序​列​主​控​台​輸​出​
34.11.3. 來​自​於​完​整​虛​擬​化​客​座​端​的​序​列​主​控​台​輸​出​
34.12. Xen 的​配​置​檔​案​
34.13. 解​讀​ Xen 的​錯​誤​訊​息​
34.14. 日​誌​目​錄​的​格​式​
35. 疑​難​排​解​
35.1. 找​出​可​用​的​儲​存​裝​置​和​分​割​區​
35.2. 重​新​啟​動​ Xen 的​客​座​端​之​後​,主​控​台​沒​有​回​應​
35.3. 網​路​作​業​工​具​無​法​找​到​虛​擬​化​的​乙​太​網​路​裝​置​
35.4. Loop 裝​置​錯​誤​
35.5. 記​憶​體​短​缺​所​造​成​的​ domain 建​置​失​敗​
35.6. 不​正​確​的​核​心​映​像​檔​
35.7. 不​正​確​的​ kernel 映​像​錯​誤​ - 在​ PAE 平​台​上​的​非​ PAE kernel
35.8. 完​整​虛​擬​化​的​ 64 位​元​客​座​端​無​法​啟​動​
35.9. 缺​少​ localhost(本​地​主​機​)項​目​造​成​了​ virt-manager 失​效​
35.10. 客​座​端​啟​動​時​所​產​生​的​微​程​式​碼​錯​誤​
35.11. 啟​動​虛​擬​機​器​時​所​產​生​的​ Python depreciation 警​告​訊​息​
35.12. 在​ BIOS 中​啟​用​ Intel VT 和​ AMD-V 虛​擬​化​硬​體​延​伸​
35.13. KVM 的​網​路​效​能​
36. Xen 半​虛​擬​化​驅​動​程​式​的​疑​難​排​解​
36.1. Red Hat Enterprise Linux 5 虛​擬​化​日​誌​檔​案​與​目​錄​
36.2. 半​虛​擬​化​客​座​端​在​一​個​ Red Hat Enterprise Linux 3 客​座​端​作​業​系​統​上​無​法​載​入​
36.3. 當​在​ Red Hat Enterprise Linux 3 上​安​裝​半​虛​擬​化​驅​動​程​式​時​,有​個​警​告​訊​息​被​顯​示​了​
36.4. 手​動​式​地​載​入​半​虛​擬​化​驅​動​程​式​
36.5. 驗​證​半​虛​擬​化​驅​動​程​式​是​否​已​成​功​載​入​
36.6. 當​使​用​半​虛​擬​化​驅​動​程​式​時​,系​統​具​有​有​限​的​產​量​
Glossary
A. 額​外​資​源​
A.1. 線​上​資​源​
A.2. 已​安​裝​的​文​件​
B. 版​權​說​明​

序​言​

The Red Hat Enterprise Linux Virtualization Guide covers all aspects of using and managing virtualization products included with Red Hat Enterprise Linux.

1. 關​於​本​指​南​

This book is divided into 8 parts:
  • 系​統​需​求​
  • 安​裝​
  • 配​置​
  • 管​理​
  • Storage
  • 參​照​
  • 提​示​與​技​巧​
  • 疑​難​排​解​
Key terms and concepts used throughout this book are covered in the Glossary.
This book covers virtualization topics for Red Hat Enterprise Linux 5. The KVM and Xen hypervisors are provided with Red Hat Enterprise Linux 5. Both the KVM and Xen hypervisors support Full virtualization. The Xen hypervisor also supports Para-virtualization. Refer to 節 4, “What is Virtualization?” and the Glossary for more details on these terms.

2. 文​​​件​​​常​​​規​​​

本​​​指​​​南​​​使​​​用​​​了​​​幾​​​種​​​常​​​規​​​,以​​​強​​​調​​​特​​​定​​​文​​​字​​​與​​​詞​​​組​​​,並​​​著​​​重​​​於​​​特​​​定​​​的​​​資​​​訊​​​。​​​
在​​​ PDF 和​​​書​​​面​​​版​​​本​​​中​​​,本​​​指​​​南​​​使​​​用​​​了​​​來​​​自​​​於​​​ Liberation Fonts 字​​​體​​​組​​​的​​​ typefaces。​​​倘​​​若​​​ Liberation Fonts 字​​​體​​​已​​​安​​​裝​​​在​​​您​​​系​​​統​​​上​​​的​​​話​​​,該​​​字​​​體​​​也​​​會​​​被​​​使​​​用​​​於​​​ HTML 版​​​本​​​中​​​。​​​若​​​是​​​沒​​​有​​​的​​​話​​​,其​​​它​​​相​​​等​​​的​​​ typefaces 便​​​會​​​被​​​顯​​​示​​​。​​​請​​​注​​​意​​​:就​​​預​​​設​​​值​​​,Red Hat Enterprise Linux 5(與​​​更​​​新​​​版​​​本​​​)已​​​包​​​含​​​了​​​ Liberation Fonts 字​​​體​​​。​​​

2.1. 排​​​字​​​上​​​的​​​常​​​規​​​

有​​​四​​​種​​​被​​​用​​​來​​​強​​​調​​​特​​​定​​​文​​​字​​​與​​​詞​​​組​​​的​​​排​​​字​​​常​​​規​​​。​​​這​​​些​​​常​​​規​​​以​​​及​​​它​​​們​​​所​​​適​​​用​​​於​​​的​​​情​​​況​​​如​​​下​​​。​​​
固​​​定​​​粗​​​體​​​字​​​型​​​(Mono-spaced Bold)
用​​​來​​​強​​​調​​​系​​​統​​​輸​​​入​​​,包​​​括​​​ shell 指​​​令​​​、​​​檔​​​案​​​名​​​稱​​​與​​​路​​​徑​​​。​​​同​​​時​​​也​​​會​​​被​​​使​​​用​​​來​​​強​​​調​​​ key caps 與​​​按​​​鍵​​​組​​​合​​​。​​​例​​​如​​​:
若​​​要​​​查​​​看​​​位​​​於​​​您​​​目​​​前​​​工​​​作​​​目​​​錄​​​中​​​的​​​ my_next_bestselling_novel 檔​​​案​​​的​​​話​​​,請​​​在​​​ shell 提​​​示​​​中​​​輸​​​入​​​ cat my_next_bestselling_novel 指​​​令​​​並​​​按​​​下​​​ Enter 來​​​執​​​行​​​該​​​指​​​令​​​。​​​
以​​​上​​​包​​​含​​​了​​​一​​​個​​​檔​​​案​​​名​​​稱​​​、​​​shell 指​​​令​​​,以​​​及​​​ key cap,並​​​且​​​全​​​部​​​以​​​固​​​定​​​粗​​​體​​​字​​​型​​​來​​​顯​​​示​​​。​​​
按​​​鍵​​​組​​​合​​​可​​​透​​​過​​​ keycaps 藉​​​由​​​連​​​字​​​符​​​號​​​連​​​接​​​組​​​合​​​鍵​​​來​​​辨​​​別​​​。​​​例​​​如​​​:
請​​​按​​​下​​​ Enter 來​​​執​​​行​​​指​​​令​​​。​​​
請​​​按​​​下​​​ Ctrl+Alt+F2 來​​​切​​​換​​​至​​​第​​​一​​​個​​​虛​​​擬​​​終​​​端​​​機​​​。​​​按​​​下​​​ Ctrl+Alt+F1 來​​​返​​​回​​​您​​​的​​​ X-Windows session。​​​
第​​​一​​​段​​​落​​​強​​​調​​​了​​​應​​​輸​​​入​​​的​​​特​​​定​​​ keycap。​​​第​​​二​​​段​​​落​​​強​​​調​​​了​​​兩​​​組​​​含​​​有​​​三​​​個​​​ keycaps 的​​​組​​​合​​​鍵​​​,各​​​組​​​組​​​合​​​鍵​​​都​​​是​​​同​​​時​​​按​​​下​​​的​​​。​​​
若​​​討​​​論​​​到​​​原​​​始​​​碼​​​的​​​話​​​,段​​​落​​​中​​​所​​​提​​​及​​​的​​​ class 名​​​稱​​​、​​​method、​​​functions、​​​variable 名​​​稱​​​與​​​回​​​傳​​​值​​​,都​​​將​​​會​​​如​​​上​​​一​​​般​​​地​​​以​​​固​​​定​​​粗​​​體​​​字​​​型​​​顯​​​示​​​。​​​例​​​如​​​:
和​​​檔​​​案​​​相​​​關​​​的​​​ class,其​​​中​​​包​​​含​​​了​​​filesystem(檔​​​案​​​系​​​統​​​)、​​​file(檔​​​案​​​)以​​​及​​​ dir(目​​​錄​​​)。​​​各​​​個​​​ class 都​​​有​​​著​​​與​​​它​​​關​​​聯​​​的​​​權​​​限​​​組​​​。​​​
相​​​稱​​​粗​​​體​​​字​​​型​​​(Proportional Bold)
這​​​代​​​表​​​在​​​系​​​統​​​上​​​所​​​會​​​看​​​見​​​的​​​文​​​字​​​或​​​詞​​​組​​​,這​​​包​​​含​​​了​​​應​​​用​​​程​​​式​​​名​​​稱​​​;對​​​話​​​方​​​塊​​​文​​​字​​​;被​​​標​​​記​​​的​​​按​​​鈕​​​;核​​​取​​​方​​​塊​​​與​​​ radio button 標​​​籤​​​;選​​​單​​​標​​​題​​​以​​​及​​​子​​​選​​​單​​​標​​​題​​​。​​​例​​​如​​​:
由​​​主​​​選​​​單​​​選​​​取​​​系​​​統​​​偏​​​好​​​設​​​定​​​滑​​​鼠​​​來​​​啟​​​動​​​滑​​​鼠​​​偏​​​好​​​設​​​定​​​。​​​請​​​在​​​按​​​鈕​​​分​​​頁​​​中​​​點​​​選​​​左​​​手​​​操​​​作​​​滑​​​鼠​​​核​​​取​​​方​​​塊​​​並​​​按​​​下​​​關​​​閉​​​來​​​將​​​主​​​要​​​滑​​​鼠​​​按​​​鍵​​​由​​​左​​​邊​​​切​​​換​​​至​​​右​​​邊​​​(這​​​可​​​讓​​​滑​​​鼠​​​適​​​合​​​以​​​左​​​手​​​使​​​用​​​)。​​​
若​​​要​​​將​​​特​​​殊​​​字​​​元​​​插​​​入​​​一​​​個​​​ gedit 檔​​​案​​​中​​​的​​​話​​​,請​​​由​​​主​​​選​​​單​​​中​​​選​​​擇​​​應​​​用​​​程​​​式​​​附​​​屬​​​應​​​用​​​程​​​式​​​字​​​元​​​對​​​應​​​表​​​。​​​接​​​下​​​來​​​,請​​​由​​​字​​​元​​​對​​​應​​​表​​​的​​​選​​​單​​​中​​​選​​​擇​​​搜​​​尋​​​尋​​​找​​​…,並​​​在​​​搜​​​尋​​​欄​​​位​​​中​​​輸​​​入​​​字​​​元​​​的​​​名​​​稱​​​,然​​​後​​​按​​​下​​​下​​​一​​​步​​​。​​​您​​​所​​​選​​​擇​​​的​​​字​​​元​​​將​​​會​​​顯​​​示​​​於​​​字​​​元​​​表​​​中​​​。​​​在​​​被​​​選​​​定​​​的​​​字​​​元​​​上​​​點​​​兩​​​下​​​滑​​​鼠​​​便​​​可​​​將​​​它​​​放​​​置​​​在​​​準​​​備​​​複​​​製​​​的​​​文​​​字​​​欄​​​位​​​中​​​,接​​​下​​​來​​​請​​​按​​​下​​​旁​​​邊​​​的​​​複​​​製​​​按​​​鈕​​​。​​​現​​​在​​​,請​​​切​​​換​​​回​​​您​​​的​​​文​​​件​​​並​​​由​​​ gedit 的​​​選​​​單​​​上​​​選​​​擇​​​編​​​輯​​​貼​​​上​​​。​​​
以​​​上​​​文​​​字​​​包​​​含​​​了​​​應​​​用​​​程​​​式​​​名​​​稱​​​;系​​​統​​​全​​​域​​​的​​​選​​​單​​​名​​​稱​​​與​​​項​​​目​​​;應​​​用​​​程​​​式​​​特​​​屬​​​的​​​選​​​單​​​名​​​稱​​​;以​​​及​​​在​​​ GUI 介​​​面​​​中​​​所​​​看​​​到​​​的​​​按​​​鈕​​​與​​​文​​​字​​​全​​​部​​​皆​​​以​​​相​​​稱​​​粗​​​體​​​字​​​型​​​來​​​顯​​​示​​​,並​​​且​​​可​​​透​​​過​​​內​​​文​​​來​​​辨​​​別​​​。​​​
Mono-spaced Bold Italic(固​​​定​​​粗​​​體​​​斜​​​體​​​字​​​型​​​)或​​​是​​​ Proportional Bold Italic(相​​​稱​​​粗​​​體​​​斜​​​體​​​字​​​型​​​)
無​​​論​​​是​​​ Mono-spaced Bold 或​​​是​​​ Proportional Bold,額​​​外​​​的​​​斜​​​體​​​字​​​型​​​便​​​表​​​示​​​可​​​替​​​換​​​或​​​是​​​變​​​數​​​文​​​字​​​。​​​斜​​​體​​​字​​​型​​​代​​​表​​​您​​​不​​​會​​​照​​​字​​​面​​​輸​​​入​​​的​​​文​​​字​​​,或​​​是​​​會​​​依​​​照​​​情​​​況​​​而​​​改​​​變​​​的​​​文​​​字​​​。​​​比​​​方​​​說​​​:
若​​​要​​​透​​​過​​​使​​​用​​​ ssh 來​​​連​​​至​​​一​​​部​​​遠​​​端​​​機​​​器​​​,請​​​在​​​ shell 提​​​示​​​中​​​輸​​​入​​​ ssh 用​​​戶​​​名​​​稱​​​@網​​​域​​​.名​​​稱​​​。​​​若​​​遠​​​端​​​機​​​器​​​為​​​ example.com 而​​​您​​​在​​​該​​​機​​​器​​​上​​​的​​​用​​​戶​​​名​​​稱​​​為​​​ john 的​​​話​​​,請​​​輸​​​入​​​ ssh john@example.com。​​​
mount -o remount 檔​​​案​​​系​​​統​​​ 指​​​令​​​會​​​將​​​ named 檔​​​案​​​系​​​統​​​重​​​新​​​掛​​​載​​​。​​​比​​​方​​​說​​​,若​​​要​​​重​​​新​​​掛​​​載​​​ /home 檔​​​案​​​系​​​統​​​的​​​話​​​,該​​​指​​​令​​​就​​​會​​​是​​​ mount -o remount /home。​​​
使​​​用​​​ rpm -q 套​​​件​​​ 指​​​令​​​來​​​查​​​看​​​目​​​前​​​已​​​安​​​裝​​​套​​​件​​​的​​​版​​​本​​​。​​​系​​​統​​​將​​​會​​​回​​​傳​​​此​​​結​​​果​​​:套​​​件​​​發​​​行​​​版​​​本​​​。​​​
請​​​注​​​意​​​以​​​上​​​以​​​粗​​​體​​​斜​​​體​​​字​​​型​​​所​​​表​​​現​​​出​​​的​​​文​​​字​​​ — 用​​​戶​​​名​​​稱​​​、​​​網​​​域​​​.名​​​稱​​​、​​​檔​​​案​​​系​​​統​​​、​​​套​​​件​​​以​​​及​​​發​​​行​​​版​​​本​​​。​​​所​​​有​​​文​​​字​​​皆​​​為​​​佔​​​位​​​符​​​號​​​,這​​​可​​​代​​​表​​​您​​​提​​​供​​​一​​​項​​​指​​​令​​​時​​​所​​​輸​​​入​​​的​​​文​​​字​​​或​​​是​​​系​​​統​​​所​​​顯​​​示​​​的​​​文​​​字​​​。​​​
除​​​了​​​用​​​來​​​顯​​​示​​​一​​​項​​​作​​​業​​​標​​​題​​​這​​​樣​​​的​​​標​​​準​​​用​​​法​​​,斜​​​體​​​字​​​也​​​可​​​代​​​表​​​第​​​一​​​次​​​使​​​用​​​的​​​重​​​要​​​新​​​詞​​​彙​​​。​​​比​​​方​​​說​​​:
Publican 是​​​個​​​ DocBook 發​​​佈​​​系​​​統​​​。​​​

2.2. 引​​​述​​​常​​​規​​​

終​​​端​​​機​​​輸​​​出​​​與​​​原​​​始​​​碼​​​資​​​料​​​會​​​被​​​設​​​為​​​在​​​附​​​近​​​的​​​文​​​字​​​間​​​不​​​會​​​被​​​看​​​見​​​。​​​
傳​​​送​​​至​​​終​​​端​​​機​​​的​​​輸​​​出​​​設​​​置​​​為​​​ mono-spaced roman,並​​​且​​​以​​​此​​​方​​​式​​​顯​​​示​​​:
books        Desktop   documentation  drafts  mss    photos   stuff  svn
books_tests  Desktop1  downloads      images  notes  scripts  svgs
原​​​始​​​碼​​​排​​​列​​​亦​​​設​​​置​​​為​​​ mono-spaced roman 不​​​過​​​會​​​如​​​下​​​加​​​上​​​語​​​法​​​強​​​調​​​:
package org.jboss.book.jca.ex1;

import javax.naming.InitialContext;

public class ExClient
{
   public static void main(String args[]) 
       throws Exception
   {
      InitialContext iniCtx = new InitialContext();
      Object         ref    = iniCtx.lookup("EchoBean");
      EchoHome       home   = (EchoHome) ref;
      Echo           echo   = home.create();

      System.out.println("Created Echo");

      System.out.println("Echo.echo('Hello') = " + echo.echo("Hello"));
   }
}

2.3. 註​​​解​​​和​​​警​​​告​​​

最​​​後​​​,我​​​們​​​將​​​使​​​用​​​三​​​種​​​視​​​覺​​​上​​​的​​​形​​​式​​​,來​​​強​​​調​​​可​​​能​​​會​​​被​​​遺​​​漏​​​掉​​​的​​​資​​​訊​​​。​​​

註​​​解​​​

註​​​解​​​代​​​表​​​某​​​些​​​作​​​業​​​上​​​的​​​提​​​示​​​、​​​捷​​​徑​​​或​​​是​​​其​​​它​​​完​​​成​​​方​​​式​​​。​​​忽​​​略​​​註​​​解​​​並​​​不​​​會​​​帶​​​來​​​太​​​大​​​的​​​負​​​面​​​影​​​響​​​,不​​​過​​​您​​​可​​​能​​​會​​​忽​​​略​​​掉​​​某​​​些​​​能​​​夠​​​較​​​輕​​​鬆​​​完​​​成​​​工​​​作​​​的​​​方​​​式​​​。​​​

重​​​點​​​

重​​​點​​​方​​​塊​​​會​​​將​​​容​​​易​​​遺​​​漏​​​掉​​​的​​​項​​​目​​​詳​​​細​​​列​​​出​​​:只​​​對​​​應​​​於​​​當​​​下​​​ session 的​​​配​​​置​​​變​​​更​​​,或​​​是​​​某​​​些​​​要​​​套​​​用​​​更​​​新​​​前​​​必​​​須​​​將​​​之​​​重​​​新​​​啟​​​用​​​的​​​服​​​務​​​。​​​倘​​​若​​​您​​​忽​​​略​​​掉​​​重​​​點​​​方​​​塊​​​,雖​​​然​​​不​​​會​​​造​​​成​​​資​​​料​​​遺​​​失​​​,不​​​過​​​卻​​​會​​​造​​​成​​​工​​​作​​​上​​​的​​​不​​​便​​​與​​​其​​​它​​​影​​​響​​​。​​​

警​​​告​​​

任​​​何​​​警​​​告​​​都​​​不​​​該​​​被​​​忽​​​略​​​掉​​​。​​​忽​​​略​​​警​​​告​​​則​​​很​​​有​​​可​​​能​​​會​​​造​​​成​​​資​​​料​​​上​​​的​​​遺​​​失​​​。​​​

3. We need your feedback

If you find a typographical error in this manual, or if you have thought of a way to make this manual better, we would love to hear from you. Submit a report in Bugzilla: http://bugzilla.redhat.com/ against Red Hat Enterprise Linux with the Virtualization_Guide component.
When submitting a bug report, be sure to mention the manual's identifier: Virtualization_Guide and version number: 5.
If you have a suggestion for improving the documentation, try to be as specific as possible when describing it. If you have found an error, include the section number and some of the surrounding text so we can find it easily.

3.1. Technical review requests

All review requests are classified into one of the following five categories:
New content
content documented for the first time —​ an entirely new feature, procedure, or concept. For example: "Section now describes the new procedure for creating bootable USB devices."
Correction
a factual error previously present in the text has been corrected. For example: "Section previously stated (incorrectly) that IPv4 and IPv6 were both supported; section now states that IPv6 has never been supported."
Clarification
material that was already factually correct but is now better explained. Clarifications are usually in response to reader feedback that the previous content was confusing or misleading in some way. For example: "Paths described in Example 1.2.3 now better reflect the directory structure of an actual installed system."
Obsoletion
a description of a feature or a procedure has been dropped. Material might be obsolete because of a feature that is no longer supported, a known issue that has been corrected, or hardware that is now obsolete. For example, "Section no longer describes how to update kernel modules using a floppy disk."
Verification
a request to check a fact, procedure, or whether material should be obsoleted. For example, "Section describes how to connect to a generic iSCSI storage device. Please verify this on your hardware" or "Section still describes how to update kernel modules using a LS-120 SuperDisk; please verify that we still need to tell readers about this obsolete hardware."

4. What is Virtualization?

Virtualization is a broad computing term for running software, usually operating systems, concurrently and isolated from other programs on one system. Most existing implementations of virtualization use a hypervisor, a software layer that controls hardware and provides guest operating systems with access to underlying hardware devices. The hypervisor allows multiple operating systems to run on the same physical system by offering virtualized hardware to the guest operating system.

5. Types of Virtualization

5.1. Full Virtualization

Red Hat Enterprise Linux contains virtualization packages and tools which provide system administrators with the means to run fully virtualized, unmodified, operating system guests on Red Hat Enterprise Linux. This provides companies with the ability to consolidate older systems onto newer, more efficient hardware. This reduces physical space and operating costs involved with powering and cooling older, less efficient systems. Full virtualization incurs worse I/O performance than native, also known as bare-metal, installations of operating systems.

5.2. Para-Virtualization

Para-virtualization is a virtualization technique which involves running modified versions of operating systems. The para-virtualized operating system is modified to be aware that it is being virtualized, offering an increased ability for optimization as the guest is more aware of its environment. Performance is generally very close to running bare-metal, non-virtualized operating systems.

5.3. Para-virtualized drivers

These two techniques, para-virtualization and full virtualization, can be combined to allow unmodified operating systems to receive near native I/O performance by using para-virtualized drivers on fully virtualized operating systems. This guide covers installation and configuration of the Red Hat Enterprise Linux para-virtualized drivers package for fully virtualized Microsoft Windows® guests.
The para-virtualized drivers package contains storage and network device drivers for fully virtualized Microsoft Windows® guests. The drivers provide Microsoft Windows® guests running on Red Hat Enterprise Linux with enhanced disk and network I/O performance.

6. How CIOs should think about virtualization

by Lee Congdon, Chief Information Officer, Red Hat, Inc.
您​可​能​已​在​新​興​的​虛​擬​化​技​術​上​做​了​不​少​投​資​,若​是​如​此​的​話​,請​參​考​下​列​資​訊​來​取​得​如​何​更​完​善​地​利​用​此​技​術​的​相​關​資​訊​。​若​您​還​未​在​虛​擬​化​技​術​上​進​行​任​何​投​資​的​話​,現​在​正​是​時​候​。​
虛​擬​化​提​供​了​一​組​可​增​加​靈​活​性​與​降​低​成​本​的​工​具​,這​是​所​有​企​業​與​ IT 組​織​中​最​重​要​的​一​環​。​虛​擬​化​解​決​方​案​現​在​已​漸​漸​變​得​更​廣​為​使​用​與​多​樣​化​了​。​
因​為​虛​擬​化​可​為​您​組​織​的​各​方​面​提​供​極​大​益​處​,因​此​您​應​該​建​置​先​導​專​案​、​開​發​專​門​的​技​術​,並​將​虛​擬​化​技​術​納​入​。​
創​新​的​虛​擬​化​技​術​
以​本​質​上​來​講​,虛​擬​化​可​透​過​由​一​個​實​體​硬​體​平​台​來​將​某​個​作​業​系​統​和​該​系​統​所​支​援​的​服​務​和​應​用​程​式​進​行​去​耦​(decoupling)來​增​強​靈​活​性​。​它​可​在​一​個​共​享​的​硬​體​平​台​上​建​置​多​重​虛​擬​環​境​。​
欲​創​新​的​組​織​會​發​現​,在​不​需​安​裝​額​外​硬​體​的​情​況​下​建​立​新​系​統​與​服​務​(以​及​快​速​地​將​不​再​需​要​的​系​統​與​服​務​卸​下​)的​能​力​,可​有​效​幫​助​達​到​創​新​的​效​果​。​
可​實​施​的​方​法​有​:快​速​地​開​發​用​來​建​立​自​訂​化​軟​體​的​系​統​,快​速​設​定​測​試​環​境​的​能​力​,可​提​供​其​它​軟​體​解​決​方​案​、​並​能​不​需​大​量​投​資​硬​體​大​量​的​情​況​下​比​較​這​些​軟​體​解​決​方​案​的​能​力​,迅​速​的​原​型​設​計​和​靈​活​開​發​環​境​上​的​支​援​,以​及​可​應​需​求​快​速​建​置​新​生​產​服​務​的​能​力​。​
這​些​環​境​可​於​內​部​建​立​或​是​於​外​部​進​行​供​給​,就​和​ Amazon 的​ EC2(Elastic Compute Cloud,彈​性​雲​端​運​算​)一​樣​。​因​為​建​立​一​個​虛​擬​環​境​的​所​需​花​費​可​能​非​常​地​少​,並​且​還​可​利​用​現​有​的​硬​體​,因​此​您​可​透​過​極​少​的​投​資​來​快​速​地​達​到​產​品​上​的​創​新​。​
虛​擬​化​也​可​用​來​支​援​新​產​品​,透​過​虛​擬​的​環​境​來​進​行​產​品​上​的​訓​練​與​學​習​。​這​些​服​務​為​虛​擬​化​技​術​的​理​想​應​用​程​式​。​學​生​可​以​從​一​個​已​知​、​標​準​的​系​統​環​境​來​進​行​教​程​工​作​。​課​堂​工​作​也​能​與​生​產​網​路​區​隔​開​來​。​學​習​者​可​在​不​使​用​專​屬​的​硬​體​資​源​的​情​況​下​,建​立​獨​特​的​軟​體​環​境​。​
隨​著​虛​擬​化​環​境​的​功​能​漸​漸​增​加​,特​定​用​戶​將​虛​擬​化​技​術​使​用​在​自​訂​的​攜​帶​式​環​境​上​,前​景​可​期​。​這​些​環​境​可​被​動​態​地​移​動​至​一​個​可​存​取​、​或​是​本​地​處​理​的​環​境​下​,無​論​用​戶​身​在​何​處​。​用​戶​的​虛​擬​環​境​可​被​儲​存​在​網​路​上​,或​是​儲​存​在​可​攜​帶​式​的​記​憶​體​裝​置​上​。​
有​個​相​關​的​概​念​就​是​ Appliance Operating System,這​是​個​被​設​計​來​執​行​於​虛​擬​環​境​下​的​應​用​程​式​套​件​導​向​的​作​業​系​統​。​使​用​套​件​的​方​式​可​降​低​開​發​和​支​援​上​的​成​本​,並​且​可​確​保​應​用​程​式​可​執​行​於​一​個​已​知​的​安​全​環​境​下​。​Appliance Operating System 這​個​解​決​方​案​為​應​用​程​式​開​發​者​以​及​這​些​應​用​程​式​的​用​戶​提​供​了​不​少​好​處​。​
這​些​虛​擬​化​技​術​的​應​用​程​式​可​以​用​多​樣​化​的​方​式​來​套​用​在​系​統​上​。​若​您​已​在​上​述​任​何​領​域​中​使​用​了​此​技​術​的​話​,請​將​它​視​為​適​用​於​一​項​快​速​開​發​的​解​決​方​案​上​的​額​外​投​資​。​若​您​還​未​開​始​使​用​虛​擬​化​技​術​的​話​,請​先​嘗​試​練​習​並​學​習​建​置​,以​建​立​相​關​技​巧​,接​著​再​進​行​應​用​程​式​建​置​與​測​試​。​具​有​較​廣​泛​的​虛​擬​化​經​驗​的​企​業​應​考​慮​實​施​可​攜​式​的​虛​擬​環​境​或​是​應​用​程​式​裝​置​。​
透​過​虛​擬​化​來​降​低​成​本​
虛​擬​化​也​可​被​用​來​降​低​成​本​。​其​中​一​個​最​明​顯​的​益​處​就​是​將​多​台​伺​服​器​合​併​至​較​小​、​較​強​大​的​硬​體​平​台​上​,執​行​多​個​虛​擬​環​境​。​這​樣​一​來​,不​只​是​成​本​可​透​過​減​少​硬​體​數​量​和​未​使​用​的​容​量​來​降​低​,實​際​上​應​用​程​式​的​效​能​也​可​得​到​改​善​,因​為​虛​擬​客​座​端​執​行​於​較​強​大​的​硬​體​上​。​
其​它​好​處​還​包​含​新​增​硬​體​容​量​時​,不​會​造​成​服​務​中​斷​,工​作​量​也​能​動​態​遷​移​至​可​用​資​源​上​的​能​力​。​
根​據​您​組​織​的​需​求​,您​可​能​需​要​建​立​一​個​虛​擬​環​境​來​進​行​災​難​復​原​(disaster recovery)。​使​用​虛​擬​化​可​大​幅​降​低​複​製​相​同​硬​體​環​境​上​的​需​要​,並​且​也​可​透​過​較​低​的​成​本​來​進​行​災​難​環​境​下​的​測​試​。​
虛​擬​化​提​供​了​查​看​尖​峰​和​周​期​性​工​作​量​的​絕​佳​方​式​。​若​您​組​織​中​含​有​相​輔​相​成​的​工​作​量​,您​可​動​態​式​地​分​配​資​源​給​目​前​正​被​大​量​使​用​的​應​用​程​式​。​若​在​組​織​中​含​有​您​正​在​進​行​供​給​的​尖​峰​工​作​量​,您​可​透​過​使​用​虛​擬​化​技​術​來​有​效​地​實​施​額​外​的​外​部​容​量​。​
透​過​伺​服​器​合​併​來​降​低​的​成​本​不​容​小​覷​。​若​您​還​未​根​據​此​用​途​利​用​虛​擬​化​的​話​,您​應​即​刻​進​行​測​試​。​您​取​得​虛​擬​化​的​相​關​經​驗​後​,也​可​探​索​負​載​平​衡​與​虛​擬​化​災​難​復​原​環​境​的​優​點​。​
將​虛​擬​化​納​入​為​標​準​的​解​決​方​案​
無​論​您​企​業​的​特​定​需​求​為​何​,您​都​應​該​將​虛​擬​化​技​術​列​入​您​系​統​和​應​用​程​式​上​的​考​量​,因​為​此​技​巧​會​變​得​相​當​普​遍​。​我​們​預​計​作​業​系​統​供​應​商​會​將​虛​擬​化​技​術​作​為​一​項​標​準​的​元​件​、​我​們​也​預​計​硬​體​供​應​商​會​在​它​們​的​平​台​上​建​置​虛​擬​化​的​功​能​,並​且​虛​擬​化​的​供​應​商​則​會​擴​展​它​們​所​提​供​的​範​圍​。​
若​您​還​未​計​劃​如​何​將​虛​擬​化​納​入​您​的​解​決​方​案​架​構​的​話​,您​可​找​出​一​個​先​導​專​案​(pilot project)、​分​配​一​些​未​充​分​利​用​的​硬​體​平​台​,並​嘗​試​使​用​這​個​靈​活​且​符​合​成​本​效​應​的​技​術​。​接​著​,您​可​延​伸​您​的​目​標​架​構​來​併​入​虛​擬​解​決​方​案​。​儘​管​虛​擬​化​現​有​的​服​務​有​多​項​好​處​,建​立​新​的​應​用​程​式​並​整​合​虛​擬​化​策​略​可​達​到​更​加​的​可​管​理​性​與​可​用​性​。​
您​可​透​過​ http://www.redhat.com/products/ 來​取​得​更​多​有​關​於​ Red Hat 虛​擬​化​解​決​方​案​的​相​關​資​訊​。​

部 I. Red Hat Enterprise Linux 虛​擬​化​方​案​的​需​求​與​限​制​

系​統​需​求​、​支​援​限​制​與​侷​限​性​

這​些​章​節​勾​勒​出​ Red Hat Enterprise Linux 虛​擬​化​的​系​統​需​求​、​支​援​的​限​制​、​以​及​其​侷​限​性​。​

章 1. 系​統​需​求​

This chapter lists system requirements for successfully running virtualization with Red Hat Enterprise Linux. Virtualization is available for Red Hat Enterprise Linux 5 Server.
The requirements for virtualization vary depending on the type of hypervisor. The Kernel-based Virtual Machine (KVM) and Xen hypervisors are provided with Red Hat Enterprise Linux 5. Both the KVM and Xen hypervisors support Full virtualization. The Xen hypervisor also supports Para-virtualization.
For information on installing the virtualization packages, read 章 6, 安​裝​虛​擬​化​套​件​.
基​本​系​統​需​求​
  • 6GB 的​可​用​磁​碟​空​間​
  • 2GB 的​記​憶​體​。​

KVM 過​量​使​用​

KVM can overcommit physical resources for virtualized guests. Overcommiting resources means the total virtualized RAM and processor cores used by the guests can exceed the physical RAM and processor cores on the host. For information on safely overcommitting resources with KVM refer to 節 32.4, “Overcommitting Resources”.
Xen 半​虛​擬​化​系​統​需​求​
若​要​使​用​半​虛​擬​化​客​座​端​,您​需​要​能​存​取​ NFS、​FTP 或​是​ HTTP 通​訊​協​定​,來​使​用​ Red Hat Enterprise Linux 5 的​安​裝​目​錄​樹​。​
Xen 完​整​虛​擬​化​系​統​需​求​
Xen Hypervisor 的​完​整​虛​擬​化​需​要​:
  • an Intel processor with the Intel VT extensions, or
  • 含​有​ AMD-V 延​伸​的​ AMD 處​理​器​,或​是​
  • Intel Itanium 處​理​器​。​
Refer to 節 32.6, “驗​證​虛​擬​化​延​伸​” to determine if your processor has the virtualization extensions.
KVM 系​統​需​求​
KVM hypervisor 需​要​:
  • 含​有​ Intel VT 以​及​ Intel 64 延​伸​的​ Intel 處​理​器​,或​是​
  • 含​有​ AMD-V 與​ AMD64 延​伸​的​ AMD 處​理​器​。​
Refer to 節 32.6, “驗​證​虛​擬​化​延​伸​” to determine if your processor has the virtualization extensions.
儲​存​裝​置​支​援​
受​到​支​援​的​客​座​端​儲​存​方​式​包​含​:
  • Files on local storage
  • Physical disk partitions
  • Locally connected physical LUNs
  • LVM partitions
  • iSCSI and Fibre Channel based LUNs

基​於​檔​案​的​客​座​端​儲​存​裝​置​

File-based guest images are stored in the /var/lib/libvirt/images/ directory by default. If you use a different directory you must label the new directory according to SELinux policy. Refer to 節 18.2, “SELinux 和​虛​擬​化​” for details.

章 2. Xen 的​限​制​與​支​援​

Red Hat Enterprise Linux 5 supports various architecture combinations for hosts and virtualized guests. All architectures have processor and memory limitations. Refer to the following URLs for the processor and memory amount limitations for Red Hat Enterprise Linux:
The following URL shows a complete chart of supported operating systems and host and guest combinations:

注意

To utilize para-virtualization on Red Hat Enterprise Linux 5, your processor must have the Physical Address Extension (PAE) instruction set.

Itanium® 支​援​

Virtualization with the Xen hypervisor on the Intel Itanium architecture requires the guest firmware image package, refer to 透​過​ yum 來​安​裝​ Xen hypervisor for more information.

章 3. KVM 的​限​制​與​支​援​

The KVM hypervisor requires a processor with the Intel-VT or AMD-V virtualization extensions.
To verify whether your processor supports the virtualization extensions and for information on enabling the virtualization extensions if they are disabled, refer to 節 32.6, “驗​證​虛​擬​化​延​伸​”.
The following URLs explain the processor and memory amount limitations for Red Hat Enterprise Linux:
The following URL shows a complete chart of supported operating systems and host and guest combinations:

章 4. Hyper-V restrictions and support

Certification of guests running under the Microsoft Hyper-V server is conducted by Microsoft. Red Hat Enterprise Linux 5 is fully certified to run under the Microsoft Hyper-V server.

注意

To avoid timing errors when running Red Hat Enterprise Linux 5 under the Microsoft Hyper-V server, use the divider=10 option in the grub.conf file.

章 5. 虛​擬​化​的​限​制​

本​章​涵​蓋​了​ Red Hat Enterprise Linux 虛​擬​套​件​的​額​外​限​制​。​

5.1. 虛​擬​化​的​一​般​限​制​

Converting between hypervisors
Presently, there is no support for converting Xen-based guests to KVM or KVM-based guests to Xen. Guests can only be supported on the hypervisor type on which they were created. However, at the time of writing, a tool is in development which may be released with future versions of Red Hat Enterprise Linux.
其​他​限​制​
For other details affecting virtualization, refer to the Red Hat Enterprise Linux Release Notes at http://docs.redhat.com for your version. The Release Notes cover the present new features, known issues and limitations as they are updated or discovered.
建​置​前​先​進​行​測​試​
You should test for the maximum anticipated system and virtualized network load before deploying heavy I/O applications. Load testing and planning are important as virtualization performance can suffer due to high I/O usage.

5.2. KVM 的​限​制​

KVM hypervisor 會​有​以​下​限​制​:
恆​定​時​間​戳​記​計​數​器​(TSC)位​元​
Systems without a Constant Time Stamp Counter require additional configuration. Refer to 章 16, KVM 客​座​端​時​間​管​理​ for details on determining whether you have a Constant Time Stamp Counter and configuration steps for fixing any related issues.
超​量​使​用​記​憶​體​
KVM supports memory overcommit and can store the memory of guests in swap. A guest will run slower if it is swapped frequently. When Kernel SamePage Merging (KSM) is used, make sure that the swap size is equivalent to the size of the overcommit ratio.
超​量​使​用​處​理​器​
每​個​實​體​處​理​器​核​心​不​支​援​超​過​十​個​虛​擬​處​理​器​。​超​量​使​用​任​何​超​過​這​實​體​處​理​器​數​量​的​虛​擬​處​理​器​,會​導​致​某​些​虛​擬​客​座​端​出​現​問​題​。​
Overcommitting CPUs has some risk and can lead to instability. Refer to 節 32.4, “Overcommitting Resources” for tips and recommendations on overcommitting CPUs.
虛​擬​化​的​ SCSI 裝​置​
SCSI emulation is presently not supported. Virtualized SCSI devices are disabled in KVM.
虛​擬​化​的​ IDE 裝​置​
KVM 在​每​台​客​座​端​上​,最​多​可​使​用​四​組​虛​擬​化​(模​擬​的​)IDE 裝​置​。​
半​虛​擬​化​裝​置​
半​虛​擬​化​裝​置​都​是​ PCI 裝​置​,使​用​的​是​ virtio 驅​動​程​式​。​目​前​用​戶​端​最​多​只​能​使​用​ 32 組​ PCI 裝​置​。​有​些​ PCI 裝​置​對​客​座​端​來​說​,是​極​為​重​要​且​不​能​被​移​除​的​。​預​設​的​必​要​裝​置​有​:
  • 主​機​橋​接​器​(host bridge)、​
  • ISA 與​ USB 橋​接​器​(這​兩​者​是​同​一​個​裝​置​)、​
  • 顯​示​卡​(使​用​ Cirrus 或​ qxl 驅​動​程​式​)、​以​及​
  • 動​態​記​憶​體​調​配​(memory balloon)裝​置​。​
客​座​端​使​用​的​ 32 組​ PCI 裝​置​裡​,有​四​組​是​不​能​移​除​的​。​這​表​示​每​個​客​座​端​還​剩​ 28 組​ PCI 插​槽​可​用​。​每​個​半​虛​擬​的​網​路​或​區​塊​裝​置​,會​使​用​一​組​插​槽​。​每​個​客​座​端​最​多​可​以​使​用​ 28 組​額​外​裝​置​,包​括​半​虛​擬​的​網​路​、​半​虛​擬​的​磁​碟​裝​置​、​或​其​他​使​用​ VT-d 的​ PCI 裝​置​。​
遷​移​的​限​制​
即​時​遷​移​僅​能​在​同​樣​廠​牌​的​處​理​器​之​間​進​行​(也​就​是​說​,Intel 遷​移​至​ Intel,AMD 遷​移​至​ AMD)。​
即​時​遷​移​時​,雙​方​處​理​器​的​ NX(No eXecution,不​可​執​行​)位​元​必​須​同​時​設​為​開​或​關​。​
Storage limitations
The host should not use disk labels to identify file systems in the fstab file, the initrd file or used by the kernel command line. If less privileged users, especially virtualized guests, have write access to whole partitions or LVM volumes the host system could be compromised.
Guests should not be given write access to whole disks or block devices (for example, /dev/sdb). Virtualized guests with access to block devices may be able to access other block devices on the system or modify volume labels which can be used to compromise the host system. Use partitions (for example, /dev/sdb1) or LVM volumes to prevent this issue.

5.3. Xen 的​限​制​

注​意​

All limitations in this chapter are limitations for Red Hat Enterprise Linux 5.8 except where noted. Older versions may have fewer limitations.
Xen 主​機​(dom0)的​限​制​
  • A limit of 254 para-virtualized block devices per host. The total number of block devices (using the tap:aio driver) attached to virtualized guests cannot exceed 254 devices.

半​虛​擬​化​裝​置​的​限​制​之​解​決​方​式​

There are two methods for working around the para-virtualized device limit: using phy devices (devices using the physical access mode) or using LVM on the guest.
只​要​主​機​有​足​夠​的​資​源​,phy 裝​置​的​數​目​沒​有​限​制​。​
LVM 或​其​他​類​似​的​邏​輯​分​割​區​工​具​,可​以​用​在​一​組​區​塊​裝​置​上​,在​半​虛​擬​區​塊​裝​置​上​建​立​額​外​的​邏​輯​分​割​區​。​
Xen 半​虛​擬​化​的​限​制​
  • For x86 guests, a maximum of 16GB memory per guest.
  • For x86_64 guests, a maximum of 168GB memory per guest.
  • A maximum of 254 devices per virtualized guest.
  • 每​個​虛​擬​客​座​端​最​多​可​以​使​用​ 15 張​網​路​卡​。​
Xen 完​整​虛​擬​化​的​限​制​
  • For x86 guests, a maximum of 16GB memory per guest.
  • 每​個​客​座​端​最​多​可​以​有​四​組​虛​擬​化​(模​擬​的​)IDE 裝​置​。​
    給​完​整​虛​擬​化​客​座​端​使​用​的​裝​置​配​上​半​虛​擬​化​驅​動​程​式​,沒​有​這​項​限​制​。​
  • Virtualized (emulated) IDE devices are limited by the total number of loopback devices supported by the system. The default number of available loopback devices on Red Hat Enterprise Linux 5.8 is 8. That is, by default, all virtualized guests on the system can each have no more than 8 virtualized (emulated) IDE devices.
    For more information on loopback devices, refer to the Red Hat KnowledgeBase, article DOC-1722.

    使​用​超​過​八​個​ loopback 裝​置​

    預​設​上​,Red Hat Enterprise Linux 會​限​制​ loopback 裝​置​的​可​用​數​量​。​這​數​量​可​以​藉​由​修​改​核​心​的​限​制​來​提​高​。​
    在​ /etc/modprobe.conf 檔​案​中​,加​入​以​下​一​行​:
    options loop max_loop=64
    
    Reboot the machine or run the following commands to update the kernel with this new limit:
    # rmmod loop
    # modprobe loop
    
  • A limit of 254 para-virtualized block devices per host. The total number of block devices (using the tap:aio driver) attached to virtualized guests cannot exceed 254 devices.
  • A maximum of 254 block devices using the para-virtualized drivers per virtualized guest.
  • 每​個​虛​擬​客​座​端​最​多​可​以​使​用​ 15 張​網​路​卡​。​
  • 每​個​虛​擬​化​客​座​端​最​多​可​以​擁​有​ 15 組​虛​擬​化​ SCSI 裝​置​。​
PCI passthrough limitations
  • PCI passthrough (attaching PCI devices to guests) is presently only supported on the following architectures:
    • 32 bit (x86) systems.
    • Intel 64 systems.
    • Intel Itanium 2 systems.

5.4. 應​用​程​式​的​限​制​

有​些​虛​擬​化​的​因​素​會​讓​虛​擬​化​不​適​用​於​某​些​應​用​程​式​。​
高​ I/O 需​求​的​應​用​程​式​應​該​為​給​完​整​虛​擬​化​的​客​座​端​,使​用​半​虛​擬​化​的​驅​動​程​式​。​沒​有​半​虛​擬​化​驅​動​程​式​,一​些​應​用​程​式​會​在​高​ I/O 需​求​下​,會​變​得​不​穩​定​。​
請​避​免​使​用​以​下​有​著​高​ I/O 需​求​的​應​用​程​式​:
  • kdump 伺​服​器​
  • netdump 伺​服​器​
You should carefully evaluate database applications before running them on a virtualized guest. Databases generally use network and storage I/O devices intensively. These applications may not be suitable for a fully virtualized environment. Consider para-virtualization or para-virtualized drivers in these cases for increased I/O performance.
Other applications and tools which heavily utilize I/O or require real-time performance should be evaluated carefully. Using full virtualization with the para-virtualized drivers or para-virtualization results in better performance with I/O intensive applications. Applications still suffer a small performance loss from running in virtualized environments. The performance benefits of virtualization through consolidating to newer and faster hardware should be evaluated against the potential application performance issues associated with using fully virtualized hardware.

部 II. 安​裝​

虛​擬​化​的​安​裝​主​題​

這​些​章​節​描​述​了​如​何​在​ Red Hat Enterprise Linux 裡​設​定​主​機​、​並​安​裝​虛​擬​化​客​座​端​。​建​議​您​仔​細​閱​讀​這​些​章​節​,以​確​保​能​成​功​安​裝​虛​擬​化​客​座​端​的​作​業​系​統​。​

章 6. 安​裝​虛​擬​化​套​件​

在​您​使​用​虛​擬​化​功​能​之​前​,必​須​在​ Red Hat Enterprise Linux 中​安​裝​虛​擬​化​套​件​。​虛​擬​化​套​件​可​以​在​ RHEL 的​安​裝​過​程​中​安​裝​,也​可​以​在​ RHEL 安​裝​之​後​使​用​ yum 與​ Red Hat Network(RHN)來​安​裝​。​
您​可​以​在​一​台​系​統​上​同​時​安​裝​ KVM 與​ Xen hypervisor。​Xen hypervisor 使​用​的​是​ kernel-xen 套​件​;KVM hypervisor 使​用​的​是​預​設​的​ Red Hat Enterprise Linux 核​心​,加​上​ kvm 核​心​模​組​。​因​為​每​種​ hypervisor 都​使​用​的​不​同​的​核​心​,因​此​任​何​時​點​只​能​啟​動​一​組​ hypervisor。​Red Hat 建​議​您​只​安​裝​您​想​要​使​用​的​ hypervisor 虛​擬​化​即​可​。​
To change hypervisor from Xen to KVM or KVM to Xen refer to 節 32.2, “在​ KVM 與​ Xen hypervisor 之​間​互​換​”.

6.1. 在​ Red Hat Enterprise Linux 安​裝​程​序​進​行​時​安​裝​ Xen

本​節​涵​蓋​了​從​頭​安​裝​ Red Hat Enterprise Linux 時​,安​裝​虛​擬​化​工​具​與​ Xen 套​件​的​內​容​。​

安​裝​時​需​要​幫​忙​嗎​?

The Installation Guide (available from redhat.com) covers installing Red Hat Enterprise Linux in detail.
  1. 用​ Red Hat Enterprise Linux 的​安​裝​光​碟​或​ PXE 啟​動​電​腦​,進​入​互​動​式​安​裝​介​面​。​
  2. You must enter a valid installation number when prompted to receive access to the virtualization and other Advanced Platform packages. Installation numbers can be obtained from Red Hat Customer Service.
  3. Complete all steps until you see the package selection step.
    請​選​擇​「​虛​擬​化​」​套​件​,然​後​點​選​「​立​即​自​訂​」​選​項​。​
  4. 選​擇​「​KVM」​套​件​群​組​。​「​虛​擬​化​」​套​件​群​組​會​選​擇​並​安​裝​ Xen hypervisor、​virt-manager、​libvirt、​virt-viewer、​以​及​所​有​相​依​性​套​件​。​。​
  5. 自​訂​套​件​(視​需​要​而​定​)

    如​果​您​需​要​其​他​的​虛​擬​化​套​件​,請​自​訂​「​虛​擬​化​」​群​組​。​
    Press the Close button then the Forward button to continue the installation.

注​意​

要​收​到​虛​擬​化​套​件​的​更​新​資​料​,您​需​要​訂​閱​ RHN 虛​擬​化​的​使​用​權​利​。​
使​用​ Kickstart 檔​案​來​安​裝​ Xen 套​件​
此​部​份​描​述​了​如​何​使​用​ kickstart 檔​案​來​安​裝​ Red Hat Enterprise Linux 與​ Xen hypervisor 套​件​。​Kickstart 檔​案​能​允​許​大​型​、​自​動​化​的​安​裝​程​序​,並​且​不​需​用​戶​手​動​式​地​安​裝​個​別​的​系​統​。​此​部​份​中​的​步​驟​將​會​協​助​您​建​立​並​使​用​ Kickstart 檔​案​來​安​裝​ Red Hat Enterprise Linux 以​及​虛​擬​化​套​件​。​
在​ Kickstart 檔​案​的​ %packages 一​節​裡​,加​入​以​下​套​件​群​組​:
%packages
@xen

針​對​ Intel Itanium 系​統​

Fully virtualized guests on the Itanium® architecture require the guest firmware image package (xen-ia64-guest-firmware). Append the following package to your kickstart file:
xen-ia64-guest-firmware
More information on Kickstart files can be found on Red Hat's website, redhat.com, in the Installation Guide.

6.2. 在​一​部​現​有​的​ Red Hat Enterprise Linux 系​統​上​安​裝​ Xen 套​件​

本​節​描​述​了​在​現​有​ Red Hat Enterprise Linux 上​安​裝​虛​擬​化​套​件​所​需​的​步​驟​。​
將​套​件​新​增​至​您​的​ Red Hat Network 權​利​清​單​中​
本​節​描​述​了​如​何​為​虛​擬​化​套​件​啟​用​ Red Hat Network(RHN)權​利​。​您​需​要​這​些​權​利​,才​能​安​裝​並​更​新​ Red Hat Enterprise Linux 中​的​虛​擬​化​套​件​。​您​需​要​有​效​的​ RHN 帳​號​,才​能​在​ Red Hat Enterprise Linux 中​安​裝​虛​擬​化​套​件​。​
除​此​之​外​,您​的​電​腦​必​須​在​ RHN 上​註​冊​。​若​要​註​冊​一​個​未​註​冊​的​ Red Hat Enterprise Linux,請​執​行​ rhn_register 指​令​並​依​照​提​示​進​行​。​
若​您​還​未​擁​有​有​效​的​ Red Hat 訂​閱​,請​參​閱​ Red Hat 線​上​商​店​。​
過程 6.1. 在​ RHN 上​加​入​虛​擬​化​的​權​利​
  1. 請​使​用​您​的​ RHN 用​戶​名​稱​和​密​碼​來​登​入​ RHN。​
  2. 請​選​擇​您​想​將​虛​擬​化​功​能​安​裝​於​哪​些​系​統​上​。​
  3. 在​「​系​統​屬​性​」​部​份​中​,目​前​的​系​統​權​利​列​在​「​權​利​」​標​頭​旁​。​請​使​用​(編​輯​這​些​屬​性​)連​結​來​更​改​您​的​權​利​。​
  4. 請​選​取​虛​擬​化​核​取​方​塊​。​
您​的​系​統​現​在​已​可​取​得​虛​擬​化​套​件​。​下​個​部​份​將​涵​蓋​有​關​於​如​何​安​裝​這​些​套​件​的​相​關​資​訊​。​
透​過​ yum 來​安​裝​ Xen hypervisor
若​要​開​始​在​ Red Hat Enterprise Linux 上​使​用​虛​擬​化​的​話​,您​需​要​ xen 和​ kernel-xen 套​件​。​xen 套​件​包​含​著​ hypervisor 與​基​本​的​虛​擬​化​工​具​。​kernel-xen 套​件​包​含​著​修​改​過​的​ Linux 核​心​,作​為​執​行​在​ hypervisor 上​的​虛​擬​機​器​客​座​端​。​
若​要​安​裝​ xen 和​ kernel-xen 套​件​,請​執​行​:
# yum install xen kernel-xen
Itanium® 架​構​上​的​完​整​虛​擬​化​客​座​端​需​要​「​補​充​安​裝​光​碟​」​上​的​客​座​端​軔​體​映​像​套​件​(xen-ia64-guest-firmware)。​此​套​件​也​可​透​過​ yum 指​令​來​由​ RHN 進​行​安​裝​:
# yum install xen-ia64-guest-firmware
It is advised to install additional virtualization packages for management and configuration. 建​議​的​虛​擬​化​套​件​: lists the recommended packages.
安​裝​其​它​建​議​的​虛​擬​化​套​件​:
# yum install virt-manager libvirt libvirt-python python-virtinst

6.3. 安​裝​ Red Hat Enterprise Linux 時​安​裝​ KVM

本​節​包​括​了​在​ Red Hat Enterprise Linux 安​裝​程​序​進​行​時​,安​裝​ KVM 套​件​的​內​容​

安​裝​時​需​要​幫​忙​嗎​?

The Installation Guide (available from redhat.com) covers installing Red Hat Enterprise Linux in detail.

您​需​要​一​組​有​效​的​安​裝​號​碼​

如​果​沒​有​有​效​的​安​裝​號​碼​,在​安​裝​過​程​中​,您​就​不​能​選​擇​虛​擬​化​套​件​。​
  1. 用​ Red Hat Enterprise Linux 的​安​裝​光​碟​或​ PXE 啟​動​電​腦​,進​入​互​動​式​安​裝​介​面​。​
  2. 您​必​須​在​提​示​畫​面​出​現​時​,輸​入​有​效​的​安​裝​號​碼​,以​存​取​虛​擬​化​套​件​及​其​他​進​階​平​台​所​使​用​的​套​件​。​
  3. Complete all steps up to the package selection step.
    請​選​擇​「​虛​擬​化​」​套​件​,然​後​點​選​「​立​即​自​訂​」​選​項​。​
  4. 選​擇​「​KVM」​套​件​群​組​。​不​要​選​擇​「​虛​擬​化​」​套​件​群​組​。​這​會​選​擇​並​安​裝​ KVM hypervisor、​virt-manager、​libvirt 與​ virt-viewer。​
  5. 自​訂​套​件​(視​需​要​而​定​)

    如​果​您​需​要​其​他​的​虛​擬​化​套​件​,請​自​訂​「​虛​擬​化​」​群​組​。​
    Press the Close button then the Forward button to continue the installation.

注​意​

要​收​到​虛​擬​化​套​件​的​更​新​資​料​,您​需​要​訂​閱​ RHN 虛​擬​化​的​使​用​權​利​。​
利​用​ kickstart 檔​案​來​安​裝​ KVM 套​件​
此​部​份​描​述​了​如​何​使​用​ kickstart 檔​案​來​安​裝​ Red Hat Enterprise Linux 與​ KVM hypervisor 套​件​。​Kickstart 檔​案​能​允​許​大​型​、​自​動​化​的​安​裝​程​序​,並​且​不​需​用​戶​手​動​式​地​安​裝​個​別​的​系​統​。​此​部​份​中​的​步​驟​將​會​協​助​您​建​立​並​使​用​ Kickstart 檔​案​來​安​裝​ Red Hat Enterprise Linux 以​及​虛​擬​化​套​件​。​
在​ Kickstart 檔​案​的​ %packages 一​節​裡​,加​入​以​下​套​件​群​組​:
%packages
@kvm
More information on Kickstart files can be found on Red Hat's website, redhat.com, in the Installation Guide.

6.4. 在​一​部​現​有​的​ Red Hat Enterprise Linux 系​統​上​安​裝​ KVM

此​部​份​描​述​了​在​現​有​的​ Red Hat Enterprise Linux 5.4(含​以​上​),安​裝​ KVM hypervisor 所​需​的​步​驟​。​
將​套​件​新​增​至​您​的​ Red Hat Network 權​利​清​單​中​
本​節​描​述​了​如​何​為​虛​擬​化​套​件​啟​用​ Red Hat Network(RHN)權​利​。​您​需​要​這​些​權​利​,才​能​安​裝​並​更​新​ Red Hat Enterprise Linux 中​的​虛​擬​化​套​件​。​您​需​要​有​效​的​ RHN 帳​號​,才​能​在​ Red Hat Enterprise Linux 中​安​裝​虛​擬​化​套​件​。​
除​此​之​外​,您​的​電​腦​必​須​在​ RHN 上​註​冊​。​若​要​註​冊​一​個​未​註​冊​的​ Red Hat Enterprise Linux,請​執​行​ rhn_register 指​令​並​依​照​提​示​進​行​。​
若​您​還​未​擁​有​有​效​的​ Red Hat 訂​閱​,請​參​閱​ Red Hat 線​上​商​店​。​
過程 6.2. 在​ RHN 上​加​入​虛​擬​化​的​權​利​
  1. 請​使​用​您​的​ RHN 用​戶​名​稱​和​密​碼​來​登​入​ RHN。​
  2. 請​選​擇​您​想​將​虛​擬​化​功​能​安​裝​於​哪​些​系​統​上​。​
  3. 在​「​系​統​屬​性​」​部​份​中​,目​前​的​系​統​權​利​列​在​「​權​利​」​標​頭​旁​。​請​使​用​(編​輯​這​些​屬​性​)連​結​來​更​改​您​的​權​利​。​
  4. 請​選​取​虛​擬​化​核​取​方​塊​。​
您​的​系​統​現​在​已​可​取​得​虛​擬​化​套​件​。​下​個​部​份​將​涵​蓋​有​關​於​如​何​安​裝​這​些​套​件​的​相​關​資​訊​。​
透​過​ yum 來​安​裝​ KVM hypervisor
若​要​開​始​在​ Red Hat Enterprise Linux 上​使​用​虛​擬​化​的​話​,您​將​需​要​ kvm 套​件​。​kvm 套​件​包​含​著​ KVM 核​心​模​組​,為​預​設​的​ Red Hat Enterprise Linux 核​心​提​供​ KVM hypervisor。​
若​要​安​裝​ kvm 套​件​,請​執​行​:
# yum install kvm
現​在​,安​裝​額​外​的​虛​擬​化​管​理​套​件​。​
安​裝​其​它​建​議​的​虛​擬​化​套​件​:
# yum install virt-manager libvirt libvirt-python python-virtinst

章 7. 虛​擬​化​客​座​端​安​裝​總​覽​

在​主​系​統​上​安​裝​了​虛​擬​化​套​件​之​後​,就​可​以​建​立​客​座​端​作​業​系​統​。​本​章​描​述​了​在​虛​擬​機​器​上​,安​裝​客​座​端​作​業​系​統​的​程​序​。​您​可​以​使​用​ virt-manager 的​新​增​按​鈕​,或​使​用​命​令​列​工​具​ virt-install 來​建​立​客​座​端​。​本​章​將​提​及​這​兩​種​方​法​。​
Detailed installation instructions are available for specific versions of Red Hat Enterprise Linux, other Linux distributions and Windows. Refer to 章 8, 客​座​端​作​業​系​統​的​安​裝​程​序​ for those procedures.

7.1. 透​過​ virt-install 來​建​立​客​座​端​

您​可​以​在​命​令​列​中​,使​用​ virt-install 指​令​來​建​立​虛​擬​化​客​座​端​。​您​可​以​藉​由​互​動​式​方​式​來​使​用​ virt-install,或​用​於​一​個​ script 中​來​自​動​化​虛​擬​機​器​的​建​置​。​當​使​用​ virt-install 和​ kickstart 檔​案​時​,您​可​進​行​無​人​式​的​虛​擬​機​器​安​裝​程​序​。​
virt-install 工​具​提​供​了​幾​個​您​可​傳​送​至​指​令​列​上​的​選​項​。​要​看​完​整​的​選​項​,請​執​行​:
$ virt-install --help
virt-install 的​ man page 也​為​每​個​選​項​與​重​要​的​變​數​,提​供​了​詳​細​資​訊​。​
qemu-img 是​相​關​指​令​,可​以​在​使​用​ virt-install 之​前​,設​定​儲​存​選​項​。​
An important option is the --vnc option which opens a graphical window for the guest's installation.
範例 7.1. 使​用​ virt-install 與​ KVM 來​建​立​ Red Hat Enterprise Linux 3 客​座​端​
本​範​例​建​立​的​是​ Red Hat Enterprise Linux 3 的​客​座​端​,名​為​ rhel3support。​本​範​例​使​用​光​碟​片​來​安​裝​,有​虛​擬​網​路​與​ 5GB 的​區​塊​裝​置​映​像​檔​;同​時​使​用​的​是​ KVM hypervisor。​
# virt-install --accelerate --hvm --connect qemu:///system \
   --network network:default \
   --name rhel3support --ram=756\
   --file=/var/lib/libvirt/images/rhel3support.img \
   --file-size=6 --vnc --cdrom=/dev/sr0

範例 7.2. 使​用​ virt-install 來​建​立​ fedora 11 客​座​端​
# virt-install --name fedora11 --ram 512 --file=/var/lib/libvirt/images/fedora11.img \
	--file-size=3 --vnc --cdrom=/var/lib/libvirt/images/fedora11.iso

7.2. 透​過​ virt-manager 來​建​立​客​座​端​

virt-manager 為​虛​擬​機​器​管​理​員​,適​用​來​建​立​、​管​理​虛​擬​客​座​端​的​圖​形​工​具​。​
過程 7.1. 使​用​ virt-manager 來​建​立​虛​擬​客​座​端​
  1. Open virt-manager

    Start virt-manager. Launch the Virtual Machine Manager application from the Applications menu and System Tools submenu. Alternatively, run the virt-manager command as root.
  2. Optional: Open a remote hypervisor

    Open the File -> Add Connection. The dialog box below appears. Select a hypervisor and click the Connect button:
  3. Create a new guest

    virt-manager 視​窗​能​讓​您​建​立​新​的​虛​擬​機​器​。​使​用​新​增​按​鈕​來​建​立​一​部​新​的​客​座​端​。​這​會​開​啟​如​圖​的​精​靈​介​面​。​
  4. New guest wizard

    The Create a new virtual machine window provides a summary of the information you must provide in order to create a virtual machine:
    檢​視​安​裝​所​需​的​資​訊​,然​後​點​選​「​下​一​步​」​。​
  5. Name the virtual machine

    Provide a name for your virtualized guest. Punctuation and whitespace characters are not permitted in versions before Red Hat Enterprise Linux 5.5. Red Hat Enterprise Linux 5.5 adds support for '_', '.' and '-' characters.
    Press Forward to continue.
  6. Choose virtualization method

    「​選​擇​虛​擬​化​方​法​」​視​窗​會​出​現​。​請​選​擇​「​半​虛​擬​化​」​或​「​完​整​虛​擬​化​」​。​
    完​整​虛​擬​化​需​要​有​ Intel® VT 或​ AMD-V 功​能​的​處​理​器​。​如​果​這​兩​種​虛​擬​化​延​伸​功​能​並​不​存​在​,完​整​虛​擬​化​按​鈕​或​啟​用​核​心​ / 硬​體​加​速​就​無​法​選​擇​。​如​果​ kernel-xen 不​是​正​在​執​行​的​核​心​,半​虛​擬​化​選​項​就​無​法​選​擇​。​
    如​果​您​使​用​的​是​ KVM hypervisor,那​就​只​有​完​整​虛​擬​化​功​能​可​以​選​擇​。​
    Choose the virtualization type and click the Forward button.
  7. Select the installation method

    The Installation Method window asks for the type of installation you selected.
    Guests can be installed using one of the following methods:
    Local media installation
    This method uses a CD-ROM or DVD or an image of an installation CD-ROM or DVD (an .iso file).
    Network installation tree
    This method uses a mirrored Red Hat Enterprise Linux installation tree to install guests. The installation tree must be accessible using one of the following network protocols: HTTP, FTP or NFS.
    The network services and files can be hosted using network services on the host or another mirror.
    Network boot
    This method uses a Preboot eXecution Environment (PXE) server to install the guest. Setting up a PXE server is covered in the Red Hat Enterprise Linux Deployment Guide. Using this method requires a guest with a routable IP address or shared network device. Refer to 章 10, 網​路​設​定​ for information on the required networking configuration for PXE installation.
    Set the OS type and OS variant.
    Choose the installation method and click Forward to proceed.

    Para-virtualized guest installation

    Para-virtualized installation must be installed with a network installation tree. The installation tree must be accessible using one of the following network protocols: HTTP, FTP or NFS. The installation media URL must contain a Red Hat Enterprise Linux installation tree. This tree is hosted using NFS, FTP or HTTP.
  8. Installation media selection

    This window is dependent on what was selected in the previous step.
    1. ISO image or physical media installation

      If Local install media was selected in the previous step this screen is called Install Media.
      Select the location of an ISO image or select a DVD or CD-ROM from the dropdown list.
      Click the Forward button to proceed.
    2. Network install tree installation

      If Network install tree was selected in the previous step this screen is called Installation Source.
      Network installation requires the address of a mirror of a Linux installation tree using NFS, FTP or HTTP. Optionally, a kickstart file can be specified to automated the installation. Kernel parameters can also be specified if required.
      Click the Forward button to proceed.
    3. Network boot (PXE)

      PXE installation does not have an additional step.
  9. Storage setup

    The Storage window displays. Choose a disk partition, LUN or create a file-based image for the guest storage.
    All image files are stored in the /var/lib/libvirt/images/ directory by default. In the default configuration, other directory locations for file-based images are prohibited by SELinux. If you use a different directory you must label the new directory according to SELinux policy. Refer to 節 18.2, “SELinux 和​虛​擬​化​” for details.
    Your guest storage image should be larger than the size of the installation, any additional packages and applications, and the size of the guests swap file. The installation process will choose the size of the guest's swap based on size of the RAM allocated to the guest.
    如​果​客​座​端​需​要​額​外​的​空​間​給​應​用​程​式​或​其​他​資​料​使​用​,請​分​配​更​多​空​間​。​舉​例​來​說​,網​站​伺​服​器​需​要​更​多​的​空​間​來​儲​存​日​誌​檔​。​
    在​您​選​擇​的​儲​存​類​型​上​,替​客​座​端​選​擇​適​當​的​大​小​,然​後​點​選​「​下​一​步​」​。​

    注意

    It is recommend that you use the default directory for virtual machine images, /var/lib/libvirt/images/. If you are using a different location (such as /images/ in this example) make sure it is added to your SELinux policy and relabeled before you continue with the installation (later in the document you will find information on how to modify your SELinux policy).
  10. Network setup

    Select either Virtual network or Shared physical device.
    The virtual network option uses Network Address Translation (NAT) to share the default network device with the virtualized guest. Use the virtual network option for wireless networks.
    The shared physical device option uses a network bond to give the virtualized guest full access to a network device.
    Press Forward to continue.
  11. Memory and CPU allocation

    The Memory and CPU Allocation window displays. Choose appropriate values for the virtualized CPUs and RAM allocation. These values affect the host's and guest's performance.
    客​座​端​需​要​足​夠​的​實​體​記​憶​體​,才​能​有​效​率​、​有​效​能​地​執​行​。​請​選​擇​適​合​客​座​端​作​業​系​統​與​應​用​程​式​所​需​的​記​憶​體​大​小​。​大​部​分​作​業​系​統​至​少​需​要​ 512MB 的​記​憶​體​,才​能​有​效​運​作​。​請​記​得​,客​座​端​使​用​的​是​實​體​記​憶​體​。​執​行​太​多​客​座​端​,或​讓​主​系​統​的​記​憶​體​不​足​,都​會​導​致​大​量​使​用​虛​擬​記​憶​體​(即​硬​碟​置​換​空​間​)。​虛​擬​記​憶​體​的​速​度​較​慢​,會​導​致​系​統​效​能​降​低​、​回​應​變​慢​。​請​確​定​您​為​主​電​腦​與​所​有​客​座​端​,分​配​了​足​夠​的​記​憶​體​,這​樣​才​能​有​效​運​作​。​
    為​虛​擬​化​客​座​端​指​定​足​夠​的​虛​擬​處​理​器​數​量​。​如​果​客​座​端​會​執​行​多​執​行​緒​的​應​用​程​式​,請​指​定​它​所​需​的​虛​擬​處​理​器​數​目​,以​取​得​最​佳​效​能​。​請​不​要​指​定​超​出​主​電​腦​的​實​體​處​理​器​(或​超​執​行​緒​)數​目​。​您​可​以​超​量​指​定​虛​擬​處​理​器​的​數​目​,但​是​這​樣​作​會​對​雙​方​的​效​能​有​著​顯​著​的​影​響​,因​為​處​理​器​會​有​內​容​置​換​(context switch)上​的​負​擔​。​
    Press Forward to continue.
  12. Verify and start guest installation

    The Finish Virtual Machine Creation window presents a summary of all configuration information you entered. Review the information presented and use the Back button to make changes, if necessary. Once you are satisfied click the Finish button and to start the installation process.
    VNC 視​窗​會​開​啟​,顯​示​客​座​端​作​業​系​統​安​裝​程​序​已​經​開​始​。​
This concludes the general process for creating guests with virt-manager. 章 8, 客​座​端​作​業​系​統​的​安​裝​程​序​ contains step-by-step instructions to installing a variety of common operating systems.

7.3. 使​用​ PXE 來​安​裝​客​座​端​

本​節​涵​蓋​了​使​用​ PXE 來​安​裝​客​座​端​的​所​需​步​驟​。​安​裝​ PXE 客​座​端​需​要​共​享​的​網​路​裝​置​,又​稱​為​網​路​橋​接​裝​置​(network bridge)。​以​下​程​序​涵​蓋​了​透​過​ PXE 來​安​裝​時​,建​立​與​使​用​橋​接​裝​置​的​步​驟​。​
  1. 建​立​新​的​橋​接​裝​置​

    1. 請​在​ /etc/sysconfig/network-scripts/ 目​錄​裡​建​立​新​的​網​路​ script 檔​。​這​範​例​建​立​了​名​為​ ifcfg-installation 的​檔​案​,並​建​立​一​組​名​為​ installation 的​橋​接​裝​置​。​
      # cd /etc/sysconfig/network-scripts/
      # vim ifcfg-installation
      DEVICE=installation
      TYPE=Bridge
      BOOTPROTO=dhcp
      ONBOOT=yes
      

      警​告​

      The line, TYPE=Bridge, is case-sensitive. It must have uppercase 'B' and lower case 'ridge'.
    2. Start the new bridge by restarting the network service. The ifup installation command can start the individual bridge but it is safer to test the entire network restarts properly.
      # service network restart
      
    3. 目​前​還​沒​有​其​他​介​面​加​入​這​個​新​的​橋​接​裝​置​。​請​使​用​ brctl show 指​令​,來​檢​視​系​統​上​關​於​橋​接​裝​置​的​詳​細​資​料​。​
      # brctl show
      bridge name     bridge id               STP enabled     interfaces
      installation    8000.000000000000       no
      virbr0          8000.000000000000       yes
      
      virbr0 橋​接​裝​置​是​ libvirt 的​預​設​橋​接​裝​置​,用​在​預​設​乙​太​網​路​的​ NAT(網​路​位​址​轉​譯​)功​能​上​。​
  2. 將​介​面​加​至​新​的​橋​接​裝​置​上​

    為​介​面​編​輯​配​置​檔​。​請​使​用​之​前​步​驟​中​建​立​的​橋​接​裝​置​名​稱​,在​配​置​檔​中​新​增​ BRIDGE 參​數​。​
    # Intel Corporation Gigabit Network Connection
    DEVICE=eth1
    BRIDGE=installation
    BOOTPROTO=dhcp
    HWADDR=00:13:20:F7:6E:8E
    ONBOOT=yes
    
    編​輯​配​置​檔​案​之​後​,重​新​啟​動​網​路​或​重​新​開​機​。​
    # service network restart
    
    使​用​ brctl show 指​令​,來​檢​查​介​面​是​否​已​經​連​上​。​
    # brctl show
    bridge name     bridge id               STP enabled     interfaces
    installation    8000.001320f76e8e       no              eth1
    virbr0          8000.000000000000       yes
    
  3. 安​全​配​置​

    配​置​ iptables,允​許​所​有​網​路​交​通​可​以​透​過​橋​接​裝​置​轉​送​。​
    # iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
    # service iptables save
    # service iptables restart
    

    停​用​橋​接​裝​置​的​防​火​牆​功​能​

    要​不​然​的​話​,讓​經​過​橋​接​裝​置​的​網​路​交​通​不​經​過​ iptables 的​規​則​來​處​理​。​在​ /etc/sysctl.conf 檔​案​中​,加​入​以​下​幾​行​:
    net.bridge.bridge-nf-call-ip6tables = 0
    net.bridge.bridge-nf-call-iptables = 0
    net.bridge.bridge-nf-call-arptables = 0
    
    透​過​ sysctl 來​重​新​載​入​核​心​參​數​。​
    # sysctl -p /etc/sysctl.conf
    
  4. 在​安​裝​之​前​重​新​啟​動​ libvirt

    重​新​啟​動​ libvirt daemon:
    # service libvirtd reload
    
橋​接​裝​置​配​置​完​成​,您​現​在​可​以​開​始​安​裝​。​
使​用​ virt-install 來​進​行​ PXE 安​裝​
在​ virt-install 裡​,新​增​ --network=bridge:installation 安​裝​參​數​,其​中​ installation 是​橋​接​裝​置​的​名​稱​。​要​透​過​ PXE 來​安​裝​,請​使​用​ --pxe 參​數​。​
範例 7.3. 使​用​ virt-install 來​進​行​ PXE 安​裝​
# virt-install --accelerate --hvm --connect qemu:///system \
    --network=bridge:installation --pxe\
    --name EL10 --ram=756 \
    --vcpus=4
    --os-type=linux --os-variant=rhel5
    --file=/var/lib/libvirt/images/EL10.img \

使​用​ virt-manager 來​進​行​ PXE 安​裝​
The steps below are the steps that vary from the standard virt-manager installation procedures. For the standard installations refer to 章 8, 客​座​端​作​業​系​統​的​安​裝​程​序​.
  1. 選​擇​ PXE

    選​擇​「​PXE」​作​為​安​裝​方​法​。​
  2. 選​擇​橋​接​裝​置​

    選​擇​「​共​享​實​體​裝​置​」​,然​後​選​擇​之​前​步​驟​裡​出​現​的​橋​接​裝​置​。​
  3. 開​始​安​裝​

    安​裝​程​序​已​經​準​備​好​,可​以​啟​動​。​
DHCP 需​求​已​經​送​出​,如​果​找​到​ PXE 伺​服​器​,客​座​端​的​安​裝​過​程​就​會​開​始​。​

章 8. 客​座​端​作​業​系​統​的​安​裝​程​序​

This chapter covers how to install various guest operating systems in a virtualized environment on Red Hat Enterprise Linux. To understand the basic processes, refer to 章 7, 虛​擬​化​客​座​端​安​裝​總​覽​.

重要

When installing a Red Hat Enterprise Linux guest, the installer will ask to perform an integrity check on your installation source (CD/DVD media, or ISO file). If you select to perform the check, once the media is tested and the installation continues, you may encounter a message that states: The Red Hat Enterprise Linux Server CD was not found in any of your CDROM drives. Please insert the Red Hat Enterprise Linux Server CD and press OK to retry.
This behavior is intentional, provided as a convenience to make sure media is ejected in case a CD install (requiring multiple discs/images) is being performed as opposed to a DVD install.
To proceed past this message, make sure you either insert the next CD, or edit the guest's XML file specifying the next ISO file (or re-insert the DVD media). Next, run virsh update-device Guest1 ~/Guest1.xml (substituting your guest's name and XML file), and select OK to continue past this step.

8.1. 將​ Red Hat Enterprise Linux 5 安​裝​為​半​虛​擬​化​的​客​座​端​

此​部​份​描​述​了​如​何​將​ Red Hat Enterprise Linux 5 安​裝​為​一​個​半​虛​擬​化​客​座​端​。​半​虛​擬​化​的​速​度​比​完​整​虛​擬​化​還​要​快​,並​且​支​援​了​完​整​虛​擬​化​的​所​有​優​點​。​半​虛​擬​化​需​要​一​種​特​殊​、​受​支​援​的​ Linux 核​心​,也​就​是​ kernel-xen 核​心​。​

半​虛​擬​化​的​相​關​重​點​

半​虛​擬​化​只​能​和​ Xen hypervisor 搭​配​使​用​。​半​虛​擬​化​無​法​和​ KVM hypervisor 搭​配​使​用​。​
在​進​行​安​裝​前​,請​先​確​認​您​擁​有​ root 權​限​。​
此​方​法​將​會​由​一​部​遠​端​伺​服​器​安​裝​ Red Hat Enterprise Linux。​此​部​份​中​所​描​述​的​安​裝​指​示​和​透​過​ Live CD 的​最​小​安​裝​類​似​。​
Create para-virtualized Red Hat Enterprise Linux 5 guests using virt-manager or virt-install. For instructions on virt-manager, refer to the procedure in 節 7.2, “透​過​ virt-manager 來​建​立​客​座​端​”.
請​透​過​基​於​指​令​列​的​ virt-install 工​具​來​建​立​半​虛​擬​化​客​座​端​。​--vnc 選​項​會​顯​示​圖​形​化​的​安​裝​程​序​。​範​例​中​的​客​座​端​名​稱​為​ rhel5PV,磁​碟​映​像​檔​案​為​ rhel5PV.dsk Red Hat Enterprise Linux 5 安​裝​目​錄​的​本​機​鏡​像​為​ ftp://10.1.1.1/trees/RHEL5-B2-Server-i386/。​請​針​對​您​系​統​與​網​路​的​實​際​狀​況​來​替​換​這​些​值​。​
# virt-install -n rhel5PV -r 500 \
-f /var/lib/libvirt/images/rhel5PV.dsk -s 3 --vnc -p \
-l ftp://10.1.1.1/trees/RHEL5-B2-Server-i386/

自​動​化​安​裝​程​序​

Red Hat Enterprise Linux 可​透​過​無​圖​形​化​介​面​或​手​動​式​輸​入​的​方​式​來​安​裝​。​請​使​用​ Kickstart 檔​案​來​將​安​裝​程​序​自​動​化​。​
使​用​這​兩​種​方​式​皆​會​出​現​此​視​窗​,它​會​顯​示​您​客​座​端​的​初​始​啟​動​階​段​:
當​您​的​客​座​端​完​成​了​它​的​初​始​啟​動​階​段​後​,Red Hat Enterprise Linux 的​標​準​安​裝​程​序​便​會​開​始​。​對​於​大​部​分​的​系​統​來​說​,預​設​值​都​是​可​以​接​受​的​。​
過程 8.1. 半​虛​擬​化​的​ Red Hat Enterprise Linux 客​座​端​安​裝​程​序​
  1. 請​選​擇​語​言​並​按​下​確​定​。​
  2. 請​選​擇​鍵​盤​格​式​並​按​下​確​定​。​
  3. Assign the guest's network address. Choose to use DHCP (as shown below) or a static IP address:
  4. 若​您​選​擇​了​ DHCP,安​裝​程​序​現​在​將​會​嘗​試​取​得​一​組​ IP 位​址​:
  5. If you chose a static IP address for your guest this prompt appears. Enter the details on the guest's networking configuration:
    1. 請​輸​入​一​組​有​效​的​ IP 位​址​。​請​確​認​您​所​輸​入​的​ IP 位​址​可​連​上​含​有​安​裝​樹​的​伺​服​器​。​
    2. 請​輸​入​一​組​有​效​的​子​網​路​遮​罩​、​預​設​閘​道​器​和​名​稱​伺​服​器​位​址​。​
    請​選​擇​語​言​並​按​下​確​定​。​
  6. 下​列​為​一​組​靜​態​ IP 位​址​設​定​的​範​例​:
  7. 安​裝​程​序​現​在​將​會​由​伺​服​器​擷​取​它​所​需​要​的​檔​案​:
一​旦​初​始​步​驟​完​成​後​,圖​形​化​安​裝​程​序​便​會​啟​動​。​
若​您​正​在​安​裝​的​是​ Beta 版​或​是​較​早​發​佈​的​發​行​版​,請​確​認​您​是​否​真​的​希​望​安​裝​該​作​業​系​統​。​請​按​下​「​照​樣​安​裝​」​,然​後​按​下​「​確​定​」​:
過程 8.2. 圖​形​化​安​裝​程​序​
  1. 請​輸​入​一​組​有​效​的​註​冊​碼​。​若​您​擁​有​一​組​有​效​的​ RHN 訂​閱​金​鑰​,請​將​它​輸​入​在​「​安​裝​號​碼​」​欄​位​中​:

    注​意​

    若​您​跳​過​此​步​驟​的​話​,您​可​透​過​使​用​ rhn_register 指​令​,在​安​裝​完​成​過​後​確​認​您​的​ Red Hat Network 帳​號​詳​情​。​rhn_register 指​令​需​要​ root 存​取​權​限​。​
  2. 安​裝​程​序​現​在​會​要​您​確​認​,是​否​希​望​刪​除​要​進​行​安​裝​的​儲​存​裝​置​上​的​資​料​:
    請​按​下​「​確​定​」​來​繼​續​進​行​。​
  3. Review the storage configuration and partition layout. You can chose to select the advanced storage configuration if you want to use iSCSI for the guest's storage.
    Make your selections then click Forward.
  4. 確​認​您​所​選​用​來​進​行​安​裝​的​儲​存​裝​置​。​
    請​按​下​「​確​定​」​來​繼​續​進​行​。​
  5. 設​定​網​路​作​業​以​及​主​機​的​組​態​設​定​。​這​些​設​定​將​會​與​您​先​前​在​安​裝​程​序​中​所​輸​入​的​資​料​集​結​。​請​依​照​需​求​來​更​改​這​些​設​定​:
    請​按​下​「​確​定​」​來​繼​續​進​行​。​
  6. 選​擇​適​合​您​環​境​的​適​當​時​區​。​
  7. 為​您​的​客​座​端​輸​入​ root 密​碼​。​
    請​按​下​「​下​一​步​」​來​繼​續​進​行​。​
  8. 請​選​擇​您​要​安​裝​的​軟​體​套​件​。​請​選​擇​「​現​在​自​訂​」​按​鈕​。​您​必​須​在​「​系​統​」​目​錄​中​安​裝​ kernel-xen 套​件​。​您​必​須​安​裝​ kernel-xen 套​件​才​可​使​用​半​虛​擬​化​。​
    Click Forward.
  9. 計​算​相​依​性​和​空​間​需​求​。​
  10. After the installation dependencies and space requirements have been verified click Forward to start the actual installation.
  11. 所​有​選​擇​的​軟​體​套​件​都​會​被​自​動​安​裝​。​
  12. 安​裝​完​成​後​,請​重​新​啟​動​您​的​客​座​端​:
  13. 您​新​安​裝​的​客​座​端​不​會​重​新​啟​動​,它​將​會​關​閉​...
  14. Boot the guest. The guest's name was chosen when you used the virt-install in 節 8.1, “將​ Red Hat Enterprise Linux 5 安​裝​為​半​虛​擬​化​的​客​座​端​”. If you used the default example the name is rhel5PV.
    使​用​ virsh 來​重​新​啟​動​客​座​端​:
    # virsh reboot rhel5PV
    此​外​,您​亦​可​開​啟​ virt-manager、​選​擇​您​客​座​端​的​名​稱​、​按​下​「​開​啟​」​,然​後​按​下​「​執​行​」​。​
    A VNC window displaying the guest's boot processes now opens.
  15. 啟​動​客​座​端​時​將​會​開​啟​First Boot(首​次​啟​動​)的​設​定​畫​面​。​此​精​靈​會​提​示​您​完​成​一​些​客​座​端​的​基​本​組​態​設​定​選​項​。​
  16. 首​先​請​詳​讀​並​接​受​使​用​條​款​。​
    請​按​下​使​用​條​款​視​窗​上​的​「​下​一​步​」​按​鈕​。​
  17. 設​定​防​火​牆​。​
    請​按​下​「​下​一​步​」​來​繼​續​進​行​。​
    1. 若​您​選​擇​了​停​用​防​火​牆​並​且​被​提​示​進​行​確​認​的​話​,請​按​下​「​確​定​」​來​確​認​並​繼​續​進​行​。​我​們​不​建​議​您​停​用​防​火​牆​。​
  18. 設​定​ SELinux。​我​們​強​烈​建​議​您​讓​ SELinux 以​「​強​制​模​式​」​執​行​。​您​可​選​擇​讓​ SELinux 以​「​寬​容​模​式​」​來​執​行​或​是​將​它​完​全​停​用​。​
    請​按​下​「​下​一​步​」​來​繼​續​進​行​。​
    1. 若​您​選​擇​停​用​ SELinux 的​話​,這​個​警​告​畫​面​便​會​出​現​。​請​按​下​「​確​定​」​來​停​用​ SELinux。​
  19. Disable kdump. The use of kdump is unsupported on para-virtualized guests.
    請​按​下​「​下​一​步​」​來​繼​續​進​行​。​
  20. Confirm time and date are set correctly for your guest. If you install a para-virtualized guest time and date should synchronize with the hypervisor.
    If the users sets the time or date during the installation it is ignored and the hypervisor's time is used.
    請​按​下​「​下​一​步​」​來​繼​續​進​行​。​
  21. 設​定​軟​體​更​新​。​若​您​擁​有​一​個​ Red Hat Network 訂​閱​或​是​希​望​先​試​用​的​話​,您​可​透​過​使​用​以​下​畫​面​來​將​您​新​安​裝​的​客​座​端​註​冊​至​ RHN 中​。​
    請​按​下​「​下​一​步​」​來​繼​續​進​行​。​
    1. 請​確​認​您​ RHN 的​選​擇​。​
    2. 如​果​您​沒​有​設​定​ RHN 的​話​,您​會​看​到​額​外​的​視​窗​。​如​果​您​停​用​ RHN 的​話​,您​將​不​會​收​到​任​何​軟​體​更​新​。​
      請​按​下​「​下​一​步​」​按​鈕​。​
  22. 建​立​一​組​非​ root 的​使​用​者​帳​號​。​我​們​建​議​您​建​立​一​組​非​ root 的​使​用​者​帳​號​,用​於​一​般​環​境​中​,以​增​加​安​全​性​。​請​輸​入​使​用​者​名​稱​、​名​稱​與​密​碼​。​
    請​按​下​「​下​一​步​」​按​鈕​。​
  23. 若​偵​測​到​了​音​效​裝​置​而​您​需​要​音​效​的​話​,請​進​行​調​整​。​請​完​成​程​序​並​按​下​「​下​一​步​」​。​
  24. You can install additional packages from a CD or another repository using this screen. It is often more efficient to not install any additional software at this point but add packages later using the yum command or RHN. Click Finish.
  25. 客​座​端​現​在​將​會​設​置​任​何​您​改​變​過​的​設​定​並​繼​續​進​行​啟​動​程​序​。​
  26. Red Hat Enterprise Linux 5 的​登​入​畫​面​將​會​出​現​。​請​使​用​先​前​步​驟​中​所​建​立​的​使​用​者​名​稱​來​登​入​。​
  27. 您​現​在​已​成​功​地​安​裝​了​半​虛​擬​化​的​ Red Hat Enterprise Linux 客​座​端​。​

8.2. 將​ Red Hat Enterprise Linux 5 安​裝​為​完​整​虛​擬​化​的​客​座​端​

This section covers installing a fully virtualized Red Hat Enterprise Linux 5 guest. This procedure covers both the KVM and the Xen hypervisors; the steps are interchangeable and different steps are noted.
The KVM hypervisor requires Red Hat Enterprise Linux 5.4 or newer.
過程 8.3. 請​使​用​ virt-manager 來​建​立​一​個​完​整​虛​擬​化​的​ Red Hat Enterprise Linux 5 客​座​端​
  1. 開​啟​ virt-manager

    啟​用​ virt-manager。​請​透​過​應​用​程​式​選​單​和​系​統​工​具​子​選​單​來​啟​用​虛​擬​主​機​管​理​員​。​此​外​,您​也​能​夠​以​ root 身​份​執​行​ virt-manager 指​令​。​
  2. 選​擇​ hypervisor

    選​擇​ hypervisor。​若​已​安​裝​了​ hypervisor 的​話​,請​選​擇​ Xen 或​ KVM。​在​此​範​例​中​請​選​擇​ KVM。​請​注​意​,目​前​ KVM 被​命​名​為​ qemu。​
    Connect to a hypervisor if you have not already done so. Open the File menu and select the Add Connection... option. Refer to 節 26.1, “The Add Connection window”.
    一​旦​選​擇​了​ hypervisor 的​連​線​後​,您​便​可​使​用​「​新​增​」​按​鈕​了​。​請​按​下​此​「​新​增​」​按​鈕​。​
  3. 啟​用​新​增​虛​擬​機​器​精​靈​

    Pressing the New button starts the virtual machine creation wizard.
    Press Forward to continue.
  4. 為​虛​擬​機​器​命​名​

    Provide a name for your virtualized guest. Punctuation and whitespace characters are not permitted in versions before Red Hat Enterprise Linux 5.5. Red Hat Enterprise Linux 5.5 adds support for '_', '.' and '-' characters.
    Press Forward to continue.
  5. 選​擇​虛​擬​化​方​式​

    Choose the virtualization method for the virtualized guest. Note you can only select an installed virtualization method. If you selected KVM or Xen earlier (步驟 4) you must use the hypervisor you selected. This example uses the KVM hypervisor.
    Press Forward to continue.
  6. 選​擇​安​裝​方​式​

    Red Hat Enterprise Linux 可​以​透​過​以​下​幾​種​方​式​安​裝​:
    • 「​本​地​的​安​裝​媒​介​」​,可​以​是​ ISO 映​像​檔​或​真​正​的​光​碟​。​
    • 如​果​您​在​某​台​電​腦​上​透​過​ HTTP、​FTP 或​ NFS 提​供​了​ Red Hat Enterprise Linux 的​安​裝​樹​,請​選​擇​「​網​路​安​裝​」​。​
    • 如​果​您​設​定​了​ PXE 伺​服​器​,讓​使​用​者​啟​動​ Red Hat Enterprise Linux 的​話​,那​麼​就​可​以​使​用​ PXE 來​安​裝​。​本​指​南​並​不​包​含​設​定​ PXE 伺​服​器​的​方​法​,不​過​開​機​之​後​的​安​裝​步​驟​都​是​一​樣​的​。​
    Set OS Type to Linux and OS Variant to Red Hat Enterprise Linux 5 as shown in the screenshot.
    Press Forward to continue.
  7. 選​擇​安​裝​媒​介​的​位​置​

    選​擇​ ISO 映​像​檔​位​置​或​是​光​碟​機​的​位​置​。​此​範​例​使​用​了​ Red Hat Enterprise Linux DVD 的​ ISO 映​像​檔​。​
    1. 請​按​下​「​瀏​覽​」​按​鈕​。​
    2. 請​尋​找​ ISO 檔​案​的​位​置​並​選​取​該​ ISO 映​像​檔​。​請​按​下​「​開​啟​」​來​確​認​您​的​選​擇​。​
    3. The file is selected and ready to install.
      Press Forward to continue.

    映​像​檔​與​ SELinux

    For ISO image files and guest storage images the recommended to use the /var/lib/libvirt/images/ directory. Any other location may require additional configuration for SELinux, refer to 節 18.2, “SELinux 和​虛​擬​化​” for details.
  8. 儲​存​裝​置​設​定​

    Assign a physical storage device (Block device) or a file-based image (File). File-based images must be stored in the /var/lib/libvirt/images/ directory. Assign sufficient space for your virtualized guest and any applications the guest requires.
    Press Forward to continue.

    遷​移​

    Live and offline migrations require guests to be installed on shared network storage. For information on setting up shared storage for guests refer to 部 V, “Virtualization Storage Topics”.
  9. 網​路​設​定​

    請​選​擇​「​虛​擬​網​路​」​或​是​「​共​享​實​體​裝​置​」​。​
    虛​擬​網​路​選​項​使​用​了​網​路​位​址​轉​譯​(NAT)來​與​虛​擬​化​客​座​端​共​享​預​設​的​網​路​裝​置​。​若​您​正​在​使​用​無​線​網​路​的​話​,請​使​用​虛​擬​網​路​選​項​。​
    The shared physical device option uses a network bond to give the virtualized guest full access to a network device.
    Press Forward to continue.
  10. 記​憶​體​和​ CPU 配​置​

    The Memory and CPU Allocation window displays. Choose appropriate values for the virtualized CPUs and RAM allocation. These values affect the host's and guest's performance.
    虛​擬​化​客​座​端​需​要​足​夠​的​實​體​記​憶​體​(RAM)才​可​有​效​率​並​有​效​地​執​行​。​請​選​擇​符​合​您​客​座​端​作​業​系​統​和​應​用​程​式​需​求​的​記​憶​體​數​量​。​請​記​得​,客​座​端​使​用​實​體​記​憶​體​。​執​行​過​多​的​客​座​端​或​提​供​給​主​機​系​統​的​記​憶​體​不​足​,將​會​造​成​大​量​的​虛​擬​記​憶​體​使​用​量​和​置​換​動​作​。​虛​擬​記​憶​體​速​度​較​慢​,並​且​會​造​成​系​統​效​能​與​反​應​速​度​下​降​。​請​確​認​您​已​為​所​有​客​座​端​和​主​機​分​配​了​足​夠​的​記​憶​體​以​確​保​它​們​能​夠​有​效​地​進​行​作​業​。​
    為​虛​擬​化​客​座​端​指​定​足​夠​的​虛​擬​處​理​器​數​量​。​如​果​客​座​端​會​執​行​多​執​行​緒​的​應​用​程​式​,請​指​定​它​所​需​的​虛​擬​處​理​器​數​目​,以​取​得​最​佳​效​能​。​請​不​要​指​定​超​出​主​電​腦​的​實​體​處​理​器​(或​超​執​行​緒​)數​目​。​您​可​以​超​量​指​定​虛​擬​處​理​器​的​數​目​,但​是​這​樣​作​會​對​雙​方​的​效​能​有​著​顯​著​的​影​響​,因​為​處​理​器​會​有​內​容​置​換​(context switch)上​的​負​擔​。​
    Press Forward to continue.
  11. 驗​證​和​啟​動​客​座​端​安​裝​程​序​

    Verify the configuration.
    Press Finish to start the guest installation procedure.
  12. 安​裝​ Red Hat Enterprise Linux

    請​完​成​ Red Hat Enterprise Linux 5 安​裝​程​序​。​安​裝​程​序​涵​蓋​於​《​安​裝​指​南​》​中​,請​參​閱​ Red Hat Documentation 來​取​得​ Red Hat Enterprise Linux 的​《​安​裝​指​南​》​。​
已​安​裝​了​完​整​虛​擬​化​的​ Red Hat Enterprise Linux 5 客​座​端​。​

8.3. 安​裝​ Windows XP 客​座​端​為​完​整​的​虛​擬​化​客​座​端​

您​可​以​安​裝​ Windows XP,使​其​成​為​完​整​的​虛​擬​化​客​座​端​。​本​節​描​述​如​何​在​ Red Hat Enterprise Linux 上​,安​裝​ Windows XP 的​方​法​。​
This procedure covers both the KVM and the Xen hypervisors; the steps are interchangeable and different steps are noted.
The KVM hypervisor requires Red Hat Enterprise Linux 5.4 or newer.
在​進​行​這​步​驟​之​前​,請​確​定​您​擁​有​ root 權​限​。​

Itanium® 支​援​

目​前​,Itanium® 架​構​上​的​ Red Hat Enterprise Linux 主​機​並​不​支​援​完​整​虛​擬​化​的​ Windows XP 客​座​端​。​只​有​專​為​ Itanium 系​統​所​設​計​的​ Windows Server 2003,才​可​以​在​此​架​構​上​執​行​。​
  1. 啟​動​ virt-manager

    Open Applications > System Tools > Virtual Machine Manager. Open a connection to a host (click File > Add Connection). Click the New button to create a new virtual machine.
  2. 為​虛​擬​系​統​命​名​

    輸​入​「​系​統​名​稱​」​然​後​點​「​下​一​步​」​。​
  3. 選​擇​虛​擬​化​的​方​法​

    If you selected KVM or Xen earlier (step 步驟 1 ) you must use the hypervisor you selected. This example uses the KVM hypervisor.
    您​只​能​使​用​完​整​虛​擬​化​來​安​裝​ Windows。​
  4. 選​擇​安​裝​方​法​

    這​畫​面​能​讓​您​指​定​安​裝​方​法​,以​及​作​業​系​統​的​類​型​。​
    在​「​作​業​系​統​類​型​」​選​單​,選​擇​「​Windows」​,然​後​從​「​作​業​系​統​種​類​」​裡​,選​擇​「​Microsoft Windows XP」​。​
    Red Hat Enterprise Linux 5.2 之​後​,支​援​使​用​ PXE 來​安​裝​用​戶​端​。​本​章​並​不​包​含​ PXE 安​裝​的​相​關​內​容​。​

    映​像​檔​與​ SELinux

    For ISO image files and guest storage images the recommended to use the /var/lib/libvirt/images/ directory. Any other location may require additional configuration for SELinux, refer to 節 18.2, “SELinux 和​虛​擬​化​” for details.
    點​選​「​下​一​步​」​來​繼​續​。​
  5. Choose installation image

    Choose the installation image or CD-ROM. For CD-ROM or DVD installation select the device with the Windows installation disc in it. If you chose ISO Image Location enter the path to a Windows installation .iso image.
    點​選​「​下​一​步​」​來​繼​續​。​
  6. The Storage window displays. Choose a disk partition, LUN or create a file-based image for the guest's storage.
    All image files are stored in the /var/lib/libvirt/images/ directory by default. In the default configuration, other directory locations for file-based images are prohibited by SELinux. If you use a different directory you must label the new directory according to SELinux policy. Refer to 節 18.2, “SELinux 和​虛​擬​化​” for details.
    如​果​客​座​端​需​要​額​外​空​間​,以​容​納​應​用​程​式​與​其​他​資​料​,請​分​配​額​外​空​間​。​舉​例​來​說​,網​站​伺​服​器​需​要​額​外​的​空​間​來​儲​存​紀​錄​檔​。​
    請​在​您​所​選​的​儲​存​類​型​上​,為​客​座​端​選​擇​適​當​的​大​小​,然​後​按​下​「​下​一​步​」​。​

    注意

    針​對​於​虛​擬​機​器​映​像​,我​們​建​議​您​使​用​預​設​的​目​錄​,該​目​錄​為​ /var/lib/libvirt/images/。​若​您​使​用​了​一​個​不​同​的​位​置​(比​方​說​在​此​範​例​中​為​ /images/),請​確​認​該​位​置​已​被​加​入​至​您​的​ SELinux 政​策​中​並​且​在​繼​續​進​行​安​裝​程​序​之​前​先​將​它​重​新​標​記​(之​後​,在​本​文​件​中​您​將​會​發​現​如​何​修​改​您​ SELinux 政​策​的​相​關​資​訊​)。​
  7. 設​定​網​路​

    選​擇​「​虛​擬​網​路​」​或​「​共​享​實​體​裝​置​」​。​
    虛​擬​網​路​的​選​項​使​用​「​網​路​位​址​轉​譯​」​(NAT),好​與​虛​擬​化​客​座​端​共​享​預​設​的​網​路​卡​。​無​線​網​路​會​使​用​這​虛​擬​網​路​選​項​。​
    The shared physical device option uses a network bond to give the virtualized guest full access to a network device.
    Press Forward to continue.
  8. The Memory and CPU Allocation window displays. Choose appropriate values for the virtualized CPUs and RAM allocation. These values affect the host's and guest's performance.
    虛​擬​化​客​座​端​需​要​足​夠​的​記​憶​體​,才​能​有​效​率​地​執​行​。​請​選​擇​符​合​客​座​端​系​統​與​應​用​程​式​的​記​憶​體​大​小​。​請​記​得​,客​座​端​使​用​的​是​實​體​記​憶​體​。​執​行​太​多​客​座​端​,或​讓​主​系​統​的​剩​餘​記​憶​體​量​太​少​,都​會​導​致​大​量​使​用​虛​擬​記​憶​體​與​記​憶​體​置​換​。​虛​擬​記​憶​體​的​速​度​慢​,會​導​致​系​統​效​能​降​低​,回​應​變​慢​。​請​確​定​您​為​所​有​客​座​端​與​主​機​分​配​了​足​夠​的​記​憶​體​,好​讓​運​作​更​有​效​率​。​
    為​虛​擬​化​客​座​端​指​定​足​夠​的​虛​擬​處​理​器​數​量​。​如​果​客​座​端​會​執​行​多​執​行​緒​的​應​用​程​式​,請​指​定​它​所​需​的​虛​擬​處​理​器​數​目​,以​取​得​最​佳​效​能​。​請​不​要​指​定​超​出​主​電​腦​的​實​體​處​理​器​(或​超​執​行​緒​)數​目​。​您​可​以​超​量​指​定​虛​擬​處​理​器​的​數​目​,但​是​這​樣​作​會​對​雙​方​的​效​能​有​著​顯​著​的​影​響​,因​為​處​理​器​會​有​內​容​置​換​(context switch)上​的​負​擔​。​
  9. 在​安​裝​繼​續​進​行​前​,您​將​會​看​見​摘​要​畫​面​。​請​按​下​「​完​成​」​來​繼​續​進​行​客​座​端​的​安​裝​程​序​:
  10. You must make a hardware selection so open a console window quickly after the installation starts. Click Finish then switch to the virt-manager summary window and select your newly started Windows guest. Double click on the system name and the console window opens. Quickly and repeatedly press F5 to select a new HAL, once you get the dialog box in the Windows install select the 'Generic i486 Platform' tab. Scroll through selections with the Up and Down arrows.
  11. 安​裝​程​序​會​像​其​它​任​何​標​準​ Windows 安​裝​程​序​一​般​地​進​行​。​
  12. 在​系​統​提​示​時​,為​硬​碟​製​作​分​割​區​。​
  13. 硬​碟​被​格​式​化​後​,Windows 便​會​開​始​將​檔​案​複​製​至​硬​碟​上​。​
  14. 檔​案​複​製​到​儲​存​裝​置​上​之​後​,Windows 會​重​新​啟​動​。​
  15. 重​新​啟​動​ Windows 客​座​端​:
    # virsh start WindowsGuest
    其​中​ WindowsGuest 是​虛​擬​機​器​的​名​稱​。​
  16. 主​控​台​視​窗​出​現​時​,您​會​看​到​安​裝​ Windows 的​設​定​階​段​。​
  17. 若​您​的​安​裝​程​序​在​設​定​階​段​看​似​卡​住​的​話​,您​可​透​過​ virsh reboot WindowsGuestName 指​令​來​重​新​啟​動​客​座​端​。​當​您​重​新​啟​動​虛​擬​機​器​時​,您​將​會​看​見​一​則​ Setup is being restarted 的​訊​息​:
  18. 設​定​完​成​後​,您​將​會​看​見​ Windows 的​啟​動​畫​面​:
  19. 現​在​,您​可​繼​續​進​行​您​ Windows 安​裝​程​序​的​標​準​設​定​:
  20. 設​定​過​程​已​經​完​成​。​

8.4. 安​裝​ Windows Server 2003 為​完​整​的​虛​擬​化​客​座​端​

This chapter describes installing a fully virtualized Windows Server 2003 guest with the virt-install command. virt-install can be used instead of virt-manager This process is similar to the Windows XP installation covered in 節 8.3, “安​裝​ Windows XP 客​座​端​為​完​整​的​虛​擬​化​客​座​端​”.

Itanium® 支​援​

目​前​,Itanium® 架​構​上​的​ Red Hat Enterprise Linux 主​機​並​不​支​援​完​整​虛​擬​化​的​ Windows 客​座​端​。​此​部​份​只​適​用​於​ x86 和​ x86-64 主​機​。​
  1. Using virt-install for installing Windows Server 2003 as the console for the Windows guest opens the virt-viewer window promptly. The examples below installs a Windows Server 2003 guest with the virt-install command.
    1. Xen virt-install

      # virt-install --virt-type=xen -hvm  \
         --name windows2003sp1 
         --file=/var/lib/libvirt/images/windows2003sp2.img \
         --file-size=6 \
         --cdrom=/var/lib/libvirt/images/ISOs/WIN/en_windows_server_2003_sp1.iso \
         --vnc --ram=1024
      
    2. KVM virt-install

      # virt-install --accelerate --hvm --connect qemu:///system \
         --name rhel3support  \
         --network network:default \
         --file=/var/lib/libvirt/images/windows2003sp2.img \
         --file-size=6 \
         --cdrom=/var/lib/libvirt/images/ISOs/WIN/en_windows_server_2003_sp1.iso \
         --vnc --ram=1024
      
  2. 一​旦​客​座​端​進​入​安​裝​程​序​後​,您​需​要​趕​快​按​下​ F5。​如​果​您​沒​有​在​一​定​時​間​內​按​下​ F5,您​必​須​重​新​啟​動​安​裝​程​序​。​按​下​ F5 之​後​,您​可​以​則​不​同​的​「​HAL」​或​「​電​腦​類​型​」​。​請​選​擇​「​標​準​ PC」​作​為​您​的​電​腦​類​型​。​選​擇​「​標​準​ PC」​是​安​裝​ Windows Server 2003 虛​擬​化​客​座​端​的​必​要​步​驟​。​
  3. 完​成​其​他​的​安​裝​步​驟​。​
  4. Windows 2003 現​在​已​經​被​安​裝​為​完​整​虛​擬​化​的​客​座​端​。​

8.5. 安​裝​ Windows Server 2008 為​完​整​的​虛​擬​化​客​座​端​

This section covers installing a fully virtualized Windows Server 2008 guest. This procedure covers both the KVM and the Xen hypervisors; the steps are interchangeable and different steps are noted.
The KVM hypervisor requires Red Hat Enterprise Linux 5.4 or newer.
過程 8.4. 使​用​ virt-manager 來​安​裝​ Windows Server 2008
  1. 開​啟​ virt-manager

    開​啟​ virt-manager。​請​在​「​應​用​程​式​」​選​單​中​點​選​「​系​統​工​具​」​,然​後​再​點​選​「​虛​擬​主​機​管​理​員​」​,或​以​ root 身​份​值​ virt-manager 指​令​。​
  2. 選​擇​ hypervisor

    選​擇​ hypervisor。​如​果​您​安​裝​了​ Xen 與​ KVM,請​從​中​選​擇​其​一​。​在​這​範​例​裡​選​的​是​ KVM。​請​注​意​,現​在​ KVM 叫​做​ qemu。​
    選​取​好​選​項​後​,「​新​的​」​按​鈕​就​會​變​成​可​點​選​狀​態​。​請​按​下​「​新​的​」​按​鈕​。​
  3. 啟​動​新​虛​擬​機​器​的​精​靈​介​面​

    Pressing the New button starts the virtual machine creation wizard.
    Press Forward to continue.
  4. 為​虛​擬​機​器​命​名​

    Provide a name for your virtualized guest. Punctuation and whitespace characters are not permitted in versions before Red Hat Enterprise Linux 5.5. Red Hat Enterprise Linux 5.5 adds support for '_', '.' and '-' characters.
    Press Forward to continue.
  5. 選​擇​虛​擬​化​的​方​法​

    Choose the virtualization method for the virtualized guest. Note you can only select an installed virtualization method. If you selected KVM or Xen earlier (step 2) you must use the hypervisor you selected. This example uses the KVM hypervisor.
    Press Forward to continue.
  6. 請​選​擇​安​裝​方​法​

    對​於​所​有​的​ Windows 版​本​,您​必​須​使​用​「​本​地​安​裝​媒​體​」​,也​就​是​ ISO 映​像​檔​或​實​際​的​光​碟​片​。​
    如​果​您​有​ PXE 伺​服​器​,也​安​裝​了​ Windows 的​網​路​安​裝​功​能​,PXE 就​可​以​運​作​。​使​用​ PXE 來​安​裝​ Windows 並​不​包​含​在​本​手​冊​中​。​
    Set OS Type to Windows and OS Variant to Microsoft Windows 2008 as shown in the screenshot.
    Press Forward to continue.
  7. 找​到​安​裝​媒​體​

    選​擇​ ISO 映​像​檔​的​位​置​,或​光​碟​機​。​這​範​例​使​用​的​是​ Windows Server 2008 安​裝​光​碟​的​ ISO 映​像​檔​。​
    1. 點​選​「​瀏​覽​」​按​鈕​。​
    2. Search to the location of the ISO file and select it.
      Press Open to confirm your selection.
    3. The file is selected and ready to install.
      Press Forward to continue.

    映​像​檔​與​ SELinux

    For ISO image files and guest storage images, the recommended directory to use is the /var/lib/libvirt/images/ directory. Any other location may require additional configuration for SELinux, refer to 節 18.2, “SELinux 和​虛​擬​化​” for details.
  8. 設​定​儲​存​空​間​

    Assign a physical storage device (Block device) or a file-based image (File). File-based images must be stored in the /var/lib/libvirt/images/ directory. Assign sufficient space for your virtualized guest and any applications the guest requires.
    Press Forward to continue.
  9. 設​定​網​路​

    選​擇​「​虛​擬​網​路​」​或​「​共​享​實​體​裝​置​」​。​
    虛​擬​網​路​的​選​項​使​用​「​網​路​位​址​轉​譯​」​(NAT),好​與​虛​擬​化​客​座​端​共​享​預​設​的​網​路​卡​。​無​線​網​路​會​使​用​這​虛​擬​網​路​選​項​。​
    The shared physical device option uses a network bond to give the virtualized guest full access to a network device.
    Press Forward to continue.
  10. 分​配​記​憶​體​與​處​理​器​

    The Memory and CPU Allocation window displays. Choose appropriate values for the virtualized CPUs and RAM allocation. These values affect the host's and guest's performance.
    虛​擬​化​客​座​端​需​要​足​夠​的​記​憶​體​,才​能​有​效​率​地​執​行​。​請​選​擇​符​合​客​座​端​系​統​與​應​用​程​式​的​記​憶​體​大​小​。​請​記​得​,客​座​端​使​用​的​是​實​體​記​憶​體​。​執​行​太​多​客​座​端​,或​讓​主​系​統​的​剩​餘​記​憶​體​量​太​少​,都​會​導​致​大​量​使​用​虛​擬​記​憶​體​與​記​憶​體​置​換​。​虛​擬​記​憶​體​的​速​度​較​慢​,會​導​致​系​統​效​能​降​低​,回​應​變​慢​。​請​確​定​您​為​所​有​客​座​端​與​主​機​分​配​了​足​夠​的​記​憶​體​,好​讓​運​作​更​有​效​率​。​
    為​虛​擬​化​客​座​端​指​定​足​夠​的​虛​擬​處​理​器​數​量​。​如​果​客​座​端​會​執​行​多​執​行​緒​的​應​用​程​式​,請​指​定​它​所​需​的​虛​擬​處​理​器​數​目​,以​取​得​最​佳​效​能​。​請​不​要​指​定​超​出​主​電​腦​的​實​體​處​理​器​(或​超​執​行​緒​)數​目​。​您​可​以​超​量​指​定​虛​擬​處​理​器​的​數​目​,但​是​這​樣​作​會​對​雙​方​的​效​能​有​著​顯​著​的​影​響​,因​為​處​理​器​會​有​內​容​置​換​(context switch)上​的​負​擔​。​
    Press Forward to continue.
  11. 檢​查​並​開​始​安​裝​客​座​端​

    Verify the configuration.
    Press Finish to start the guest installation procedure.
  12. 安​裝​ Windows

    Complete the Windows Server 2008 installation sequence. The installation sequence is not covered by this guide, refer to Microsoft's documentation for information on installing Windows.

部 III. 配​置​

設​定​ Red Hat Enterprise Linux 的​虛​擬​化​功​能​

These chapters cover configuration procedures for various advanced virtualization tasks. These tasks include adding network and storage devices, enhancing security, improving performance, and using the Para-virtualized drivers on fully virtualized guests.

內容目錄

9. Virtualized storage devices
9.1. 建​立​虛​擬​化​軟​碟​控​制​器​
9.2. 在​客​座​端​上​新​增​儲​存​裝​置​
9.3. 在​ Red Hat Enterprise Linux 5 環​境​下​設​定​持​續​性​儲​存​裝​置​
9.4. 新​增​虛​擬​化​的​ CD-ROM 或​ DVD 裝​置​至​客​座​端​上​
10. 網​路​設​定​
10.1. 使​用​ libvirt 來​進​行​網​路​位​址​轉​譯​
10.2. 透​過​ libvirt 來​進​行​橋​接​網​路​作​業​
11. Red Hat Enterprise Linux 5.4 Xen 網​路​作​業​
11.1. 設​定​多​重​客​座​端​網​路​橋​接​來​使​用​多​重​乙​太​網​路​卡​
11.2. Red Hat Enterprise Linux 5.0 手​提​電​腦​網​路​配​置​
12. Xen 半​虛​擬​化​驅​動​程​式​
12.1. 系​統​需​求​
12.2. 半​虛​擬​化​的​限​制​與​支​援​
12.3. 安​裝​半​虛​擬​化​驅​動​程​式​
12.3.1. 一​般​安​裝​步​驟​
12.3.2. Red Hat Enterprise Linux 3 上​的​半​虛​擬​化​驅​動​程​式​安​裝​與​設​定​
12.3.3. Red Hat Enterprise Linux 4 上​的​半​虛​擬​化​驅​動​程​式​的​安​裝​和​配​置​
12.3.4. Xen Para-virtualized Drivers on Red Hat Enterprise Linux 5
12.3.5. Xen Para-virtualized Drivers on Red Hat Enterprise Linux 6
12.4. 半​虛​擬​化​的​網​路​驅​動​程​式​設​定​
12.5. 額​外​的​半​虛​擬​化​硬​體​設​定​
12.5.1. 虛​擬​網​路​介​面​卡​
12.5.2. 虛​擬​儲​存​裝​置​
13. KVM 半​虛​擬​化​驅​動​程​式​
13.1. 安​裝​ KVM Windows 半​虛​擬​化​驅​動​程​式​
13.2. Installing drivers with a virtualized floppy disk
13.3. 將​ KVM 半​虛​擬​化​驅​動​程​式​使​用​於​現​有​的​裝​置​上​
13.4. 使​用​ KVM 半​虛​擬​化​驅​動​程​式​於​新​裝​置​上​
14. PCI 的​通​透​性​
14.1. Adding a PCI device with virsh
14.2. Adding a PCI device with virt-manager
14.3. PCI passthrough with virt-install
14.4. PCI passthrough for para-virtualized Xen guests on Red Hat Enterprise Linux
15. SR-IOV
15.1. Introduction
15.2. Using SR-IOV
15.3. Troubleshooting SR-IOV
16. KVM 客​座​端​時​間​管​理​

章 9. Virtualized storage devices

This chapter covers installing and configuring storage devices in virtualized guests. The term block devices refers to various forms of storage devices. All the procedures in this chapter work with both Xen and KVM hypervisors.

Valid disk targets

The target variable in libvirt configuration files accepts only the following device names:
  • /dev/xvd[a to z][1 to 15]
    Example: /dev/xvdb13
  • /dev/xvd[a to i][a to z][1 to 15]
    Example: /dev/xvdbz13
  • /dev/sd[a to p][1 to 15]
    Example: /dev/sda1
  • /dev/hd[a to t][1 to 63]
    Example: /dev/hdd3

9.1. 建​立​虛​擬​化​軟​碟​控​制​器​

有​些​較​舊​的​作​業​系​統​需​要​用​到​軟​碟​控​制​器​,特​別​是​用​來​安​裝​驅​動​程​式​時​。​目​前​,實​體​軟​碟​裝​置​無​法​藉​由​虛​擬​化​客​座​端​來​存​取​。​然​而​,由​虛​擬​化​軟​碟​驅​動​程​式​來​建​立​、​存​取​磁​碟​片​映​像​檔​的​功​能​,卻​是​支​援​的​。​此​部​份​涵​蓋​了​如​何​建​立​虛​擬​化​軟​碟​裝​置​的​相​關​資​訊​。​
An image file of a floppy disk is required. Create floppy disk image files with the dd command. Replace /dev/fd0 with the name of a floppy device and name the disk appropriately.
# dd if=/dev/fd0 of=~/legacydrivers.img

半​虛​擬​化​驅​動​程​式​備​註​

The para-virtualized drivers can map physical floppy devices to fully virtualized guests. For more information on using para-virtualized drivers read 章 13, KVM 半​虛​擬​化​驅​動​程​式​.
此​範​例​使​用​的​客​座​端​,是​在​執​行​完​整​虛​擬​化​的​ Red Hat Enterprise Linux 上​執​行​ virt-manager 所​建​立​的​,它​的​映​像​檔​位​於​ /var/lib/libvirt/images/rhel5FV.img。​範​例​中​使​用​了​ Xen hypervisor。​
  1. 請​藉​由​在​運​作​中​的​客​座​端​上​執​行​ virsh 指​令​,來​為​您​的​客​座​端​映​像​檔​建​立​ XML 配​置​檔​案​。​
    # virsh dumpxml rhel5FV > rhel5FV.xml
    
    This saves the configuration settings as an XML file which can be edited to customize the operations and devices used by the guest. For more information on using the virsh XML configuration files, refer to 章 33, 建​立​自​訂​化​的​ libvirt script.
  2. 為​客​座​端​建​立​磁​碟​片​映​像​。​
    # dd if=/dev/zero of=/var/lib/libvirt/images/rhel5FV-floppy.img bs=512 count=2880
    
  3. Add the content below, changing where appropriate, to your guest's configuration XML file. This example is an emulated floppy device using a file-based image.
    <disk type='file' device='floppy'>
    	<source file='/var/lib/libvirt/images/rhel5FV-floppy.img'/>
    	<target dev='fda'/>
    </disk>
    
  4. Force the guest to stop. To shut down the guest gracefully, use the virsh shutdown command instead.
    # virsh destroy rhel5FV
  5. 透​過​使​用​ XML 配​置​檔​案​來​重​新​啟​動​客​座​端​。​
    # virsh create rhel5FV.xml
    
客​座​端​中​現​在​已​可​使​用​磁​碟​片​裝​置​,並​且​會​以​映​像​檔​的​方​式​,儲​存​在​主​機​上​。​

9.2. 在​客​座​端​上​新​增​儲​存​裝​置​

此​部​份​涵​蓋​了​如​何​新​增​儲​存​裝​置​至​虛​擬​客​座​端​上​。​額​外​的​儲​存​裝​置​只​能​在​客​座​端​建​立​後​才​可​被​新​增​。​受​支​援​的​儲​存​裝​置​與​協​定​包​含​:
  • 本​機​硬​碟​分​割​區​、​
  • 本​機​卷​冊​、​
  • 直​接​連​至​主​機​的​光​纖​通​道​或​是​ iSCSI。​
  • 位​於​主​機​上​的​檔​案​系​統​中​的​檔​案​容​器​(file container)。​
  • NFS 檔​案​系​統​會​被​虛​擬​機​器​直​接​地​掛​載​。​
  • iSCSI 儲​存​裝​置​會​被​客​座​端​直​接​地​存​取​。​
  • 叢​集​檔​案​系​統​(GFS)。​
新​增​基​於​檔​案​的​儲​存​裝​置​至​客​座​端​
基​於​檔​案​的​儲​存​裝​置​或​基​於​檔​案​的​容​器​(container)皆​為​主​機​檔​案​系​統​上​的​檔​案​,它​們​會​被​作​為​虛​擬​化​客​座​端​的​虛​擬​硬​碟​來​使​用​。​若​要​新​增​基​於​檔​案​的​容​器​,請​執​行​下​列​步​驟​:
  1. 建​立​一​個​空​的​容​器​檔​案​或​使​用​現​有​的​檔​案​容​器​(例​如​ ISO 檔​案​)。​
    1. 請​使​用​ dd 指​令​來​建​立​一​個​ sparse 檔​案​。​基​於​資​料​完​整​性​以​及​效​能​上​的​考​量​,我​們​不​建​議​您​使​用​ sparse 檔​案​。​Sparse 檔​案​可​快​速​地​建​立​,並​且​可​被​使​用​來​進​行​測​試​,不​過​不​該​使​用​於​生​產​環​境​中​。​
      # dd if=/dev/zero of=/var/lib/libvirt/images/FileName.img bs=1M seek=4096 count=0
      
    2. 建​議​使​用​非​ sparse、​預​先​分​配​的​檔​案​,來​作​為​基​於​檔​案​的​儲​存​映​像​。​若​要​建​立​非​ sparse 的​檔​案​,請​執​行​:
      # dd if=/dev/zero of=/var/lib/libvirt/images/FileName.img bs=1M count=4096
      
    Both commands create a 4GB file which can be used as additional storage for a virtualized guest.
  2. 傾​印​客​座​端​的​設​定​。​在​此​範​例​中​,客​座​端​稱​為​ Guest1 並​且​檔​案​儲​存​在​使​用​者​的​家​目​錄​中​。​
    # virsh dumpxml Guest1 > ~/Guest1.xml
    
  3. 請​以​文​字​編​輯​器​開​啟​配​置​檔​案​(在​此​範​例​中​為​ Guest1.xml),並​尋​找​「​<disk>」​相​關​字​串​,這​些​字​串​描​述​了​儲​存​裝​置​。​以​下​為​這​些​字​串​的​範​例​:
    <disk type='file' device='disk'>
        <driver name='tap' type='aio'/>
        <source file='/var/lib/libvirt/images/Guest1.img'/>
        <target dev='xvda'/>
    </disk>
    
  4. 您​可​透​過​複​製​或​編​寫​新​的​ <disk> 項​目​來​新​增​額​外​的​儲​存​裝​置​。​請​確​認​您​已​為​虛​擬​區​塊​裝​置​指​定​了​一​組​裝​置​名​稱​。​各​個​客​座​端​配​置​檔​案​中​的​這​些​值​皆​必​須​是​獨​特​的​。​下​列​範​例​為​配​置​檔​案​的​一​部​分​,並​包​含​了​一​個​名​為​ FileName.img、​基​於​檔​案​的​儲​存​容​器​:
    <disk type='file' device='disk'>
        <driver name='tap' type='aio'/>
        <source file='/var/lib/libvirt/images/Guest1.img'/>
        <target dev='xvda'/>
    </disk>
    <disk type='file' device='disk'>
        <driver name='tap' type='aio'/>
        <source file='/var/lib/libvirt/images/FileName.img'/>
        <target dev='hda'/>
    </disk>
    
  5. 透​過​已​更​新​的​配​置​檔​案​來​重​新​啟​動​客​座​端​。​
    # virsh create Guest1.xml
    
  6. The following steps are Linux guest specific. Other operating systems handle new storage devices in different ways. For other systems, refer to that operating system's documentation
    The guest now uses the file FileName.img as the device called /dev/sdb. This device requires formatting from the guest. On the guest, partition the device into one primary partition for the entire device then format the device.
    1. 請​按​下​ n 來​建​立​新​分​割​區​。​
      # fdisk /dev/sdb
      Command (m for help):
      
    2. 請​按​下​ p 來​選​擇​主​要​分​割​區​。​
      Command action
         e   extended
         p   primary partition (1-4)
      
    3. 請​選​擇​可​用​的​分​割​區​號​碼​。​在​此​範​例​中​,第​一​個​分​割​區​可​藉​由​輸​入​ 1 來​選​取​。​
      Partition number (1-4): 1
      
    4. 請​藉​由​按​下​ Enter 來​輸​入​預​設​的​第​一​個​磁​柱​。​
      First cylinder (1-400, default 1):
      
    5. 請​選​擇​分​割​區​的​大​小​。​在​此​範​例​中​,您​可​藉​由​按​下​ Enter 來​分​配​整​個​磁​碟​。​
      Last cylinder or +size or +sizeM or +sizeK (2-400, default 400):
      
    6. 請​藉​由​按​下​ t 來​設​定​分​割​區​類​型​。​
      Command (m for help): t
      
    7. 請​選​擇​您​在​先​前​步​驟​中​所​建​立​的​分​割​區​。​在​此​範​例​中​,分​割​區​編​號​為​ 1。​
      Partition number (1-4): 1
      
    8. Linux 分​割​請​輸​入​ 83。​
      Hex code (type L to list codes): 83
      
    9. 將​變​更​寫​入​磁​碟​並​退​出​。​
      Command (m for help): w 
      Command (m for help): q
      
    10. 透​過​ ext3 檔​案​系​統​來​格​式​化​新​的​分​割​區​。​
      # mke2fs -j /dev/sdb1
      
  7. 將​磁​碟​掛​載​在​客​座​端​上​。​
    # mount /dev/sdb1 /myfiles
    
客​座​端​現​在​已​有​了​額​外​的​虛​擬​化​、​基​於​檔​案​的​儲​存​裝​置​。​
新​增​硬​碟​與​其​它​區​塊​裝​置​至​客​座​端​上​
System administrators use additional hard drives for to provide more storage space or to separate system data from user data. This procedure, 過程 9.1, “新​增​實​體​區​塊​裝​置​至​虛​擬​化​客​座​端​上​”, describes how to add a hard drive on the host to a virtualized guest.
此​程​序​適​用​於​所​有​實​體​區​塊​裝​置​,這​包​括​ CD-ROM、​DVD 以​及​磁​碟​片​裝​置​。​

Block device security

The host should not use disk labels to identify file systems in the fstab file, the initrd file or used by the kernel command line. If less privileged users, especially virtualized guests, have write access to whole partitions or LVM volumes the host system could be compromised.
Guest should not be given write access to whole disks or block devices (for example, /dev/sdb). Virtualized guests with access to block devices may be able to access other block devices on the system or modify volume labels which can be used to compromise the host system. Use partitions (for example, /dev/sdb1) or LVM volumes to prevent this issue.
過程 9.1. 新​增​實​體​區​塊​裝​置​至​虛​擬​化​客​座​端​上​
  1. 將​硬​碟​裝​置​實​體​連​接​至​主​機​上​。​如​果​預​設​上​,該​磁​碟​無​法​被​存​取​的​話​,請​設​定​主​機​。​
  2. 請​視​需​求​透​過​ multipath 來​設​定​裝​置​以​及​主​機​上​的​一​致​性​。​
  3. Use the virsh attach command. Replace: myguest with your guest's name, /dev/sdb1 with the device to add, and sdc with the location for the device on the guest. The sdc must be an unused device name. Use the sd* notation for Windows guests as well, the guest will recognize the device correctly.
    Append the --type cdrom parameter to the command for CD-ROM or DVD devices.
    若​是​磁​碟​片​裝​置​的​話​,請​附​加​ --type floppy 參​數​至​指​令​。​
    # virsh attach-disk myguest
    					/dev/sdb1
    					sdc --driver tap --mode readonly
    
  4. The guest now has a new hard disk device called /dev/sdb on Linux or D: drive, or similar, on Windows. This device may require formatting.

9.3. 在​ Red Hat Enterprise Linux 5 環​境​下​設​定​持​續​性​儲​存​裝​置​

此​部​份​乃​針​對​於​使​用​了​外​部​或​網​路​儲​存​裝​置​(例​如​光​纖​頻​道​或​是​ iSCSI)的​系​統​。​我​們​建​議​您​為​您​的​主​機​設​定​具​有​永​久​性​裝​置​名​稱​的​系​統​。​這​能​協​助​即​時​遷​移​(live migration)功​能​並​為​多​重​虛​擬​化​系​統​提​供​一​致​的​裝​置​名​稱​與​儲​存​裝​置​。​
通​用​唯​一​識​別​碼​(UUID)是​個​在​電​腦​計​算​環​境​中​辨​識​電​腦​與​裝​置​的​一​種​標​準​方​式​。​此​部​份​使​用​了​ UUID 來​辨​識​了​ iSCSI 或​光​纖​頻​道​ LUN。​UUID 的​一​致​性​在​系​統​重​新​啟​動​、​斷​線​和​裝​置​ swap 的​情​況​下​依​然​可​保​留​住​。​UUID 和​裝​置​上​的​標​籤​相​似​。​
Systems which are not running multipath must use 單​路​徑​設​定​. Systems running multipath can use 多​路​徑​的​配​置​.
單​路​徑​設​定​
This procedure implements LUN device persistence using udev. Only use this procedure for hosts which are not using multipath.
  1. 編​輯​ /etc/scsi_id.config 檔​案​。​
    1. 請​確​認​ options=-b 一​行​已​被​標​為​註​解​。​
      # options=-b
      
    2. 新​增​下​列​一​行​:
      options=-g
      
      此​選​項​可​將​ udev 設​定​為​假​設​所​有​連​接​的​ SCSI 裝​置​都​會​回​傳​一​組​ UUID。​
  2. 若​要​顯​示​某​個​裝​置​的​ UUID,請​執​行​ scsi_id -g -s /block/sd* 這​項​指​令​。​例​如​:
    # scsi_id -g -s /block/sd*
    3600a0b800013275100000015427b625e
    
    輸​出​可​能​會​和​上​述​範​例​有​所​不​同​。​輸​出​顯​示​了​ /dev/sdc 裝​置​的​ UUID。​
  3. 請​驗​證​透​過​ scsi_id -g -s /block/sd* 指​令​所​得​到​的​ UUID 輸​出​與​存​取​該​裝​置​的​電​腦​的​ UUID 是​相​同​的​。​
  4. 建​立​一​項​裝​置​命​名​上​的​規​則​。​請​在​ /etc/udev/rules.d 目​錄​中​建​立​一​個​名​為​ 20-names.rules 的​檔​案​。​請​將​新​的​規​則​新​增​至​此​檔​案​中​。​所​有​規​則​都​會​以​相​同​的​格​式​被​附​加​至​相​同​的​檔​案​中​。​規​則​的​格​式​如​下​:
    KERNEL=="sd[a-z]", BUS=="scsi", PROGRAM="/sbin/scsi_id -g -s /block/%k", RESULT="UUID", NAME="devicename"
    
    請​將​ UUID 和​ devicename 取​代​為​以​上​所​取​得​的​ UUID,以​及​裝​置​的​名​稱​。​以​下​為​上​述​範​例​的​規​則​:
    KERNEL="sd*", BUS="scsi", PROGRAM="/sbin/scsi_id -g -s", RESULT="3600a0b800013275100000015427b625e", NAME="rack4row16"
    
    udev daemon 現​在​會​為​規​則​中​的​ UUID 搜​尋​所​有​名​為​ /dev/sd* 的​裝​置​。​一​旦​符​合​的​裝​置​連​上​了​系​統​,該​裝​置​就​會​被​分​配​來​自​於​規​則​中​的​名​稱​。​UUID 為​ 3600a0b800013275100000015427b625e 的​裝​置​將​會​被​顯​示​為​ /dev/rack4row16。​
  5. 將​此​行​附​加​至​ /etc/rc.local
    /sbin/start_udev
    
  6. 請​將​ /etc/scsi_id.config、​/etc/udev/rules.d/20-names.rules 和​ /etc/rc.local 檔​案​中​的​變​更​複​製​至​所​有​相​關​的​主​機​上​。​
    /sbin/start_udev
    
設​置​了​規​則​的​網​路​儲​存​裝​置​現​在​在​所​有​主​機​上​皆​有​一​致​的​名​稱​並​且​檔​案​已​被​更​新​。​這​代​表​您​可​藉​由​使​用​共​享​儲​存​裝​置​,在​主​機​之​間​進​行​客​座​端​的​遷​移​,並​且​客​座​端​能​夠​存​取​它​們​的​配​置​檔​案​中​的​儲​存​裝​置​。​
多​路​徑​的​配​置​
multipath 套​件​適​用​於​由​電​腦​至​儲​存​裝​置​含​有​超​過​一​個​實​體​路​徑​的​系​統​。​multipath 為​連​至​ Red Hat Enterprise Linux 系​統​的​網​路​儲​存​裝​置​提​供​了​容​錯​(fault tolerance)、​錯​誤​移​轉​(fail-over)以​及​增​強​的​效​能​。​
Implementing LUN persistence in a multipath environment requires defined alias names for your multipath devices. Each storage device has a UUID which acts as a key for the aliased names. Identify a device's UUID using the scsi_id command.
# scsi_id -g -s /block/sdc
Multipath 裝​置​將​會​被​建​立​在​ /dev/mpath 目​錄​中​。​在​下​列​範​例​中​,有​ 4 個​裝​置​定​義​於​ /etc/multipath.conf 中​:
multipaths { 
	multipath { 
	wwid		3600805f30015987000000000768a0019 
	alias		oramp1 
	} 
	multipath { 
	wwid		3600805f30015987000000000d643001a 
	alias		oramp2 
	} 
	mulitpath { 
	wwid		3600805f3001598700000000086fc001b 
	alias		oramp3 
	} 
	mulitpath { 
	wwid		3600805f300159870000000000984001c 
	alias		oramp4 
	} 
}
This configuration will create 4 LUNs named /dev/mpath/oramp1, /dev/mpath/oramp2, /dev/mpath/oramp3 and /dev/mpath/oramp4. Once entered, the mapping of the devices' WWID to their new names are now persistent after rebooting.

9.4. 新​增​虛​擬​化​的​ CD-ROM 或​ DVD 裝​置​至​客​座​端​上​

To attach an ISO file to a guest while the guest is online use virsh with the attach-disk parameter.
# virsh attach-disk [domain-id] [source] [target] --driver file --type cdrom --mode readonly
The source and target parameters are paths for the files and devices, on the host and guest respectively. The source parameter can be a path to an ISO file or the device from the /dev directory.

章 10. 網​路​設​定​

本​頁​提​供​了​基​於​ libvirt 的​應​用​程​式​的​一​般​網​路​作​業​設​定​上​的​簡​介​。​這​項​資​訊​適​用​於​所​有​ hypervisor,無​論​是​ Xen、​KVM 或​其​它​ hypervisor。​欲​取​得​額​外​資​訊​,請​參​閱​ libvirt 網​路​架​構​文​件​。​
兩​種​一​般​的​設​定​分​別​為​「​虛​擬​網​路​」​或​是​「​共​享​實​體​裝​置​」​。​前​者​在​所​有​發​行​版​上​皆​為​相​同​的​,並​且​經​過​安​裝​便​可​使​用​。​後​者​則​需​要​發​行​版​特​屬​的​手​動​式​設​定​。​
Network services on virtualized guests are not accessible by default from external hosts. You must enable either Network address translation (NAT) ir a network Bridge to allow external hosts access to network services on virtualized guests.

10.1. 使​用​ libvirt 來​進​行​網​路​位​址​轉​譯​

最​常​被​使​用​來​共​享​網​路​連​線​的​方​式​,是​使​用​網​路​位​址​轉​譯​(NAT,Network address translation)來​轉​發​(亦​稱​為​虛​擬​網​路​)。​
主​機​設​定​
Every standard libvirt installation provides NAT based connectivity to virtual machines out of the box. This is the so called 'default virtual network'. Verify that it is available with the virsh net-list --all command.
# virsh net-list --all
Name                 State      Autostart 
-----------------------------------------
default              active     yes
若​您​找​不​到​這​個​檔​案​的​話​,您​可​重​新​載​入​並​啟​用​ XML 配​置​檔​案​範​本​:
# virsh net-define /usr/share/libvirt/networks/default.xml
預​設​網​路​是​由​ /usr/share/libvirt/networks/default.xml 來​定​義​的​
將​預​設​網​路​標​為​自​動​啟​動​:
# virsh net-autostart default
Network default marked as autostarted
啟​用​預​設​網​路​:
# virsh net-start default
Network default started
一​旦​ libvirt 預​設​網​路​開​始​運​作​後​,您​將​會​看​見​一​個​孤​立​的​橋​接​裝​置​。​此​裝​置​沒​有​附​加​任​何​實​體​介​面​卡​,因​為​它​使​用​了​ NAT 與​ IP 轉​發​來​連​至​外​面​的​世​界​。​請​勿​新​增​介​面​卡​。​
# brctl show
bridge name     bridge id               STP enabled     interfaces
virbr0          8000.000000000000       yes
libvirt 會​新​增​ iptables 規​則​以​允​許​來​自​於​客​座​端​以​及​至​客​座​端​的​流​量​,此​客​座​端​連​至​了​ INPUT、​FORWARD、​OUTPUT 和​ POSTROUTING chain 中​的​ virbr0 裝​置​。​libvirt 接​著​便​會​嘗​試​啟​用​ ip_forward 這​個​參​數​。​有​些​應​用​程​式​可​能​會​將​ ip_forward 停​用​,因​此​最​好​的​作​法​就​是​將​下​列​一​行​附​加​至​ /etc/sysctl.conf。​
 net.ipv4.ip_forward = 1
客​座​端​設​定​
Once the host configuration is complete, a guest can be connected to the virtual network based on its name. To connect a guest to the 'default' virtual network, the following XML can be used in the guest:
<interface type='network'>
  <source network='default'/>
</interface>

注​意​

您​不​一​定​要​定​義​ MAC 位​址​。​若​不​定​義​的​話​,MAC 位​址​將​會​自​動​產​生​。​某​些​情​況​下​,手​動​設​定​ MAC 位​址​會​相​當​有​幫​助​。​
<interface type='network'>
  <source network='default'/>
  <mac address='00:16:3e:1a:b3:4a'/>
  </interface>

10.2. 透​過​ libvirt 來​進​行​橋​接​網​路​作​業​

橋​接​網​路​(亦​稱​為​實​體​裝​置​共​享​)是​用​來​將​實​體​裝​置​用​於​虛​擬​機​器​用​的​。​橋​接​通​常​用​在​較​為​進​階​的​設​定​、​以​及​擁​有​多​重​網​路​介​面​卡​的​伺​服​器​上​。​
停​用​ Xen 網​路​ script
若​您​的​系​統​是​使​用​ Xen 橋​接​的​話​,我​們​建​議​您​透​過​編​輯​ /etc/xen/xend-config.sxp 並​更​改​下​列​一​行​來​停​用​預​設​的​ Xen 網​路​橋​接​:
 (network-script network-bridge)
To:
 (network-script /bin/true)
停​用​ NetworkManager(網​路​管​理​員​)
NetworkManager does not support bridging. Running NetworkManager will overwrite any manual bridge configuration. Because of this, NetworkManager should be disabled in order to use networking via the network scripts (located in the /etc/sysconfig/network-scripts/ directory):
# chkconfig NetworkManager off
# chkconfig network on
# service NetworkManager stop
# service network start

注​意​

As an alternative to turning off NetworkManager, add "NM_CONTROLLED=no" to the ifcfg-* scripts used in the examples. If you do not either set this parameter or disable NetworkManager entirely, any bridge configuration will be overwritten and lost when NetworkManager next starts.
建​立​網​路​ initscript
請​建​立​或​編​輯​下​列​的​兩​個​網​路​配​置​檔​案​。​這​項​步​驟​可​被​重​複​(使​用​不​同​名​稱​)來​進​行​額​外​的​網​路​橋​接​。​
更​換​為​ /etc/sysconfig/network-scripts 目​錄​:
# cd /etc/sysconfig/network-scripts
請​開​啟​您​要​新​增​至​橋​接​的​裝​置​的​網​路​ script。​在​此​範​例​中​,ifcfg-eth0 定​義​了​實​體​網​路​介​面​卡​,並​且​它​已​被​設​為​橋​接​的​一​部​分​。​
DEVICE=eth0
# change the hardware address to match the hardware address your NIC uses
HWADDR=00:16:76:D6:C9:45
ONBOOT=yes
BRIDGE=br0

Tip

You can configure the device's Maximum Transfer Unit (MTU) by appending an MTU variable to the end of the configuration file.
MTU=9000
請​在​ /etc/sysconfig/network-scripts 目​錄​中​,建​立​一​個​新​的​網​路​ script,並​命​名​為​ ifcfg-br0 或​類​似​名​稱​。​br0 為​橋​接​的​名​稱​,只​要​檔​案​名​稱​與​ DEVICE 參​數​相​同​的​話​,這​組​名​稱​將​能​設​為​任​何​名​稱​。​
DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes
DELAY=0

IP address configuration

IP address configuration, be it dynamic or static, should be configured on the bridge itself (for example, in the ifcfg-br0 file). Network access will not function as expected if IP address details are configured on the physical interface that the bridge is connected to.

警​告​

The line, TYPE=Bridge, is case-sensitive. It must have uppercase 'B' and lower case 'ridge'.
在​設​定​完​成​後​,請​重​新​啟​用​網​路​作​業​或​重​新​開​機​。​
# service network restart
設​定​ iptables 來​允​許​所​有​流​量​能​跨​過​橋​接​來​被​轉​發​。​
# iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
# service iptables save
# service iptables restart

停​用​橋​接​上​的​ iptables

此​外​,請​防​止​橋​接​的​流​量​被​ iptables 規​則​處​理​。​請​在​ /etc/sysctl.conf 中​附​加​下​列​幾​行​:
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
重​新​載​入​透​過​ sysctl 所​配​置​的​ kernel 參​數​。​
# sysctl -p /etc/sysctl.conf
重​新​啟​動​ libvirt daemon。​
# service libvirtd reload
您​現​在​應​該​會​有​個​「​共​享​實​體​裝​置​」​,您​可​將​客​座​端​連​至​它​並​擁​有​完​整​的​區​域​網​路​存​取​權​限​。​請​驗​證​您​的​新​橋​接​裝​置​:
# brctl show
bridge name     bridge id               STP enabled     interfaces
virbr0          8000.000000000000       yes
br0             8000.000e0cb30550       no              eth0
請​注​意​,橋​接​和​ virbr0 橋​接​是​完​全​獨​立​的​。​「​請​勿​」​嘗​試​將​實​體​裝​置​連​至​ virbr0。​virbr0 橋​接​只​適​用​於​網​路​位​址​轉​譯​(NAT)連​結​性​。​

章 11. Red Hat Enterprise Linux 5.4 Xen 網​路​作​業​

本​章​節​涵​蓋​了​ Xen hypervisor 的​網​路​作​業​,以​及​網​路​設​定​的​相​關​特​殊​主​題​。​
Most guest network configuration occurs during the guest initialization and installation process. To learn about configuring networking during the guest installation process, read the relevant sections of the installation process, 章 7, 虛​擬​化​客​座​端​安​裝​總​覽​.
Network configuration is also covered in the tool specific reference chapters for virsh (章 25, 透​過​ virsh 來​管​理​客​座​端​) and virt-manager (章 26, 使​用​虛​擬​主​機​管​理​程​式​(Virtual Machine Manager,virt-manager)來​管​理​客​座​端​). Those chapters provide a detailed description of the networking configuration tasks using both tools.

Tip

Using para-virtualized network drivers improves performance on fully virtualized Linux guests. 章 12, Xen 半​虛​擬​化​驅​動​程​式​ explains how to utilize para-virtualized network drivers.

11.1. 設​定​多​重​客​座​端​網​路​橋​接​來​使​用​多​重​乙​太​網​路​卡​

設​定​網​路​橋​接​的​程​序​(搭​配​ Xen hypervisor):
  1. 請​使​用​ system-config-network 應​用​程​式​來​設​定​另​一​個​網​路​介​面​卡​。​另​外​您​亦​可​在​ /etc/sysconfig/network-scripts/ 目​錄​中​建​立​一​個​名​為​ ifcfg-ethX 的​新​配​置​檔​案​,X 代​表​任​何​未​被​使​用​中​的​編​號​。​下​列​為​一​個​稱​為​ eth1 的​第​二​網​路​介​面​卡​的​配​置​檔​案​範​本​:
    $ cat /etc/sysconfig/network-scripts/ifcfg-eth1
    DEVICE=eth1
    BOOTPROTO=static
    ONBOOT=yes
    USERCTL=no
    IPV6INIT=no
    PEERDNS=yes
    TYPE=Ethernet
    NETMASK=255.255.255.0
    IPADDR=10.1.1.1
    GATEWAY=10.1.1.254
    ARP=yes
    
  2. 請​將​ /etc/xen/scripts/network-bridge 檔​案​複​製​至​ /etc/xen/scripts/network-bridge.xen。​
  3. Comment out any existing network scripts in /etc/xen/xend-config.sxp and add the line (network-xen-multi-bridge). A typical xend-config.sxp file should have the following line. Comment this line out. Use the # symbol to comment out lines.
    network-script network-bridge
    
    Below is the commented out line and the new line, containing the network-xen-multi-bridge parameter to enable multiple network bridges.
    #network-script network-bridge
    network-script network-xen-multi-bridge
  4. Create a script to create multiple network bridges. This example creates a script called network-xen-multi-bridge.sh in the /etc/xen/scripts/ directory. A sample scripts is below, this example script will create two Xen network bridges (xenbr0 and xenbr1) one will be attached to eth1 and the other one to eth0. If you want to create additional bridges just follow the example in the script and copy nad paste the lines as required:
    #!/bin/sh
    # network-xen-multi-bridge
    # Exit if anything goes wrong.
    set -e
    # First arg is the operation.
    OP=$1
    shift
    script=/etc/xen/scripts/network-bridge.xen
    case ${OP} in
    start)
    	$script start vifnum=1 bridge=xenbr1 netdev=eth1
    	$script start vifnum=0 bridge=xenbr0 netdev=eth0
    	;;
    stop)
    	$script stop vifnum=1 bridge=xenbr1 netdev=eth1
    	$script stop vifnum=0 bridge=xenbr0 netdev=eth0
    	;;
    status)
    	$script status vifnum=1 bridge=xenbr1 netdev=eth1
    	$script status vifnum=0 bridge=xenbr0 netdev=eth0
    	;;
    *)
    	echo 'Unknown command: ' ${OP}
    	echo 'Valid commands are: start, stop, status'
    	exit 1
    esac
    
  5. Make the script executable.
    # chmod +x /etc/xen/scripts/network-xen-multi-bridge.sh
  6. Restart networking or restart the system to activate the bridges.
    # service network restart
Multiple bridges should now be configured for guests on the Xen hypervisor.

11.2. Red Hat Enterprise Linux 5.0 手​提​電​腦​網​路​配​置​

適​用​於​ Red Hat Enterprise Linux 5.1 或​更​新​版​本​

此​部​份​描​述​了​如​何​手​動​式​地​新​增​網​路​橋​接​值​裝​置​。​不​建​議​(或​不​需​要​)在​ Red Hat Enterprise Linux 5.0 或​更​新​版​本​上​進​行​這​項​程​序​。​較​新​的​版​本​在​使​用​ virt-manager 來​建​立​客​座​端​時​請​使​用​「​虛​擬​網​路​」​卡​。​就​預​設​值​來​說​,在​ Red Hat Enterprise Linux 5.1 或​更​新​版​本​中​,NetworkManager 可​適​用​於​虛​擬​網​路​裝​置​。​
以​下​為​一​個​虛​擬​網​路​裝​置​的​ virsh XML 配​置​檔​案​範​本​:
<interface type='network'>
	<mac address='AA:AA:AA:AA:AA:AA'/>
	<source network='default'/>
	<target dev='vnet0'/>
	<model type='virtio'/>
</interface>
在​ xm 配​置​檔​案​中​,虛​擬​網​路​裝​置​會​被​標​記​為​「​vif」​。​
The challenge in running the Xen hypervisor on a laptop is that most laptops will connected to the network via wireless network or wired connections. Often these connections are switched multiple times a day. In such an environment, the system assumes it has access to the same interface all the time and it also can perform ifup or ifdown calls to the network interface it is using. In addition wireless network cards do not work well in a virtualization environment due to Xen's (default) bridged network usage.
此​設​定​也​可​讓​您​在​手​提​電​腦​上​沒​有​網​路​連​線​時​,能​夠​透​過​離​線​模​式​執​行​ Xen。​要​在​手​提​電​腦​上​執​行​ Xen,最​簡​單​方​法​就​是​依​照​下​列​所​列​出​的​程​序​進​行​:
  • You will be configuring a 'dummy' network interface which will be used by Xen. In this example the interface is called dummy0. This will also allow you to use a hidden IP address space for your guests.
  • 您​將​需​要​使​用​靜​態​ IP 位​址​,因​為​ DHCP 不​會​在​虛​擬​介​面​卡​上​監​聽​ DHCP 請​求​。​您​可​編​譯​您​自​己​的​ DHCP 版​本​來​在​虛​擬​介​面​卡​上​進​行​監​聽​,不​過​您​也​許​會​希​望​嘗​試​在​ Xen 環​境​下​使​用​ DNS 的​ dnsmasq、​DHCP 或​是​ tftpboot 服​務​。​有​關​於​設​定​與​配​置​上​的​相​關​資​訊​之​後​會​於​本​部​份​章​節​後​段​詳​細​解​說​。​
  • 您​也​可​設​定​網​路​位​址​轉​譯​(NAT,Network Address Translation)與​ IP 偽​冒​(IP masquerading),來​得​到​由​客​座​端​存​取​網​路​的​權​限​。​
設​定​一​個​虛​擬​網​路​介​面​卡​
請​在​您​的​主​機​上​進​行​下​列​設​定​步​驟​:
  1. 請​建​立​一​個​ dummy0 網​路​介​面​卡​並​為​它​指​派​一​組​靜​態​ IP 位​址​。​我​們​在​範​例​中​選​擇​了​ 10.1.1.1 來​避​免​在​我​們​的​環​境​下​產​生​路​由​問​題​。​若​要​啟​用​虛​擬​裝​置​支​援​,請​將​下​列​幾​行​附​加​至​ /etc/modprobe.conf
    alias dummy0 dummy
    options dummy numdummies=1
    
  2. 若​要​為​ dummy0 設​定​網​路​作​業​,請​編​輯​/建​立​ /etc/sysconfig/network-scripts/ifcfg-dummy0
    DEVICE=dummy0
    BOOTPROTO=none
    ONBOOT=yes
    USERCTL=no
    IPV6INIT=no
    PEERDNS=yes
    TYPE=Ethernet
    NETMASK=255.255.255.0
    IPADDR=10.1.1.1
    ARP=yes
    
  3. 請​將​ xenbr0 綁​定​至​ dummy0,如​此​一​來​就​算​未​連​至​一​個​實​體​網​路​,您​也​還​是​能​夠​使​用​網​路​作​業​。​請​編​輯​ /etc/xen/xend-config.sxp 並​使​其​包​含​ netdev=dummy0 這​個​項​目​:
    (network-script 'network-bridge bridge=xenbr0 netdev=dummy0')
    
  4. Open /etc/sysconfig/network in the guest and modify the default gateway to point to dummy0. If you are using a static IP, set the guest's IP address to exist on the same subnet as dummy0.
    NETWORKING=yes
    HOSTNAME=localhost.localdomain
    GATEWAY=10.1.1.1
    IPADDR=10.1.1.10
    NETMASK=255.255.255.0
    
  5. 設​定​主​機​中​的​ NAT 能​讓​客​座​端​存​取​網​路​,這​包​括​使​用​無​線​網​路​,並​且​可​解​決​ Xen 的​無​線​網​路​卡​上​的​問​題​。​以​下​ script 將​會​根​據​您​網​路​連​線​目​前​所​使​用​的​介​面​卡​來​啟​用​ NAT。​
為​虛​擬​客​座​端​設​定​ NAT
網​路​位​址​轉​譯​(NAT)能​透​過​截​取​封​包​並​將​它​們​傳​送​至​私​密​ IP 位​址​,來​讓​多​重​網​路​位​址​通​過​一​個​單​獨​的​ IP 位​址​來​進​行​連​線​。​您​可​將​下​列​ script 複​製​至​ /etc/init.d/xenLaptopNAT 並​建​立​一​個​連​至​ /etc/rc3.d/S99xenLaptopNAT 的​捷​徑​。​這​會​使​ NAT 在​開​機​時​自​動​地​啟​動​。​

NetworkManager 與​無​線​ NAT

基​於​啟​動​上​的​延​遲​,下​列​ script 不​適​合​使​用​於​無​線​網​路​或​ NetworkManager。​在​此​情​況​下​,請​在​機​器​啟​動​時​手​動​式​地​執​行​該​ script 一​遍​。​
#!/bin/bash
PATH=/usr/bin:/sbin:/bin:/usr/sbin
export PATH
GATEWAYDEV=`ip route | grep default | awk {'print $5'}`
iptables -F
case "$1" in
start)
	if test -z "$GATEWAYDEV"; then
	echo "No gateway device found"
    else
	echo  "Masquerading using $GATEWAYDEV"
	/sbin/iptables -t nat -A POSTROUTING -o $GATEWAYDEV -j MASQUERADE
fi
	echo "Enabling IP forwarding"
	echo 1 > /proc/sys/net/ipv4/ip_forward
	echo "IP forwarding set to `cat /proc/sys/net/ipv4/ip_forward`"
	echo "done."
	;;
*)
echo "Usage: $0 {start|restart|status}"
;;
esac
為​ DNS、​DHCP 和​ tftpboot 服​務​設​定​ dnsmasq
在​手​提​電​腦​(或​任​何​其​它​未​透​過​一​個​單​獨​或​穩​定​網​路​連​線​的​電​腦​)上​執​行​虛​擬​化​的​一​大​挑​戰​,是​網​路​介​面​卡​會​有​所​更​動​,使​其​可​用​性​降​低​。​使​用​一​個​虛​擬​網​路​介​面​卡​可​協​助​您​建​立​一​個​更​加​穩​定​的​環​境​,不​過​它​也​會​產​生​一​些​在​提​供​ DHCP、​DNS 與​ tftpboot 服​務​至​您​的​虛​擬​機​器​/客​座​端​上​的​問​題​。​Red Hat Enterprise Linux 與​ Fedora Core 中​所​提​供​的​預​設​ DHCP daemon 不​會​在​虛​擬​介​面​卡​上​進​行​監​聽​,您​的​ DNS 所​轉​發​的​資​訊​可​能​會​隨​著​您​連​至​不​同​的​網​路​和​ VPN 而​改​變​。​
以​上​問​題​的​解​決​方​法​之​一​就​是​使​用​ dnsmasq,它​能​以​一​個​單​獨​的​套​件​來​提​供​以​上​所​有​的​服​務​,並​且​亦​可​讓​您​控​制​它​的​服​務​使​其​只​能​用​於​來​自​您​虛​擬​介​面​卡​的​請​求​。​以​下​為​如​何​在​一​部​執​行​虛​擬​化​中​的​手​提​電​腦​上​設​定​ dnsmasq 的​簡​短​指​南​:
  • 您​可​透​過​點​選​此​處​來​取​得​最​新​版​本​的​ dnsmasq。​
  • Documentation for dnsmasq can be found here.
  • Copy the other files referenced below from http://et.redhat.com/~jmh/tools/xen/ and grab the file dnsmasq.tgz. The tar archive includes the following files:
    • nm-dnsmasq 可​被​用​來​作​為​ NetworkManager 的​調​度​ script。​每​次​當​ NetworkManager 偵​測​到​連​接​性​上​的​變​更​時​,它​便​會​執​行​並​且​強​制​ dnsmasq 重​新​啟​動​/重​新​載​入​。​它​應​被​複​製​至​ /etc/NetworkManager/dispatcher.d/nm-dnsmasq。​
    • xenDNSmasq 可​被​用​來​作​為​ /etc/init.d/xenDNSmasq 的​主​要​啟​動​或​關​閉​的​ script。​
    • dnsmasq.conf 為​ /etc/dnsmasq.conf 的​範​例​配​置​檔​案​。​
    • dnsmasq 為​ /usr/local/sbin/dnsmasq 的​ binary 映​像​檔​。​
  • 當​您​解​壓​縮​並​建​置​了​ dnsmasq(預​設​安​裝​為​ /usr/local/sbin/dnsmasq 之​中​的​ binary)之​後​,您​將​需​要​編​輯​您​的​ dnsmasq 配​置​檔​案​。​該​檔​案​位​於​ /etc/dnsmaqs.conf 之​中​。​
  • 請​編​輯​配​置​使​其​配​合​您​的​本​地​需​求​。​以​下​可​能​會​是​您​所​需​要​修​改​的​參​數​:
    • interface 這​個​參​數​能​讓​ dnsmasq 在​特​定​介​面​卡​上​監​聽​ DHCP 與​ DNS 請​求​。​這​可​能​是​虛​擬​介​面​卡​而​非​您​的​公​用​介​面​卡​或​本​地​ loopback 介​面​卡​。​請​在​多​於​一​個​介​面​卡​的​情​況​下​附​加​另​一​行​ interface。​interface=dummy0 就​是​一​個​在​ dummy0 介​面​卡​上​進​行​監​聽​的​範​例​。​
    • dhcp-range 若​要​啟​用​整​合​的​ DHCP 伺​服​器​,您​必​須​提​供​可​租​借​(lease)的​位​址​範​圍​與​/或​租​借​時​間​。​若​您​擁​有​超​過​一​個​網​路​的​話​,您​將​需​要​針​對​您​所​希​望​提​供​ DHCP 服​務​的​各​個​網​路​重​複​此​步​驟​。​其​中​一​個​範​例​為​(網​路​ 10.1.1.* 以​及​ 12 小​時​的​租​借​時​間​):dhcp-range=10.1.1.10,10.1.1.50,255.255.255.0,12h。​
    • dhcp-option 可​置​換​ dnsmasq 所​提​供​的​預​設​路​由​,這​會​假​設​路​由​器​和​執​行​ dnsmasq 的​機​器​是​相​同​的​。​例​如​:dhcp-option=3,10.1.1.1。​
  • 在​設​定​了​ dnsmasq 之​後​,您​可​將​以​下​ script 複​製​為​ xenDNSmasq 至​ /etc/init.d。​
  • 若​您​希​望​在​系​統​啟​動​時​自​動​地​啟​用​ dnsmasq,您​應​使​用​ chkconfig 來​註​冊​它​:
    chkconfig --add xenDNSmasq
    
    使​它​可​自​動​啟​動​:
    chkconfig --levels 345 xenDNSmasq on
    
  • 若​要​將​ dnsmasq 配​置​成​每​當​ NetworkManager 偵​測​到​連​接​性​上​的​改​變​時​,就​會​重​新​啟​動​的​話​,您​可​使​用​提​供​的​ script:nm-dnsmasq。​
    • 請​將​ nm-dnsmasq script 複​製​至​ /etc/NetworkManager/dispatcher.d/
    • 每​當​連​接​性​上​有​變​更​時​,NetworkManager 調​度​器​便​會​(若​相​同​目​錄​中​還​有​其​它​ script 的​話​便​會​按​照​字​母​順​序​)執​行​ script
  • dnsmasq 也​會​偵​測​您​ /etc/resolv.conf 中​的​變​更​並​自​動​地​(在​您​啟​用​了​一​個​ VPN session 時​)將​它​們​重​新​載​入​。​
  • 若​您​的​虛​擬​機​器​位​於​一​個​隱​藏​的​網​路​上​,nm-dnsmasq 和​ xenDNSmasq 這​兩​個​ script 也​會​設​定​ NAT,以​允​許​它​們​存​取​公​共​網​路​。​

章 12. Xen 半​虛​擬​化​驅​動​程​式​

Para-virtualized drivers provide increased performance for fully virtualized Red Hat Enterprise Linux guests. Use these drivers if you are using fully virtualized Red Hat Enterprise Linux guests and require better performance.

其​它​半​虛​擬​化​驅​動​程​式​

Xen 與​ KVM hypervisor 皆​有​其​它​針​對​於​ Windows 的​半​虛​擬​化​驅​動​程​式​。​
在​ Xen 主​機​上​使​用​ Windows 客​座​端​時​,請​參​閱​涵​蓋​了​安​裝​與​管​理​資​訊​的​《​Windows 半​虛​擬​化​驅​動​程​式​指​南​》​。​
For Windows guests on KVM hosts, refer to 章 13, KVM 半​虛​擬​化​驅​動​程​式​.
半​虛​擬​化​驅​動​程​式​的​ RPM 套​件​包​含​了​儲​存​模​組​、​以​及​受​支​援​的​ Red Hat Enterprise Linux 客​座​端​作​業​系​統​之​網​路​半​虛​擬​化​驅​動​程​式​。​這​些​驅​動​程​式​在​ Red Hat Enterprise Linux 5.1(或​更​新​版​本​)主​機​上​未​經​修​改​的​ Red Hat Enterprise Linux 客​座​作​業​系​統​中​,可​提​供​高​效​能​產​量​的​ I/O 作​業​。​
受​支​援​的​客​座​端​作​業​系​統​包​含​:
  • Red Hat Enterprise Linux 3
  • Red Hat Enterprise Linux 4
  • Red Hat Enterprise Linux 5

半​虛​擬​化​驅​動​程​式​的​架​構​支​援​

最​小​的​客​座​端​作​業​系​統​需​求​取​決​於​架​構​本​身​。​目​前​只​支​援​ x86 和​ x86-64 客​座​端​。​
這​些​驅​動​程​式​在​ Red Hat Enterprise Linux 3 之​前​的​ Red Hat Enterprise Linux 客​座​端​上​並​不​受​到​支​援​。​
當​使​用​ Red Hat Enterprise Linux 5 作​為​虛​擬​化​平​台​時​,系​統​管​理​員​能​將​ Linux 和​ Windows 的​工​作​量​整​合​至​較​新​、​較​強​大​、​具​有​增​強​的​效​能​和​冷​卻​效​率​較​佳​的​硬​體​上​。​Red Hat Enterprise Linux 4(Update 6 以​上​)以​及​ Red Hat Enterprise Linux 5 客​座​端​作​業​系​統​可​偵​測​到​潛​在​的​虛​擬​化​技​術​,並​能​透​過​使​用​特​定​介​面​卡​和​功​能​,與​它​進​行​有​效​的​交​互​作​用​。​此​方​法​可​達​到​近​於​空​機​系​統​的​效​率​與​產​能​。​
As para-virtualization requires a modified guest operating system, not all operating systems can use para-virtualization. For operating systems which can not be modified, full virtualization is required. Full virtualization, by default, uses emulated disk, network, video and other hardware devices. Emulated I/O devices can be very slow and are not suited for applications requiring high disk and/or network throughput. The majority of the performance loss with virtualization occurs through the use of emulated devices.
半​虛​擬​化​裝​置​的​驅​動​程​式​都​附​在​ Red Hat Enterprise Linux 裡​。​這​些​驅​動​程​式​能​為​未​修​改​的​作​業​系​統​帶​來​許​多​半​虛​擬​化​客​座​端​作​業​系​統​的​效​能​優​勢​,因​為​只​有​「​半​虛​擬​化​裝​置​驅​動​程​式​」​(而​非​作​業​系​統​的​其​他​部​份​)偵​測​到​下​方​的​虛​擬​化​平​台​。​
安​裝​了​半​虛​擬​裝​置​驅​動​程​式​後​,磁​碟​裝​置​或​網​路​卡​將​會​持​續​顯​得​正​常​。​不​過​現​在​裝​置​驅​動​程​式​已​直​接​與​虛​擬​化​平​台​(非​模​擬​)產​生​互​動​來​有​效​地​交​付​磁​碟​和​網​路​的​存​取​,並​允​許​磁​碟​和​網​路​子​系​統​就​算​位​於​一​個​虛​擬​化​的​環​境​中​,也​可​在​不​更​改​現​有​的​客​座​端​作​業​系​統​的​情​況​下​,以​接​近​本​機​的​速​度​運​作​。​
半​虛​擬​化​的​驅​動​程​式​含​有​特​定​主​機​需​求​。​64 位​元​的​主​機​可​執​行​:
  • 32 位​元​的​客​座​端​。​
  • 64 位​元​的​客​座​端​。​
  • 32 位​元​與​ 64 位​元​客​座​端​的​組​合​。​

12.1. 系​統​需​求​

此​部​份​提​供​了​ Red Hat Enterprise Linux 上​的​半​虛​擬​化​驅​動​程​式​的​需​求​。​
安​裝​
在​您​安​裝​半​虛​擬​化​驅​動​程​式​之​前​,您​必​須​滿​足​以​下​系​統​需​求​。​

Red Hat Enterprise Linux 4.7 和​ 5.3 以​及​更​新​版​本​

所​有​從​ 4.7 至​ 5.3 版​本​的​ Red Hat Enterprise Linux 都​擁​有​半​虛​擬​化​驅​動​程​式​的​ kernel 模​組​,也​就​是​預​設​ kernel 套​件​中​的​ pv-on-hvm 模​組​。​這​代​表​ Red Hat Enterprise Linux 4.7 和​更​新​版​本​以​及​ 5.3 與​更​新​版​本​的​客​座​端​皆​可​使​用​半​虛​擬​化​驅​動​程​式​。​
當​進​行​各​個​客​座​端​作​業​系​統​的​安​裝​程​序​時​,您​將​需​要​下​列​的​半​虛​擬​化​驅​動​程​式​ RPM 套​件​。​
Minimum host operating system version:
  • Red Hat Enterprise Linux 5.1 or newer.
Minimum guest operating system version:
  • Red Hat Enterprise Linux 5.1 or newer.
  • Red Hat Enterprise Linux 4 Update 6 or newer.
  • Red Hat Enterprise Linux 3 Update 9 or newer.
Red Hat Enterprise Linux 5 requires:
  • kmod-xenpv.
Red Hat Enterprise Linux 4 requires:
  • kmod-xenpv,
  • modules-init-tools (for versions prior to Red Hat Enterprise Linux 4.6z you require modules-init-tools-3.1-0.pre5.3.4.el4_6.1 or greater), and
  • modversions.
Red Hat Enterprise Linux 3 requires:
  • kmod-xenpv.
You require at least 50MB of free disk space in the /lib file system.

12.2. 半​虛​擬​化​的​限​制​與​支​援​

此​部​份​列​出​了​在​ Red Hat Enterprise Linux 上​使​用​半​虛​擬​化​驅​動​程​式​的​支​援​上​的​限​制​與​需​求​。​您​可​在​以​下​部​份​中​,查​到​我​們​所​支​援​的​半​虛​擬​化​驅​動​程​式​與​限​制​為​何​。​
受​支​援​的​客​座​端​作​業​系​統​
我​們​支​援​在​下​列​作​業​系​統​與​版​本​上​,使​用​半​虛​擬​化​驅​動​程​式​:
  • Red Hat Enterprise Linux 5.1 與​更​新​版​本​。​
  • Red Hat Enterprise Linux 4 Update 6 與​更​新​版​本​。​
  • Red Hat Enterprise Linux 3 Update 9 與​更​新​版​本​。​
我​們​支​援​您​在​ 64 位​元​的​ Red Hat Enterprise Linux 5 虛​擬​化​產​品​上​,以​半​虛​擬​化​的​驅​動​程​式​,執​行​ 32 位​元​的​客​座​端​作​業​系​統​。​
下​列​表​格​顯​示​了​半​虛​擬​化​驅​動​程​式​所​支​援​的​ kernel 種​類​。​您​可​使​用​下​列​指​令​來​辨​識​您​主​機​上​目​前​所​安​裝​的​確​切​ kernel 修​訂​版​為​何​。​請​利​用​輸​出​資​訊​和​該​表​格​進​行​比​較​,以​判​斷​它​是​否​受​到​支​援​。​
# rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' kernel
Red Hat Enterprise Linux 5 i686 和​ x86_64 kernel 種​類​包​含​著​對​稱​式​多​重​處​理​(Symmetric Multiprocessing,SMP),因​此​不​需​要​個​別​的​ SMP kernel RPM。​
請​注​意​下​列​表​格​中​ Red Hat Enterprise Linux 3 Guest 的​處​理​器​特​屬​的​ kernel 需​求​。​
表格 12.1. 支​援​使​用​虛​擬​化​驅​動​程​式​的​客​座​端​ kernel 架​構​
Kernel 架​構​ Red Hat Enterprise Linux 3 Red Hat Enterprise Linux 4 Red Hat Enterprise Linux 5
athlon 已​支​援​(AMD)   
athlon-SMP 已​支​援​(AMD)   
i32e 已​支​援​(Intel)   
i686 已​支​援​(Intel) 已​支​援​ 已​支​援​
i686-PAE 已​支​援​
i686-SMP 已​支​援​(Intel) 已​支​援​  
i686-HUGEMEM 已​支​援​(Intel) 已​支​援​  
x86_64 已​支​援​(AMD) 已​支​援​ 已​支​援​
x86_64-SMP 已​支​援​(AMD) 已​支​援​  
x86_64-LARGESMP 已​支​援​  
Itanium(IA64) 已​支​援​

重​要​

主​機​系​統​需​要​ Red Hat Enterprise Linux 5.1 或​更​新​版​本​。​

找​出​您​正​在​使​用​哪​個​ kernel

請​將​以​下​指​令​的​輸​出​寫​下​或​記​起​來​。​這​是​個​判​斷​您​所​需​下​載​的​套​件​和​模​組​為​何​的​值​。​
# rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' kernel
您​的​輸​出​應​看​似​:
kernel-PAE-2.6.18-53.1.4.el5.i686
Kernel 的​名​稱​為​ PAE(Physical Address Extension,實​體​位​置​延​伸​的​縮​寫​),kernel 版​本​為​ 2.6.18,發​行​版​為​ 53.1.4.el5 並​且​架​構​為​ i686。​kernel rpm 的​格​式​應​該​總​是​為​ kernel-name-version-release.arch.rpm。​
重​要​的​限​制​
半​虛​擬​化​裝​置​的​驅​動​程​式​能​在​成​功​地​安​裝​了​客​座​端​作​業​系​統​後​進​行​安​裝​。​您​需​要​一​部​可​運​作​的​主​機​和​客​座​端​,才​可​安​裝​這​些​驅​動​程​式​。​

半​虛​擬​化​的​區​塊​裝​置​與​ GRUB

GRUB 目​前​還​無​法​存​取​半​虛​擬​化​的​區​塊​裝​置​。​因​此​,客​座​端​無​法​由​使​用​半​虛​擬​化​區​塊​裝​置​驅​動​程​式​的​裝​置​啟​動​。​具​體​地​來​講​就​是​包​含​著​ MBR 的​磁​碟​、​包​含​著​開​機​載​入​程​式​的​磁​碟​(GRUB),或​是​一​個​包​含​著​ kernel initrd 映​像​的​磁​碟​。​也​就​是​說​所​有​包​含​著​ /boot 目​錄​或​是​分​割​區​的​磁​碟​,都​無​法​使​用​半​虛​擬​化​區​塊​裝​置​的​驅​動​程​式​。​
Red Hat Enterprise Linux 3 kernel 種​類​架​構​相​依​性​
在​基​於​ Red Hat Enterprise Linux 3 的​客​座​端​作​業​系​統​上​,您​必​須​如​同​下​列​表​格​所​顯​示​的​,來​使​用​處​理​器​特​屬​的​ kernel 和​半​虛​擬​化​驅​動​程​式​ RPM。​若​您​未​正​確​地​安​裝​相​符​的​半​虛​擬​化​驅​動​程​式​套​件​,xen-pci-platform 模​組​的​載​入​便​會​失​敗​。​
下​列​表​格​顯​示​了​為​ Intel 處​理​器​所​編​譯​的​ Red Hat Enterprise Linux 3 客​座​端​,應​執​行​於​哪​個​主​機​ kernel 上​。​
表格 12.2. 在​使​用​ Intel 處​理​器​的​ Red Hat Enterprise Linux 3 上​,使​用​半​虛​擬​化​驅​動​程​式​的​客​座​端​所​需​的​主​機​ kernel 架​構​
客​座​端​ kernel 類​型​ 必​要​的​主​機​ kernel 類​型​
ia32e(UP 和​ SMP) x86_64
i686 i686
i686-SMP i686
i686-HUGEMEM i686

下​列​表​格​顯​示​了​為​ AMD 處​理​器​所​編​譯​的​ Red Hat Enterprise Linux 3 客​座​端​,應​執​行​於​哪​個​主​機​ kernel 上​。​
表格 12.3. 在​使​用​ AMD 處​理​器​的​ Red Hat Enterprise Linux 3 上​,使​用​半​虛​擬​化​驅​動​程​式​的​客​座​端​所​需​的​主​機​ kernel 架​構​
客​座​端​ kernel 類​型​ 必​要​的​主​機​ kernel 類​型​
athlon i686
athlon-SMP i686
x86_64 x86_64
x86_64-SMP x86_64

12.3. 安​裝​半​虛​擬​化​驅​動​程​式​

下​列​三​個​章​節​描​述​了​如​何​安​裝​與​設​定​您​的​完​整​虛​擬​化​客​座​端​,以​便​執​行​於​ Red Hat Enterprise Linux 5.1(或​更​新​版​本​)上​,以​及​使​用​半​虛​擬​化​驅​動​程​式​上​的​相​關​資​訊​。​

在​進​行​之​前​,請​驗​證​您​的​架​構​是​否​受​到​支​援​

半​虛​擬​化​驅​動​程​式​只​在​特​定​硬​體​和​版​本​的​組​合​上​受​到​支​援​。​請​在​進​行​半​虛​擬​化​驅​動​程​式​的​安​裝​前​先​驗​證​您​是​否​有​達​到​硬​體​和​作​業​系​統​上​的​需​求​。​

當​進​行​新​安​裝​時​,將​半​虛​擬​化​驅​動​程​式​的​益​處​發​揮​的​淋​漓​盡​致​

當​您​要​安​裝​一​部​新​的​客​座​端​系​統​時​,若​要​淋​漓​盡​致​地​利​用​半​虛​擬​化​區​塊​裝​置​驅​動​程​式​,您​應​使​用​至​少​兩​個​磁​碟​來​建​立​客​座​端​。​
針​對​於​包​含​了​ MBR 和​開​機​載​入​程​式​(GRUB),以​及​ /boot 分​割​區​使​用​半​虛​擬​化​驅​動​程​式​。​這​個​磁​碟​的​容​量​不​用​很​大​,因​為​它​只​需​要​擁​有​足​夠​的​空​間​來​容​納​ /boot 分​割​區​即​可​。​
請​使​用​第​二​個​磁​碟​以​及​任​何​額​外​的​磁​碟​來​作​為​所​有​其​它​的​分​割​區​(例​如​ /、​/usr)或​是​邏​輯​卷​冊​。​
使​用​此​安​裝​方​式​時​,若​半​虛​擬​化​區​塊​裝​置​的​驅​動​程​式​在​完​成​了​客​座​端​的​安​裝​之​後​才​被​安​裝​的​話​,那​麼​只​有​啟​動​客​座​端​、​並​存​取​ /boot 分​割​區​後​,才​可​使​用​虛​擬​化​區​塊​裝​置​的​驅​動​程​式​。​

12.3.1. 一​般​安​裝​步​驟​

下​列​清​單​涵​蓋​了​所​有​客​座​端​作​業​系​統​版​本​上​的​一​般​高​階​安​裝​步​驟​。​
  1. Copy the RPMs for your hardware architecture to a suitable location in your guest operating system. Your home directory is sufficient. If you do not know which RPM you require verify against the table at 節 12.2, “半​虛​擬​化​的​限​制​與​支​援​”.
  2. 請​使​用​ rpm 指​令​或​是​ yum 指​令​來​安​裝​套​件​。​rpm 工​具​程​式​會​將​以​下​的​四​個​新​ kernel 模​組​安​裝​至​ /lib/modules/[%kversion][%kvariant]/extra/xenpv/%release 中​:
    • the PCI infrastructure module, xen_platform_pci.ko,
    • the ballooning module, xen_balloon.ko,
    • the virtual block device module, xen_vbd.ko,
    • and the virtual network device module, xen_vnif.ko.
  3. 若​客​座​端​作​業​系​統​不​支​援​自​動​載​入​半​虛​擬​化​驅​動​程​式​的​話​(比​方​說​ Red Hat Enterprise Linux 3),請​在​安​裝​後​執​行​必​要​的​步​驟​來​將​驅​動​程​式​複​製​至​作​業​系​統​特​屬​的​位​置​中​。​
  4. 關​閉​您​的​客​座​端​作​業​系​統​。​
  5. Reconfigure the guest operating system's configuration file on the host to use the installed para-virtualized drivers.
  6. 將​網​路​裝​置​的​「​type=ioemu」​項​目​移​除​。​
  7. Add any additional disk partitions, volumes or LUNs to the guest so that they can be accessed via the para-virtualized (xen-vbd) disk driver.
  8. For each physical device, LUN, partition or volume you want to use the para-virtualized drivers you must edit the disk entry for that device in the libvirt configuration file.
  9. A typical disk entry resembles the following:
    <disk type='file' device='disk'>
      <driver name='file'/>
      <source file='/dev/hda6'/>
      <target dev='hda'/>
    </disk>
    
    Modify each disk entry, as desired, to use the para-virtualized by changing the driver elements as shown below.
    <disk type='file' device='disk'>
      <driver name='tap' type='aio'/>
      <source file='/dev/hda6'/>
      <target dev='xvda'/>
    </disk>
    
  10. 將​任​何​您​所​希​望​使​用​於​半​虛​擬​化​區​塊​裝​置​驅​動​程​式​的​額​外​儲​存​實​體​加​入​。​
  11. 重​新​啟​動​您​的​客​座​端​:
    # xm start YourGuestName
    Where YourGuestName is the name of the configuration file or the guest operating system's name as defined in its configuration file in the name = "os_name" parameter.
  12. Reconfigure the guest network.

12.3.2. Red Hat Enterprise Linux 3 上​的​半​虛​擬​化​驅​動​程​式​安​裝​與​設​定​

此​部​份​包​含​著​ Red Hat Enterprise Linux 3 客​座​端​作​業​系​統​中​的​半​虛​擬​化​驅​動​程​式​的​詳​細​指​示​。​

注​意​

這​些​套​件​並​不​支​援​透​過​半​虛​擬​化​磁​碟​來​啟​動​。​啟​動​客​座​端​作​業​系​統​ kernel 還​需​要​使​用​模​擬​的​ IDE 驅​動​程​式​,任​何​其​它​的​(非​系​統​)用​戶​空​間​應​用​程​式​和​資​料​則​可​使​用​半​虛​擬​化​的​區​塊​裝​置​驅​動​程​式​。​
驅​動​程​式​安​裝​
下​列​清​單​涵​蓋​了​安​裝​含​有​半​虛​擬​化​驅​動​程​式​的​ Red Hat Enterprise Linux 3 客​座​端​的​詳​細​步​驟​。​
  1. Install the latest kernel version. The para-virtualized drivers require at least Red Hat Enterprise Linux 3.9 kernel version kernel-2.4.21-60.EL for all the required headers.
  2. 請​將​適​合​您​的​硬​體​架​構​與​ kernel 的​ kmod-xenpv rpm 複​製​到​您​的​客​座​端​作​業​系​統​上​。​
  3. 請​使​用​ rpm 工​具​來​安​裝​ RPM 套​件​。​請​確​認​您​已​正​確​地​辨​識​了​您​客​座​端​作​業​系​統​類​型​與​架​構​所​需​的​套​件​為​何​。​
    [root@rhel3]# rpm -ivh kmod-xenpv*
    
  4. Use the commands below load the para-virtualized driver modules. %kvariant is the kernel variant the para-virtualized drivers have been build against and %release corresponds to the release version of the para-virtualized drivers.
    [root@rhel3]# mkdir -p /lib/modules/'uname -r'/extra/xenpv
    [root@rhel3]# cp -R /lib/modules/2.4.21-52.EL[%kvariant]/extra/xenpv/%release \
    /lib/modules/'uname -r'/extra/xenpv
    [root@rhel3]# depmod -ae
    [root@rhel3]# modprobe xen-vbd
    [root@rhel3]# modprobe xen-vnif
    

    注​意​

    因​為​ Red Hat Enterprise Linux 3 啟​用​了​ MODVERSIONS,因​此​當​安​裝​二​進​位​驅​動​程​式​模​組​時​,insmod 會​產​生​警​告​訊​息​。​您​可​忽​略​這​些​警​告​訊​息​。​
  5. 請​驗​證​ /etc/modules.conf 並​確​認​ eth0 擁​有​一​組​類​似​下​列​的​別​名​。​若​您​計​畫​設​定​多​張​網​路​卡​,請​為​各​個​網​路​卡​附​加​額​外​一​行​。​
    alias eth0 xen-vnif
    
    請​編​輯​ /etc/rc.local 並​新​增​一​行​:
    insmod /lib/modules/'uname -r'/extra/xenpv/%release/xen-vbd.o
    

    注​意​

    請​將​「​%release」​替​換​為​半​虛​擬​化​驅​動​程​式​的​實​際​版​本​(例​如​ 0.1-5.el)。​若​您​更​新​了​半​虛​擬​化​驅​動​程​式​的​ RPM 套​件​,請​確​認​您​是​否​有​將​發​行​版​本​更​新​為​正​確​的​版​本​。​
  6. 關​閉​虛​擬​機​器​(請​在​客​座​端​中​使​用​「​#shutdown -h now」​)。​
  7. Edit the guest configuration file in /etc/xen/YourGuestName with a text editor, performing the following changes:
    • 請​將​「​type=ioemu」​項​目​由​「​vif=」​項​目​中​移​除​。​
    • 將​任​何​額​外​的​磁​碟​分​割​、​卷​冊​或​ LUN 新​增​至​客​座​端​,如​此​一​來​它​們​才​可​透​過​半​虛​擬​化​(xen-vbd)的​磁​碟​驅​動​程​式​來​被​存​取​。​
    • For each physical device, LUN, partition or volume you want to use the para-virtualized drivers you must edit the disk entry for that device in the libvirt configuration file.
    • A typical disk entry resembles the following:
      <disk type='file' device='disk'>
        <driver name='file'/>
        <source file='/dev/hda6'/>
        <target dev='hda'/>
      </disk>
      
      Modify each disk entry, as desired, to use the para-virtualized by changing the driver elements as shown below.
      <disk type='file' device='disk'>
        <driver name='tap' type='aio'/>
        <source file='/dev/hda6'/>
        <target dev='xvda'/>
      </disk>
      
      
    • Once complete, save the modified configuration file and restart the guest.
  8. Boot the virtual machine:
    # xm start YourGuestName
    Where YourGuestName is the name of the configuration file or the guest operating system's name as defined in its configuration file in the name = "os_name" parameter.

注​意​

因​為​ Red Hat Enterprise Linux 3 中​並​不​支​援​ weak-modules 與​ modversions,因​此​半​虛​擬​化​驅​動​程​式​不​會​被​自​動​地​新​增​並​載​入​系​統​中​。​若​要​插​入​模​組​,請​執​行​下​列​指​令​。​
insmod xen_vbd.ko
Red Hat Enterprise Linux 3 需​要​您​手​動​式​地​為​使​用​ xen-vbd 的​區​塊​裝​置​建​立​特​殊​檔​案​。​下​列​步​驟​將​會​涵​蓋​如​何​建​立​與​註​冊​半​虛​擬​化​區​塊​裝​置​。​
當​半​虛​擬​化​區​塊​裝​置​被​載​入​後​,請​使​用​下​列​ script 來​建​立​特​殊​檔​案​。​
#!/bin/sh
module="xvd"
mode="664"
major=`awk "\\$2==\"$module\" {print \\$1}" /proc/devices`
# < mknod for as many or few partitions on xvd disk attached to FV guest >
# change/add xvda to xvdb, xvbd, etc. for 2nd, 3rd, etc., disk added in
# in xen config file, respectively.
mknod /dev/xvdb b $major 16
mknod /dev/xvdb1 b $major 17
mknod /dev/xvdb2 b $major 18
chgrp disk /dev/xvd*
chmod 0660 /dev/xvd*
請​為​各​個​額​外​的​虛​擬​磁​碟​的​ minor number 增​加​ 16。​在​下​列​範​例​中​,有​個​額​外​的​裝​置​ minor number 16 被​建​立​了​。​
# mknod /dev/xvdc b $major 16
# mknod /dev/xvdc1 b $major 17
這​會​使​下​一​個​裝​置​為​ 32 並​且​可​透​過​以​下​來​建​立​:
# mknod /dev/xvdd b $major 32
# mknod /dev/xvdd1 b $major 33
現​在​您​應​驗​證​您​所​建​立​的​分​割​區​是​否​可​使​用​。​
[root@rhel3]# cat /proc/partitions
major   minor     #blocks   name

  3        0      10485760  hda
  3        1        104391  hda1
  3        2      10377990  hda2
202        16         64000  xvdb
202        17         32000  xvdb1
202        18        32000  xvdb2
253        0       8257536  dm-0
253        1       2031616  dm-1
在​上​述​輸​出​中​,您​可​觀​察​到​被​分​割​的​裝​置​「​xvdb」​可​使​用​於​系​統​。​
以​下​程​序​會​新​增​裝​置​至​客​座​端​,並​使​裝​置​在​重​新​開​機​後​仍​然​存​在​。​所​有​指​令​都​在​客​座​端​上​面​執​行​。​
  1. 建​立​目​錄​,以​掛​載​區​塊​裝​置​的​映​像​檔​。​
    [root@rhel3]# mkdir /mnt/pvdisk_p1
    [root@rhel3]# mkdir /mnt/pvdisk_p2
    
  2. 將​裝​置​掛​載​到​新​目​錄​上​。​
    [root@rhel3]# mount /dev/xvdb1 /mnt/pvdisk_p1
    [root@rhel3]# mount /dev/xvdb2 /mnt/pvdisk_p2
    
  3. 驗​證​裝​置​是​否​掛​載​成​功​。​
    [root@rhel3]# df /mnt/pvdisk_p1
    Filesystem           1K-blocks      Used   Available Use%  Mounted on
    /dev/xvdb1               32000        15       31985   1%  /mnt/pvdisk_p1
    
  4. 更​新​客​座​端​的​ /etc/fstab 檔​案​,在​開​機​時​掛​載​這​些​裝​置​。​請​新​增​以​下​幾​行​:
    /dev/xvdb1   /mnt/pvdisk_p1   ext3    defaults        1 2
    /dev/xvdb2   /mnt/pvdisk_p2   ext3    defaults        1 2
    

效​能​提​示​

Using a Red Hat Enterprise Linux 5.1 host (dom0), the "noapic" parameter should be added to the kernel boot line in your virtual guest's /boot/grub/grub.conf entry as seen below. Keep in mind your architecture and kernel version may be different.
kernel /vmlinuz-2.6.9-67.EL ro root=/dev/VolGroup00/rhel4_x86_64 rhgb noapic
Red Hat Enterprise Linux 5.2 dom0 的​客​座​端​不​會​需​要​此​ kernel 參​數​。​

重​要​

Itanium(ia64)的​二​進​位​ RPM 套​件​和​組​建​目​前​還​無​法​使​用​。​

12.3.3. Red Hat Enterprise Linux 4 上​的​半​虛​擬​化​驅​動​程​式​的​安​裝​和​配​置​

此​部​份​包​含​著​ Red Hat Enterprise 4 客​座​端​作​業​系​統​中​的​半​虛​擬​化​驅​動​程​式​的​詳​細​資​訊​。​

注​意​

這​些​套​件​並​不​支​援​由​半​虛​擬​化​磁​碟​來​啟​動​。​啟​動​客​座​端​作​業​系​統​ kernel 依​然​需​要​使​用​模​擬​的​ IDE 驅​動​程​式​,而​任​何​其​它​的​(非​系​統​)用​戶​空​間​應​用​程​式​和​資​料​則​可​使​用​半​虛​擬​化​的​區​塊​裝​置​驅​動​程​式​。​
驅​動​程​式​安​裝​
下​列​清​單​涵​蓋​了​安​裝​含​有​半​虛​擬​化​驅​動​程​式​的​ Red Hat Enterprise Linux 4 客​座​端​的​步​驟​。​
  1. 將​您​硬​體​架​構​和​ kernel 的​ kmod-xenpv、​modules-init-tools 和​ modversions RPM 複​製​至​您​的​客​座​端​系​統​上​。​
  2. 請​使​用​ rpm 工​具​來​安​裝​ RPM 套​件​。​請​確​認​您​已​正​確​地​辨​識​了​您​的​客​座​端​作​業​系​統​種​類​和​架​構​所​需​的​套​件​為​何​。​此​套​件​需​要​一​個​更​新​的​ module-init-tools,這​可​藉​由​ Red Hat Enterprise Linux 4-6-z kernel 或​更​新​版​本​來​提​供​。​
    [root@rhel4]# rpm -ivh modversions
    [root@rhel4]# rpm -Uvh module-init-tools
    [root@rhel4]# rpm -ivh kmod-xenpv*
    

    注​意​

    UP、​SMP、​Hugemem 和​ architectures 皆​有​不​同​的​套​件​,因​此​請​確​認​您​的​ kernel 擁​有​正​確​的​ RPM。​
  3. Execute cat /etc/modprobe.conf to verify you have an alias for eth0 like the one below. If you are planning to configure multiple interfaces add an additional line for each interface. If it does not look like the entry below change it.
    alias eth0 xen-vnif
    
  4. 關​閉​虛​擬​機​器​(請​在​客​座​端​中​使​用​「​#shutdown -h now」​)。​
  5. 請​透​過​下​列​方​式​來​編​輯​ /etc/xen/YourGuestsName 中​的​客​座​端​配​置​檔​案​:
    • 將​「​type=ioemu」​項​目​由​「​vif=」​項​目​中​移​除​。​
    • 將​任​何​額​外​的​磁​碟​分​割​、​卷​冊​或​ LUN 新​增​至​客​座​端​,這​樣​它​們​才​可​被​透​過​半​虛​擬​化​(xen-vbd)的​磁​碟​驅​動​程​式​來​存​取​。​
    • 請​為​各​個​額​外​的​實​體​裝​置​、​LUN、​分​割​區​或​卷​冊​新​增​一​行​類​似​下​列​的​項​目​,請​將​這​些​項​目​新​增​至​客​座​端​配​置​檔​案​中​的​「​disk=」​部​份​。​原​本​的​「​disk=」​項​目​也​有​可​能​看​似​下​列​項​目​。​
      disk = [ "file:/var/lib/libvirt/images/rhel4_64_fv.dsk,hda,w"]
      
    • 一​旦​您​新​增​了​額​外​實​體​裝​置​、​LUN、​分​割​區​或​卷​冊​之​後​,您​ XML 配​置​檔​案​中​的​半​虛​擬​驅​動​程​式​項​目​會​和​下​列​所​顯​示​的​項​目​相​似​。​
      disk = [ "file:/var/lib/libvirt/images/rhel3_64_fv.dsk,hda,w",
      "tap:aio:/var/lib/libvirt/images/UserStorage.dsk,xvda,w" ]
      

      注​意​

      若​使​用​了​基​於​檔​案​的​映​像​檔​,請​將​「​tap:aio」​使​用​於​半​虛​擬​化​的​裝​置​。​
  6. 請​透​過​使​用​ virsh 指​令​來​啟​動​虛​擬​機​器​:
    # virsh start YourGuestName
虛​擬​客​座​端​第​一​次​重​新​啟​動​時​,kudzu 會​詢​問​您​「​Keep or Delete the Realtek Network device(保​留​或​刪​除​ Realtek 網​路​裝​置​)」​和​「​Configure the xen-bridge device(配​置​ xen-bridge 裝​置​)」​。​您​應​該​配​置​ xen-bridge 並​刪​除​ Realtek 網​路​裝​置​。​

效​能​提​示​

Using a Red Hat Enterprise Linux 5.1 host (dom0), the "noapic" parameter should be added to the kernel boot line in your virtual guest's /boot/grub/grub.conf entry as seen below. Keep in mind your architecture and kernel version may be different.
kernel /vmlinuz-2.6.9-67.EL ro root=/dev/VolGroup00/rhel4_x86_64 rhgb noapic
Red Hat Enterprise Linux 5.2 dom0 的​客​座​端​將​不​會​需​要​此​ kernel 參​數​。​
現​在​請​驗​證​您​所​建​立​的​分​割​區​是​否​可​用​。​
[root@rhel4]# cat /proc/partitions
major    minor   #blocks   name

   3        0    10485760  hda
   3        1      104391  hda1
   3        2    10377990  hda2
 202        0       64000  xvdb
 202        1       32000  xvdb1
 202        2       32000  xvdb2
 253        0     8257536  dm-0
 253        1     2031616  dm-1
在​以​上​輸​出​中​,您​可​看​見​被​分​割​的​裝​置​「​xvdb」​可​用​於​系​統​。​
以​下​程​序​會​新​增​裝​置​至​客​座​端​,並​使​裝​置​在​重​新​開​機​後​仍​然​存​在​。​所​有​指​令​都​在​客​座​端​上​面​執​行​。​
  1. 建​立​目​錄​,以​掛​載​區​塊​裝​置​映​像​檔​。​
    [root@rhel4]# mkdir /mnt/pvdisk_p1
    [root@rhel4]# mkdir /mnt/pvdisk_p2
    
  2. 將​裝​置​掛​載​到​新​目​錄​上​。​
    [root@rhel4]# mount /dev/xvdb1 /mnt/pvdisk_p1
    [root@rhel4]# mount /dev/xvdb2 /mnt/pvdisk_p2
    
  3. 驗​證​裝​置​是​否​掛​載​成​功​。​
    [root@rhel4]# df /mnt/pvdisk_p1
    Filesystem           1K-blocks      Used   Available Use%  Mounted on
    /dev/xvdb1               32000        15       31985   1%  /mnt/pvdisk_p1
    
  4. 更​新​客​座​端​的​ /etc/fstab 檔​案​,在​開​機​時​掛​載​這​些​裝​置​。​請​新​增​以​下​幾​行​:
    /dev/xvdb1   /mnt/pvdisk_p1   ext3    defaults        1 2
    /dev/xvdb2   /mnt/pvdisk_p2   ext3    defaults        1 2
    

注​意​

此​套​件​從​ Red Hat Enterprise Linux 4-GA 至​ Red Hat Enterprise Linux 4 update 2 系​統​與​ kernel 皆​不​受​到​支​援​。​

重​點​

IA64 的​二​進​位​ RPM 套​件​和​組​建​目​前​還​無​法​使​用​。​

自​動​載​入​模​組​

xen-vbd 驅​動​程​式​可​能​無​法​自​動​載​入​。​若​是​如​此​,請​在​客​座​端​上​輸​入​下​列​指​令​,將​ %release 更​改​為​半​虛​擬​化​驅​動​程​式​的​正​確​發​行​版​本​。​
# insmod /lib/modules/'uname -r'/weak-updates/xenpv/%release/xen_vbd.ko

12.3.4. Xen Para-virtualized Drivers on Red Hat Enterprise Linux 5

This section contains detailed instructions for the para-virtualized drivers in a Red Hat Enterprise Linux 5 guest operating system.

請​注​意​

這​些​套​件​並​不​支​援​透​過​半​虛​擬​化​磁​碟​來​啟​動​。​啟​動​客​座​端​作​業​系​統​ kernel 依​然​需​要​透​過​使​用​模​擬​的​ IDE 驅​動​程​式​,任​何​其​它​的​(非​系​統​)用​戶​空​間​應​用​程​式​和​資​料​則​皆​可​使​用​半​虛​擬​化​的​區​塊​裝​置​驅​動​程​式​。​
The procedure below covers the steps to enable the para-virtualized drivers for a Red Hat Enterprise Linux 5 guest.
過程 12.1. Enable para-virtualized drivers for a Red Hat Enterprise Linux Guest
  1. 關​閉​虛​擬​機​器​(請​在​客​座​端​中​使​用​「​#shutdown -h now」​)。​
  2. 請​透​過​下​列​方​式​來​編​輯​ /etc/xen/<Your GuestsName> 中​的​客​座​端​配​置​檔​案​:
    1. 將​「​type=ioemu」​項​目​由​「​vif=」​項​目​中​移​除​。​
    2. 將​任​何​額​外​的​磁​碟​分​割​、​卷​冊​或​ LUN 新​增​至​客​座​端​,這​樣​它​們​才​可​被​透​過​半​虛​擬​化​(xen-vbd)的​磁​碟​驅​動​程​式​來​存​取​。​
    3. 請​為​各​個​額​外​的​實​體​裝​置​、​LUN、​分​割​區​或​卷​冊​新​增​一​個​類​似​下​列​的​項​目​,請​將​這​些​項​目​新​增​至​客​座​端​配​置​檔​案​中​的​「​disk=」​部​份​。​原​本​的​「​disk=」​項​目​也​有​可​能​看​似​下​列​項​目​。​
      disk = [ "file:/var/lib/libvirt/images/rhel4_64_fv.dsk,hda,w"]
      
    4. 一​旦​您​新​增​了​額​外​實​體​裝​置​、​LUN、​分​割​區​或​卷​冊​之​後​,您​ XML 配​置​檔​案​中​的​半​虛​擬​驅​動​程​式​項​目​應​會​和​下​列​所​顯​示​的​項​目​相​似​。​
      disk = [ "file:/var/lib/libvirt/images/rhel3_64_fv.dsk,hda,w",
      "tap:aio:/var/lib/libvirt/images/UserStorage.dsk,xvda,w" ]
      

      請​注​意​

      若​使​用​了​基​於​檔​案​的​映​像​檔​,請​將​「​tap:aio」​使​用​於​半​虛​擬​化​的​裝​置​。​
  3. 請​透​過​使​用​ virsh 指​令​來​啟​動​虛​擬​機​器​:
    # virsh start YourGuestName
    
若​要​驗​證​網​路​介​面​卡​在​安​裝​了​半​虛​擬​化​驅​動​程​式​後​是​否​被​啟​用​,請​在​客​座​端​上​輸​入​下​列​指​令​。​它​應​顯​示​介​面​卡​資​訊​,包​括​一​組​分​配​的​ IP 位​址​。​
[root@rhel5]# ifconfig eth0
現​在​請​驗​證​您​所​建​立​的​分​割​區​是​否​可​用​。​
[root@rhel5]# cat /proc/partitions
major minor  #blocks    name
   3     0   10485760   hda
   3     1     104391   hda1
   3     2   10377990   hda2
 202     0      64000   xvdb
 202     1      32000   xvdb1
 202     2      32000   xvdb2
 253     0    8257536   dm-0
 253     1    2031616   dm-1
在​以​上​輸​出​中​,您​可​看​見​被​分​割​的​裝​置​「​xvdb」​可​用​於​系​統​。​
以​下​程​序​會​新​增​裝​置​至​客​座​端​,並​使​裝​置​在​重​新​開​機​後​仍​然​存​在​。​所​有​指​令​都​在​客​座​端​上​面​執​行​。​
  1. 建​立​目​錄​,以​掛​載​區​塊​裝​置​映​像​檔​。​
    [root@rhel5]# mkdir /mnt/pvdisk_p1
    [root@rhel5]# mkdir /mnt/pvdisk_p2
    
  2. 將​裝​置​掛​載​到​新​目​錄​上​。​
    [root@rhel5]# mount /dev/xvdb1 /mnt/pvdisk_p1
    [root@rhel5]# mount /dev/xvdb2 /mnt/pvdisk_p2
    
  3. 驗​證​裝​置​是​否​掛​載​成​功​。​
    [root@rhel5]# df /mnt/pvdisk_p1
    Filesystem           1K-blocks      Used   Available Use%  Mounted on
    /dev/xvdb1               32000        15       31985   1%  /mnt/pvdisk_p1
    
  4. 更​新​客​座​端​的​ /etc/fstab 檔​案​,在​開​機​時​掛​載​這​些​裝​置​。​請​新​增​以​下​幾​行​:
    /dev/xvdb1   /mnt/pvdisk_p1   ext3    defaults        1 2
    /dev/xvdb2   /mnt/pvdisk_p2   ext3    defaults        1 2
    

效​能​提​示​

Using a Red Hat Enterprise Linux 5.1 host (dom0), the "noapic" parameter should be added to the kernel boot line in your virtual guest's /boot/grub/grub.conf entry as seen below. Keep in mind your architecture and kernel version may be different.
kernel /vmlinuz-2.6.9-67.EL ro root=/dev/VolGroup00/rhel4_x86_64 rhgb noapic
Red Hat Enterprise Linux 5.2 dom0 的​客​座​端​將​不​會​需​要​此​ kernel 參​數​。​
Hiding fake interfaces
Sometimes, activating the para-virtualized drivers does not delete the old virtualized network interfaces. To remove these interfaces from guests use the following procedure.
  1. Add the following lines to the /etc/modprobe.d/blacklist file. Blacklist 8139cp and 8139too for the RealTek 8139 and e1000 for the virtualized Intel e1000 NIC.
    8139cp
    8139too
    e1000
    
  2. Remove the old network scripts from the /etc/sysconfig/network-scripts directory.
  3. Reboot the guest. The default network interface should now use the para-virtualized drivers.

12.3.5. Xen Para-virtualized Drivers on Red Hat Enterprise Linux 6

This section describes the use of para-virtualized drivers in a Red Hat Enterprise Linux 6 guest.
The para-virtualized drivers are enabled by default for a Red Hat Enterprise Linux 6 guest. The guest will automatically unplug any emulated devices that are presented to it, and will use the para-virtualized drivers instead.
Although the para-virtualized drivers are enabled by default, they can be disabled. Add the following to the guest kernel command line upon boot to disable the para-virtualized drivers:
xen_emul_unplug=never

12.4. 半​虛​擬​化​的​網​路​驅​動​程​式​設​定​

Once the para-virtualized network driver is loaded you may need to reconfigure the guest's network interface to reflect the driver and virtual Ethernet card change.
請​執​行​下​列​步​驟​來​重​新​配​置​客​座​端​中​的​網​路​介​面​卡​。​
  1. 請​在​ virt-manager 中​開​啟​客​座​端​的​主​控​台​視​窗​並​以​ root 身​份​登​入​。​
  2. 若​在​ Red Hat Enterprise Linux 4 上​,請​驗​證​ /etc/modprobe.conf 中​是​否​含​有​「​alias eth0 xen-vnif」​這​一​行​。​
    # cat /etc/modprobe.conf
    alias eth0 xen-vnif
    
  3. To display the present settings for eth0 execute “​# ifconfig eth0”​. If you receive an error about the device not existing you should load the modules manually as outlined in 節 36.4, “手​動​式​地​載​入​半​虛​擬​化​驅​動​程​式​”.
    ifconfig eth0
    eth0      Link encap:Ethernet  HWaddr 00:00:00:6A:27:3A  
              BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:630150 errors:0 dropped:0 overruns:0 frame:0
              TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:109336431 (104.2 MiB)  TX bytes:846 (846.0 b)
    
  4. Start the network configuration utility(NetworkManager) with the command “​# system-config-network”​. Click on the “​Forward”​ button to start the network card configuration.
  5. Select the 'Xen Virtual Ethernet Card (eth0)' entry and click 'Forward'.
    Configure the network settings as required.
  6. Complete the configuration by pressing the 'Apply' button.
  7. Press the 'Activate' button to apply the new settings and restart the network.
  8. 您​現​在​應​該​會​看​見​一​張​新​的​網​路​介​面​卡​,並​且​該​介​面​卡​已​被​設​置​了​一​組​ IP 位​址​。​
    ifconfig eth0
    eth0      Link encap:Ethernet  HWaddr 00:16:3E:49:E4:E0
              inet addr:192.168.78.180  Bcast:192.168.79.255  Mask:255.255.252.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:630150 errors:0 dropped:0 overruns:0 frame:0
              TX packets:501209 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:109336431 (104.2 MiB)  TX bytes:46265452 (44.1 MiB)
    

12.5. 額​外​的​半​虛​擬​化​硬​體​設​定​

此​部​份​將​解​釋​如​何​新​增​額​外​的​虛​擬​網​路​或​儲​存​裝​置​至​一​個​客​座​端​作​業​系​統​上​。​如​欲​取​得​更​多​有​關​於​設​定​ Red Hat Enterprise Linux 5 虛​擬​化​產​品​的​網​路​和​儲​存​資​源​的​相​關​資​訊​,請​參​閱​ Red Hat 新​興​科​技​上​的​文​件​。​

12.5.1. 虛​擬​網​路​介​面​卡​

請​執​行​下​列​步​驟​來​為​您​的​客​座​端​設​定​額​外​的​網​路​裝​置​。​
請​編​輯​您​ /etc/xen/YourGuestName 中​的​客​座​端​配​置​檔​案​並​將​ YourGuestName 替​換​為​您​客​座​端​的​名​稱​。​
原​本​的​項​目​看​起​來​像​:
vif = [ "mac=00:16:3e:2e:c5:a9,bridge=xenbr0" ]
請​如​下​新​增​一​個​額​外​項​目​至​配​置​檔​案​的​「​vif=」​部​份​中​。​
vif = [ "mac=00:16:3e:2e:c5:a9,bridge=xenbr0",
    "mac=00:16:3e:2f:d5:a9,bridge=xenbr0" ]
請​確​認​您​為​新​的​介​面​卡​產​生​了​一​個​獨​特​的​ MAC 位​址​。​您​可​使​用​下​列​指​令​。​
# echo 'import virtinst.util ; print virtinst.util.randomMAC()' | python
當​客​座​端​被​重​新​啟​動​後​,請​在​客​座​端​作​業​系​統​中​執​行​下​列​步​驟​。​請​確​認​更​新​已​被​新​增​至​您​ Red Hat Enterprise Linux 3 的​ /etc/modules.conf,或​是​ Red Hat Enterprise Linux 4 與​ Red Hat Enterprise Linux 5 的​ /etc/modprobe.conf 中​。​請​為​您​所​新​增​的​各​個​新​介​面​卡​加​上​一​個​新​的​別​名​。​
alias eth1 xen-vnif
現​在​請​測​試​新​增​的​介​面​卡​,並​確​認​它​們​可​用​於​客​座​端​中​。​
# ifconfig eth1
以​上​指​令​會​顯​示​ eth1 的​屬​性​,若​您​新​增​了​第​三​個​介​面​卡​請​對​ eth2 重​複​這​項​指​令​,餘​此​類​推​。​
現​在​請​透​過​在​ Red Hat Enterprise Linux 3 上​使​用​ redhat-config-network,或​在​ Red Hat Enterprise Linux 4 和​ Red Hat Enterprise Linux 5 上​使​用​ system-config-network 來​配​置​新​的​網​路​介​面​卡​。​

12.5.2. 虛​擬​儲​存​裝​置​

請​執​行​下​列​步​驟​來​為​您​的​客​座​端​配​置​額​外​的​虛​擬​儲​存​裝​置​。​
請​編​輯​您​ /etc/xen/YourGuestName 中​的​客​座​端​配​置​檔​案​,並​將​ YourGuestName 替​換​為​您​客​座​端​的​名​稱​。​原​本​的​項​目​會​看​似​下​列​範​例​。​
disk = [ "file:/var/lib/libvirt/images/rhel5_64_fv.dsk,hda,w"]
現​在​,請​為​您​新​的​實​體​裝​置​、​LUN、​分​割​區​或​是​卷​冊​新​增​一​個​額​外​的​項​目​至​配​置​檔​案​的​「​disk=」​參​數​中​。​使​用​半​虛​擬​化​驅​動​程​式​的​儲​存​實​體​會​看​似​以​下​項​目​。​「​tap:aio」​這​個​參​數​會​指​示​ hypervisor 使​用​半​虛​擬​化​的​驅​動​程​式​。​
disk = [ "file:/var/lib/libvirt/images/rhel5_64_fv.dsk,hda,w",
    "tap:aio:/var/lib/libvirt/images/UserStorage1.dsk,xvda,w" ]
若​您​希​望​新​增​更​多​項​目​,請​將​它​們​新​增​至​「​disk=」​部​份​為​逗​號​區​隔​的​清​單​。​

注​意​

You need to increment the letter for the 'xvd' device, that is for your second storage entity it would be 'xvdb' instead of 'xvda'.
disk = [ "file:/var/lib/libvirt/images/rhel5_64_fv.dsk,hda,w",
    "tap:aio:/var/lib/libvirt/images/UserStorage1.dsk,xvda,w",
    "tap:aio:/var/lib/libvirt/images/UserStorage2.dsk,xvdb,w" ]
請​驗​證​分​割​區​是​否​已​被​建​立​並​且​可​用​。​
# cat /proc/partitions
major minor  #blocks    name
   3     0   10485760   hda
   3     1     104391   hda1
   3     2   10377990   hda2
 202     0      64000   xvda
 202     1      64000   xvdb
 253     0    8257536   dm-0
 253     1    2031616   dm-1
在​以​上​輸​出​中​,您​可​看​見​系​統​可​使​用​分​割​區​或​「​xvdb」​裝​置​。​
請​將​新​的​裝​置​和​磁​碟​掛​載​至​本​機​掛​載​點​,並​更​新​客​座​端​中​的​ /etc/fstab,以​便​在​啟​動​時​掛​載​裝​置​和​分​割​區​。​
# mkdir /mnt/pvdisk_xvda
# mkdir /mnt/pvdisk_xvdb
# mount /dev/xvda /mnt/pvdisk_xvda
# mount /dev/xvdb /mnt/pvdisk_xvdb
# df /mnt
Filesystem           1K-blocks      Used   Available Use%  Mounted on
/dev/xvda                64000        15       63985   1%  /mnt/pvdisk_xvda
/dev/xvdb                64000        15       63985   1%  /mnt/pvdisk_xvdb

章 13. KVM 半​虛​擬​化​驅​動​程​式​

Para-virtualized drivers are available for virtualized Windows guests running on KVM hosts. These para-virtualized drivers are included in the virtio-win package. The virtio-win package supports block (storage) devices and network interface controllers.
As with the KVM module, the virtio-win drivers package is only available on hosts running Red Hat Enterprise Linux 5.4 and newer.
半​虛​擬​化​驅​動​程​式​可​提​昇​完​整​虛​擬​化​客​座​端​的​效​能​。​當​使​用​半​虛​擬​化​驅​動​程​式​時​,客​座​端​ I/O 延​遲​時​間​會​減​少​,並​且​總​處​理​能​力​會​提​昇​至​與​空​機​等​級​相​近​的​效​能​。​我​們​建​議​當​完​整​虛​擬​化​客​座​端​執​行​大​量​ I/O 的​工​作​和​應​用​程​式​時​,使​用​半​虛​擬​化​驅​動​程​式​。​
The KVM para-virtualized drivers are automatically loaded and installed on the following versions of Red Hat Enterprise Linux:
  • Red Hat Enterprise Linux 4.8 and newer
  • Red Hat Enterprise Linux 5.3 and newer
  • Red Hat Enterprise Linux 6.
Those Red Hat Enterprise Linux versions detect and install the drivers so additional installation steps are not required.

注​意​

PCI devices are limited by the virtualized system architecture. Out of the 32 available PCI devices for a guest 4 are not removable. This means there are up to 28 PCI slots available for additional devices per guest. Each PCI device can have up to 8 functions; some PCI devices have multiple functions and only use one slot. Para-virtualized network, para-virtualized disk devices, or other PCI devices using VT-d all use slots or functions. The exact number of devices available is difficult to calculate due to the number of available devices. Each guest can use up to 32 PCI devices with each device having up to 8 functions.
下​列​ Microsoft Windows 版​本​支​援​了​ KVM 半​虛​擬​化​驅​動​程​式​:
  • Windows XP (32-bit only)
  • Windows Server 2003 (32-bit and 64-bit versions)
  • Windows Server 2008 (32-bit and 64-bit versions)
  • Windows 7 (32-bit and 64-bit versions)

13.1. 安​裝​ KVM Windows 半​虛​擬​化​驅​動​程​式​

此​部​份​涵​蓋​了​ KVM Windows 半​虛​擬​化​驅​動​程​式​的​安​裝​程​序​。​KVM 半​虛​擬​化​驅​動​程​式​能​在​ Windows 安​裝​程​序​進​行​時​載​入​,或​在​客​座​端​安​裝​完​成​後​進​行​安​裝​。​
You can install the para-virtualized drivers on your guest by one of the following methods:
  • hosting the installation files on a network accessible to the guest,
  • using a virtualized CD-ROM device of the driver installation disk .iso file, or
  • using a virtualized floppy device to install the drivers during boot time (for Windows guests).
This guide describes installation from the para-virtualized installer disk as a virtualized CD-ROM device.
  1. 下​載​驅​動​程​式​

    The virtio-win package contains the para-virtualized block and network drivers for all supported Windows guests.
    If the Red Hat Enterprise Linux Supplementary channel entitlements are not enabled for the system, the download will not be available. Enable the Red Hat Enterprise Linux Supplementary channel to access the virtio-win package.
    Download the virtio-win package with the yum command.
    # yum install virtio-win
    
    The drivers are also available on the Red Hat Enterprise Linux Supplementary disc or from Microsoft (windowsservercatalog.com). Note that the Red Hat Enterprise Virtualization Hypervisor and Red Hat Enterprise Linux are created on the same code base so the drivers for the same version (for example, 5.5) are supported for both environments.
    virtio-win 套​件​會​在​ /usr/share/virtio-win/ 目​錄​中​安​裝​一​個​光​碟​映​像​檔​ virtio-win.iso。​
  2. 安​裝​半​虛​擬​化​驅​動​程​式​

    我​們​建​議​您​在​附​加​或​修​改​某​個​裝​置​,以​使​用​半​虛​擬​化​驅​動​程​式​前​,先​在​客​座​端​上​安​裝​驅​動​程​式​。​
    對​於​儲​存​區​塊​裝​置​的​ root 檔​案​系​統​、​或​是​其​它​啟​動​客​座​端​所​需​的​區​塊​裝​置​來​說​,在​修​改​裝​置​之​前​必​須​先​安​裝​驅​動​程​式​。​若​驅​動​程​式​未​安​裝​在​客​座​端​上​並​且​驅​動​程​式​被​設​為​ virtio 驅​動​程​式​的​話​,客​座​端​將​無​法​啟​動​。​
Installing drivers with a virtualized CD-ROM
This procedure covers installing the para-virtualized drivers with a virtualized CD-ROM after Windows is installed.
過程 13.1. 若​是​ Windows 客​座​端​的​話​請​使​用​ virt-manager 來​掛​載​光​碟​映​像​檔​。​
  1. Open virt-manager and the virtualized guest

    Open virt-manager, select your virtualized guest from the list by double clicking the guest name.
  2. Open the hardware tab

    Click the Add Hardware button in the Hardware tab.
  3. Select the device type

    This opens a wizard for adding the new device. Select Storage from the dropdown menu.
    Click the Forward button to proceed.
  4. Select the ISO file

    Choose the File (disk image) option and set the file location of the para-virtualized drivers .iso image file. The location file is named /usr/share/virtio-win/virtio-win.iso.
    若​驅​動​程​式​儲​存​在​實​體​光​碟​上​的​話​,請​使​用​「​正​常​磁​碟​分​割​」​選​項​。​
    Set the Device type to IDE cdrom and click Forward to proceed.
  5. Disc assigned

    The disk has been assigned and is available for the guest once the guest is started. Click Finish to close the wizard or back if you made a mistake.
  6. Reboot

    Reboot or start the guest to add the new device. Virtualized IDE devices require a restart before they can be recognized by guests.
Once the CD-ROM with the drivers is attached and the guest has started, proceed with 過程 13.2, “Windows installation”.
過程 13.2. Windows installation
  1. Open My Computer

    On the Windows guest, open My Computer and select the CD-ROM drive.
  2. Select the correct installation files

    There are four files available on the disc. Select the drivers you require for your guest's architecture:
    • the para-virtualized block device driver (RHEV-Block.msi for 32-bit guests or RHEV-Block64.msi for 64-bit guests),
    • the para-virtualized network device driver (RHEV-Network.msi for 32-bit guests or RHEV-Block64.msi for 64-bit guests),
    • or both the block and network device drivers.
    Double click the installation files to install the drivers.
  3. Install the block device driver

    1. Start the block device driver installation

      Double click RHEV-Block.msi or RHEV-Block64.msi.
      Press Next to continue.
    2. Confirm the exception

      Windows may prompt for a security exception.
      Press Yes if it is correct.
    3. Finish

      Press Finish to complete the installation.
  4. Install the network device driver

    1. Start the network device driver installation

      Double click RHEV-Network.msi or RHEV-Network64.msi.
      Press Next to continue.
    2. Performance setting

      This screen configures advanced TCP settings for the network driver. TCP timestamps and TCP window scaling can be enabled or disabled. The default is, 1, for window scaling to be enabled.
      TCP window scaling is covered by IETF RFC 1323. The RFC defines a method of increasing the receive window size to a size greater than the default maximum of 65,535 bytes up to a new maximum of 1 gigabyte (1,073,741,824 bytes). TCP window scaling allows networks to transfer at closer to theoretical network bandwidth limits. Larger receive windows may not be supported by some networking hardware or operating systems.
      TCP timestamps are also defined by IETF RFC 1323. TCP timestamps are used to better calculate Return Travel Time estimates by embedding timing information is embedded in packets. TCP timestamps help the system to adapt to changing traffic levels and avoid congestion issues on busy networks.
      ValueAction
      0Disable TCP timestamps and window scaling.
      1Enable TCP window scaling.
      2Enable TCP timestamps.
      3Enable TCP timestamps and window scaling.
      Press Next to continue.
    3. Confirm the exception

      Windows may prompt for a security exception.
      Press Yes if it is correct.
    4. Finish

      Press Finish to complete the installation.
  5. Reboot

    Reboot the guest to complete the driver installation.

13.2. Installing drivers with a virtualized floppy disk

這​項​程​序​涵​蓋​了​如​何​在​進​行​ Windows 安​裝​程​序​時​,安​裝​半​虛​擬​化​驅​動​程​式​。​
  • 在​第​一​次​安​裝​ Windows VM 時​,請​使​用​ run-once(單​次​執​行​)選​單​來​將​ viostor.vfd 附​加​為​一​片​磁​碟​片​。​
    1. Windows Server 2003

      當​ windows 提​示​您​按​下​ F6 來​選​擇​第​三​方​驅​動​程​式​時​,請​按​下​ F6,並​依​照​畫​面​上​的​步​驟​進​行​。​
    2. Windows Server 2008

      當​安​裝​程​式​提​示​您​選​擇​驅​動​程​式​時​,請​點​選​「​載​入​驅​動​程​式​」​,將​安​裝​程​式​指​向​ A: 並​選​取​適​合​您​客​座​端​作​業​系​統​與​架​構​的​驅​動​程​式​。​

13.3. 將​ KVM 半​虛​擬​化​驅​動​程​式​使​用​於​現​有​的​裝​置​上​

Modify an existing hard disk device attached to the guest to use the virtio driver instead of virtualized IDE driver. This example edits libvirt configuration files. Alternatively, virt-manager, virsh attach-disk or virsh attach-interface can add a new device using the para-virtualized drivers 節 13.4, “使​用​ KVM 半​虛​擬​化​驅​動​程​式​於​新​裝​置​上​”.
  1. 以​下​為​一​個​使​用​了​虛​擬​化​ IDE 驅​動​程​式​、​基​於​檔​案​的​區​塊​裝​置​。​這​是​個​不​使​用​半​虛​擬​化​驅​動​程​式​的​虛​擬​化​客​座​端​的​典​型​項​目​。​
    <disk type='file' device='disk'>
       <source file='/var/lib/libvirt/images/disk1.img'/>
       <target dev='vda' bus='ide'/>
    </disk>
    
  2. 藉​由​將​ bus= 項​目​更​改​為​ virtio 來​使​用​半​虛​擬​化​裝​置​。​
    <disk type='file' device='disk'>
       <source file='/var/lib/libvirt/images/disk1.img'/>
       <target dev='vda' bus='virtio'/>
    </disk>
    

13.4. 使​用​ KVM 半​虛​擬​化​驅​動​程​式​於​新​裝​置​上​

本​程​序​涵​蓋​了​如​何​搭​配​使​用​ KVM 半​虛​擬​化​驅​動​程​式​與​ virt-manager 來​新​建​裝​置​。​
此​外​,virsh attach-disk 或​ virsh attach-interface 指​令​皆​可​被​使​用​來​連​接​使​用​了​半​虛​擬​化​驅​動​程​式​的​裝​置​。​

首​先​安​裝​驅​動​程​式​

在​繼​續​進​行​新​裝​置​的​安​裝​前​,請​先​確​認​驅​動​程​式​已​安​裝​在​ Windows 客​座​端​上​。​若​沒​有​驅​動​程​式​的​話​,裝​置​便​無​法​被​辨​識​並​且​將​無​法​運​作​。​
  1. 請​透​過​點​選​ virt-manager 中​的​客​座​端​名​稱​,來​開​虛​擬​化​客​座​端​。​
  2. 開​啟​「​硬​體​」​分​頁​。​
  3. 按​下​「​新​增​硬​體​」​按​鈕​。​
  4. 請​在​「​新​增​虛​擬​硬​體​」​分​頁​中​,點​選​「​儲​存​裝​置​」​或​「​網​路​」​來​作​為​裝​置​類​型​。​
    1. New disk devices
      請​選​擇​儲​存​裝​置​或​基​於​檔​案​的​映​像​檔​。​請​選​擇​「​Virtio 磁​碟​」​來​作​為​「​裝​置​類​型​」​並​按​下​「​下​一​步​」​。​
    2. New network devices
      請​選​擇​「​虛​擬​網​路​」​或​「​共​享​實​體​裝​置​」​。​請​選​擇​「​virtio」​來​作​為​「​裝​置​類​型​」​並​按​下​「​下​一​步​」​。​
  5. 請​按​下​「​完​成​」​來​儲​存​裝​置​。​
  6. 請​重​新​啟​動​客​座​端​。​裝​置​可​能​要​在​ Windows 客​座​端​重​新​啟​動​後​才​能​被​辨​識​。​

章 14. PCI 的​通​透​性​

本​章​描​述​如​何​在​ Xen 與​ KVM hypervisor 中​,使​用​ PCI 通​透​功​能​(PCI passthrough)。​
KVM and Xen hypervisors support attaching PCI devices on the host system to virtualized guests. PCI passthrough allows guests to have exclusive access to PCI devices for a range of tasks. PCI passthrough allows PCI devices to appear and behave as if they were physically attached to the guest operating system.
PCI devices are limited by the virtualized system architecture. Out of the 32 available PCI devices for a guest 4 are not removable. This means there are up to 28 PCI slots available for additional devices per guest. Each PCI device can have up to 8 functions; some PCI devices have multiple functions and only use one slot. Para-virtualized network, para-virtualized disk devices, or other PCI devices using VT-d all use slots or functions. The exact number of devices available is difficult to calculate due to the number of available devices. Each guest can use up to 32 PCI devices with each device having up to 8 functions.
The VT-d or AMD IOMMU extensions must be enabled in BIOS.
過程 14.1. Preparing an Intel system for PCI passthrough
  1. Enable the Intel VT-d extensions

    The Intel VT-d extensions provides hardware support for directly assigning a physical devices to guest. The main benefit of the feature is to improve the performance as native for device access.
    The VT-d extensions are required for PCI passthrough with Red Hat Enterprise Linux. The extensions must be enabled in the BIOS. Some system manufacturers disable these extensions by default.
    These extensions are often called various terms in BIOS which differ from manufacturer to manufacturer. Consult your system manufacturer's documentation.
  2. Activate Intel VT-d in the kernel

    Activate Intel VT-d in the kernel by appending the intel_iommu=on parameter to the kernel line of the kernel line in the /boot/grub/grub.conf file.
    The example below is a modified grub.conf file with Intel VT-d activated.
    default=0
    timeout=5
    splashimage=(hd0,0)/grub/splash.xpm.gz
    hiddenmenu
    title Red Hat Enterprise Linux Server (2.6.18-190.el5)
       root (hd0,0)
       kernel /vmlinuz-2.6.18-190.el5 ro root=/dev/VolGroup00/LogVol00 intel_iommu=on
       initrd /initrd-2.6.18-190.el5.img
  3. Ready to use

    Reboot the system to enable the changes. Your system is now PCI passthrough capable.
過程 14.2. Preparing an AMD system for PCI passthrough
  • Enable AMD IOMMU extensions

    The AMD IOMMU extensions are required for PCI passthrough with Red Hat Enterprise Linux. The extensions must be enabled in the BIOS. Some system manufacturers disable these extensions by default.
AMD systems only require that the IOMMU is enabled in the BIOS. The system is ready for PCI passthrough once the IOMMU is enabled.

PCI passthrough with Xen

Xen and KVM require different kernel arguments to enable PCI passthrough. The previous instructions are for KVM. For both AMD and Intel systems, PCI passthrough on Xen requires the iommu=on parameter to the hypervisor command line. Modify the /boot/grub/grub.conf file as follows to enable PCI passthrough:
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.18-192.el5)
   root (hd0,0)
   kernel /xen.gz-2.6.18-192.el5 iommu=on
   module /vmlinuz-2.6.18-192.el5xen ro root=/dev/VolGroup00/LogVol00 
   module /initrd-2.6.18-190.el5xen.img

14.1. Adding a PCI device with virsh

These steps cover adding a PCI device to a fully virtualized guest under the Xen or KVM hypervisors using hardware-assisted PCI passthrough. Refer to 節 14.4, “PCI passthrough for para-virtualized Xen guests on Red Hat Enterprise Linux” for details on adding a PCI device to a para-virtualized Xen guest.

重要

The VT-d or AMD IOMMU extensions must be enabled in BIOS.
This example uses a USB controller device with the PCI identifier code, pci_8086_3a6c, and a fully virtualized guest named win2k3.
  1. Identify the device

    Identify the PCI device designated for passthrough to the guest. The virsh nodedev-list command lists all devices attached to the system. The --tree option is useful for identifying devices attached to the PCI device (for example, disk controllers and USB controllers).
    # virsh nodedev-list --tree
    For a list of only PCI devices, run the following command:
    # virsh nodedev-list | grep pci
    Each PCI device is identified by a string in the following format (Where **** is a four digit hexadecimal code):
    pci_8086_****
    

    Tip: determining the PCI device

    Comparing lspci output to lspci -n (which turns off name resolution) output can assist in deriving which device has which device identifier code.
    Record the PCI device number; the number is needed in other steps.
  2. Information on the domain, bus and function are available from output of the virsh nodedev-dumpxml command:
    # virsh nodedev-dumpxml pci_8086_3a6c
    <device>
      <name>pci_8086_3a6c</name>
      <parent>computer</parent>
      <capability type='pci'>
        <domain>0</domain>
        <bus>0</bus>
        <slot>26</slot>
        <function>7</function>
        <id='0x3a6c'>82801JD/DO (ICH10 Family) USB2 EHCI Controller #2</product>
        <vendor id='0x8086'>Intel Corporation</vendor>
      </capability>
    </device>
  3. Detach the device from the system. Attached devices cannot be used and may cause various errors if connected to a guest without detaching first.
    # virsh nodedev-dettach pci_8086_3a6c 
    Device pci_8086_3a6c dettached
  4. Convert slot and function values to hexadecimal values (from decimal) to get the PCI bus addresses. Append "0x" to the beginning of the output to tell the computer that the value is a hexadecimal number.
    For example, if bus = 0, slot = 26 and function = 7 run the following:
    $ printf %x 0
    0
    $ printf %x 26
    1a
    $ printf %x 7
    7
    The values to use:
    bus='0x00'
    slot='0x1a'
    function='0x7'
  5. Run virsh edit (or virsh attach device) and add a device entry in the <devices> section to attach the PCI device to the guest. Only run this command on offline guests. Red Hat Enterprise Linux does not support hotplugging PCI devices at this time.
    # virsh edit win2k3
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
          <address domain='0x0000' bus='0x00' slot='0x1a' function='0x7'/>
      </source>
    </hostdev>
  6. Once the guest system is configured to use the PCI address, we need to tell the host system to stop using it. The ehci driver is loaded by default for the USB PCI controller.
    $ readlink /sys/bus/pci/devices/0000\:00\:1d.7/driver
    ../../../bus/pci/drivers/ehci_hcd
  7. Detach the device:
    $ virsh nodedev-dettach pci_8086_3a6c
  8. Verify it is now under the control of pci_stub:
    $ readlink /sys/bus/pci/devices/0000\:00\:1d.7/driver
    ../../../bus/pci/drivers/pci-stub
  9. Set a sebool to allow the management of the PCI device from the guest:
    # setsebool -P virt_use_sysfs 1
  10. Start the guest system :
    # virsh start win2k3
    
The PCI device should now be successfully attached to the guest and accessible to the guest operating system.

14.2. Adding a PCI device with virt-manager

PCI devices can be added to guests using the graphical virt-manager tool. The following procedure adds a 2 port USB controller to a virtualized guest.
  1. Identify the device

    Identify the PCI device designated for passthrough to the guest. The virsh nodedev-list command lists all devices attached to the system. The --tree option is useful for identifying devices attached to the PCI device (for example, disk controllers and USB controllers).
    # virsh nodedev-list --tree
    For a list of only PCI devices, run the following command:
    # virsh nodedev-list | grep pci
    Each PCI device is identified by a string in the following format (Where **** is a four digit hexadecimal code):
    pci_8086_****
    

    Tip: determining the PCI device

    Comparing lspci output to lspci -n (which turns off name resolution) output can assist in deriving which device has which device identifier code.
    Record the PCI device number; the number is needed in other steps.
  2. Detach the PCI device

    Detach the device from the system.
    # virsh nodedev-dettach pci_8086_3a6c 
    Device pci_8086_3a6c dettached
  3. Power off the guest

    Power off the guest. Hotplugging PCI devices into guests is presently unsupported and may fail or crash.
  4. Open the hardware settings

    Open the virtual machine and select the Hardware tab. Click the Add Hardware button to add a new device to the guest.
  5. Add the new device

    Select Physical Host Device from the Hardware type list. The Physical Host Device represents PCI devices. Click Forward to continue.
  6. Select a PCI device

    Select an unused PCI device. Note that selecting PCI devices presently in use on the host causes errors. In this example a PCI to USB interface device is used.
  7. Confirm the new device

    Click the Finish button to confirm the device setup and add the device to the guest.
The setup is complete and the guest can now use the PCI device.

14.3. PCI passthrough with virt-install

To use PCI passthrough with the virt-install parameter, use the additional --host-device parameter.
  1. Identify the PCI device

    Identify the PCI device designated for passthrough to the guest. The virsh nodedev-list command lists all devices attached to the system. The --tree option is useful for identifying devices attached to the PCI device (for example, disk controllers and USB controllers).
    # virsh nodedev-list --tree
    For a list of only PCI devices, run the following command:
    # virsh nodedev-list | grep pci
    Each PCI device is identified by a string in the following format (Where **** is a four digit hexadecimal code):
    pci_8086_****
    

    Tip: determining the PCI device

    Comparing lspci output to lspci -n (which turns off name resolution) output can assist in deriving which device has which device identifier code.
  2. Add the device

    Use the PCI identifier output from the virsh nodedev command as the value for the --host-device parameter.
    # virt-install \
     -n hostdev-test -r 1024 --vcpus 2 \
     --os-variant fedora11 -v --accelerate \
     -l http://download.fedoraproject.org/pub/fedora/linux/development/x86_64/os \
     -x 'console=ttyS0 vnc' --nonetworks --nographics  \
     --disk pool=default,size=8 \
     --debug --host-device=pci_8086_10bd 
    
  3. Complete the installation

    Complete the guest installation. The PCI device should be attached to the guest.

14.4. PCI passthrough for para-virtualized Xen guests on Red Hat Enterprise Linux

PCI passthrough is used to allow a Xen guest exclusive access to a PCI device, rather than sharing with other guests or with dom0. PCI passthrough for para-virtualized Xen guests is supported on all Red Hat Enterprise Linux 5 systems, however PCI passthrough with fully virtualized guests is only supported on Red Hat Enterprise Linux 5.4 and newer.

警告

PCI passthrough to para-virtualized guests is considered insecure and is not supported for Red Hat Enterprise Linux 6 guests.
Limitations of Xen PCI passthrough:
Any guest using PCI passthrough will no longer be available for save, restore, or migration capabilities, as it will be tied to a particular non-virtualized hardware configuration.
A guest which has access to a non-virtualized PCI device via PCI passthrough also has the potential to access the DMA address space of dom0, which is a potential security concern.
To link a PCI device to a guest the device must first be hidden from the host. If the host is using the device the device cannot be assigned to the guest.
過程 14.3. Example: attaching a PCI device
  1. Given a network device which uses the bnx2 driver and has a PCI id of 0000:09:00.0, the following lines added to /etc/modprobe.conf hides the device from dom0. Either the bnx2 module must be reloaded or the host must be restarted.
    install bnx2 /sbin/modprobe pciback; /sbin/modprobe --first-time --ignore-install bnx2
    options pciback hide=(0000:09:00.0)
  2. Multiple PCI identifiers can be added to /etc/modprobe.conf to hide multiple devices.
    options pciback hide=(0000:09:00.0)(0000:0a:04.1)
  3. Use one of the following methods to add the passed-through device to the guest's configuration file:

章 15. SR-IOV

15.1. Introduction

The PCI-SIG (PCI Special Interest Group) developed the Single Root I/O Virtualization (SR-IOV) specification. The PCI-SIG Single Root IOV specification is a standard for a type of PCI passthrough which natively shares a single device to multiple guests. SR-IOV does not require hypervisor involvement in data transfer and management by providing an independent memory space, interrupts, and DMA streams for virtualized guests.
SR-IOV enables a Single Root Function (for example, a single Ethernet port), to appear as multiple, separate, physical devices. A physical device with SR-IOV capabilities can be configured to appear in the PCI configuration space as multiple functions, each device has its own configuration space complete with Base Address Registers (BARs).
SR-IOV uses two new PCI functions:
  • Physical Functions (PFs) are full PCIe devices that include the SR-IOV capabilities. Physical Functions are discovered, managed, and configured as normal PCI devices. Physical Functions configure and manage the SR-IOV functionality by assigning Virtual Functions.
  • Virtual Functions (VFs) are simple PCIe functions that only process I/O. Each Virtual Function is derived from a Physical Function. The number of Virtual Functions a device may have is limited by the device hardware. A single Ethernet port, the Physical Device, may map to many Virtual Functions that can be shared to virtualized guests.
The hypervisor can map one or more Virtual Functions to a virtualized guest. The Virtual Function's configuration space is mapped, by the hypervisor, to the virtualized guest's configuration space.
Each Virtual Function can only be mapped once as Virtual Functions require real hardware. A virtualized guest can have multiple Virtual Functions. A Virtual Function appears as a network card in the same way as a normal network card would appear to an operating system.
The SR-IOV drivers are implemented in the kernel. The core implementation is contained in the PCI subsystem, but there must also be driver support for both the Physical Function (PF) and Virtual Function (VF) devices. With an SR-IOV capable device one can allocate VFs from a PF. The VFs appear as PCI devices which are backed on the physical PCI device by resources (queues, and register sets).
Advantages of SR-IOV
SR-IOV devices can share a single physical port with multiple virtualized guests.
Virtual Functions have near-native performance and provide better performance than para-virtualized drivers and emulated access. Virtual Functions provide data protection between virtualized guests on the same physical server as the data is managed and controlled by the hardware.
These features allow for increased virtualized guest density on hosts within a data center.
Disadvantages of SR-IOV
Live migration is presently unsupported. As with PCI passthrough, identical device configurations are required for live (and offline) migrations. Without identical device configurations, guest's cannot access the passed-through devices after migrating.

15.2. Using SR-IOV

This section covers attaching Virtual Function to a guest as an additional network device.
SR-IOV requires Intel VT-d support.

SR-IOV with Xen

Xen requires additional kernel arguments to use SR-IOV. Modify the /boot/grub/grub.conf file to enable SR-IOV. To enable SR-IOV with Xen for Intel systems append the pci_pt_e820_access=on parameter to the kernel.
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.18-192.el5xen)
   root (hd0,0)
   kernel /xen.gz-2.6.18-192.el5 iommu=1
   module /vmlinuz-2.6.18-192.el5xen ro root=/dev/VolGroup00/LogVol00 pci_pt_e820_access=on
   module /initrd-2.6.18-192.el5xen.img
過程 15.1. Attach an SR-IOV network device
  1. Enable Intel VT-d in BIOS and in the kernel

    Enable Intel VT-D in BIOS. Refer to 過程 14.1, “Preparing an Intel system for PCI passthrough” for more information on enabling Intel VT-d in BIOS and the kernel, or refer to your system manufacturer's documentation for specific instructions.
  2. Verify support

    Verify if the PCI device with SR-IOV capabilities are detected. This example lists an Intel 82576 network interface card which supports SR-IOV. Use the lspci command to verify if the device was detected.
    # lspci
    03:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
    03:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
    

    注意

    Note that the output has been modified to remove all other devices.
  3. Start the SR-IOV kernel modules

    If the device is supported the driver kernel module should be loaded automatically by the kernel. Optional parameters can be passed to the module using the modprobe command. The Intel 82576 network interface card uses the igb driver kernel module.
    # modprobe igb [<option>=<VAL1>,<VAL2>,]
    # lsmod |grep igb
    igb    87592  0
    dca    6708    1 igb
    
  4. Activate Virtual Functions

    The max_vfs parameter of the igb module allocates the maximum number of Virtual Functions. The max_vfs parameter causes the driver to spawn, up to the value of the parameter in, Virtual Functions. For this particular card the valid range is 0 to 7.
    Remove the module to change the variable.
    # modprobe -r igb
    Restart the module with the max_vfs set to 1 or any number of Virtual Functions up to the maximum supported by your device.
    # modprobe igb max_vfs=1
    
  5. Inspect the new Virtual Functions

    Using the lspci command, list the newly added Virtual Functions attached to the Intel 82576 network device.
    # lspci | grep 82576
    03:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
    03:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
    03:10.0 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
    03:10.1 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
    
    The identifier for the PCI device is found with the -n parameter of the lspci command.
    # lspci -n | grep 03:00.0
    03:00.0 0200: 8086:10c9 (rev 01)
    # lspci -n | grep 03:10.0
    03:10.0 0200: 8086:10ca (rev 01)
    
    The Physical Function corresponds to 8086:10c9 and the Virtual Function to 8086:10ca.
  6. Find the devices with virsh

    The libvirt service must find the device to add a device to a guest. Use the virsh nodedev-list command to list available host devices.
    # virsh nodedev-list | grep 8086
    pci_8086_10c9
    pci_8086_10c9_0
    pci_8086_10ca
    pci_8086_10ca_0
    [output truncated]
    
    The serial numbers for the Virtual Functions and Physical Functions should be in the list.
  7. Get advanced details

    The pci_8086_10c9 is one of the Physical Functions and pci_8086_10ca_0 is the first corresponding Virtual Function for that Physical Function. Use the virsh nodedev-dumpxml command to get advanced output for both devices.
    # virsh nodedev-dumpxml pci_8086_10ca
    # virsh nodedev-dumpxml pci_8086_10ca_0
    <device>
      <name>pci_8086_10ca_0</name>
      <parent>pci_8086_3408</parent>
      <driver>
        <name>igbvf</name>
      </driver>
      <capability type='pci'>
        <domain>0</domain>
        <bus>3</bus>
        <slot>16</slot>
        <function>1</function>
        <product id='0x10ca'>82576 Virtual Function</product>
        <vendor id='0x8086'>Intel Corporation</vendor>
      </capability>
    </device>
    
    This example adds the Virtual Function pci_8086_10ca_0 to the guest in 步驟 8. Note the bus, slot and function parameters of the Virtual Function, these are required for adding the device.
  8. Add the Virtual Function to the guest

    1. Shut down the guest.
    2. Use the output from the virsh nodedev-dumpxml pci_8086_10ca_0 command to calculate the values for the configuration file. Convert slot and function values to hexadecimal values (from decimal) to get the PCI bus addresses. Append "0x" to the beginning of the output to tell the computer that the value is a hexadecimal number.
      The example device has the following values: bus = 3, slot = 16 and function = 1. Use the printf utility to convert decimal values to hexadecimal values.
      $ printf %x 3
      3
      $ printf %x 16
      10
      $ printf %x 1
      1
      This example would use the following values in the configuration file:
      bus='0x03'
      slot='0x10'
      function='0x01'
    3. Open the XML configuration file with the virsh edit command. This example edits a guest named MyGuest.
      # virsh edit MyGuest
      
    4. The default text editor will open the libvirt configuration file for the guest. Add the new device to the devices section of the XML configuration file.
      <hostdev mode='subsystem' type='pci' managed='yes'>
            <source>
              <address bus='0x03' slot='0x10' function='0x01'/>
            </source>
      </hostdev>
      
    5. Save the configuration.
  9. Restart

    Restart the guest to complete the installation.
    # virsh start MyGuest
    
The guest should start successfully and detect a new network interface card. This new card is the Virtual Function of the SR-IOV device.

15.3. Troubleshooting SR-IOV

This section contains some issues and solutions for problems which may affect SR-IOV.
Error starting the guest
Start the configured vm , an error reported as follows:
# virsh start test
error: Failed to start domain test
error: internal error unable to start guest: char device redirected to
/dev/pts/2
get_real_device: /sys/bus/pci/devices/0000:03:10.0/config: Permission denied
init_assigned_device: Error: Couldn't get real device (03:10.0)!
Failed to initialize assigned device host=03:10.0
This error is often caused by a device which is already assigned to another guest or to the host itself.

章 16. KVM 客​座​端​時​間​管​理​

虛​擬​化​會​造​成​一​些​客​座​端​上​的​計​時​問​題​。​使​用​了​時​間​戳​記​計​數​器​(Time Stamp Counter,TSC)來​作​為​時​鐘​的​客​座​端​客​能​會​遇​上​一​些​計​時​上​的​問​題​,因​為​有​些​ CPU 沒​有​一​致​的​時​間​戳​記​計​數​器​。​客​座​端​在​沒​有​準​確​的​時​間​紀​錄​的​情​況​下​運​作​,可​能​會​嚴​重​影​響​某​些​網​路​應​用​程​式​,因​為​您​的​客​座​端​將​會​以​要​比​實​際​時​間​更​快​或​更​慢​的​速​度​來​運​作​。​
KVM 透​過​為​客​座​端​提​供​了​半​虛​擬​化​時​鐘​來​解​決​了​這​項​問​題​。​此​外​,有​些​客​座​端​在​未​來​版​本​的​作​業​系​統​上​可​能​會​使​用​其​它​的​ x86 時​鐘​來​源​來​作​為​它​們​的​計​時​工​具​。​
目​前​,只​有​ Red Hat Enterprise Linux 5.4 以​及​較​新​的​客​座​端​可​完​整​支​援​半​虛​擬​化​時​鐘​。​
不​準​確​的​時​鐘​和​計​數​器​可​能​會​造​成​客​座​端​的​一​些​問​題​發​生​:
  • 時​鐘​可​能​會​無​法​與​實​際​的​時​間​同​步​,以​致​ session 無​法​驗​證​並​影​響​網​路​。​
  • 時​鐘​較​慢​的​客​座​端​可​能​在​遷​移​時​會​發​生​問​題​。​
這​些​問​題​也​存​在​其​它​虛​擬​化​平​台​上​,因​此​必​須​每​次​測​試​時​間​。​

NTP

網​路​時​間​協​定​(Network Time Protocol,NTP)daemon 應​在​主​機​以​及​客​座​端​上​執​行​。​請​啟​用​ ntpd 服​務​:
# service ntpd start
將​ ntpd 服​務​新​增​至​預​設​的​啟​動​序​列​中​:
# chkconfig ntpd on
使​用​ ntpd 服​務​便​能​有​效​降​低​所​有​時​鐘​偏​移​(clock skew)情​況​下​所​造​成​的​影​響​。​
偵​測​您​的​ CPU 是​否​擁​有​一​致​的​時​間​戳​記​計​數​器​
若​ constant_tsc 旗​標​存​在​的​話​,您​的​ CPU 便​擁​有​一​致​的​時​間​戳​記​計​數​器​。​若​要​檢​查​您​的​ CPU 是​否​擁​有​ constant_tsc 旗​標​,請​執​行​下​列​指​令​:
$ cat /proc/cpuinfo | grep constant_tsc
若​您​得​到​任​何​輸​出​結​果​的​話​,您​的​ CPU 便​擁​有​ constant_tsc。​若​沒​有​得​到​任​何​結​果​的​話​,請​依​照​下​列​步​驟​進​行​。​
設​定​時​間​戳​記​計​數​器​不​一​致​的​主​機​
時​間​戳​記​計​數​器​不​一​致​的​系​統​需​要​經​過​額​外​的​設​定​。​電​源​管​理​功​能​會​影​響​正​確​的​時​間​紀​錄​,並​且​客​座​端​上​必​須​將​它​停​用​,才​可​在​使​用​ KVM 時​正​確​地​紀​錄​時​間​。​

注​意​

這​些​指​南​只​對​應​於​ AMD 修​訂​版​ F cpu。​
若​ CPU 沒​有​ constant_tsc bit 的​話​,請​停​用​所​有​電​源​管​理​功​能​(BZ#513138)。​每​部​系​統​都​有​幾​個​它​用​來​管​理​時​間​的​計​時​器​。​TSC 在​主​機​上​不​穩​定​,這​有​時​是​因​為​ cpufreq 的​變​更​、​deep C 狀​態​(休​眠​狀​態​的​一​種​),或​是​遷​移​至​一​部​含​有​較​快​ TSC 的​主​機​所​造​成​的​。​若​要​預​防​ kernel 使​用​ deep C 狀​態​的​話​,請​將​「​processor.max_cstate=1」​附​加​至​主​機​上​ grub.conf 檔​案​中​的​ kernel 開​機​選​項​:
term Red Hat Enterprise Linux Server (2.6.18-159.el5)
        root (hd0,0)
	kernel /vmlinuz-2.6.18-159.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet processor.max_cstate=1
請​透​過​編​輯​ /etc/sysconfig/cpuspeed 配​置​檔​案​來​停​用​ cpufreq(只​有​在​沒​有​ constant_tsc 的​主​機​上​才​需​要​這​麼​作​)並​將​ MIN_SPEED 和​ MAX_SPEED 更​改​為​最​高​的​速​率​。​有​效​的​限​制​可​在​ /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_frequencies 檔​案​中​找​到​。​
與​ Red Hat Enterprise Linux 客​座​端​搭​配​使​用​半​虛​擬​化​時​鐘​
某​些​特​定​ Red Hat Enterprise Linux 客​座​端​需​要​額​外​的​核​心​參​數​。​這​些​參​數​可​藉​由​將​其​附​加​至​客​座​端​的​ /boot/grub/grub.conf 檔​案​中​的​ /kernel 一​行​尾​端​來​設​定​。​
下​列​表​格​列​出​了​ Red Hat Enterprise Linux 的​版​本​,以​及​沒​有​一​致​時​間​戳​記​計​數​器​的​系​統​所​需​的​參​數​。​
Red Hat Enterprise Linux額​外​的​客​座​端​ kernel 參​數​
含​有​半​虛​擬​化​時​鐘​的​ 5.4 AMD64/Intel 64無​須​額​外​的​參​數​
無​半​虛​擬​化​時​鐘​的​ 5.4 AMD64/Intel 64divider=10 notsc lpj=n
含​有​半​虛​擬​化​時​鐘​的​ 5.4 x86無​須​額​外​的​參​數​
沒​有​半​虛​擬​化​時​鐘​的​ 5.4 x86divider=10 clocksource=acpi_pm lpj=n
5.3 AMD64/Intel 64divider=10 notsc
5.3 x86divider=10 clocksource=acpi_pm
4.8 AMD64/Intel 64notsc divider=10
4.8 x86clock=pmtmr divider=10
3.9 AMD64/Intel 64無​須​額​外​的​參​數​
3.9 x86無​須​額​外​的​參​數​
Using the Real-Time Clock with Windows Server 2003 and Windows XP guests
Windows 同​時​使​用​了​即​時​時​鐘​(Real-Time Clock,RTC)以​及​時​間​戳​計​數​器​(TSC)。​在​ Windows 客​座​端​上​,您​可​使​用​即​時​時​鐘​來​取​代​ TSC 來​作​為​所​有​的​時​間​來​源​,這​將​可​解​決​客​座​端​上​的​時​間​問​題​。​
若​要​啟​用​ PMTIMER clocksource 的​即​時​時​鐘​(PMTIMER 一​般​使​用​ TSC),請​將​下​列​一​行​附​加​至​ Windows 的​開​機​設​定​中​。​Windows 的​開​機​設​定​儲​存​在​ boot.ini 檔​案​中​。​請​將​下​列​一​行​附​加​至​ boot.ini 檔​案​中​:
/use pmtimer
欲​取​得​更​多​有​關​於​ Windows 開​機​設​定​以​及​ pmtimer 選​項​上​的​相​關​資​訊​,請​參​閱​ Windows XP 和​ Windows Server 2003 Boot.ini 檔​案​的​有​效​切​換​選​項​。​
Using the Real-Time Clock with Windows Vista, Windows Server 2008 and Windows 7 guests
Windows 同​時​使​用​了​即​時​時​鐘​(Real-Time Clock,RTC)以​及​時​間​戳​計​數​器​(TSC)。​在​ Windows 客​座​端​上​,您​可​使​用​即​時​時​鐘​來​取​代​ TSC 來​作​為​所​有​的​時​間​來​源​,這​將​可​解​決​客​座​端​上​的​時​間​問​題​。​
The boot.ini file is no longer used from Windows Vista and newer. Windows Vista, Windows Server 2008 and Windows 7 use the Boot Configuration Data Editor (bcdedit.exe) to modify the Windows boot parameters.
This procedure is only required if the guest is having time keeping issues. Time keeping issues may not affect guests on all host systems.
  1. Open the Windows guest.
  2. Open the Accessories menu of the start menu. Right click on the Command Prompt application, select Run as Administrator.
  3. Confirm the security exception, if prompted.
  4. Set the boot manager to use the platform clock. This should instruct Windows to use the PM timer for the primary clock source. The system UUID ({default} in the example below) should be changed if the system UUID is different than the default boot device.
    C:\Windows\system32>bcdedit /set {default} USEPLATFORMCLOCK on
    The operation completed successfully
This fix should improve time keeping for Windows Vista, Windows Server 2008 and Windows 7 guests.

部 IV. 管​理​

章 17. 良​好​的​伺​服​器​使​用​習​慣​

下​列​工​作​和​提​示​可​協​助​您​確​保​您​ Red Hat Enterprise Linux 5 伺​服​器​主​機​(dom0)的​安​全​性​和​可​靠​性​。​
  • 請​將​ SELinux 設​為​強​制​(enforcing)模​式​。​您​可​透​過​執​行​以​下​指​令​來​完​成​此​動​作​。​
    # setenforce 1
    
  • 請​將​任​何​不​必​要​的​服​務​移​除​或​停​用​(例​如​ AutoFS、​NFS、​FTP、​HTTP、​NIS、​telnetd、​sendmail 等​等​)。​
  • 只​在​伺​服​器​上​新​增​最​低​限​度​的​使​用​者​帳​號​,用​於​管​理​伺​服​器​平​台​;並​移​除​不​必​要​的​使​用​者​帳​號​。​
  • 請​避​免​在​您​的​主​機​上​執​行​任​何​非​必​要​的​應​用​程​式​。​在​主​機​上​執​行​應​用​程​式​可​能​會​影​響​虛​擬​機​器​的​效​能​以​及​伺​服​器​的​穩​定​性​。​任​何​會​使​伺​服​器​停​止​運​作​的​應​用​程​式​,也​會​造​成​伺​服​器​上​所​有​虛​擬​機​器​被​停​用​。​
  • 請​為​虛​擬​機​器​和​映​像​檔​使​用​一​個​集​中​的​位​置​。​虛​擬​機​器​映​像​檔​應​儲​存​在​ /var/lib/libvirt/images/ 下​。​若​您​的​虛​擬​機​器​映​像​檔​處​於​一​個​不​同​的​目​錄​中​,請​確​認​您​有​將​該​目​錄​附​加​至​您​的​ SELinux 政​策​中​,並​在​啟​動​安​裝​程​序​之​前​將​它​重​新​標​記​。​
  • 安​裝​來​源​、​安​裝​樹​和​映​像​檔​都​應​儲​存​在​一​個​集​中​的​位​置​上​,這​通​常​會​是​您​ vsftpd 伺​服​器​的​位​置​。​

章 18. 虛​擬​化​的​安​全​性​

當​您​在​企​業​架​構​上​建​置​虛​擬​化​技​術​時​,請​確​認​主​機​不​會​受​到​危​害​。​Xen hypervisor 中​的​主​機​是​個​處​理​系​統​管​理​和​虛​擬​機​器​管​理​的​特​權​網​域​。​假​如​主​機​處​於​不​安​全​的​狀​態​下​,系​統​中​所​有​的​網​域​也​會​相​對​地​變​得​易​受​攻​擊​。​有​很​多​種​方​法​能​夠​提​升​虛​擬​化​的​系​統​安​全​性​。​您​或​您​的​組​織​應​該​建​立​一​份​「​建​置​計​劃​書​」​,這​裡​面​應​包​含​著​作​業​操​作​說​明​書​,並​指​定​您​的​虛​擬​客​座​端​和​主​機​伺​服​器​上​需​要​哪​些​服​務​,以​及​這​些​服​務​所​需​的​支​援​種​類​為​何​。​以​下​列​出​了​一​些​建​立​一​份​建​置​計​劃​書​時​,所​需​注​意​的​潛​在​安​全​性​問​題​:
  • 在​主​機​上​只​執​行​必​要​的​服​務​。​在​主​機​上​執​行​的​程​序​與​服​務​數​量​愈​少​,安​全​性​與​效​能​就​愈​高​。​
  • Enable Security-Enhanced Linux (SELinux) on the hypervisor. Read 節 18.2, “SELinux 和​虛​擬​化​” for more information on using SELinux and virtualization.
  • 請​利​用​防​火​牆​來​限​制​ dom0 的​流​量​。​您​能​夠​以​預​設​的​拒​絕​規​則​來​設​置​一​道​防​火​牆​,避​免​ dom0 受​到​攻​擊​。​限​制​網​路​表​面​的​服​務​其​實​也​是​很​重​要​的​。​
  • 請​不​要​允​許​一​般​使​用​者​存​取​ dom0。​假​如​您​允​許​一​般​使​用​者​存​取​ dom0 的​話​,這​可​能​會​危​及​ dom0 的​安​全​性​而​且​讓​它​變​得​易​遭​受​到​攻​擊​。​請​記​得​,dom0 是​有​特​權​的​,授​權​給​無​特​權​的​帳​號​極​可​能​會​造​成​危​害​並​且​降​低​安​全​性​。​

18.1. Storage security issues

Administrators of virtualized guests can change the partitions the host boots in certain circumstances. To prevent this administrators should follow these recommendations:
The host should not use disk labels to identify file systems in the fstab file, the initrd file or used by the kernel command line. If less privileged users, especially virtualized guests, have write access to whole partitions or LVM volumes.
Guest should not be given write access to whole disks or block devices (for example, /dev/sdb). Use partitions (for example, /dev/sdb1) or LVM volumes.

18.2. SELinux 和​虛​擬​化​

Security Enhanced Linux was developed by the NSA with assistance from the Linux community to provide stronger security for Linux. SELinux limits an attackers abilities and works to prevent many common security exploits such as buffer overflow attacks and privilege escalation. It is because of these benefits that Red Hat recommends all Red Hat Enterprise Linux systems should run with SELinux enabled and in enforcing mode.
SELinux prevents guest images from loading if SELinux is enabled and the images are not correctly labeled. SELinux requires that image files have the virt_image_t label applied to them. The /var/lib/libvirt/images directory has this label applied to it and its contents by default. This does not mean that images must be stored in this directory; images can be stored anywhere, provided they are labeled with virt_image_t.
新​增​基​於​ LVM 的​儲​存​裝​置​,並​啟​用​ SELinux 強​制​模​式​
以​下​部​份​為​一​個​在​啟​用​ SELinux 的​情​況​下​,將​邏​輯​卷​冊​新​增​至​虛​擬​客​座​端​的​範​例​。​這​些​指​示​也​適​用​於​硬​碟​分​割​區​。​
過程 18.1. 在​啟​用​了​ SELinux 的​虛​擬​化​客​座​端​上​建​立​與​掛​載​邏​輯​卷​冊​
  1. 建​立​邏​輯​卷​冊​。​此​範​例​在​名​為​ volumegroup 的​卷​冊​群​組​上​建​立​了​一​個​ 5GB 的​邏​輯​卷​冊​,名​為​ NewVolumeName。​
    # lvcreate -n NewVolumeName -L 5G volumegroup
  2. 請​以​支​援​延​伸​屬​性​的​檔​案​系​統​(例​如​ ext3)來​格​式​化​ NewVolumeName 邏​輯​卷​冊​。​
    # mke2fs -j /dev/volumegroup/NewVolumeName
    
  3. 建​立​新​目​錄​來​掛​載​新​的​邏​輯​卷​冊​。​此​目​錄​能​夠​位​於​您​檔​案​系​統​中​的​任​何​位​置​上​。​建​議​您​不​要​將​它​放​置​在​重​要​的​系​統​目​錄​中​(/etc、​/var、​/sys)或​是​家​目​錄​中​(/home 或​ /root)。​此​範​例​使​用​了​一​個​名​為​ /virtstorage 的​目​錄​。​
    # mkdir /virtstorage
    
  4. 掛​載​邏​輯​卷​冊​。​
    # mount /dev/volumegroup/NewVolumeName /virtstorage
  5. Set the correct SELinux type for a Xen folder.
    semanage fcontext -a -t xen_image_t "/virtstorage(/.*)?"
    
    另​外​,請​為​ KVM 資​料​夾​設​置​正​確​的​ SELinux 類​型​。​
    semanage fcontext -a -t virt_image_t "/virtstorage(/.*)?"
    
    若​使​用​了​目​標​政​策​(目​標​政​策​為​預​設​政​策​)的​話​,這​項​指​令​便​會​附​加​一​行​至​ /etc/selinux/targeted/contexts/files/file_contexts.local 檔​案​中​,這​將​可​保​留​變​更​的​一​致​性​。​附​加​的​一​行​看​似​:
    /virtstorage(/.*)?    system_u:object_r:xen_image_t:s0
    
  6. Label the device node (for example, /dev/volumegroup/NewVolumeName with the correct label:
    # semanage fcontext -a -t xen_image_t /dev/volumegroup/NewVolumeName
    # restorecon /dev/volumegroup/NewVolumeName
    

18.3. SELinux

此​部​份​包​含​了​使​用​ SELinux 建​置​虛​擬​化​環​境​時​,所​需​要​思​考​的​問​題​。​當​您​建​置​系​統​變​更​或​新​增​裝​置​時​,您​必​須​依​照​變​更​來​更​新​您​的​ SElinux 政​策​。​若​要​為​客​座​端​設​定​ LVM 卷​冊​時​,您​必​須​針​對​對​應​的​區​塊​裝​置​與​卷​冊​群​組​來​修​改​ SELinux 的​內​容​。​
# semanage fcontext -a -t xen_image_t -f -b /dev/sda2
# restorecon /dev/sda2
xend_disable_t 這​個​ boolean 參​數​可​被​用​來​在​重​新​啟​動​ daemon 後​將​ xend 設​定​為​自​由​模​式​(unconfined mode)。​建​議​您​不​要​將​目​錄​重​新​標​記​為​您​會​在​其​它​地​方​使​用​到​的​ xen_image_t。​
KVM and SELinux
There are several SELinux booleans which affect KVM. These booleans are listed below for your convenience.
KVM SELinux Booleans
SELinux BooleanDescription
allow_unconfined_qemu_transitionDefault: off. This boolean controls whether KVM guests can be transitioned to unconfined users.
qemu_full_networkDefault: on. This boolean controls full network access to KVM guests.
qemu_use_cifsDefault: on. This boolean controls KVM's access to CIFS or Samba file systems.
qemu_use_commDefault: off. This boolean controls whether KVM can access serial or parallel communications ports.
qemu_use_nfsDefault: on. This boolean controls KVM's access to NFS file systems.
qemu_use_usbDefault: on. This boolean allows KVM to access USB devices.

18.4. Virtualization firewall information

Various ports are used for communication between virtualized guests and management utilities.

Guest network services

Any network service on a virtualized guest must have the applicable ports open on the guest to allow external access. If a network service on a guest is firewalled it will be inaccessible. Always verify the guests network configuration first.
  • ICMP requests must be accepted. ICMP packets are used for network testing. You cannot ping guests if ICMP packets are blocked.
  • Port 22 should be open for SSH access and the initial installation.
  • Ports 80 or 443 (depending on the security settings on the RHEV Manager) are used by the vdsm-reg service to communicate information about the host.
  • Ports 5634 to 6166 are used for guest console access with the SPICE protocol.
  • Port 8002 is used by Xen for live migration.
  • Ports 49152 to 49216 are used for migrations with KVM. Migration may use any port in this range depending on the number of concurrent migrations occurring.
  • Enabling IP forwarding (net.ipv4.ip_forward = 1) is required for virtual bridge devices. Note that installing libvirt enables this variable so it will be enabled when the virtualization packages are installed unless it was manually disabled.

注意

Note that enabling IP forwarding is not required for physical bridge devices. When a guest is connected through a physical bridge, traffic only operates at a level that does not require IP configuration such as IP forwarding.

章 19. 使​用​ xend 來​管​理​客​座​端​

xend 節​點​控​制​ daemon 會​執​行​特​定​與​虛​擬​機​器​相​關​的​系​統​管​理​功​能​。​此​ daemon 可​控​管​虛​擬​化​的​資​源​,而​ xend 則​必​須​被​執​行​以​便​與​虛​擬​機​器​進​行​互​動​。​在​您​啟​用​ xend 之​前​,您​必​須​經​由​修​改​ xend 的​配​置​檔​案​ /etc/xen/xend-config.sxp 來​指​定​作​業​參​數​。​下​列​為​能​在​ xend-config.sxp 配​置​檔​案​中​啟​用​與​停​用​的​參​數​:
表格 19.1. xend 配​置​參​數​
項​目​ 描​述​
(console-limit)
Determines the console server's memory buffer limit and assigns that limit on a per domain basis.
(min-mem)
測​定​預​留​給​ domain0(如​果​輸​入​為​ 0,則​數​值​不​會​改​變​)的​最​小​數​值​(以​ megabyte 為​單​位​)。​
(dom0-cpus)
測​定​ domain0 所​使​用​的​ CPU 數​量​(就​預​設​值​來​講​,至​少​會​有​一​個​ CPU 被​指​定​)。​
(enable-dump)
如​果​啟​用​的​話​,在​發​生​當​機​時​ Xen 會​建​立​傾​印​檔​案​(預​設​為​ 0)。​
(external-migration-tool)
決​定​用​來​處​理​外​部​裝​置​遷​移​的​ script 或​應​用​程​式​。​script 必​須​置​於​ /etc/xen/scripts/external-device-migrate/ 目​錄​中​。​
(logfile)
決​定​日​誌​檔​案​的​位​置​(預​設​為​/var/log/xend.log)。​
(loglevel)
過​濾​記​錄​模​式​的​數​值​:DEBUG、​INFO、​WARNING、​ERROR 或​ CRITICAL(預​設​值​為​ DEBUG)。​
(network-script)
決​定​用​來​啟​用​網​路​環​境​的​ script(該​ script 必​須​置​於​ /etc/xen/scripts/ 目​錄​中​)。​
(xend-http-server)
啟​用​ http 串​流​封​包​管​理​伺​服​器​(預​設​值​為​停​用​)。​
(xend-unix-server)
啟​用​ UNIX domain socket 伺​服​器​(這​伺​服​器​是​通​訊​的​終​點​,用​來​因​應​低​層​級​網​路​連​線​並​接​受​或​拒​絕​進​入​的​連​線​)。​預​設​值​為​啟​用​。​
(xend-relocation-server)
啟​用​重​置​的​伺​服​器​來​跨​主​機​移​植​(預​設​為​停​用​)。​
(xend-unix-path)
決​定​ xend-unix-server 指​令​輸​出​資​料​的​位​置​(預​設​為​ /var/lib/xend/xend-socket
(xend-port)
決​定​ http 管​理​伺​服​器​所​使​用​的​通​訊​埠​(預​設​為​ 8000)。​
(xend-relocation-port)
決​定​重​置​伺​服​器​所​使​用​的​通​訊​埠​(預​設​為​ 8002)。​
(xend-relocation-address)
決​定​允​許​系​統​移​植​的​虛​擬​主​機​位​址​。​預​設​值​為​ xend-address 的​值​。​
(xend-address)
決​定​ domain socket 伺​服​器​所​綁​定​至​的​位​址​。​預​設​值​可​允​許​所​有​的​連​線​。​

在​設​定​這​些​作​業​參​數​後​,您​應​該​確​認​ xend 是​否​能​正​常​運​作​,若​沒​有​的​話​請​將​ daemon 初​始​化​。​您​可​在​指​令​提​示​符​號​下​輸​入​下​列​指​令​來​啟​動​ xend daemon:
service xend start
您​可​以​使​用​ xend 來​停​止​ daemon:
service xend stop
如​此​便​會​停​止​ daemon 運​行​。​
您​可​以​使​用​ xend 來​重​新​啟​動​ daemon:
service xend restart
daemon 再​次​啟​動​。​
您​可​以​確​認​ xend daemon 的​狀​態​。​
service xend status
The output displays the daemon's status.

在​開​機​時​啟​用​ xend

使​用​ chkconfig 指​令​來​將​ xend 附​加​至​ initscript。​
chkconfig --level 345 xend
xend 現​在​會​在​ runlevel 3、​4 和​ 5 模​式​下​啟​動​。​

章 20. Xen 即​時​遷​移​

The Xen hypervisor supports Virtualization Migration for para-virtualized guests and fully virtualized guests. Migration is only supported on Red Hat Enterprise Linux 5.1 and newer systems. Migration can be performed offline or live.
  • 離​線​遷​移​會​暫​停​原​有​主​機​上​的​虛​擬​客​戶​端​,將​其​轉​移​到​目​的​地​電​腦​上​,然​後​在​完​全​遷​移​過​後​,重​新​開​始​客​戶​端​。​離​線​遷​移​使​用​的​是​ virsh migrate 指​令​。​
    # virsh migrate GuestName libvirtURI
  • A live migration keeps the guest running on the source host and begins moving the memory without stopping the guest. All modified memory pages are monitored for changes and sent to the destination while the image is sent. The memory is updated with the changed pages. The process continues until the amount of pause time allowed for the guest equals the predicted time for the final few pages to be transfer. The Xen hypervisor estimates the time remaining and attempts to transfer the maximum amount of page files from the source to the destination until Xen predicts the amount of remaining pages can be transferred during a very brief time while the virtualized guest is paused. The registers are loaded on the new host and the guest is then resumed on the destination host. If the guest cannot be merged (which happens when guests are under extreme loads) the guest is paused and then an offline migration is started instead.
    即​時​遷​移​使​用​的​是​ virsh migrate 指​令​的​ --live 選​項​。​
    # virsh migrate--live GuestName libvirtURI

Itanium® 支​援​註​解​

遷​移​功​能​目​前​尚​不​支​援​ Itanium® 架​構​。​
若​要​啟​用​ Xen 的​遷​移​功​能​,您​需​要​修​改​ /etc/xen/xend-config.sxp 配​置​檔​案​。​基​於​對​主​機​安​全​性​上​持​有​潛​在​的​有​害​影​響​,因​此​遷​移​就​預​設​值​來​講​會​是​停​用​的​。​開​啟​遷​移​連​接​埠​時​可​能​會​導​致​未​經​授​權​的​主​機​實​施​遷​移​,或​是​連​至​重​定​位​連​接​埠​。​因​為​遷​移​請​求​並​不​需​要​特​定​的​授​權​,並​且​唯​一​的​控​制​機​制​是​基​於​主​機​名​稱​和​ IP 位​址​,因​此​您​必​須​小​心​確​認​遷​移​連​接​埠​與​伺​服​器​不​會​被​未​授​權​的​主​機​所​存​取​。​

虛​擬​化​遷​移​的​安​全​性​問​題​

IP 位​址​和​主​機​名​稱​過​濾​器​只​提​供​少​量​的​安​全​性​。​若​攻​擊​者​知​道​遷​移​客​戶​端​的​位​址​或​主​機​名​稱​為​何​,這​兩​個​屬​性​將​很​容​易​被​偽​造​。​確​保​遷​移​安​全​性​的​最​好​方​式​,是​把​網​路​獨​立​設​置​,與​外​部​及​未​經​授​權​的​內​部​連​線​隔​開​。​
啟​用​遷​移​
請​修​改​下​列​位​於​ /etc/xen/xend-config.sxp 中​的​項​目​以​便​啟​動​遷​移​。​請​視​需​要​修​改​這​些​參​數​,或​移​除​參​數​之​前​的​註​解​符​號​(#):
(xend-relocation-server yes)
預​設​值​是​ no,表​示​停​用​遷​移​功​能​。​請​將​ xend-relocation-server 的​值​設​為​ yes,以​啟​用​遷​移​功​能​。​
(xend-relocation-port 8002)
若​ xend-relocation-server 被​設​為​了​ yes 的​話​,(xend-relocation-port) 這​個​參​數​便​會​指​定​ xend 的​這​個​連​接​埠​應​使​用​於​重​定​位​介​面​。​
此​變​數​的​預​設​值​應​該​在​大​部​分​安​裝​程​序​下​都​可​使​用​。​若​您​更​改​了​這​個​值​,請​確​認​您​正​在​使​用​重​定​位​伺​服​器​上​一​個​未​使​用​的​連​接​埠​。​
xend-relocation-port 參​數​所​設​定​的​連​接​埠​,必​須​在​兩​邊​的​系​統​上​設​定​。​
(xend-relocation-address '')
若​ xend-relocation-server 被​設​置​的​話​,(xend-relocation-address) 就​應​該​是​ xend 為​ relocation-socket 連​線​所​應​監​聽​的​位​址​。​
The default is to listen on all active interfaces. The (xend-relocation-address) parameter restricts the migration server to only listen to a specific interface. The default value in /etc/xen/xend-config.sxp is an empty string(''). This value should be replaced with a single, valid IP address. For example:
(xend-relocation-address '10.0.0.1')
(xend-relocation-hosts-allow '')
The (xend-relocation-hosts-allow 'hosts') parameter controls which hostnames can communicate on the relocation port.
Unless you are using SSH or TLS, the guest's virtual memory is transferred in raw form without encryption of the communication. Modify the xend-relocation-hosts-allow option to restrict access to the migration server.
若​這​個​值​和​上​述​範​例​一​樣​是​空​的​話​,那​麼​所​有​連​線​都​會​被​允​許​。​這​假​設​連​線​會​抵​達​一​個​重​定​位​的​伺​服​器​所​監​聽​的​通​訊​埠​和​介​面​上​,請​參​閱​上​述​的​ xend-relocation-port 和​ xend-relocation-address。​
否​則​,(xend-relocation-hosts-allow) 這​個​參​數​應​該​會​是​一​連​串​以​空​格​來​區​隔​開​的​常​規​表​示​式​。​任​何​具​有​完​整​網​域​名​稱​或​匹​配​其​中​一​個​正​規​表​示​式​的​ IP 位​址​的​主​機​都​會​被​接​受​。​
(xend-relocation-hosts-allow) 屬​性​的​範​例​:
(xend-relocation-hosts-allow '^localhost$ ^localhost\\.localdomain$')
在​您​配​置​了​您​配​置​檔​案​中​的​參​數​後​,請​重​新​啟​動​ Xen 服​務​。​
# service xend restart

20.1. 即​時​遷​移​的​範​例​

以​下​為​如​何​設​定​一​個​即​時​遷​移​的​基​本​環​境​之​範​例​。​此​配​置​使​用​了​ NFS 來​作​為​共​享​儲​存​。​NFS 適​合​用​於​展​示​用​的​環​境​中​,不​過​若​要​使​用​在​生​產​環​境​下​,我​們​建​議​您​透​過​使​用​光​纖​通​道​或​ iSCSI 和​ GFS 來​進​行​較​為​強​大​的​共​享​儲​存​配​置​。​
以​下​的​配​置​包​含​著​兩​台​伺​服​器​(et-virt07 和​ et-virt08),兩​者​都​使​用​ eth1 來​作​為​它​們​的​預​設​網​路​介​面​,因​為​它​們​都​使​用​ xenbr1 為​它​們​的​ Xen 網​路​作​業​橋​接​。​我​們​在​ et-virt07 上​使​用​了​本​地​連​接​的​ SCSI 磁​碟​(/dev/sdb)來​作​為​使​用​ NFS 的​共​享​儲​存​空​間​。​
即​時​遷​移​設​定​
建​立​與​掛​載​使​用​於​遷​移​的​目​錄​:
# mkdir /var/lib/libvirt/images
# mount /dev/sdb /var/lib/libvirt/images

重​要​

請​確​認​該​目​錄​已​透​過​使​用​正​確​的​選​項​來​匯​出​了​。​若​您​要​匯​出​預​設​的​ /var/lib/libvert/images/ 目​錄​,請​確​認​您​「​只​」​匯​出​ /var/lib/libvert/images/ 而​「​非​」​/var/lib/xen/,因​為​此​目​錄​已​被​ xend daemon 和​其​它​工​具​所​使​用​。​若​共​享​ /var/lib/xen/ 的​話​可​能​會​發​生​無​法​預​估​的​問​題​。​
# cat /etc/exports
/var/lib/libvirt/images  *(rw,async,no_root_squash)
請​驗​證​它​是​否​是​透​過​ NFS 所​匯​出​的​:
# showmount -e et-virt07
Export list for et-virt07:
/var/lib/libvirt/images *
安​裝​客​座​端​
範​例​中​的​安​裝​指​令​是​用​來​安​裝​客​座​端​用​的​:
# virt-install -p -f /var/lib/libvirt/images/testvm1.dsk -s 5 -n\
testvm1 --vnc -r 1024 -l http://example.com/RHEL5-tree\
Server/x86-64/os/ -b xenbr1
For step by step installation instructions, refer to 章 8, 客​座​端​作​業​系​統​的​安​裝​程​序​.
驗​證​遷​移​的​環​境​
請​確​認​虛​擬​化​的​網​路​橋​接​已​正​確​配​置​,並​且​兩​個​主​機​都​含​有​相​同​名​稱​:
[et-virt08 ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
xenbr1          8000.feffffffffff       no              peth1
vif0.1
[et-virt07 ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
xenbr1          8000.feffffffffff       no              peth1
vif0.1
請​檢​查​重​定​位​參​數​是​否​已​被​配​置​於​這​兩​台​主​機​上​:
[et-virt07 ~]# grep xend-relocation /etc/xen/xend-config.sxp |grep -v '#'
(xend-relocation-server yes)
(xend-relocation-port 8002)
(xend-relocation-address '')
(xend-relocation-hosts-allow '')
[et-virt08 ~]# grep xend-relocation /etc/xen/xend-config.sxp |grep -v '#'
(xend-relocation-server yes)
(xend-relocation-port 8002)
(xend-relocation-address '')
(xend-relocation-hosts-allow '')
請​確​認​重​定​位​伺​服​器​已​啟​用​,並​且​正​在​專​屬​的​通​訊​埠​上​監​聽​ Xen 遷​移​工​作​(8002):
[et-virt07 ~]# lsof -i :8002
COMMAND  PID  USER   FD   TYPE  DEVICE SIZE NODE NAME
python 3445 root 14u IPv4 10223 TCP *:teradataordbms (LISTEN)
[et-virt08 ~]# lsof -i :8002
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
python 3252 root 14u IPv4 10901 TCP *:teradataordbms (LISTEN)
That the default /var/lib/libvirt/images directory is available and mounted with networked storage on both hosts. Shared, networked storage is required for migrations.
[et-virt08 ~]# df /var/lib/libvirt/images
Filesystem           1K-blocks      Used Available Use% Mounted on
et-virt07:/var/lib/libvirt/images    70562400   2379712  64598336   4% /var/lib/libvirt/images
[et-virt08 ~]# file /var/lib/libvirt/images/testvm1.dsk 
/var/lib/libvirt/images/testvm1.dsk: x86 boot sector; partition 1: ID=0x83,
active, starthead 1, startsector 63, 208782 sectors; partition 2: ID=0x8e, 
starthead 0, startsector 208845, 10265535 sectors, code offset 0x48
[et-virt08 ~]# touch /var/lib/libvirt/images/foo
[et-virt08 ~]# rm -f /var/lib/libvirt/images/foo
驗​證​客​座​端​上​的​儲​存​和​恢​復​
啟​動​虛​擬​機​器​(若​還​未​啟​動​的​話​):
[et-virt07 ~]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
[et-virt07 ~]# virsh start testvm1
Domain testvm1 started
驗​證​虛​擬​機​器​是​否​正​在​運​作​:
[et-virt07 ~]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
testvm1        blocked
將​虛​擬​機​器​儲​存​在​本​地​主​機​上​:
[et-virt07 images]# time virsh save testvm1 testvm1.sav
real    0m15.744s
user    0m0.188s
sys     0m0.044s
[et-virt07 images]# ls -lrt testvm1.sav
-rwxr-xr-x 1 root root 1075657716 Jan 12 06:46 testvm1.sav
[et-virt07 images]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
在​本​地​主​機​上​恢​復​虛​擬​機​器​:
[et-virt07 images]# virsh restore testvm1.sav
[et-virt07 images]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
testvm1        blocked
Start the live migration of domain-id from et-virt08 to et-virt07. The hostname you are migrating to and <domain-id> must be replaced with valid values. This example uses the et-virt08 host which must have SSH access to et-virt07
[et-virt08 ~]# xm migrate --live testvm1 et-virt07
Verify the virtual machine is no longer present on et-virt08
[et-virt08 ~]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
Verify the virtual machine has been migrated to et-virt07:
[et-virt07 ~]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
testvm1        running
測​試​進​度​並​實​施​即​時​遷​移​
Create the following script inside the virtual machine to log date and hostname during the migration. This script performs I/O tasks on the guest's file system.
#!/bin/bash

while true
do
touch /var/tmp/$$.log
echo `hostname` >>  /var/tmp/$$.log
	echo `date`     >>  /var/tmp/$$.log
	cat  /var/tmp/$$.log
	df /var/tmp
	ls -l  /var/tmp/$$.log
	sleep 3
	done
請​記​住​,這​個​ script 只​適​用​於​測​試​,在​生​產​環​境​下​進​行​即​時​遷​移​時​則​不​需​使​用​到​。​
請​在​嘗​試​將​虛​擬​機​器​遷​移​至​ et-virt07 之​前​,驗​證​虛​擬​機​器​是​否​正​在​ et-virt08 上​執​行​:
[et-virt08 ~]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
testvm1        blocked
實​施​即​時​遷​移​至​ et-virt07。​您​可​加​入​ time 指​令​來​查​看​遷​移​所​需​時​間​有​多​久​:
[et-virt08 ~]# xm migrate --live testvm1 et-virt07
請​在​客​座​端​中​執​行​此​ script:
# ./doit
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:26:27 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 62 Jan 12 02:26 /var/tmp/2279.log
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:26:27 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:26:30 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 124 Jan 12 02:26 /var/tmp/2279.log
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:26:27 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:26:30 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:26:33 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 186 Jan 12 02:26 /var/tmp/2279.log
Fri Jan 12 02:26:45 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:26:48 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:26:51 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:54:57 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:55:00 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:55:03 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 744 Jan 12 06:55 /var/tmp/2279.log
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:26:27 EST 2007
請​驗​證​虛​擬​機​器​在​ et-virt08 上​是​否​已​被​關​閉​:
[et-virt08 ~]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
請​驗​證​虛​擬​機​器​在​ et-virt07 上​是​否​已​被​啟​動​:
[et-virt07 images]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
testvm1        blocked
請​執​行​另​一​項​由​ et-virt07 至​ et-virt08 的​循​環​遷​移​。​請​實​施​一​項​由​ et-virt07 至​ et-virt08 的​遷​移​:
[et-virt07 images]# xm migrate --live testvm1 et-virt08
請​驗​證​虛​擬​機​器​是​否​已​被​關​閉​:
[et-virt07 images]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
在​實​施​遷​移​之​前​,請​先​在​客​座​端​中​啟​用​這​簡​短​的​ script,並​留​意​遷​移​客​座​端​時​所​產​生​的​任​何​變​更​:
# ./doit
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:53 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 62 Jan 12 06:57 /var/tmp/2418.log
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:53 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:56 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 124 Jan 12 06:57 /var/tmp/2418.log
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:53 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:56 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:58:00 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 186 Jan 12 06:57 /var/tmp/2418.log
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:53 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:56 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:58:00 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:30:00 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 248 Jan 12 02:30 /var/tmp/2418.log
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:53 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:56 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:58:00 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:30:00 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:30:03 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 310 Jan 12 02:30 /var/tmp/2418.log
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:53 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:57:56 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 06:58:00 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:30:00 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:30:03 EST 2007
dhcp78-218.lab.boston.redhat.com
Fri Jan 12 02:30:06 EST 2007
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2983664   2043120    786536  73% /
-rw-r--r-- 1 root root 372 Jan 12 02:30 /var/tmp/2418.log
當​遷​移​指​令​在​ et-virt07 上​完​成​之​後​,請​在​ et-virt08 上​驗​證​虛​擬​機​器​是​否​已​啟​動​:
[et-virt08 ~]# virsh list
 Id Name                 State
----------------------------------
Domain-0                 running
testvm1        blocked
然​後​執​行​另​一​個​循​環​:
[et-virt08 ~]# time virsh migrate --live testvm1 et-virt07
real    0m10.378s
user    0m0.068s
sys     0m0.052s
至​此​,您​應​該​成​功​地​進​行​了​離​線​與​即​時​遷​移​測​試​了​。​

20.2. 配​置​客​座​端​即​時​遷​移​

本​節​涵​蓋​了​以​離​線​遷​移​的​方​式​,把​ Xen 客​座​端​遷​移​到​其​他​執​行​ Red Hat Enterprise Linux 的​伺​服​器​上​面​去​。​此​外​,您​可​以​在​離​線​狀​態​執​行​遷​移​(使​用​ xm migrate 指​令​)。​即​時​遷​移​可​以​使​用​相​同​指​令​來​完​成​。​但​您​必​須​在​ xend-config 配​置​檔​案​上​作​進​一​步​的​修​改​。​這​個​例​子​顯​示​您​必​須​修​改​的​項​目​,以​確​保​遷​移​成​功​:
(xend-relocation-server yes)
The default for this parameter is 'no', which keeps the relocation/migration server deactivated (unless on a trusted network) and the domain virtual memory is exchanged in raw form without encryption.
(xend-relocation-port 8002)
這​個​參​數​設​定​ xend 用​來​移​動​的​連​接​埠​。​除​非​您​的​網​路​環​境​需​要​自​訂​連​接​埠​,否​則​使​用​這​個​值​即​可​。​請​移​除​這​一​行​之​前​的​註​解​符​號​,以​啟​用​連​接​埠​。​
(xend-relocation-address )
在​您​啟​動​ xend-relocation-server 後​,這​個​參​數​為​接​收​重​定​位​槽​連​接​的​位​置​。​Xen hypervisor 只​會​聆​聽​特​定​介​面​卡​上​的​遷​移​網​路​交​通​。​
(xend-relocation-hosts-allow )
此​參​數​可​控​制​和​重​定​位​通​訊​埠​進​行​通​訊​的​主​機​。​若​這​個​值​是​空​的​話​,那​麼​所​有​連​入​的​連​線​都​會​被​允​許​。​您​必​須​針​對​於​此​進​行​更​改​,將​它​更​改​為​以​空​格​區​隔​開​的​正​規​表​示​式​序​列​,例​如​:
(xend-relocation-hosts-allow- '^localhost\\.localdomain$' )>
可​接​受​的​值​包​括​完​整​網​域​名​稱​、​IP 位​址​、​或​用​空​白​字​元​隔​開​的​常​規​表​示​式​。​
配​置​完​成​之​後​,重​新​開​機​以​載​入​新​的​設​定​。​

章 21. KVM 即​時​遷​移​

此​章​節​涵​蓋​了​如​何​將​ KVM hypervisor 上​運​作​的​客​座​端​,遷​移​至​另​一​台​ KVM 主​機​上​。​
Migration is the process of moving a virtualized guest from one host to another. Migration is a key feature of virtualization as software is completely separated from hardware. Migration is useful for:
  • 負​載​平​衡​(Load Balancing) - 當​主​機​負​載​過​高​時​,客​座​端​可​被​移​至​另​一​個​使​用​量​較​低​的​主​機​上​。​
  • 硬​體​容​錯​移​轉​(Hardware Failover)- 當​主​機​上​的​硬​體​裝​置​開​始​出​現​問​題​時​,客​座​端​可​被​安​全​地​進​行​重​置​,如​此​一​來​主​機​便​能​停​機​以​進​行​修​復​。​
  • 節​能​(Energy Saving)- 當​使​用​量​低​時​,客​座​端​可​被​重​新​發​佈​至​其​它​主​機​上​,然​後​關​閉​不​需​要​用​的​主​機​系​統​,來​節​省​能​源​並​降​低​成​本​。​
  • 實​際​位​置​的​遷​移​(Geographic Migration)- 在​嚴​重​的​情​況​下​,客​座​端​可​被​遷​移​至​另​一​個​位​置​上​,來​達​到​較​低​的​延​遲​時​間​。​
Migrations can be performed live or offline. To migrate guests the storage must be shared. Migration works by sending the guests memory to the destination host. The shared storage stores the guest's default file system. The file system image is not sent over the network from the source host to the destination host.
進​行​離​線​遷​移​時​客​座​端​將​會​被​暫​停​並​且​客​座​端​記​憶​體​的​映​像​檔​會​被​移​至​目​標​主​機​上​。​客​座​端​會​在​目​標​主​機​上​復​原​,如​此​一​來​客​座​端​在​來​源​主​機​上​所​使​用​的​記​憶​體​便​會​被​釋​放​。​
離​線​遷​移​程​序​的​所​需​時​間​取​決​於​網​路​頻​寬​和​延​遲​時​間​。​在​一​個​ 1 Gbit 的​乙​太​網​路​上​,遷​移​一​台​擁​有​ 2GB 記​憶​體​的​客​座​端​大​約​會​花​上​十​秒​鐘​左​右​的​時​間​。​
即​時​遷​移​會​讓​客​座​端​持​續​在​來​源​主​機​上​執​行​,並​且​在​不​停​用​該​客​座​端​的​情​況​下​開​始​移​動​記​憶​體​。​當​映​像​檔​被​傳​送​時​,所​有​經​過​修​改​的​記​憶​體​分​頁​(memory page)皆​會​被​監​控​是​否​有​任​何​變​更​,並​傳​送​至​目​的​地​。​記​憶​體​會​隨​著​受​到​變​更​的​分​頁​一​起​更​新​。​這​項​程​序​會​持​續​進​行​,直​到​客​座​端​被​允​許​的​暫​停​時​間​與​最​後​幾​個​分​頁​傳​輸​的​預​計​時​間​相​等​。​KVM 會​判​斷​出​剩​餘​的​時​間​有​多​久​,並​嘗​試​將​最​大​量​的​分​頁​由​來​源​傳​輸​至​目​的​地​,直​到​ KVM 能​預​測​出​剩​下​的​分​頁​可​在​虛​擬​客​座​端​暫​停​時​,在​設​定​的​時​間​內​傳​輸​完​成​。​暫​存​器​會​被​載​入​到​新​的​主​機​上​,並​且​客​戶​端​將​會​在​目​標​主​機​上​復​原​。​若​客​座​端​無​法​合​併​的​話​(當​客​座​端​負​載​過​高​時​),客​座​端​將​會​暫​停​,並​且​離​線​遷​移​程​序​將​會​啟​動​。​
離​線​遷​移​程​序​的​所​需​時​間​,取​決​於​網​路​頻​寬​和​延​遲​時​間​。​若​客​座​端​正​被​大​量​,使​用​或​是​頻​寬​過​低​的​話​,遷​移​程​序​將​會​花​上​較​久​的​時​間​。​

21.1. 即​時​遷​移​需​求​

遷​移​客​座​端​的​需​求​如​下​:
遷​移​需​求​
  • 虛​擬​化​客​座​端​必​須​透​過​使​用​下​列​其​中​一​種​協​定​,安​裝​在​共​享​的​網​路​儲​存​裝​置​上​:
    • 光​纖​通​道​
    • iSCSI
    • NFS
    • GFS2
  • 兩​部​(或​更​多​)裝​有​相​同​版​本​以​及​相​同​更​新​的​ Red Hat Enterprise Linux 的​系​統​。​
  • 兩​部​系​統​皆​必​須​開​啟​正​確​的​連​接​埠​。​
  • 兩​部​系​統​皆​必​須​擁​有​相​同​的​網​路​設​定​。​這​兩​台​主​機​上​的​所​有​橋​接​與​網​路​設​定​都​必​須​是​相​同​的​。​
  • 共​享​儲​存​裝​置​必​須​掛​載​在​來​源​與​目​標​系​統​上​的​相​同​的​位​置​上​。​掛​載​的​目​錄​名​稱​必​須​是​相​同​的​。​
設​定​網​路​儲​存​裝​置​
Configure shared storage and install a guest on the shared storage. For shared storage instructions, refer to 部 V, “Virtualization Storage Topics”.

21.2. 共​享​儲​存​裝​置​範​例​:用​來​進​行​基​本​遷​移​的​ NFS

此​範​例​使​用​了​ NFS 來​與​其​它​ KVM 主​機​共​享​客​座​端​映​像​檔​。​此​範​例​不​適​用​於​大​型​安​裝​,該​範​例​只​適​用​於​遷​移​技​巧​以​及​小​型​建​置​上​的​示​範​。​請​勿​使​用​此​範​例​來​遷​移​或​執​行​大​量​虛​擬​化​客​座​端​。​
For advanced and more robust shared storage instructions, refer to 部 V, “Virtualization Storage Topics”
  1. 匯​出​您​的​ libvirt 映​像​檔​目​錄​

    請​將​預​設​映​像​檔​目​錄​新​增​至​ /etc/exports 檔​案​中​:
    /var/lib/libvirt/images *.example.com(rw,no_root_squash,async)
    
    依​照​您​的​環​境​需​求​更​改​主​機​參​數​。​
  2. 啟​用​ NFS

    1. 若​ NFS 套​件​還​未​安​裝​的​話​便​將​它​安​裝​:
      # yum install nfs
      
    2. 在​ iptables 中​開​啟​ NFS 的​連​接​埠​,並​將​ NFS 新​增​至​ /etc/hosts.allow 檔​案​中​。​
    3. 啟​用​ NFS 服​務​:
      # service nfs start
      
  3. 將​共​享​儲​存​裝​置​掛​載​在​目​標​系​統​上​

    在​目​標​系​統​上​掛​載​ /var/lib/libvirt/images 目​錄​:
    # mount sourceURL:/var/lib/libvirt/images /var/lib/libvirt/images
    

    來​源​與​目​的​地​上​的​位​置​必​須​是​相​同​的​

    無​論​為​客​座​端​選​擇​了​哪​個​目​錄​,在​主​機​與​客​座​端​上​都​必​須​是​相​同​的​。​對​於​所​有​類​型​的​共​享​儲​存​裝​置​都​必​須​是​如​此​。​目​錄​必​須​是​相​同​的​,否​則​遷​移​將​會​失​敗​。​

21.3. 以​ virsh 來​進​行​即​時​ KVM 遷​移​

您​可​透​過​ virsh 指​令​來​將​客​座​端​遷​移​至​另​一​部​主​機​上​。​migrate 指​令​接​受​下​列​參​數​格​式​:
# virsh migrate --live GuestName DestinationURL
GuestName 參​數​代​表​您​希​望​遷​移​的​客​座​端​之​名​稱​。​
DestinationURL 參​數​代​表​目​標​系​統​的​ URL 或​主​機​名​稱​。​目​標​系​統​必​須​執​行​相​同​版​本​的​ Red Hat Enterprise Linux、​使​用​相​同​的​ hypervisor 並​且​皆​需​要​執​行​ libvirt。​
一​旦​輸​入​了​指​令​之​後​,您​將​會​被​提​示​輸​入​目​標​系​統​的​ root 密​碼​。​
範​例​:以​ virsh 來​進​行​即​時​遷​移​
此​範​例​顯​示​了​由​ test1.example.com 遷​移​至​ test2.example.com。​請​更​改​您​環​境​的​主​機​名​稱​。​此​範​例​遷​移​了​一​部​名​為​ RHEL4test 的​虛​擬​機​器​。​
This example assumes you have fully configured shared storage and meet all the prerequisites (listed here: 遷​移​需​求​).
  1. 驗​證​客​座​端​是​否​正​在​運​作​

    請​由​來​源​系​統​ test1.example.com 上​驗​證​ RHEL4test 是​否​正​在​運​作​:
    [root@test1 ~]# virsh list
    Id Name                 State
    ----------------------------------
     10 RHEL4                running
    
  2. 遷​移​客​座​端​

    請​執​行​下​列​指​令​來​將​客​座​端​即​時​遷​移​至​目​的​地​ test2.example.com。​請​將​ /system 附​加​至​目​標​ URL 的​尾​端​來​讓​ libvirt 知​道​您​需​要​完​整​的​存​取​權​限​。​
    # virsh migrate --live RHEL4test qemu+ssh://test2.example.com/system
    一​旦​輸​入​了​指​令​之​後​,您​將​會​被​提​示​輸​入​目​標​系​統​的​ root 密​碼​。​
  3. 等​待​

    遷​移​程​序​可​能​會​根​據​客​座​端​的​負​載​和​大​小​而​花​上​一​段​時​間​。​virsh 只​會​回​報​錯​誤​。​客​座​端​會​繼​續​在​來​源​主​機​上​執​行​直​到​完​全​被​遷​移​。​
  4. 驗​證​客​座​端​已​到​達​目​標​主​機​

    請​由​目​標​系​統​ test2.example.com 上​驗​證​ RHEL4test 是​否​有​在​運​作​:
    [root@test2 ~]# virsh list
    Id Name                 State
    ----------------------------------
     10 RHEL4                running
    
即​時​遷​移​已​完​成​。​

其​它​網​路​作​業​方​式​

libvirt supports a variety of networking methods including TLS/SSL, unix sockets, SSH, and unencrypted TCP. Refer to 章 22, 虛​擬​化​客​座​端​的​遠​端​管​理​ for more information on using other methods.

21.4. 以​ virt-manager 來​進​行​遷​移​

此​部​份​涵​蓋​了​如​何​透​過​ virt-manager 來​遷​移​基​於​ KVM 的​客​座​端​。​
  1. 連​至​來​源​與​目​標​主​機​。​請​在​「​檔​案​」​選​單​上​選​取​「​新​增​連​線​」​,接​著​「​新​增​連​線​」​視​窗​便​會​出​現​。​
    請​輸​入​下​列​資​訊​:
    • Hypervisor:選​擇​ 「​QEMU」​。​
    • 連​線​:選​擇​連​線​類​型​。​
    • 主​機​名​稱​:輸​入​主​機​名​稱​。​
    點​選​「​連​線​」​。​
    虛​擬​主​機​管​理​程​式​將​會​顯​示​已​連​接​的​主​機​列​表​。​
  2. 新​增​一​個​含​有​與​來​源​與​目​標​主​機​相​同​ NFS 的​儲​存​裝​置​ pool。​
    請​在​「​編​輯​」​選​單​上​點​選​「​主​機​詳​細​資​訊​」​,接​著​主​機​詳​細​資​訊​的​視​窗​便​會​出​現​。​
    請​點​選​「​儲​存​裝​置​」​分​頁​。​
  3. 新​增​儲​存​裝​置​ pool。​請​點​選​位​於​視​窗​的​左​下​角​的​「​+」​按​鈕​。​接​著​「​新​增​儲​存​裝​置​ Pool」​的​視​窗​便​會​出​現​。​
    請​輸​入​下​列​資​訊​:
    • 名​稱​:輸​入​儲​存​裝​置​ pool 的​名​稱​。​
    • 類​型​:選​擇​「​netfs:網​路​匯​出​目​錄​」​。​
    點​選​「​下​一​步​」​。​
  4. 請​輸​入​下​列​資​訊​:
    • 格​式​:選​擇​儲​存​裝​置​類​型​。​若​是​即​時​遷​移​的​話​,這​必​須​是​ NFS 或​是​ iSCSI。​
    • 主​機​名​稱​:輸​入​儲​存​裝​置​伺​服​器​的​ IP 位​址​或​完​整​網​域​名​稱​。​
    點​選​「​完​成​」​。​
  5. 在​共​享​儲​存​裝​置​ pool 中​建​立​新​卷​冊​,請​點​選​「​新​建​卷​冊​」​。​
  6. 請​輸​入​詳​細​資​料​並​按​下​「​建​立​卷​冊​」​。​
  7. 以​新​建​的​卷​冊​來​建​立​虛​擬​機​器​,然​後​執​行​虛​擬​機​器​。​
    虛​擬​主​機​視​窗​將​會​出​現​。​
  8. 請​在​虛​擬​主​機​管​理​主​視​窗​中​以​滑​鼠​右​鍵​點​選​虛​擬​機​器​、​選​擇​「​遷​移​」​,然​後​點​選​遷​移​位​置​。​
  9. 點​選​「​是​」​來​確​認​遷​移​。​
    The Virtual Machine Manager displays the virtual machine in its new location.
    The VNC connection displays the remote host's address in its title bar.

章 22. 虛​擬​化​客​座​端​的​遠​端​管​理​

此​部​份​解​釋​了​如​何​透​過​使​用​ ssh 或​是​ TLS 與​ SSL 來​遠​端​管​理​您​的​虛​擬​化​客​座​端​。​

22.1. 透​過​使​用​ SSH 來​進​行​遠​端​管​理​

ssh 這​個​套​件​提​供​了​安​全​的​加​密​網​路​通​訊​協​定​,用​來​將​管​理​功​能​傳​送​至​遠​端​虛​擬​伺​服​器​。​在​此​所​描​述​的​方​法​使​用​了​ libvirt 管​理​連​線​並​安​全​地​通​過​了​一​個​ SSH 連​線​來​管​理​遠​端​機​器​。​所​有​認​證​都​是​透​過​使​用​ SSH 公​共​金​鑰​加​密​,以​及​透​過​您​本​機​ SSH 代​理​程​式​所​蒐​集​的​密​碼​或​密​語​來​進​行​的​。​此​外​,各​個​客​座​端​虛​擬​機​器​的​ VNC 主​控​台​都​會​通​過​ SSH。​
SSH 一​般​已​透​過​預​設​值​配​置​,因​此​您​的​ SSH 金​鑰​可​能​早​就​已​經​設​置​妥​當​,並​且​無​須​額​外​的​防​火​牆​規​則​便​能​存​取​管​理​服​務​或​是​ VNC 主​控​台​。​
請​小​心​使​用​ SSH 來​為​您​的​虛​擬​機​器​進​行​遠​端​管​理​上​的​一​些​問​題​,這​些​問​題​包​含​:
  • 您​需​要​ root 登​入​權​限​才​可​存​取​用​來​管​理​虛​擬​主​機​的​遠​端​機​器​、​
  • 初​始​連​線​設​定​程​序​可​能​會​較​緩​慢​、​
  • there is no standard or trivial way to revoke a user's key on all hosts or guests, and
  • ssh 不​適​用​於​大​量​的​遠​端​機​器​。​
Configuring password less or password managed SSH access for virt-manager
The following instructions assume you are starting from scratch and do not already have SSH keys set up. If you have SSH keys set up and copied to the other systems you can skip this procedure.

The user is important for remote management

SSH keys are user dependent. Only the user who owns the key may access that key.
virt-manager must run as the user who owns the keys to connect to the remote host. That means, if the remote systems are managed by a non-root user virt-manager must be run in unprivileged mode. If the remote systems are managed by the local root user then the SSH keys must be own and created by root.
You cannot manage the local host as an unprivileged user with virt-manager.
  1. Optional: Changing user

    Change user, if required. This example uses the local root user for remotely managing the other hosts and the local host.
    $ su -
  2. Generating the SSH key pair

    Generate a public key pair on the machine virt-manager is used. This example uses the default key location, in the ~/.ssh/ directory.
    $ ssh-keygen -t rsa
    
  3. Coping the keys to the remote hosts

    Remote login without a password, or with a passphrase, requires an SSH key to be distributed to the systems being managed. Use the ssh-copy-id command to copy the key to root user at the system address provided (in the example, root@example.com).
    # ssh-copy-id -i ~/.ssh/id_rsa.pub root@example.com root@example.com's password: Now try logging into the machine, with "ssh 'root@example.com'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting 
    
    Repeat for other systems, as required.
  4. Optional: Add the passphrase to the ssh-agent

    Add the passphrase for the SSH key to the ssh-agent, if required. On the local host, use the following command to add the passphrase (if there was one) to enable password-less login.
    # ssh-add ~/.ssh/id_rsa.pub
The SSH key was added to the remote system.
libvirt daemon(libvirtd
The libvirt daemon provide an interface for managing virtual machines. You must have the libvirtd daemon installed and running on every remote host that needs managing.
$ ssh root@somehost
# chkconfig libvirtd on
# service libvirtd start
當​ libvirtd 和​ SSH 經​過​設​定​後​,您​便​應​該​能​夠​遠​端​存​取​並​管​理​您​的​虛​擬​機​器​。​至​此​,您​也​應​該​能​夠​透​過​ VNC 來​存​取​您​的​客​座​端​。​
Accessing remote hosts with virt-manager
Remote hosts can be managed with the virt-manager GUI tool. SSH keys must belong to the user executing virt-manager for password-less login to work.
  1. Start virt-manager.
  2. Open the File->Add Connection menu.
  3. Input values for the hypervisor type, the connection, Connection->Remote tunnel over SSH, and enter the desired hostname, then click connection.

22.2. 透​過​使​用​ TLS 與​ SSL 來​進​行​遠​端​管​理​

You can manage virtual machines using TLS and SSL. TLS and SSL provides greater scalability but is more complicated than ssh (refer to 節 22.1, “透​過​使​用​ SSH 來​進​行​遠​端​管​理​”). TLS and SSL is the same technology used by web browsers for secure connections. The libvirt management connection opens a TCP port for incoming connections, which is securely encrypted and authenticated based on x509 certificates. In addition the VNC console for each guest virtual machine will be setup to use TLS with x509 certificate authentication.
This method does not require shell accounts on the remote machines being managed. However, extra firewall rules are needed to access the management service or VNC console. Certificate revocation lists can revoke users' access.
為​ virt-manager 設​定​ TLS/SSL 存​取​的​步​驟​
下​列​簡​短​的​指​南​假​設​您​是​從​頭​開​始​並​且​沒​有​任​何​ TLS/SSL 認​證​的​相​關​知​識​。​若​您​有​一​部​憑​證​管​理​伺​服​器​,您​也​許​可​以​跳​過​第​一​個​步​驟​。​
libvirt 伺​服​器​設​定​
欲​取​得​更​多​有​關​於​建​立​憑​證​的​相​關​資​訊​,請​參​閱​ libvirt 網​站​ http://libvirt.org/remote.html。​
Xen VNC 伺​服​器​
Xen VNC 伺​服​器​可​透​過​編​輯​ /etc/xen/xend-config.sxp 這​個​配​置​檔​案​來​啟​用​ TLS。​請​將​配​置​檔​案​中​的​ (vnc-tls 1) 設​定​參​數​的​註​解​符​號​移​除​掉​。​
The /etc/xen/vnc directory needs the following 3 files:
  • ca-cert.pem - The CA certificate
  • server-cert.pem - The Server certificate signed by the CA
  • server-key.pem - The server private key
This provides encryption of the data channel. It might be appropriate to require that clients present their own x509 certificate as a form of authentication. To enable this remove the commenting on the (vnc-x509-verify 1) parameter.
virt-manager 和​ virsh 客​戶​端​設​定​
客​戶​端​的​設​定​目​前​還​不​太​一​致​。​若​要​啟​用​ libvirt 管​理​ API,CA 與​客​戶​端​憑​證​就​必​須​被​放​置​在​ /etc/pki 中​。​如​欲​取​得​更​多​相​關​資​訊​,請​參​閱​ http://libvirt.org/remote.html。​
In the virt-manager user interface, use the 'SSL/TLS' transport mechanism option when connecting to a host.
使​用​ virsh 的​話​ URI 的​格​式​會​如​下​:
  • 使​用​ KVM 的​話​:qemu://hostname.guestname/system。​
  • 使​用​ Xen 的​話​:xen://hostname.guestname/。​
若​要​啟​用​ VNC 的​ SSL 和​ TLS,您​需​要​將​憑​證​授​權​和​客​戶​端​憑​證​放​置​在​ $HOME/.pki 之​中​,也​就​是​以​下​的​三​個​檔​案​:
  • CA 或​是​ ca-cert.pem - CA 憑​證​。​
  • libvirt-vnc 或​ clientcert.pem - CA 所​簽​署​的​客​戶​端​憑​證​。​
  • libvirt-vnc 或​ clientkey.pem - 客​戶​端​私​密​金​鑰​。​

22.3. 傳​輸​模​式​

當​進​行​遠​端​管​理​時​,libvirt 支​援​下​列​傳​輸​模​式​:
傳​輸​層​安​全​性​(Transport Layer Security,TLS)
傳​輸​層​安​全​性​ TLS 1.0(SSL 3.1)驗​證​並​加​密​了​ TCP/IP socket,一​般​會​在​公​用​的​連​線​埠​號​上​進​行​監​聽​。​若​要​使​用​它​,您​將​需​要​產​生​客​戶​端​與​伺​服​器​憑​證​。​標​準​通​訊​埠​為​ 16514。​
UNIX socket
Unix 網​域​ socket 只​有​透​過​本​機​機​器​才​可​被​存​取​。​Socket 並​未​加​密​,並​且​使​用​了​ UNIX 權​限​或​是​ SELinux 來​進​行​驗​證​。​標​準​的​ socket 名​稱​為​ /var/run/libvirt/libvirt-sock 以​及​ /var/run/libvirt/libvirt-sock-ro(唯​讀​連​線​)。​
SSH
透​過​安​全​性​ Shell 協​定​(SSH)連​線​來​傳​輸​。​需​要​安​裝​ Netcat(nc 套​件​)。​libvirt daemon(libvirtd)必​須​在​遠​端​機​器​上​執​行​。​通​訊​埠​ 22 必​須​開​啟​才​可​進​行​ SSH 存​取​。​您​應​該​使​用​某​種​ ssh 金​鑰​管​理​(例​如​ ssh-agent 工​具​),否​則​系​統​會​提​示​您​輸​入​密​碼​。​
ext
ext 參​數​用​於​任​何​能​夠​連​至​遠​端​機​器​,libvirt 所​無​法​處​理​的​外​部​程​式​。​這​參​數​並​不​支​援​。​
tcp
未​加​密​的​ TCP/IP socket。​不​建​議​使​用​於​生​產​環​境​下​,這​一​般​會​被​停​用​,不​過​管​理​員​亦​可​啟​用​它​來​進​行​測​試​或​是​在​信​任​的​網​路​上​使​用​。​預​設​通​訊​埠​為​ 16509。​
若​沒​有​指​定​的​話​,預​設​傳​輸​將​會​是​ tls。​
遠​端​ URI
統​一​資​源​識​別​元​(Uniform Resource Identifier,URI)一​般​會​被​ virsh 和​ libvirt 使​用​來​連​至​遠​端​主​機​。​URI 亦​可​與​ --connect 參​數​搭​配​使​用​,讓​ virsh 指​令​在​遠​端​主​機​上​執​行​單​獨​的​指​令​或​遷​移​。​
libvirt URI 的​格​式​為​(中​括​號​ [] 裡​的​內​容​是​選​用​的​功​能​):
driver[+transport]://[username@][hostname][:port]/[path][?extraparameters]
您​必​須​提​供​傳​輸​方​式​或​是​主​機​名​稱​,才​能​找​到​外​部​位​置​。​
遠​端​管​理​參​數​的​範​例​
  • 使​用​ SSH 通​訊​協​定​與​使​用​者​名​稱​ ccurran,連​至​遠​端​ Xen hypervisor 上​名​為​ towada 的​主​機​。​
    xen+ssh://ccurran@towada/
    
  • 使​用​ TLS 來​連​至​主​機​上​一​個​名​為​ towada 的​遠​端​ Xen hypervisor。​
    xen://towada/
    
  • Connect to a remote Xen hypervisor on host towada using TLS. The no_verify=1 tells libvirt not to verify the server's certificate.
    xen://towada/?no_verify=1
    
  • 使​用​ SSH 來​連​至​主​機​ towada 上​的​遠​端​ KVM hypervisor。​
    qemu+ssh://towada/system
    
測​試​範​例​
  • 透​過​非​標​準​的​ UNIX socket 來​連​至​本​機​ KVM hypervisor。​Unix socket 的​完​整​路​徑​在​此​範​例​中​會​明​確​地​提​供​。​
    qemu+unix:///system?socket=/opt/libvirt/run/libvirt/libvirt-sock
    
  • 連​至​一​個​透​過​了​未​加​密​的​ TCP/IP 連​線​至​通​訊​埠​ 5000,IP 位​址​為​ 10.0.0.10 的​ libvirt daemon。​這​使​用​了​測​試​驅​動​程​式​和​預​設​設​定​。​
    test+tcp://10.1.1.10:5000/default
    
額​外​的​ URI 參​數​
Extra parameters can be appended to remote URIs. The table below 表格 22.1, “額​外​的​ URI 參​數​” covers the recognized parameters. All other parameters are ignored. Note that parameter values must be URI-escaped (that is, a question mark (?) is appended before the parameter and special characters are converted into the URI format).
表格 22.1. 額​外​的​ URI 參​數​
名​稱​ 傳​輸​模​式​ 描​述​ 使​用​範​例​
name 所​有​模​式​ 傳​送​至​遠​端​ virConnectOpen 函​式​的​名​稱​。​這​組​名​稱​一​般​是​透​過​移​除​來​自​於​遠​端​ URI 的​傳​輸​、​主​機​名​稱​、​連​接​埠​號​、​使​用​者​名​稱​和​額​外​參​數​所​形​成​的​,不​過​在​一​些​非​常​複​雜​的​情​況​下​,您​最​好​明​確​地​提​供​這​組​名​稱​。​ name=qemu:///system
command ssh 和​ ext 外​部​指​令​。​進​行​ ext 傳​輸​時​需​要​這​項​指​令​。​ssh 的​預​設​值​則​是​ ssh。​指​令​的​路​徑​(PATH)會​被​搜​尋​。​ command=/opt/openssh/bin/ssh
socket unix 和​ ssh UNIX 網​域​ socket 的​路​徑​,這​會​置​換​掉​預​設​值​。​進​行​ ssh 傳​輸​時​,這​會​被​傳​送​至​遠​端​的​ netcat 指​令​(請​查​看​ netcat)。​ socket=/opt/libvirt/run/libvirt/libvirt-sock
netcat ssh
netcat 指​令​可​以​用​來​連​接​遠​端​系​統​。​netcat 的​預​設​參​數​使​用​了​ nc 指​令​。​要​使​用​ SSH 傳​輸​,libvirt 會​使​用​以​下​格​式​來​建​構​ SSH 指​令​:
								command -p port [-l username] hostname
								netcat -U socket
port、​username 與​ hostname 參​數​可​以​用​來​當​作​遠​端​ URI 的​一​部​分​。​command、​netcat 與​ socket 則​來​自​其​他​的​額​外​參​數​。​
netcat=/opt/netcat/bin/nc
no_verify tls If set to a non-zero value, this disables client checks of the server's certificate. Note that to disable server checks of the client's certificate or IP address you must change the libvirtd configuration. no_verify=1
no_tty ssh 若​設​為​一​個​非​零​的​值​,這​將​會​停​止​ ssh 在​無​法​自​動​地​(透​過​使​用​ ssh-agent 等​等​)登​入​遠​端​機​器​時​,要​求​使​用​者​輸​入​密​碼​。​請​在​您​沒​有​終​端​機​存​取​權​限​時​使​用​它​ - 比​方​說​在​使​用​ libvirt 的​圖​形​化​程​式​中​。​ no_tty=1

部 V. Virtualization Storage Topics

Introduction to storage administration for virtualization

This part covers using shared, networked storage with virtualization on Red Hat Enterprise Linux.
The following methods are supported for virtualization:
  • Fibre Channel
  • iSCSI
  • NFS
  • GFS2
Networked storage is essential for live and offline guest migrations. You cannot migrate guests without shared storage.

章 23. Using shared storage with virtual disk images

This chapter covers the use of shared and network storage devices for virtual disks.

23.1. Using iSCSI for storing virtual disk images

This section demonstrates how to set up an iSCSI target on Red Hat Enterprise Linux and how to configure iSCSI on a libvirt KVM host using virsh, and finally how to provision a guest on iSCSI using virt-install.

重要

Setting up a Red Hat Enterprise Linux server as an iSCSI target is not recommended. The example used in this section should not be used in production, and is provided as an example which should only be referred to for basic shared storage testing and educational purposes.

23.1.1. How to set up an iSCSI target on Red Hat Enterprise Linux

  1. Install and enable the iSCSI target service

    Install and enable the iSCSI target service with the following commands:
    # yum install scsi-target-utils
    # chkconfig tgtd on
    # service tgtd start
    

    重要

    The scsi-target-utils package required for this example is provided only in the Cluster Storage add-on for Red Hat Enterprise Linux 5, and may not be available for your system. Contact your support agent to activate this add-on if you are currently unable to install this package.
  2. Allocate storage for the LUNs

    The iSCSI target service is not dependent on a particular type of exported LUN. The LUNs can be plain files, LVM volumes, or block devices. There is however a performance overhead if using the LVM and/or file system layers as compared to block devices. The guest providing the iSCSI service in this example has no spare block or LVM devices, so raw files will be used.
    This example demonstrates the creation of two LUNs; one is a 10GB thin-provisioned (sparse file) LUN, and the other has 500MB, of which are fully-allocated. The following commands will achieve this configuration. Be aware that your environment will be different and this is provided only as an example:
    # mkdir -p /var/lib/tgtd/kvmguest
    # dd if=/dev/zero of=/var/lib/tgtd/kvmguest/rhelx86_64.img bs=1M seek=10240 count=0
    # dd if=/dev/zero of=/var/lib/tgtd/kvmguest/shareddata.img bs=1M count=512
    # restorecon -R /var/lib/tgtd
    
  3. Export the iSCSI target and LUNs

    For Red Hat Enterprise Linux 5, a series of tgtadm commands is required to create a target and associate the storage volumes created earlier. First, the following command adds a target using an iSCSI Qualified Name (IQN):
    # tgtadm --lld iscsi --op new --mode target --tid 1 --targetname \ 
    iqn.2004-04.rhel:rhel5:iscsi.kvmguest
    
    Now the storage volumes must be associated with LUNs in the iSCSI target with these two commands:
    # tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 \
    --backing-store /var/lib/tgtd/kvmguest/rhelx86_64.img
    
    # tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 2 \
    --backing-store /var/lib/tgtd/kvmguest/shareddata.img
    

    重要

    Add the previous 3 tgtadm commands to the end of the /etc/rc.local file to ensure normal operation upon restarting of the system.
    To confirm the successful operation of the previous commands, query the iSCSI target setup:
    tgtadm --lld iscsi --op show --mode target
    Target 1: iqn.2004-04.rhel:rhel5:iscsi.kvmguest
        System information:
            Driver: iscsi
            State: ready
        I_T nexus information:
        LUN information:
            LUN: 0
                Type: controller
                SCSI ID: IET     00010000
                SCSI SN: beaf10
                Size: 0 MB, Block size: 1
                Online: Yes
                Removable media: No
                Readonly: No
                Backing store type: null
                Backing store path: None
                Backing store flags: 
            LUN: 1
                Type: disk
                SCSI ID: IET     00010001
                SCSI SN: beaf11
                Size: 10737 MB, Block size: 512
                Online: Yes
                Removable media: No
                Readonly: No
                Backing store type: rdwr
                Backing store path: /var/lib/tgtd/kvmguest/rhelx86_64.img
                Backing store flags: 
            LUN: 2
                Type: disk
                SCSI ID: IET     00010002
                SCSI SN: beaf12
                Size: 537 MB, Block size: 512
                Online: Yes
                Removable media: No
                Readonly: No
                Backing store type: rdwr
                Backing store path: /var/lib/tgtd/kvmguest/shareddata.img
                Backing store flags: 
        Account information:
        ACL information:
    
  4. Allow client access to the target

    Finally, this example command allows access to all clients without any authentication:
    # tgtadm --lld iscsi --op bind --mode target --tid 1 --initiator-address ALL
    

Two common mistakes

The two most common problems encountered when configuring the iSCSI target are SELinux and iptables. If adding plain files as LUNs in an iSCSI target, ensure the files are labelled system_u:object_r:tgtd_var_lib_t:s0. TCP port 3260 must also be open in your iptables configuration.

23.1.2. How to configure iSCSI on a libvirt KVM host and provision a guest using virt-install

The previous section described how to set up an iSCSI target. This section demonstrates how to configure iSCSI on a libvirt KVM instance using virsh, and then how to provision a guest using virt-install.
  1. Defining the storage pool

    All libvirt storage is managed through storage pools, of which there are many possible types: SCSI, NFS, ext4, plain directory and iSCSI. All libvirt objects are configured via XML description files, and storage pools are no different in this regard. For an iSCSI storage pool there are three important pieces of information to provide:
    • The target path - this determines how libvirt will expose device paths for the pool. Paths like /dev/sda and /dev/sdb are not an ideal choice as they can change between reboots, and can change across machines within a cluster; in other words, the names are assigned on a first come, first served basis by the kernel. It is strongly recommended to use the /dev/disk/by-path format. This results in a consistent naming scheme across all machines.
    • The host name - this is simply the fully-qualified DNS name of the iSCSI server.
    • The source path - this is the iSCSI qualified name (IQN) seen in the previous setup procedure (iqn.2004-04.rhel:rhel5:iscsi.kvmguest).
    Although your environment will likely be different, the following text is what an iSCSI configuration will look like:
    <pool type='iscsi'>
        <name>kvmguest</name>
        <source>
            <host name='myiscsi.example.com'/>
            <device path='iqn.2004-04.rhel:rhel5:iscsi.kvmguest'/>
        </source>
        <target>
            <path>/dev/disk/by-path</path>
        </target>
    </pool>
    
    Save this XML code to a file named iscsirhel5.xml and load it into libvirt using the pool-define command:
    # virsh pool-define iscsirhel5.xml
    Pool kvmguest defined from iscsirhel5.xml
    
    # virsh pool-list --all
    Name                 State      Autostart
    -----------------------------------------
    default              active     yes
    kvmguest             inactive   no
    
  2. Starting the storage pool

    The configuration is saved, but the iSCSI target has not yet been logged into, so no LUNs will be visible on the host at this point. Use the pool-start command the make the LUNs visible with the vol-list command.
    # virsh pool-start kvmguest
    Pool kvmguest started
    
    # virsh vol-list kvmguest
    Name                 Path
    -----------------------------------------
    10.0.0.1             /dev/disk/by-path/ip-192.168.122.2:3260-iscsi-iqn.2004-04.rhel:rhel5:iscsi.kvmguest-lun-1
    10.0.0.2             /dev/disk/by-path/ip-192.168.122.2:3260-iscsi-iqn.2004-04.rhel:rhel5:iscsi.kvmguest-lun-2
    
  3. Querying LUN information

    Further information about each LUN can be obtained using the vol-info and vol-dumpxml commands:
    # virsh vol-info /dev/disk/by-path/ip-192.168.122.2:3260-iscsi-iqn.2004-04.rhel:rhel5:iscsi.kvmguest-lun-1
    
    Name:           10.0.0.1
    Type:           block
    Capacity:       10.00 GB
    Allocation:     10.00 GB
    
    
    # virsh vol-dumpxml /dev/disk/by-path/ip-192.168.122.2:3260-iscsi-iqn.2004-04.rhel:rhel5:iscsi.kvmguest-lun-1
    <volume>
      <name>10.0.0.1</name>
      <key>/dev/disk/by-path/ip-192.168.122.2:3260-iscsi-iqn.2004-04.rhel:rhel5:iscsi.kvmguest-lun-1</key>
      <source>
      </source>
      <capacity>10737418240</capacity>
      <allocation>10737418240</allocation>
      <target>
        <path>/dev/disk/by-path/ip-192.168.122.2:3260-iscsi-iqn.2004-04.rhel:rhel5:iscsi.kvmguest-lun-2</path>
        <format type='unknown'/>
        <permissions>
          <mode>0660</mode>
          <owner>0</owner>
          <group>6</group>
          <label>system_u:object_r:fixed_disk_device_t:s0</label>
        </permissions>
      </target>
    </volume>
    
  4. Activating the storage at boot time

    If everything is configured properly, the pool can be set to start automatically upon booting of the host:
    # virsh pool-autostart kvmguest
    Pool kvmguest marked as autostarted
    
  5. Provisioning a guest on iSCSI

    The virt-install command can be used to install new guests from the command line. The --disk argument can take the name of a storage pool, followed by the name of any contained volumes. Continuing this example, the following command will begin the installation of a guest with two disks; the first disk is the root file system, the second disk can be shared between multiple guests for common data:
    # virt-install --accelerate --name rhelx86_64 --ram 800 --vnc --disk \ vol=kvmguest/10.0.0.1 --disk vol=kvmguest/10.0.0.2,perms=sh --pxe
    
    Once this rhelx86_64 guest is installed, the following command and output shows the XML that virt-install used to associate the guest with the iSCSI LUNs:
    # virsh dumpxml rhelx86_64
    
    <domain type='kvm' id='4'>
      <name>rhelx86_64</name>
      <uuid>ad8961e9-156f-746f-5a4e-f220bfafd08d</uuid>
      <memory>819200</memory>
      <currentMemory>819200</currentMemory>
      <vcpu>1</vcpu>
      <os>
        <type arch='x86_64' machine='rhel'>hvm</type>
        <boot dev='network'/>
      </os>
      <features>
        <acpi/>
        <apic/>
        <pae/>
      </features>
      <clock offset='utc'/>
      <on_poweroff>destroy</on_poweroff>
      <on_reboot>destroy</on_reboot>
      <on_crash>destroy</on_crash>
      <devices>
        <emulator>/usr/libexec/qemu-kvm</emulator>
        <disk type='block' device='disk'>
          <driver name='qemu' type='raw'/>
          <source dev='/dev/disk/by-path/ip-192.168.122.170:3260-iscsi-iqn.2004-04.rhel:rhel5:iscsi.kvmguest-lun-1'/>
          <target dev='hda' bus='ide'/>
          <alias name='ide0-0-0'/>
          <address type='drive' controller='0' bus='0' unit='0'/>
        </disk>
        <disk type='block' device='disk'>
          <driver name='qemu' type='raw'/>
          <source dev='/dev/disk/by-path/ip-192.168.122.170:3260-iscsi-iqn.2004-04.rhel:rhel5:iscsi.kvmguest-lun-2'/>
          <target dev='hdb' bus='ide'/>
          <shareable/>
          <alias name='ide0-0-1'/>
          <address type='drive' controller='0' bus='0' unit='1'/>
        </disk>
        <controller type='ide' index='0'>
          <alias name='ide0'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
        </controller>
        <interface type='network'>
          <mac address='52:54:00:0a:ca:84'/>
          <source network='default'/>
          <target dev='vnet1'/>
          <alias name='net0'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
        </interface>
        <serial type='pty'>
          <source path='/dev/pts/28'/>
          <target port='0'/>
          <alias name='serial0'/>
        </serial>
        <console type='pty' tty='/dev/pts/28'>
          <source path='/dev/pts/28'/>
          <target port='0'/>
          <alias name='serial0'/>
        </console>
        <input type='mouse' bus='ps2'/>
        <graphics type='vnc' port='5901' autoport='yes' keymap='en-us'/>
        <video>
          <model type='cirrus' vram='9216' heads='1'/>
          <alias name='video0'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
        </video>
      </devices>
    </domain>
    
    There are two important items of note in this output:
    • The guest uses the large /dev/disk/by-path paths to refer to the LUNs. As described earlier, this is so that file names and paths will remain constant.
    • The second disk has the <shareable/> flag set. Critical for the disk to be safely shared between guests, this ensures that the SELinux labelling will be appropriate for multiple guests to access the disk and that all I/O caching is disabled on the host.
For migration of guests between hosts to succeed, some form of shared storage is required. Although NFS is often used for this purpose, the lack of SELinux labelling for NFS means there is limited sVirt protection between guests. This lack of sVirt support could allow one guest to use another guest's disks, which is usually undesirable.
Using iSCSI provides full sVirt isolation between guests to the same degree of non-shared storage.

部 VI. 虛​擬​化​參​考​指​南​

虛​擬​化​指​令​、​系​統​工​具​、​應​用​程​式​與​其​他​的​系​統​參​考​資​料​

這​些​章​節​提​供​了​ Red Hat Enterprise Linux 的​虛​擬​化​指​令​、​系​統​工​具​、​以​及​應​用​程​式​之​詳​細​描​述​。​這​些​章​節​乃​針​對​需​要​進​階​功​能​資​訊​的​使​用​者​所​撰​寫​。​

章 24. 虛​擬​化​工​具​

以​下​是​虛​擬​化​管​理​工​具​、​除​錯​與​網​路​工​具​的​清​單​,這​些​工​具​有​助​於​執​行​ Xen 的​系​統​。​
系​統​管​理​員​工​具​
  • vmstat
  • iostat
  • lsof
    # lsof -i :5900
    xen-vncfb 10635  root  5u  IPv4 218738  TCP grumble.boston.redhat.com:5900 (LISTEN)
    
  • qemu-img
進​階​的​除​錯​工​具​
  • systemTap
  • crash
  • xen-gdbserver
  • sysrq
  • sysrq t
  • sysrq w
  • sysrq c
網​路​作​業​
brtcl
  • # brctl show
    bridge name  bridge id            STP enabled    interfaces
    xenbr0       8000.feffffffffff    no             vif13.0
    						 pdummy0
                                                     vif0.0
    
  • # brctl showmacs xenbr0
    port no  mac addr                is local?       aging timer
      1      fe:ff:ff:ff:ff:ff       yes             0.00
    
  • # brctl showstp xenbr0
    xenbr0
    bridge id              8000.feffffffffff
    designated root        8000.feffffffffff
    root port              0                    path cost                 0
    max age                20.00                bridge max age            20.00
    hello time             2.00                 bridge hello time         2.00
    forward delay          0.00                 bridge forward delay      0.00
    aging time            300.01
    hello timer            1.43                 tcn timer                 0.00
    topology change timer  0.00                 gc timer                  0.02
    flags
    
    vif13.0 (3)
    port id                8003                 state                    forwarding
    designated root        8000.feffffffffff    path cost                100
    designated bridge      8000.feffffffffff    message age timer        0.00
    designated port        8003                 forward delay timer      0.00
    designated cost        0                    hold timer               0.43
    flags
    
    pdummy0 (2)
    port id                8002                 state                    forwarding
    designated root        8000.feffffffffff    path cost                100
    designated bridge      8000.feffffffffff    message age timer        0.00
    designated port        8002                 forward delay timer      0.00
    designated cost        0                    hold timer               0.43
    flags
    
    vif0.0 (1)
    port id                8001                 state                    forwarding
    designated root        8000.feffffffffff    path cost                100
    designated bridge      8000.feffffffffff    message age timer        0.00
    designated port        8001                 forward delay timer      0.00
    designated cost        0                    hold timer               0.43
    flags
    
  • ifconfig
  • tcpdump
KVM 工​具​
  • ps
  • pstree
  • top
  • kvmtrace
  • kvm_stat
Xen 工​具​
  • xentop
  • xm dmesg
  • xm log

章 25. 透​過​ virsh 來​管​理​客​座​端​

virsh 是​個​用​來​管​理​客​座​端​和​ hypervisor(管​理​程​序​)的​指​令​列​介​面​工​具​。​
virsh 這​項​工​具​建​置​於​ libvirt 管​理​ API 上​,並​且​可​作​為​替​代​ xm 工​具​和​圖​形​化​客​座​端​管​理​程​式​(virt-manager)的​額​外​選​項​來​進​行​作​業​。​無​權​限​的​使​用​者​只​可​使​用​ virsh 的​唯​讀​模​式​。​您​可​使​用​ virsh 來​執​行​客​座​端​機​器​的​ script。​
virsh 指​令​快​速​參​照​指​南​
下​列​表​格​提​供​了​所​有​ virsh 指​令​列​選​項​的​快​速​參​照​指​南​。​
表格 25.1. 客​座​端​管​理​指​令​
指​令​ 描​述​
help 印​出​基​本​協​助​資​訊​。​
list 列​出​所​有​客​座​端​。​
dumpxml 輸​出​客​座​端​的​ XML 配​置​檔​案​。​
create 由​一​個​ XML 配​置​檔​案​來​建​立​客​座​端​並​啟​用​新​的​客​座​端​。​
start 啟​用​一​個​未​啟​用​中​的​客​座​端​。​
destroy 強​制​客​座​端​停​下​。​
define 輸​出​客​座​端​的​ XML 配​置​檔​案​。​
domid Displays the guest's ID.
domuuid Displays the guest's UUID.
dominfo 顯​示​客​座​端​的​相​關​資​訊​。​
domname Displays the guest's name.
domstate 顯​示​客​座​端​的​狀​態​。​
quit 退​出​互​動​式​終​端​機​。​
reboot 重​新​啟​動​客​座​端​。​
restore 恢​復​之​前​已​儲​存​於​一​個​檔​案​中​的​客​座​端​。​
resume 恢​復​一​個​暫​停​中​的​客​座​端​。​
save 將​客​座​端​目​前​的​狀​態​儲​存​至​一​個​檔​案​中​。​
shutdown 正​常​地​停​用​客​座​端​。​
suspend 將​客​座​端​暫​停​。​
undefine 刪​除​與​某​個​客​座​端​有​關​聯​的​所​有​檔​案​。​
migrate 將​客​座​端​遷​移​至​另​一​部​主​機​上​。​

請​使​用​下​列​ virsh 指​令​選​項​,來​管​理​客​座​端​和​ hypervisor 資​源​:
表格 25.2. 資​源​管​理​選​項​
指​令​ 描​述​
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 將​網​路​介​面​卡​由​客​座​端​上​移​除​。​

以​下​為​其​它​的​ virsh 指​令​:
表格 25.3. 其​它​選​項​
指​令​ 描​述​
version 顯​示​ virsh 的​版​本​
nodeinfo 輸​出​有​關​於​ hypervisor 的​相​關​資​訊​

連​至​ hypervisor
透​過​ virsh 來​連​至​一​個​ hypervisor session:
# virsh connect {hostname OR URL}
<name> 為​ hypervisor 的​機​器​名​稱​。​若​您​希​望​進​行​唯​讀​的​連​線​,請​搭​配​使​用​上​述​指​令​與​ -readonly。​
建​立​一​個​虛​擬​機​器​的​ XML 傾​印​(配​置​檔​案​)
Output a guest's XML configuration file with virsh:
# virsh dumpxml {domain-id, domain-name or domain-uuid}
This command outputs the guest's XML configuration file to standard out (stdout). You can save the data by piping the output to a file. An example of piping the output to a file called guest.xml:
# virsh dumpxml GuestID > guest.xml
This file guest.xml can recreate the guest (refer to Editing a guest's configuration file. You can edit this XML configuration file to configure additional devices or to deploy additional guests. Refer to 節 33.1, “搭​配​使​用​ virsh 與​ XML 配​置​檔​案​” for more information on modifying files created with virsh dumpxml.
virsh dumpxml 輸​出​的​範​例​:
# virsh dumpxml r5b2-mySQL01
<domain type='xen' id='13'>
    <name>r5b2-mySQL01</name>
    <uuid>4a4c59a7ee3fc78196e4288f2862f011</uuid>
    <bootloader>/usr/bin/pygrub</bootloader>
    <os>
        <type>linux</type>
        <kernel>/var/lib/libvirt/vmlinuz.2dgnU_</kernel>
	<initrd>/var/lib/libvirt/initrd.UQafMw</initrd>
        <cmdline>ro root=/dev/VolGroup00/LogVol00 rhgb quiet</cmdline>
    </os>
    <memory>512000</memory>
    <vcpu>1</vcpu>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>restart</on_crash>
    <devices>
        <interface type='bridge'>
            <source bridge='xenbr0'/>
            <mac address='00:16:3e:49:1d:11'/>
            <script path='vif-bridge'/>
        </interface>
        <graphics type='vnc' port='5900'/>
        <console tty='/dev/pts/4'/>
    </devices>
</domain>
由​配​置​檔​案​建​立​客​座​端​
Guests can be created from XML configuration files. You can copy existing XML from previously created guests or use the dumpxml option (refer to 建​立​一​個​虛​擬​機​器​的​ XML 傾​印​(配​置​檔​案​)). To create a guest with virsh from an XML file:
# virsh create configuration_file.xml
Editing a guest's configuration file
Instead of using the dumpxml option (refer to 建​立​一​個​虛​擬​機​器​的​ XML 傾​印​(配​置​檔​案​)) guests can be edited either while they run or while they are offline. The virsh edit command provides this functionality. For example, to edit the guest named softwaretesting:
# virsh edit softwaretesting
這​將​會​開​啟​一​個​文​字​編​輯​器​。​預​設​文​字​編​輯​器​為​ $EDITOR shell 參​數​(預​設​值​為​ vi)。​
中​止​客​座​端​
透​過​ virsh 來​中​止​客​座​端​:
# virsh suspend {domain-id, domain-name or domain-uuid}
When a guest is in a suspended state, it consumes system RAM but not processor resources. Disk and network I/O does not occur while the guest is suspended. This operation is immediate and the guest can be restarted with the resume (復​原​客​座​端​) option.
復​原​客​座​端​
透​過​ virsh 指​令​和​ resume 選​項​來​恢​復​使​用​一​個​中​止​的​客​座​端​:
# virsh resume {domain-id, domain-name or domain-uuid}
這​項​作​業​會​即​刻​執​行​,而​客​座​端​參​數​會​被​保​存​來​進​行​ suspend 和​ resume 作​業​。​
儲​存​客​座​端​
透​過​使​用​ virsh 指​令​來​將​客​座​端​目​前​的​狀​態​儲​存​至​一​個​檔​案​中​:
# virsh save {domain-name, domain-id or domain-uuid} filename
This stops the guest you specify and saves the data to a file, which may take some time given the amount of memory in use by your guest. You can restore the state of the guest with the restore (復​原​客​座​端​) option. Save is similar to pause, instead of just pausing a guest the present state of the guest is saved.
復​原​客​座​端​
Restore a guest previously saved with the virsh save command (儲​存​客​座​端​) using virsh:
# virsh restore filename
This restarts the saved guest, which may take some time. The guest's name and UUID are preserved but are allocated for a new id.
關​閉​客​座​端​
透​過​使​用​ virsh 指​令​來​關​閉​客​座​端​:
# virsh shutdown {domain-id, domain-name or domain-uuid}
You can control the behavior of the rebooting guest by modifying the on_shutdown parameter in the guest's configuration file.
重​新​啟​動​客​座​端​
使​用​ virsh 指​令​來​重​新​啟​動​客​座​端​:
#virsh reboot {domain-id, domain-name or domain-uuid}
You can control the behavior of the rebooting guest by modifying the on_reboot element in the guest's configuration file.
強​制​客​座​端​停​止​
透​過​使​用​ virsh 指​令​來​停​止​客​座​端​:
# virsh destroy {domain-id, domain-name or domain-uuid}
This command does an immediate ungraceful shutdown and stops the specified guest. Using virsh destroy can corrupt guest file systems . Use the destroy option only when the guest is unresponsive. For para-virtualized guests, use the shutdown option(關​閉​客​座​端​) instead.
取​得​客​座​端​的​網​域​ ID
若​要​取​得​客​座​端​的​網​域​ ID:
# virsh domid {domain-name or domain-uuid}
取​得​客​座​端​的​網​域​名​稱​
若​要​取​得​客​座​端​的​網​域​名​稱​:
# virsh domname {domain-id or domain-uuid}
取​得​客​座​端​的​ UUID
若​要​取​得​客​座​端​的​ UUID:
# virsh domuuid {domain-id or domain-name}
virsh domuuid 指​令​輸​出​的​範​例​:
# virsh domuuid r5b2-mySQL01
4a4c59a7-ee3f-c781-96e4-288f2862f011
顯​示​客​座​端​資​訊​
Using virsh with the guest's domain ID, domain name or UUID you can display information on the specified guest:
# virsh dominfo {domain-id, domain-name or domain-uuid}
以​下​為​來​自​ virsh dominfo 指​令​的​輸​出​範​例​:
# virsh dominfo r5b2-mySQL01
id:             13
name:           r5b2-mysql01
uuid:           4a4c59a7-ee3f-c781-96e4-288f2862f011
os type:      	linux
state:          blocked
cpu(s):         1
cpu time:     	11.0s
max memory:     512000 kb
used memory:    512000 kb
顯​示​主​機​資​訊​
若​要​顯​示​主​機​的​相​關​資​訊​:
# virsh nodeinfo
virsh nodeinfo 指​令​輸​出​的​範​例​:
# virsh nodeinfo
CPU model                    x86_64
CPU (s)                      8
CPU frequency                2895 Mhz
CPU socket(s)                2      
Core(s) per socket           2
Threads per core:            2
Numa cell(s)                 1
Memory size:                 1046528 kb
這​會​顯​示​節​點​的​資​訊​,以​及​支​援​虛​擬​化​程​序​的​主​機​。​
顯​示​客​座​端​
透​過​使​用​ virsh 來​顯​示​客​座​端​清​單​以​及​它​們​目​前​的​狀​態​:
# virsh list
其​它​可​用​選​項​包​含​:
--inactive 選​項​可​列​出​非​啟​用​中​的​客​座​端​(也​就​是​已​定​義​但​尚​未​啟​用​的​客​座​端​),以​及​
--all 選​項​將​會​列​出​所​有​客​座​端​。​例​如​:
# virsh list --all
 Id Name                 State
----------------------------------
  0 Domain-0             running
  1 Domain202            paused
  2 Domain010            inactive
  3 Domain9600           crashed
來​自​於​ virsh list 的​輸​出​被​分​為​下​列​六​個​狀​態​的​其​中​之​一​。​
  • running 狀​態​代​表​ CPU 上​正​啟​用​中​的​客​座​端​。​
  • 被​列​為​ blocked 的​客​座​端​已​被​封​鎖​,並​且​沒​有​在​執​行​中​或​是​無​法​執​行​。​這​可​能​是​因​為​客​座​端​等​待​ I/O(傳​統​的​等​待​狀​態​)或​是​客​座​端​進​入​睡​眠​模​式​所​造​成​的​。​
  • paused 狀​態​會​列​出​被​暫​停​的​網​域​。​若​是​有​位​系​統​管​理​員​使​用​了​ virt-manager 中​的​ pause 按​鈕​、​xm pause 或​ virsh suspend 的​話​,這​就​有​可​能​會​發​生​。​當​客​座​端​暫​停​時​,它​會​消​耗​記​憶​體​與​其​它​資​源​,不​過​它​無​法​透​過​ hypervisor 來​進​行​記​憶​體​與​ CPU 資​源​的​排​程​。​
  • shutdown 狀​態​為​正​在​進​行​關​閉​程​序​的​客​座​端​。​客​座​端​會​收​到​一​則​關​閉​訊​號​,並​且​應​該​要​正​常​地​進​行​它​的​作​業​關​閉​程​序​。​這​也​許​無​法​適​用​於​所​有​客​座​端​作​業​系​統​;有​些​作​業​系​統​不​會​回​應​這​些​訊​號​。​
  • 狀​態​為​ dying 的​網​域​正​處​於​關​閉​狀​態​中​,在​此​狀​態​下​,網​域​還​未​完​全​關​閉​或​當​機​。​
  • 狀​態​為​ crashed 的​客​座​端​在​執​行​時​發​生​了​錯​誤​並​且​已​不​再​運​作​了​。​此​狀​態​只​可​能​在​客​座​端​被​設​為​當​機​時​不​會​重​新​啟​動​的​情​況​下​才​會​發​生​。​
顯​示​虛​擬​ CPU 資​訊​
透​過​ virsh 來​由​客​座​端​顯​示​虛​擬​ CPU 資​訊​:
# virsh vcpuinfo {domain-id, domain-name or domain-uuid}
virsh vcpuinfo 指​令​的​輸​出​範​例​:
# virsh vcpuinfo r5b2-mySQL01
VCPU:           0
CPU:            0
State:          blocked
CPU time:       0.0s
CPU Affinity:   yy
設​定​虛​擬​ CPU 的​相​似​性​
設​定​虛​擬​ CPU 和​實​體​ CPU 的​相​似​性​:
# virsh vcpupin domain-id vcpu cpulist
The domain-id parameter is the guest's ID number or name.
vcpu 參​數​表​示​分​配​給​客​座​端​的​虛​擬​處​理​器​數​目​。​您​必​須​提​供​ vcpu 參​數​。​
cpulist 參​數​是​實​體​處​理​器​的​識​別​號​碼​之​清​單​,這​些​號​碼​會​以​逗​號​隔​開​。​cpulist 參​數​會​決​定​何​種​實​體​處​理​器​是​ VCPU 可​以​在​其​上​執​行​的​。​
設​定​虛​擬​ CPU 計​數​
透​過​ virsh 來​修​改​指​定​給​客​座​端​的​ CPU 數​量​:
# virsh setvcpus {domain-name, domain-id or domain-uuid} count
新​的​ count 計​數​值​不​可​超​過​當​您​建​立​客​座​端​時​所​指​定​的​數​值​。​
設​定​記​憶​體​配​置​
To modify a guest's memory allocation with virsh :
# virsh setmem {domain-id or domain-name} count
您​必​須​以​ kb 為​單​位​來​指​定​「​count」​參​數​。​新​的​ count 值​不​可​超​過​建​立​客​座​端​時​所​指​定​的​數​值​。​低​於​ 64 MB 的​數​值​也​許​無​法​運​作​於​大​部​分​客​座​端​作​業​系​統​上​。​較​高​的​最​大​記​憶​體​數​值​不​會​影​響​目​前​啟​用​中​的​客​座​端​。​如​果​新​的​數​值​較​低​,可​用​記​憶​體​會​變​小​,客​座​端​就​可​能​會​當​機​。​
顯​示​客​座​端​的​區​塊​裝​置​資​訊​
請​使​用​ virsh domblkstat 來​顯​示​啟​用​中​的​客​座​端​的​區​塊​裝​置​數​據​。​
# virsh domblkstat GuestName block-device
顯​示​客​座​端​網​路​裝​置​資​訊​
使​用​ virsh domifstat 來​顯​示​執​行​中​的​客​座​端​的​網​路​介​面​卡​數​據​。​
# virsh domifstat GuestName interface-device 
透​過​ virsh 來​遷​移​客​座​端​
客​座​端​可​藉​由​使​用​ virsh 來​被​遷​移​至​另​一​部​主​機​上​。​將​網​域​遷​移​至​另​一​部​主​機​上​。​附​加​ --live 來​進​行​即​時​遷​移​。​migrate 指​令​接​受​下​列​格​式​的​參​數​:
# virsh migrate --live GuestName DestinationURL
--live 參​數​為​可​選​用​的​參​數​。​請​附​加​ --live 參​數​來​進​行​即​時​遷​移​。​
GuestName 參​數​代​表​您​希​望​遷​移​的​客​座​端​之​名​稱​。​
DestinationURL 參​數​代​表​目​標​系​統​的​ URL 或​主​機​名​稱​。​目​標​系​統​需​要​:
  • 有​著​同​樣​版​本​的​ Red Hat Enterprise Linux、​
  • 同​樣​版​本​的​ hypervisor(KVM 或​ Xen)、​同​時​
  • libvirt 服​務​必​須​要​啟​動​。​
一​旦​輸​入​了​指​令​之​後​,您​將​會​提​示​輸​入​目​標​系​統​的​ root 密​碼​。​
管​理​虛​擬​網​路​
此​部​份​涵​蓋​了​如​何​透​過​ virsh 指​令​來​管​理​虛​擬​網​路​。​若​要​列​出​虛​擬​網​路​請​輸​入​:
# virsh net-list
您​可​以​使​這​項​指​令​來​產​生​類​似​以​下​的​輸​出​:
# virsh net-list
Name                 State      Autostart
-----------------------------------------
default              active     yes      
vnet1	             active     yes      
vnet2	             active     yes
欲​瀏​覽​特​定​虛​擬​網​路​的​網​路​資​訊​:
# virsh net-dumpxml NetworkName
這​會​以​ XML 格​式​顯​示​有​關​於​所​指​定​的​虛​擬​網​路​之​資​訊​:
# virsh net-dumpxml vnet1
<network>
  <name>vnet1</name>
  <uuid>98361b46-1581-acb7-1643-85a412626e70</uuid>
  <forward dev='eth0'/>
  <bridge name='vnet0' stp='on' forwardDelay='0' />
  <ip address='192.168.100.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.100.128' end='192.168.100.254' />
    </dhcp>
  </ip>
</network>
其​它​使​用​來​管​理​虛​擬​網​路​的​ virsh 指​令​還​包​括​:
  • virsh net-autostart 網​路​名​稱​ — 自​動​啟​用​一​個​被​指​定​為​網​路​名​稱​的​網​路​。​
  • virsh net-create XMLfile — 透​過​使​用​現​有​的​ XML 檔​案​來​產​生​並​啟​用​一​個​新​的​網​路​。​
  • virsh net-define XMLfile — 透​過​現​有​的​ XML 檔​案​產​生​新​的​網​路​裝​置​不​過​不​啟​用​該​裝​置​。​
  • virsh net-destroy 網​路​名​稱​ — 刪​除​一​個​被​指​定​為​網​路​名​稱​的​網​路​。​
  • virsh net-name networkUUID — 將​一​個​指​定​的​ networkUUID 轉​換​成​網​路​名​稱​。​
  • virsh net-uuid 網​路​名​稱​ — 將​一​個​指​定​的​網​路​名​稱​轉​換​成​網​路​ UUID。​
  • virsh net-start 未​啟​用​的​網​路​之​名​稱​ — 啟​用​一​個​未​啟​用​的​網​路​。​
  • virsh net-undefine 未​啟​用​的​網​路​之​名​稱​ — 將​未​啟​用​的​網​路​的​定​義​移​除​。​

章 26. 使​用​虛​擬​主​機​管​理​程​式​(Virtual Machine Manager,virt-manager)來​管​理​客​座​端​

本​章​節​將​描​述​虛​擬​主​機​管​理​程​式​(virt-manager)視​窗​、​對​話​方​塊​與​各​種​不​同​的​ GUI 控​制​。​
virt-manager 提​供​了​您​系​統​上​以​及​許​端​機​器​上​的​ hypervisor 和​客​座​端​的​圖​形​化​視​點​。​您​可​使​用​ virt-manager 來​定​義​半​虛​擬​化​和​完​整​虛​擬​化​的​客​座​端​。​virt-manager 可​進​行​虛​擬​化​管​理​工​作​,這​包​含​了​:
  • 分​配​記​憶​體​、​
  • 分​配​虛​擬​ CPU、​
  • 監​控​作​業​效​能​、​
  • 儲​存​和​復​原​、​暫​停​和​恢​復​,以​及​關​閉​和​啟​動​虛​擬​化​客​座​端​、​
  • 連​至​文​字​與​圖​形​化​主​控​台​,以​及​
  • 即​時​與​離​線​遷​移​。​

26.1. The Add Connection window

此​視​窗​將​會​出​現​並​提​示​使​用​者​選​擇​一​個​ hypervisor session。​無​特​權​的​使​用​者​只​可​進​行​唯​讀​的​ session。​Root 使​用​者​可​啟​用​一​個​含​有​完​整​讀​寫​權​限​的​ session。​一​般​使​用​上​請​選​擇​本​機​ Xen 主​機​選​項​或​是​ QEMU(KVM)。​
虛​擬​主​機​管​理​程​式​連​接​視​窗​
圖形 26.1. 虛​擬​主​機​管​理​程​式​連​接​視​窗​

26.2. 虛​擬​主​機​管​理​程​式​的​主​視​窗​

This main window displays all the running guests and resources used by guests. Select a virtualized guest by double clicking the guest's name.
虛​擬​主​機​管​理​程​式​的​主​要​視​窗​
圖形 26.2. 虛​擬​主​機​管​理​程​式​的​主​要​視​窗​

26.3. The guest Overview tab

The Overview tab displays graphs and statistics of a guest's live resource utilization data available from virt-manager. The UUID field displays the globally unique identifier for the virtual machines.
The Overview tab
圖形 26.3. The Overview tab

26.4. 虛​擬​主​機​圖​形​主​控​台​

This window displays a virtual machine's graphical console. Para-virtualized and fully virtualized guests use different techniques to export their local virtual framebuffers, but both technologies use VNC to make them available to the Virtual Machine Manager's console window. If your virtual machine is set to require authentication, the Virtual Machine Graphical console prompts you for a password before the display appears.
圖​形​化​主​控​台​視​窗​
圖形 26.4. 圖​形​化​主​控​台​視​窗​

安​全​性​和​ VNC 上​的​重​點​

VNC is considered insecure by many security experts, however, several changes have been made to enable the secure usage of VNC for virtualization on Red Hat enterprise Linux. The guest machines only listen to the local host (dom0)'s loopback address (127.0.0.1). This ensures only those with shell privileges on the host can access virt-manager and the virtual machine through VNC.
Remote administration can be performed following the instructions in 章 22, 虛​擬​化​客​座​端​的​遠​端​管​理​. TLS can provide enterprise level security for managing guest and host systems.
Your local desktop can intercept key combinations (for example, Ctrl+Alt+F11) to prevent them from being sent to the guest machine. You can use the virt-manager sticky key capability to send these sequences. To use this capability, you must press any modifier key (Ctrl or Alt) 3 times and the key you specify gets treated as active until the next non-modifier key is pressed. You can then send Ctrl-Alt-F11 to the guest by entering the key sequence 'Ctrl Ctrl Ctrl Alt+F1'.

注意

Due to a limitation of virt-manager, it is not possible to use this sticky key feature to send a Sysrq key combination to a guest.

26.5. 啟​動​ virt-manager

若​要​啟​用​ virt-manager session,請​開​啟​應​用​程​式​選​單​、​系​統​工​具​選​單​,然​後​再​點​選​虛​擬​主​機​管​理​員​virt-manager
virt-manager 的​主​視​窗​將​會​出​現​。​
啟​用​ virt-manager
圖形 26.5. 啟​用​ virt-manager

Alternatively, virt-manager can be started remotely using ssh as demonstrated in the following command:
ssh -X host's address[remotehost]# virt-manager
Using ssh to manage virtual machines and hosts is discussed further in 節 22.1, “透​過​使​用​ SSH 來​進​行​遠​端​管​理​”.

26.6. 復​原​已​儲​存​的​機​器​

在​您​啟​用​虛​擬​主​機​管​理​員​之​後​,所​有​於​系​統​上​的​虛​擬​主​機​都​會​顯​示​於​主​視​窗​中​。​Domain0 為​您​的​主​機​系​統​。​如​果​沒​有​任​何​主​機​被​顯​示​出​,這​就​表​示​目​前​系​統​尚​無​主​機​執​行​中​。​
復​原​之​前​已​儲​存​的​ session:
  1. 請​由​檔​案​選​單​中​選​取​復​原​一​部​儲​存​的​主​機​。​
    復​原​一​部​虛​擬​主​機​
    圖形 26.6. 復​原​一​部​虛​擬​主​機​

  2. 復​原​虛​擬​主​機​主​視​窗​將​會​出​現​。​
  3. 導​引​至​正​確​的​目​錄​然​後​選​取​已​儲​存​的​ session 檔​案​。​
  4. 點​選​開​啟​。​
已​儲​存​的​虛​擬​系​統​會​出​現​在​虛​擬​主​機​管​理​員​的​主​視​窗​中​。​
已​復​原​的​虛​擬​主​機​管​理​員​ session
圖形 26.7. 已​復​原​的​虛​擬​主​機​管​理​員​ session

26.7. 顯​示​客​座​端​詳​細​資​訊​

您​可​以​使​用​虛​擬​主​機​監​控​程​式​(Virtual Machine Monitor)來​瀏​覽​您​系​統​上​任​何​虛​擬​主​機​的​活​動​資​料​資​訊​。​
To view a virtual system's details:
  1. 請​在​虛​擬​主​機​管​理​主​視​窗​中​,選​取​您​欲​檢​視​的​虛​擬​主​機​。​
    選​取​欲​顯​示​的​虛​擬​主​機​
    圖形 26.8. 選​取​欲​顯​示​的​虛​擬​主​機​

  2. From the Virtual Machine Manager Edit menu, select Machine Details (or click the Details button on the bottom of the Virtual Machine Manager main window).
    Displaying the overview window
    圖形 26.9. Displaying the overview window

    On the Virtual Machine window, click the Overview tab.
    The Overview tab summarizes CPU and memory usage for the virtualized guest you specified.
    顯​示​客​座​端​詳​細​資​料​總​覽​
    圖形 26.10. 顯​示​客​座​端​詳​細​資​料​總​覽​

  3. On the Virtual Machine window, click the Hardwaretab.
    顯​示​客​座​端​硬​體​詳​細​資​料​
    圖形 26.11. 顯​示​客​座​端​硬​體​詳​細​資​料​

  4. 請​在​硬​體​分​頁​上​點​選​處​理​器​來​檢​視​或​更​改​目​前​的​處​理​器​配​置​。​
    處​理​器​配​置​面​板​
    圖形 26.12. 處​理​器​配​置​面​板​

  5. 請​在​硬​體​分​頁​上​點​選​ 記​憶​體​來​檢​視​或​更​改​目​前​的​ RAM 記​憶​體​配​置​。​
    顯​示​記​憶​體​配​置​
    圖形 26.13. 顯​示​記​憶​體​配​置​

  6. 請​在​硬​體​分​頁​上​點​選​磁​碟​來​檢​視​或​更​改​目​前​的​硬​碟​組​態​設​定​。​
    顯​示​磁​碟​的​組​態​設​定​
    圖形 26.14. 顯​示​磁​碟​的​組​態​設​定​

  7. On the Hardware tab, click on NIC to view or change the current network configuration.
    顯​示​網​路​的​組​態​設​定​
    圖形 26.15. 顯​示​網​路​的​組​態​設​定​

26.8. 狀​態​監​控​

Status status monitoring preferences can be modified with virt-manager's preferences window.
To configure status monitoring:
  1. 請​由​編​輯​選​單​中​選​取​偏​好​設​定​。​
    修​改​客​座​端​上​的​偏​好​設​定​
    圖形 26.16. 修​改​客​座​端​上​的​偏​好​設​定​

    The Preferences window appears.
  2. From the Stats tab specify the time in seconds or stats polling options.
    設​定​狀​態​監​控​
    圖形 26.17. 設​定​狀​態​監​控​

26.9. 顯​示​客​座​端​的​標​識​符​號​

如​欲​檢​視​您​系​統​上​所​有​虛​擬​主​機​的​客​座​端​ ID:
  1. 請​由​檢​視​選​單​中​選​取​網​域​ ID 核​取​方​塊​。​
    檢​視​客​座​端​ ID
    圖形 26.18. 檢​視​客​座​端​ ID

  2. 虛​擬​主​機​管​理​程​式​會​將​您​系​統​上​所​有​網​域​的​網​域​ ID 列​出​。​
    顯​示​網​域​ ID
    圖形 26.19. 顯​示​網​域​ ID

26.10. Displaying a guest's status

瀏​覽​所​有​系​統​上​虛​擬​主​機​的​狀​態​:
  1. 請​由​檢​視​選​單​中​選​取​狀​態​核​取​方​塊​。​
    Selecting a virtual machine's status
    圖形 26.20. Selecting a virtual machine's status

  2. 虛​擬​主​機​管​理​程​式​會​將​您​系​統​上​所​有​虛​擬​主​機​的​狀​態​列​出​。​
    Displaying a virtual machine's status
    圖形 26.21. Displaying a virtual machine's status

26.11. 顯​示​虛​擬​ CPU

欲​檢​視​您​系​統​上​所​有​虛​擬​主​機​的​虛​擬​ CPU 數​量​:
  1. 請​在​檢​視​選​單​中​選​取​虛​擬​ CPU 的​核​取​方​塊​。​
    選​擇​虛​擬​ CPU 的​選​項​
    圖形 26.22. 選​擇​虛​擬​ CPU 的​選​項​

  2. 虛​擬​主​機​管​理​員​會​將​系​統​上​所​有​虛​擬​主​機​的​虛​擬​ CPU 列​出​。​
    顯​示​虛​擬​ CPU
    圖形 26.23. 顯​示​虛​擬​ CPU

26.12. 顯​示​ CPU 使​用​率​

欲​檢​視​您​系​統​上​所​有​虛​擬​主​機​的​ CPU 使​用​率​:
  1. 請​在​檢​視​選​單​中​選​取​ CPU 使​用​率​核​取​方​塊​。​
    選​擇​ CPU 使​用​量​
    圖形 26.24. 選​擇​ CPU 使​用​量​

  2. 虛​擬​主​機​管​理​員​會​將​系​統​上​所​有​虛​擬​主​機​的​ CPU 使​用​比​率​列​出​。​
    顯​示​ CPU 使​用​率​
    圖形 26.25. 顯​示​ CPU 使​用​率​

26.13. 顯​示​記​憶​體​使​用​率​

檢​視​系​統​上​所​有​虛​擬​主​機​的​記​憶​體​使​用​率​:
  1. 請​在​檢​視​選​單​中​選​取​記​憶​體​使​用​率​核​取​方​塊​。​
    選​擇​記​憶​體​使​用​率​
    圖形 26.26. 選​擇​記​憶​體​使​用​率​

  2. 虛​擬​主​機​管​理​員​會​將​系​統​上​所​有​虛​擬​主​機​的​記​憶​體​(以​ MB 為​單​位​)使​用​比​率​列​出​。​
    顯​示​記​憶​體​使​用​率​
    圖形 26.27. 顯​示​記​憶​體​使​用​率​

26.14. 管​理​虛​擬​網​路​

欲​在​您​的​系​統​上​設​定​虛​擬​網​路​:
  1. 請​在​編​輯​選​單​中​選​取​主​機​資​料​。​
    Selecting a host's details
    圖形 26.28. Selecting a host's details

  2. 這​將​會​開​啟​主​機​資​料​選​單​。​請​點​選​虛​擬​網​路​分​頁​。​
    虛​擬​網​路​組​態​設​定​
    圖形 26.29. 虛​擬​網​路​組​態​設​定​

  3. 所​有​可​用​的​虛​擬​網​路​都​會​列​在​選​單​左​邊​的​方​塊​上​。​您​可​以​從​這​個​方​塊​選​擇​虛​擬​網​路​組​態​設​定​並​加​以​編​輯​。​

26.15. 建​立​一​個​虛​擬​網​路​

在​您​的​系​統​上​建​立​一​個​虛​擬​網​路​:
  1. Open the Host Details menu (refer to 節 26.14, “管​理​虛​擬​網​路​”) and click the Add button.
    虛​擬​網​路​組​態​設​定​
    圖形 26.30. 虛​擬​網​路​組​態​設​定​

    如​此​將​會​開​啟​建​立​新​的​虛​擬​網​路​選​單​。​請​按​下​「​下​一​步​」​來​繼​續​進​行​。​
    建​立​新​的​虛​擬​網​路​
    圖形 26.31. 建​立​新​的​虛​擬​網​路​

  2. 替​虛​擬​網​路​輸​入​適​合​的​名​稱​然​後​點​選​「​下​一​步​」​。​
    為​虛​擬​系​統​命​名​
    圖形 26.32. 為​虛​擬​系​統​命​名​

  3. 請​為​您​的​虛​擬​網​路​輸​入​一​組​ IPv4 位​址​空​間​然​後​按​下​「​下​一​步​」​。​
    選​擇​一​組​ IPv4 位​址​空​間​
    圖形 26.33. 選​擇​一​組​ IPv4 位​址​空​間​

  4. 請​經​由​指​定​ IP 位​置​的​起​始​與​結​尾​範​圍​來​定​義​您​的​虛​擬​網​路​的​ DHCP 範​圍​。​請​點​選​「​下​一​步​」​來​繼​續​進​行​。​
    選​擇​ DHCP 範​圍​
    圖形 26.34. 選​擇​ DHCP 範​圍​

  5. 選​擇​虛​擬​網​路​連​接​到​實​體​網​路​的​方​式​。​
    連​至​實​體​網​路​
    圖形 26.35. 連​至​實​體​網​路​

    如​果​您​選​擇​了​發​送​到​實​體​網​路​,請​將​目​的​選​擇​為​ NAT 至​任​何​實​體​裝​置​或​是​ NAT 至​實​體​裝​置​ eth0。​
    請​點​選​「​下​一​步​」​來​繼​續​進​行​。​
  6. 您​現​在​已​能​夠​建​立​網​路​。​請​確​認​您​的​網​路​組​態​設​定​並​點​選​完​成​。​
    已​準​備​好​建​立​網​路​
    圖形 26.36. 已​準​備​好​建​立​網​路​

  7. 新​的​虛​擬​網​路​現​在​已​能​透​過​主​機​資​料​選​單​上​的​虛​擬​網​路​分​頁​中​取​得​。​
    新​的​虛​擬​網​路​已​能​夠​使​用​
    圖形 26.37. 新​的​虛​擬​網​路​已​能​夠​使​用​

章 27. xm 指​令​快​速​參​照​指​南​

xm 指​令​可​管​理​ Xen hypervisor。​大​部​分​的​作​業​都​可​透​過​ virt-manager 應​用​程​式​或​是​ virsh 指​令​這​些​ libvirt 工​具​來​進​行​。​xm 指​令​沒​有​檢​查​ libvirt 工​具​錯​誤​的​功​能​,因​此​不​該​被​使​用​來​進​行​ libvirt 工​具​所​支​援​的​工​作​。​
目​前​有​幾​項​透​過​使​用​ virt-manager 所​無​法​進​行​的​作​業​。​有​些​ xm 指​令​的​其​它​ Xen 實​做​的​選​項​無​法​在​ Red Hat Enterprise Linux 5 上​使​用​。​以​下​清​單​提​供​了​可​用​與​不​可​使​用​的​指​令​選​項​總​覽​。​

警​告​

建​議​您​使​用​ virsh 或​ virt-manager 來​代​替​ xm。​xm 指​令​無​法​有​效​地​處​理​錯​誤​檢​測​或​配​置​檔​案​錯​誤​,而​錯​誤​可​能​會​造​成​系​統​不​穩​定​或​是​在​虛​擬​機​器​中​發​生​錯​誤​。​手​動​式​地​編​輯​ Xen 配​置​檔​案​非​常​危​險​,因​此​您​應​該​避​免​這​麼​作​。​您​必​須​承​擔​使​用​本​章​節​的​所​有​風​險​。​
基​本​管​理​選​項​
以​下​為​一​些​常​用​的​基​本​ xm 指​令​:
  • xm help [--long]:檢​視​可​用​的​選​項​和​協​助​文​件​。​
  • 使​用​ xm list 指​令​來​列​出​運​作​中​的​網​域​:
    $ xm list
    Name                                ID  Mem(MiB)   VCPUs      State      Time(s)
    Domain-0                            0     520       2         r-----     1275.5
    r5b2-mySQL01                       13     500       1         -b----       16.1
    
  • xm create [-c] DomainName/ID: start a virtual machine. If the -c option is used, the start up process will attach to the guest's console.
  • xm console DomainName/ID: attach to a virtual machine's console.
  • xm destroy 網​域​名​稱​/ID:終​止​一​部​虛​擬​機​器​,似​同​關​閉​電​源​。​
  • xm reboot DomainName/ID:重​新​啟​動​一​部​虛​擬​機​器​,通​過​平​常​的​系​統​關​閉​以​及​啟​動​程​序​。​
  • xm shutdown DomainName/ID:關​閉​一​部​虛​擬​機​器​,執​行​一​項​系​統​關​閉​程​序​。​
  • xm pause
  • xm unpause
  • xm save
  • xm restore
  • xm migrate
資​源​管​理​選​項​
請​使​用​下​列​ xm 指​令​來​管​理​資​源​:
  • xm mem-set
  • 請​使​用​ xm vcpu-list 來​列​出​虛​擬​化​ CPU 的​相​似​性​:
    $ xm vcpu-list
    Name                          ID  VCPUs   CPU State  Time(s)  CPU Affinity
    Domain-0                       0    0      0    r--   708.9    any cpu
    Domain-0                       0    1      1   -b-    572.1    any cpu
    r5b2-mySQL01                  13    0      1   -b-     16.1    any cpu
    
  • xm vcpu-pin
  • xm vcpu-set
  • 請​使​用​ xm sched-credit 指​令​來​顯​示​某​個​特​定​網​域​的​排​程​參​數​:
    $ xm sched-credit -d 0
    {'cap': 0, 'weight': 256}
    $ xm sched-credit -d 13
    {'cap': 25, 'weight': 256}
    
監​控​與​疑​難​排​解​選​項​
請​使​用​下​列​ xm 指​令​來​進​行​監​控​與​疑​難​排​解​:
  • xm top
  • xm dmesg
  • xm info
  • xm log
  • 請​使​用​ xm uptime 來​顯​示​客​座​端​與​主​機​的​連​線​時​間​:
    $ xm uptime
    Name                       ID  Uptime
    Domain-0                    0  3:42:18
    r5b2-mySQL01               13  0:06:27
    
  • xm sysrq
  • xm dump-core
  • xm rename
  • xm domid
  • xm domname
目​前​未​受​支​援​的​選​項​
xm vnet-list 目​前​尚​未​受​到​支​援​。​

章 28. 設​定​ Xen 核​心​的​開​機​參​數​

GNU Grand Unified Boot Loader(GRUB)是​個​讓​用​戶​在​系​統​開​機​時​,能​夠​選​擇​要​載​入​哪​個​已​安​裝​的​作​業​系​統​或​是​核​心​的​程​式​。​它​也​允​許​使​用​者​將​引​數​傳​送​至​核​心​。​GRUB 的​配​置​檔​案​(位​於​ /boot/grub/grub.conf)可​用​來​建​立​ GRUB 選​單​介​面​下​啟​動​的​作​業​系​統​清​單​。​當​您​安​裝​ kernel-xen RPM 時​,預​設​上​,一​組​ script 會​將​ kernel-xen 項​目​附​加​至​ GRUB 的​配​置​檔​案​中​。​您​可​編​輯​ grub.conf 檔​案​來​修​改​預​設​的​核​心​,或​新​增​其​他​的​核​心​參​數​。​
title Red Hat Enterprise Linux Server (2.6.18-3.el5xen)
root (hd0,0)
	kernel  /xen.gz.-2.6.18-3.el5
	module  /vmlinuz-2.6..18-3.el5xen ro root=/dev/VolGroup00/LogVol00  rhgb quiet
	module  /initrd-2.6.18-3. el5xenxen.img
假​如​您​將​您​的​ Linux GRUB 項​目​設​定​來​反​映​這​項​範​例​,開​機​載​入​程​式​就​會​載​入​超​管​理​器​(hypervisor)、​initrd 映​像​檔​,以​及​ Linux kernel。​因​為​ kernel 的​項​目​位​於​其​它​項​目​的​上​方​,所​以​核​心​會​先​載​入​記​憶​體​中​。​接​著​開​機​載​入​程​式​會​傳​送​(與​接​收​)指​令​列​引​數​至​ hypervisor 與​ Linux kernel(或​由​它​們​接​收​指​令​列​引​數​)。​這​項​範​例​顯​示​了​您​該​如​何​將​ Dom0 linux核​心​的​記​憶​體​限​制​為​ 800MB。​
title Red Hat Enterprise Linux Server (2.6.18-3.el5xen)
root (hd0,0)
	kernel  /xen.gz.-2.6.18-3.el5 dom0_mem=800M
	module  /vmlinuz-2.6..18-3.el5xen ro root=/dev/VolGroup00/LogVol00  rhgb quiet
	module  /initrd-2.6.18-3. el5xenxen.img
您​能​夠​使​用​這​些​ GRUB 參​數​來​設​定​虛​擬​化​的​管​理​程​序​:
mem
這​會​限​制​ hypervisor 核​心​所​能​使​用​的​記​憶​體​。​
com1=115200, 8n1
這​能​使​系​統​中​的​第​一​個​序​列​埠​擔​任​序​列​埠​主​控​台​(com2 會​被​指​定​為​下​一​個​埠​口​,以​此​類​推​)。​
dom0_mem
這​會​限​制​ hypervisor 所​能​使​用​的​記​憶​體​。​
dom0_max_vcpus
這​會​限​制​ Xen domain0 所​能​看​到​的​ CPU 數​量​。​
acpi
這​會​將​ ACPI 管​理​程​序​切​換​到​管​理​程​序​與​ domain0。​ACPI 的​參​數​選​項​包​括​:
/*   ****  Linux config options: propagated to domain0  ****/
/*   "acpi=off":      Disables both ACPI table parsing and interpreter.   */
/*   "acpi=force":    Overrides the disable blacklist.                    */
/*   "acpi=strict":   Disables out-of-spec workarounds.                   */
/*   "acpi=ht":       Limits ACPI from boot-time to enable HT.            */
/*   "acpi=noirq":    Disables ACPI interrupt routing.                    */
noacpi
這​會​將​ ACPI 停​用​以​中​斷​結​果​。​

章 29. 配​置​ ELILO

ELILO 為​基​於​ EFI 的​系​統​上​所​使​用​的​開​機​載​入​程​式​,特​別​是​ Itanium®。​和​ GRUB(x86 和​ x86-64 上​的​開​機​載​入​程​式​)相​似​,ELILO 能​讓​使​用​者​在​系​統​啟​動​時​選​擇​要​載​入​哪​個​已​安​裝​的​核​心​。​ELILO 也​允​許​使​用​者​將​參​數​傳​遞​至​核​心​內​。​位​於​ EFI boot 分​割​區​、​並​透​過​符​號​連​結​連​至​ /etc/elilo.conf 的​ ELILO 配​置​檔​案​,包​含​著​全​域​選​項​和​映​像​的​資​料​清​單​。​當​您​安​裝​ kernel-xen RPM 時​,有​個​安​裝​後​執​行​的​描​述​檔​會​將​適​當​的​映​像​資​料​新​增​至​ elilo.conf 中​。​

ELILO

本​節​關​於​ ELILO 的​敘​述​,適​用​於​ Intel Itanium 架​構​、​並​執​行​ Xen 核​心​的​系​統​。​
ELILO 配​置​檔​案​含​有​兩​個​部​份​:
  • 會​影​響​ ELILO 特​性​與​所​有​項​目​的​全​域​選​項​。​一​般​來​講​您​無​須​對​這​些​選​項​的​預​設​值​進​行​更​改​。​
  • 定​義​一​個​ boot 選​項​以​及​相​關​選​項​的​映​像​ stanza。​
Here is a sample image stanza in elilo.conf:
image=vmlinuz-2.6.18-92.el5xen
        vmm=xen.gz-2.6.18-92.el5
        label=linux
        initrd=initrd-2.6.18-92.el5xen.img
        read-only
        root=/dev/VolGroup00/rhel5_2
        append="-- rhgb quiet"
The image parameter indicates the following lines apply to a single boot selection. This stanza defines a hypervisor (vmm), initrd, and command line arguments (read-only, root and append) to the hypervisor and kernel. When ELILO is loaded during the boot sequence, the image is labeled linux.
ELILO 會​將​ read-only 參​數​轉​換​至​核​心​指​令​列​選​項​ ro,這​會​使​ root 檔​案​系​統​以​唯​讀​掛​載​,直​到​ initscripts 將​ root 檔​案​系​統​掛​載​為​可​讀​寫​為​止​。​ELILO 會​將​「​root」​這​一​行​複​製​至​核​心​指​令​列​上​。​這​些​會​被​合​併​於​「​append」​一​行​以​建​立​一​個​完​整​的​指​令​列​:
"-- root=/dev/VolGroup00/rhel5_2 ro rhgb quiet"
-- 可​被​用​來​界​定​ hypervisor 和​核​心​引​數​。​首​先​是​ hypervisor 引​數​,接​著​便​是​ -- 界​定​符​號​,然​後​才​是​核​心​引​數​。​Hypervisor 通​常​不​會​有​任​何​引​數​。​

技​術​註​解​

ELILO 會​將​整​個​指​令​列​傳​送​至​ hypervisor。​Hypervisor 會​將​內​容​劃​分​並​將​核​心​選​項​傳​送​至​ kernel。​
若​要​自​訂​化​ hypervisor,請​在​ -- 之​前​輸​入​參​數​。​以​下​為​ hypervisor 記​憶​體​(mem)參​數​和​核​心​的​ quiet 參​數​之​範​例​:
append="dom0_mem=2G -- quiet"
ELILO hypervisor 參​數​
參​數​描​述​
mem=mem 參​數​定​義​了​ hypervisor 的​最​大​記​憶​體​使​用​量​。​系​統​中​任​何​額​外​的​記​憶​體​都​會​被​忽​略​掉​。​該​參​數​可​以​用​ B、​K、​M 或​ G 字​尾​來​指​定​;它​們​分​別​代​表​位​元​組​(B)、​千​位​元​組​(KB)、​百​萬​位​元​組​(MB)和​十​億​位​元​組​(GB)。​若​沒​有​指​定​任​何​字​尾​的​話​,預​設​值​就​會​是​ KB。​
dom0_mem=dom0_mem= 可​設​置​分​配​至​ dom0 的​記​憶​體​數​量​。​您​也​可​使​用​和​上​述​ mem 參​數​相​同​的​字​尾​。​Itanium® 上​的​ Red Hat Enterprise Linux 5.2 中​的​預​設​值​為​ 4G。​
dom0_max_vcpus=dom0_max_vcpus= 可​設​置​分​配​給​ hypervisor 的​ CPU 數​量​。​Itanium® 上​的​ Red Hat Enterprise Linux 5.2 中​的​預​設​值​為​ 4。​
com1=<baud>,DPS,<io_base>,<irq>com1= 可​設​置​第​一​個​序​列​線​路​的​參​數​(例​如​ com1=9600,8n1,0x408,5)。​io_base 和​ irq 選​項​可​被​省​略​以​將​它​們​保​留​為​標​準​的​預​設​值​。​baud 參​數​可​被​設​為​ auto 來​表​示​開​機​載​入​程​式​設​定​應​被​保​留​。​若​是​序​列​參​數​在​ ELILO 或​ EFI 配​置​中​被​設​為​了​全​域​選​項​的​話​,com1 參​數​就​可​被​省​略​掉​。​
com2=<baud>,DPS,<io_base>,<irq>請​設​置​第​二​個​序​列​線​路​的​參​數​。​請​參​閱​以​上​ com1 參​數​的​描​述​。​
console=<specifier_list>console 是​個​以​逗​號​來​區​隔​開​的​ Xen 主​控​台​選​項​的​偏​好​清​單​。​這​些​選​項​包​含​ vga、​com1 和​ com2。​此​設​定​應​被​省​略​掉​,因​為​ hypervisor 會​嘗​試​繼​承​ EFI 主​控​台​的​設​定​。​

更​多​有​關​於​ ELILO 參​數​上​的​相​關​資​訊​

您​可​由​ XenSource 來​取​得​完​整​的​ ELILO 參​數​清​單​。​
下​列​為​以​上​配​置​的​修​改​範​例​,顯​示​了​將​記​憶​體​和​ cpu 配​置​參​數​附​加​至​ hypervisor 的​語​法​:
image=vmlinuz-2.6.18-92.el5xen
        vmm=xen.gz-2.6.18-92.el5
        label=linux
        initrd=initrd-2.6.18-92.el5xen.img
        read-only
        root=/dev/VolGroup00/rhel5_2
        append="dom0_mem=2G dom0_max_vcpus=2 --"
另​外​,此​範​例​移​除​了​「​rhgb quiet」​這​個​核​心​參​數​,這​樣​一​來​核​心​和​ initscript 輸​出​便​會​產​生​於​主​控​台​上​。​請​注​意​「​--」​會​繼​續​存​在​,這​樣​一​來​被​附​加​的​一​行​就​會​被​正​確​地​視​為​是​ hypervisor 引​數​。​

章 30. libvirt configuration reference

This chapter provides is a references for various parameters of libvirt XML configuration files
表格 30.1. libvirt configuration files
Item Description
pae
Specifies the physical address extension configuration data.
apic
Specifies the advanced programmable interrupt controller configuration data.
memory
Specifies the memory size in megabytes.
vcpus
Specifies the numbers of virtual CPUs.
console
Specifies the port numbers to export the domain consoles to.
nic
Specifies the number of virtual network interfaces.
vif
Lists the randomly-assigned MAC addresses and bridges assigned to use for the domain's network addresses.
disk
Lists the block devices to export to the domain and exports physical devices to domain with read only access.
dhcp
Enables networking using DHCP.
netmask
Specifies the configured IP netmasks.
gateway
Specifies the configured IP gateways.
acpi
Specifies the advanced configuration power interface configuration data.

章 31. Xen 配​置​檔​案​

Red Hat Enterprise Linux uses libvirt configuration files for most tasks. Some users may need Xen configuration files which contain the following standard variables. Configuration items within these files must be enclosed in single quotes('). These configuration files reside in the /etc/xen directory.
The table below, 表格 31.1, “Xen 配​置​檔​案​參​照​”, is formatted output from xm create --help_config.
表格 31.1. Xen 配​置​檔​案​參​照​
Parameter
Description
vncpasswd=NAME HVM 網​域​上​的​ VNC 主​控​台​密​碼​。​
vncviewer=no | yes 衍​生​一​個​在​網​域​中​監​聽​ vnc 伺​服​器​的​ vncviewer。​vncviewer 的​位​址​可​透​過​ VNC_SERVER=<host>:<port> 來​被​傳​送​至​ kernel 指​令​列​上​的​網​域​。​vnc 所​使​用​的​通​訊​埠​為​ 5500 + DISPLAY。​可​能​的​話​,某​個​ display 值​和​空​出​的​通​訊​埠​會​被​選​取​。​只​有​當​ vnc=1 時​才​有​效​。​
vncconsole=no | yes Spawn a vncviewer process for the domain's graphical console. Only valid when vnc=1.
name=NAME 網​域​名​稱​。​這​組​名​稱​必​須​是​獨​特​的​。​
bootloader=FILE 開​機​載​入​程​式​的​路​徑​。​
bootargs=NAME 傳​送​至​開​機​載​入​程​式​的​引​數​。​
bootentry=NAME 不​建​議​使​用​。​透​過​開​機​載​入​程​式​來​進​入​開​機​程​序​。​請​使​用​ bootargs。​
kernel=FILE Kernel 映​像​檔​的​路​徑​。​
ramdisk=FILE ramdisk 的​路​徑​。​
features=FEATURES 客​座​端​ kernel 中​所​啟​用​的​功​能​
builder=FUNCTION 用​來​建​立​網​域​的​函​式​。​
memory=MEMORY 網​域​記​憶​體​(MB)。​
maxmem=MEMORY 最​大​網​域​記​憶​體​(單​位​為​ MB)。​
shadow_memory=MEMORY 網​域​映​射​記​憶​體​(單​位​為​ MB)。​
cpu=CPU 可​ host VCPU0 的​中​央​處​理​器​。​
cpus=CPUS 執​行​網​域​的​ CPU。​
pae=PAE 停​用​或​啟​用​ HVM 網​域​的​ PAE。​
acpi=ACPI 停​用​或​啟​用​ HVM 網​域​的​ ACPI。​
apic=APIC 停​用​或​啟​用​ HVM 網​域​的​ APIC。​
vcpus=VCPUs 網​域​中​的​虛​擬​ CPU 數​量​。​
cpu_weight=WEIGHT Set the new domain's cpu weight. WEIGHT is a float that controls the domain's share of the cpu.
restart=onreboot | always | never 不​建​議​使​用​。​使​用​ on_poweroff、​on_reboot 和​ on_crash 來​代​替​。​當​退​出​網​域​時​該​網​域​是​否​應​被​重​新​啟​用​。​- onreboot:透​過​關​閉​編​碼​ reboot 來​在​退​出​時​重​新​啟​用​ - always:總​是​在​退​出​時​重​新​啟​用​,忽​略​退​出​編​碼​ - never:永​不​在​退​出​時​重​新​啟​用​,忽​略​退​出​編​碼​
on_poweroff=destroy | restart | preserve | destroy Behavior when a domain exits with reason 'poweroff'. - destroy: the domain is cleaned up as normal; - restart: a new domain is started in place of the old one; - preserve: no clean-up is done until the domain is manually destroyed (using xm destroy, for example); - rename-restart: the old domain is not cleaned up, but is renamed and a new domain started in its place.
on_reboot=destroy | restart | preserve | destroy Behavior when a domain exits with reason 'reboot'. - destroy: the domain is cleaned up as normal; - restart: a new domain is started in place of the old one; - preserve: no clean-up is done until the domain is manually destroyed (using xm destroy, for example); - rename-restart: the old domain is not cleaned up, but is renamed and a new domain started in its place.
on_crash=destroy | restart | preserve | destroy Behavior when a domain exits with reason 'crash'. - destroy: the domain is cleaned up as normal; - restart: a new domain is started in place of the old one; - preserve: no clean-up is done until the domain is manually destroyed (using xm destroy, for example); - rename-restart: the old domain is not cleaned up, but is renamed and a new domain started in its place.
blkif=no | yes 使​網​域​成​為​一​個​區​塊​裝​置​後​端​。​
netif=no | yes 使​網​域​成​為​一​個​網​路​介​面​卡​後​端​。​
tpmif=no | yes 使​網​域​成​為​一​個​ TPM 介​面​卡​後​端​。​
disk=phy:DEV,VDEV,MODE[,DOM] 新​增​一​個​磁​碟​裝​置​至​網​域​。​實​體​裝​置​為​ DEV,它​被​匯​出​至​網​域​為​ VDEV。​若​ MODE 是​ r 的​話​,磁​碟​就​會​是​唯​讀​的​,若​ MODE 是​ w 的​話​磁​碟​則​可​讀​寫​。​若​ DOM 被​指​定​的​話​,它​會​定​義​磁​碟​所​使​用​的​後​端​驅​動​程​式​網​域​。​若​要​新​增​不​只​一​個​磁​碟​的​話​,該​選​項​可​被​重​複​使​用​。​
pci=BUS:DEV.FUNC 新​增​一​個​ PCI 裝​置​至​網​域​,並​使​用​提​供​的​參​數​(單​位​為​十​六​進​制​)。​例​如​ pci=c0:02.1a。​該​選​項​可​被​重​複​使​用​來​新​增​額​外​的​ pci 裝​置​。​
ioports=FROM[-TO] 新​增​一​個​ legacy I/O 範​圍​至​網​域​,使​用​提​供​的​參​數​(單​位​為​十​六​進​制​)。​例​如​ ioports=02f8-02ff。​該​選​項​可​被​重​複​使​用​來​新​增​額​外​的​ i/o 範​圍​。​
irq=IRQ 新​增​一​個​ IRQ(中​斷​行​)至​網​域​。​例​如​ irq=7。​該​選​項​可​被​重​複​使​用​來​新​增​額​外​的​ IRQ。​
usbport=PATH 新​增​一​個​實​體​ USB 連​接​埠​至​網​域​(透​過​該​連​接​埠​的​路​徑​所​指​定​)。​此​選​項​可​被​重​複​使​用​來​新​增​額​外​的​連​接​埠​。​
vfb=type={vnc,sdl}, vncunused=1, vncdisplay=N,
vnclisten=ADDR, display=DISPLAY,
xauthority=XAUTHORITY, vncpasswd=PASSWORD,
keymap=KEYMAP
Make the domain a framebuffer backend. The backend type should be either sdl or vnc. For type=vnc, connect an external vncviewer. The server will listen on ADDR (default 127.0.0.1) on port N+5900. N defaults to the domain id. If vncunused=1, the server will try to find an arbitrary unused port above 5900. For type=sdl, a viewer will be started automatically using the given DISPLAY and XAUTHORITY, which default to the current user's ones.
vif=type=TYPE, mac=MAC, bridge=BRIDGE, ip=IPADDR,
script=SCRIPT, backend=DOM, vifname=NAME
透​過​提​供​的​ MAC 位​址​和​橋​接​裝​置​來​新​增​網​路​介​面​卡​。​vif 可​透​過​調​用​提​供​的​設​定​ script 來​進​行​配​置​。​若​類​型​未​被​指​定​的​話​,預​設​值​為​ netfront 而​非​ ioemu 裝​置​。​若​ mac 未​被​指​定​的​話​,隨​機​產​生​的​ MAC 位​址​將​會​被​使​用​。​若​未​指​定​的​話​,網​路​後​端​便​會​選​擇​它​自​己​的​ MAC 位​址​。​若​橋​接​裝​置​沒​有​指​定​的​話​,第​一​個​找​到​的​橋​接​裝​置​便​會​被​使​用​。​若​ script 未​被​指​定​的​話​,預​設​的​ script 就​會​被​使​用​。​若​後​端​未​被​指​定​的​話​,預​設​的​後​端​驅​動​程​式​網​域​便​會​被​使​用​。​若​ vifname 未​被​指​定​的​話​,後​端​虛​擬​介​面​卡​的​名​稱​就​會​是​ vifD.N(D 為​網​域​ id,同​時​ N 為​介​面​ id)。​此​選​項​可​被​重​複​使​用​來​新​增​額​外​的​ vif。​指​定​ vif 將​可​按​照​需​求​增​加​介​面​卡​數​量​。​
vtpm=instance=INSTANCE,backend=DOM 新​增​一​個​ TPM 介​面​卡​。​在​後​端​使​用​提​供​的​事​例​為​虛​擬​ TPM 事​例​。​提​供​的​號​碼​不​過​是​偏​好​的​事​例​號​碼​。​hotplug script 會​判​斷​出​實​際​上​哪​個​事​例​號​碼​會​被​指​派​至​網​域​。​虛​擬​機​器​和​ TPM 事​例​號​碼​之​間​的​關​聯​可​在​ /etc/xen/vtpm.db 中​找​到​。​請​使​用​提​供​的​網​域​中​的​後​端​。​
access_control=policy=POLICY,label=LABEL 新​增​一​個​安​全​性​標​籤​以​及​一​個​定​義​它​的​安​全​性​政​策​參​照​。​當​啟​用​或​復​原​網​域​時​,本​機​的​ ssid 參​照​就​會​被​計​算​。​這​時​,該​政​策​便​會​被​拿​來​和​現​有​的​政​策​進​行​比​較​。​如​此​一​來​,透​過​儲​存​或​復​原​功​能​來​遷​移​就​被​涵​蓋​了​,並​且​本​機​標​籤​會​自​動​且​正​確​地​被​建​立​於​網​域​啟​用​或​復​原​的​系​統​上​。​
nics=NUM 不​建​議​使​用​。​請​使​用​空​的​ vif 項​目​來​代​替​。​設​置​網​路​介​面​卡​的​數​量​。​使​用​ vif 選​項​來​定​義​介​面​卡​參​數​,否​則​預​設​值​便​會​被​使​用​。​指​定​ vif 將​可​依​照​需​求​來​增​加​介​面​卡​的​數​量​。​
root=DEVICE 在​ kernel 指​令​列​上​設​置​ root= 參​數​。​使​用​一​個​ NFS root 的​裝​置​(例​如​ /dev/sda1 或​ /dev/nfs)。​
extra=ARGS 設​置​額​外​的​引​數​來​附​加​至​ kernel 指​令​列​。​
ip=IPADDR 設​置​ kernel IP 介​面​卡​位​址​。​
gateway=IPADDR 設​置​ kernel 的​ IP 閘​道​器​。​
netmask=MASK 設​置​ kernel 的​ IP 網​路​遮​罩​。​
hostname=NAME 設​置​ kernel 的​ IP 主​機​名​稱​。​
interface=INTF 設​置​ kernel 的​ IP 介​面​卡​名​稱​。​
dhcp=off|dhcp 設​置​ kernel 的​ dhcp 選​項​。​
nfs_server=IPADDR 設​置​ NFS root 的​ NFS 伺​服​器​位​址​。​
nfs_root=PATH 設​置​ root NFS 目​錄​的​路​徑​。​
device_model=FILE 裝​置​型​號​程​式​的​路​徑​。​
fda=FILE fda 的​路​徑​
fdb=FILE fdb 的​路​徑​
serial=FILE 序​列​或​ pty 或​ vc 的​路​徑​
localtime=no | yes 將​ RTC 設​為​本​地​時​間​
keymap=FILE 設​置​使​用​的​鍵​盤​格​式​
usb=no | yes 模​擬​ USB 裝​置​
usbdevice=NAME 欲​新​增​的​ USB 裝​置​的​名​稱​
stdvga=no | yes Use std vga or Cirrus Logic graphics
isa=no | yes 模​擬​一​部​只​有​ ISA 的​系​統​
boot=a|b|c|d 預​設​ boot 裝​置​
nographic=no | yes 裝​置​型​號​是​否​應​使​用​到​圖​形​?
soundhw=audiodev 裝​置​型​號​是​否​應​啟​用​音​效​裝​置​?
vnc 裝​置​型​號​是​否​應​使​用​ VNC?
vncdisplay 欲​使​用​的​ VNC 顯​示​
vnclisten VNC 伺​服​器​應​監​聽​的​位​址​。​
vncunused 嘗​試​為​ VNC 伺​服​器​尋​找​一​個​未​使​用​的​通​訊​埠​。​只​有​ vnc=1 時​才​有​效​。​
sdl 裝​置​型​號​是​否​應​使​用​ SDL?
display=DISPLAY 欲​使​用​的​ X11 顯​示​
xauthority=XAUTHORITY 欲​使​用​的​ X11 驗​證​
uuid 欲​使​用​的​ xenstore UUID(universally unique identifier,通​用​唯​一​識​別​碼​)。​若​此​選​項​未​被​設​置​的​話​,會​有​一​個​ xenstore UUID 被​隨​機​產​生​,就​和​虛​擬​網​路​介​面​卡​的​ MAC 位​址​一​樣​。​這​個​值​在​整​個​叢​集​上​必​須​是​獨​一​無​二​的​。​

表格 31.3, “設​定​參​數​的​預​設​值​” lists all configuration parameters available, the Python parser function which sets the value and default values. The setter function gives an idea of what the parser does with the values you specify. It reads these as Python values, then feeds them to a setter function to store them. If the value is not valid Python, you get an obscure error message. If the setter rejects your value, you should get a reasonable error message, except it appears to get lost somehow, along with your bogus setting. If the setter accepts, but the value is incorrect the application may fail.
表格 31.2. 用​來​設​置​參​數​值​的​ Python 函​式​
剖​析​器​函​式​ 有​效​的​引​數​
set_bool
接​受​的​值​:
  • yes
  • y
  • no
  • yes
set_float
Accepts a floating point number with Python's float(). For example:
  • 3.14
  • 10.
  • .001
  • 1e100
  • 3.14e-10
set_int
Accepts an integer with Python's int().
set_value
接​受​任​何​ Python 的​值​。​
append_value
接​受​任​何​ Python 的​值​,並​且​會​將​它​附​加​至​先​前​儲​存​在​陣​列​中​的​值​。​

表格 31.3. 設​定​參​數​的​預​設​值​
Parameter 剖​析​器​函​式​ 預​設​值​
name setter default value
vncpasswd set_value None
vncviewer set_bool None
vncconsole set_bool None
name set_value None
bootloader set_value None
bootargs set_value None
bootentry set_value None
kernel set_value None
ramdisk set_value ''
features set_value ''
builder set_value 'linux'
memory set_int 128
maxmem set_int None
shadow_memory set_int 0
cpu set_int None
cpus set_value None
pae set_int 0
acpi set_int 0
apic set_int 0
vcpus set_int 1
cpu_weight set_float None
restart set_value None
on_poweroff set_value None
on_reboot set_value None
on_crash set_value None
blkif set_bool 0
netif set_bool 0
tpmif append_value 0
disk append_value []
pci append_value []
ioports append_value []
irq append_value []
usbport append_value []
vfb append_value []
vif append_value []
vtpm append_value []
access_control append_value []
nics set_int -1
root set_value ''
extra set_value ''
ip set_value ''
gateway set_value ''
netmask set_value ''
hostname set_value ''
interface set_value "eth0"
dhcp set_value 'off'
nfs_server set_value None
nfs_root set_value None
device_model set_value ''
fda set_value ''
fdb set_value ''
serial set_value ''
localtime set_bool 0
keymap set_value ''
usb set_bool 0
usbdevice set_value ''
stdvga set_bool 0
isa set_bool 0
boot set_value 'c'
nographic set_bool 0
soundhw set_value ''
vnc set_value None
vncdisplay set_value None
vnclisten set_value None
vncunused set_bool 1
sdl set_value None
display set_value None
xauthority set_value None
uuid set_value None

部 VII. 提​示​與​技​巧​

增​強​生​產​力​的​提​示​與​技​巧​

這​些​章​節​包​含​了​有​用​的​指​示​與​提​示​,以​改​進​虛​擬​化​環​境​的​效​能​、​可​擴​充​性​與​穩​定​度​。​

章 32. 提​示​和​技​巧​

這​些​章​節​包​含​著​改​善​虛​擬​化​效​能​的​有​用​提​示​與​技​巧​。​

32.1. 自​動​啟​動​客​座​端​

This section covers how to make virtualized guests start automatically during the host system's boot phase.
本​範​例​使​用​ virsh 來​設​定​客​座​端​ TestServer,使​其​在​主​系​統​開​機​時​自​動​啟​動​。​
# virsh autostart TestServer
Domain TestServer marked as autostarted
現​在​這​客​座​端​會​在​主​系​統​開​機​時​,自​動​啟​動​。​
要​讓​客​座​端​不​在​開​機​時​自​動​啟​動​,請​使​用​ --disable 參​數​
# virsh autostart --disable TestServer
Domain TestServer unmarked as autostarted
主​系​統​啟​動​時​,這​客​座​端​不​再​會​自​動​啟​動​。​

32.2. 在​ KVM 與​ Xen hypervisor 之​間​互​換​

本​節​涵​蓋​了​在​ KVM 與​ Xen hypervisor 之​間​互​換​的​資​訊​。​
Red Hat 一​次​只​能​讓​一​種​ hypervisor 執​行​

在​ hypervisor 之​間​轉​移​虛​擬​客​座​端​

目​前​還​沒​有​應​用​程​式​可​以​將​ Xen 與​ KVM 的​客​座​端​互​相​轉​換​。​客​座​端​只​能​使​用​建​立​時​使​用​的​ hypervisor 類​型​。​

警​告​

本​步​驟​只​適​用​於​ Red Hat Enterprise Linux 5.4 以​上​,Intel 64 或​ AMD64 的​版​本​。​其​他​設​定​或​其​他​ Red Hat Enterprise Linux 版​本​並​不​支​援​。​Red Hat Enterprise Linux 5.4 之​前​的​版​本​並​沒​有​ KVM。​

32.2.1. 從​ Xen 到​ KVM

以​下​內​容​涵​蓋​了​從​ Xen 轉​移​到​ KVM hypervisor 的​步​驟​。​這​步​驟​假​定​ kernel-xen 套​件​已​經​安​裝​並​啟​用​。​
  1. 安​裝​ KVM 套​件​

    如​果​您​尚​未​安​裝​ kvm 套​件​,請​先​安​裝​。​
    # yum install kvm
    
  2. 檢​查​使​用​中​的​核​心​版​本​

    kernel-xen 套​件​可​能​已​經​安​裝​。​請​使​用​ uname 指​令​來​確​定​正​在​執​行​的​是​哪​個​核​心​:
    $ uname -r
    2.6.18-159.el5xen
    
    目​前​已​安​裝​、​同​時​也​在​執​行​中​的​核​心​是​「​2.6.18-159.el5xen」​。​如​果​您​執​行​的​是​預​設​的​核​心​「​2.6.18-159.el5」​,您​可​以​跳​過​這​個​子​步​驟​。​
    1. 將​ Xen 核​心​改​成​預​設​核​心​

      grub.conf 檔​案​設​定​了​開​機​時​使​用​的​核​心​。​要​改​變​預​設​的​核​心​,請​編​輯​ /boot/grub/grub.conf 檔​案​,如​下​所​示​:
      								default=1
      timeout=5
      splashimage=(hd0,0)/grub/splash.xpm.gz
      hiddenmenu
      title Red Hat Enterprise Linux Server (2.6.18-159.el5)
              root (hd0,0)
              kernel /vmlinuz-2.6.18-159.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
              initrd /initrd-2.6.18-159.el5.img
      title Red Hat Enterprise Linux Server (2.6.18-159.el5xen)
              root (hd0,0)
              kernel /xen.gz-2.6.18-159.el5
              module /vmlinuz-2.6.18-159.el5xen ro root=/dev/VolGroup00/LogVol00 rhgb quiet
              module /initrd-2.6.18-159.el5xen.img
      
      請​注​意​ default=1 參​數​。​這​會​讓​ GRUB 開​機​載​入​程​式​啟​動​第​二​個​項​目​,也​就​是​ Xen 核​心​。​請​將​其​改​成​預​設​核​心​的​ 0(或​其​他​適​用​於​預​設​核​心​的​值​):
      								default=0
      timeout=5
      splashimage=(hd0,0)/grub/splash.xpm.gz
      hiddenmenu
      title Red Hat Enterprise Linux Server (2.6.18-159.el5)
              root (hd0,0)
              kernel /vmlinuz-2.6.18-159.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
              initrd /initrd-2.6.18-159.el5.img
      title Red Hat Enterprise Linux Server (2.6.18-159.el5xen)
              root (hd0,0)
              kernel /xen.gz-2.6.18-159.el5
              module /vmlinuz-2.6.18-159.el5xen ro root=/dev/VolGroup00/LogVol00 rhgb quiet
              module /initrd-2.6.18-159.el5xen.img
      
  3. 重​新​開​機​,載​入​新​的​核​心​

    重​新​開​機​。​電​腦​會​用​預​設​核​心​開​機​。​KVM 模​組​應​該​會​與​核​心​一​起​自​動​載​入​。​請​檢​查​ KVM 是​否​已​經​執​行​:
    $ lsmod | grep kvm
    kvm_intel              85992  1 
    kvm                   222368  2 ksm,kvm_intel
    
    如​果​運​作​正​常​,您​會​看​到​ kvm 模​組​與​ kvm_intel 或​ kvm_amd 模​組​之​一​。​

32.2.2. 從​ KVM 到​ Xen

以​下​步​驟​涵​蓋​了​從​ KVM 轉​為​ Xen hypervisor 的​步​驟​。​這​步​驟​假​設​ kvm 套​件​已​經​安​裝​並​啟​用​。​
  1. 安​裝​ Xen 套​件​

    如​果​您​尚​未​安​裝​ kernel-xen 與​ xen 套​件​,請​安​裝​之​。​
    # yum install kernel-xen xen
    
    kernel-xen 套​件​可​能​已​經​安​裝​,但​是​尚​未​啟​用​。​
  2. 檢​查​使​用​中​的​核​心​版​本​

    請​使​用​ uname 指​令​,確​定​執​行​中​的​套​件​為​何​。​
    $ uname -r
    2.6.18-159.el5
    
    目​前​執​行​中​的​核​心​是​「​2.6.18-159.el5」​。​這​是​預​設​的​核​心​。​如​果​核​心​的​檔​名​最​後​有​ xen 字​樣​(例​如​ 2.6.18-159.el5xen),那​表​示​您​現​在​執​行​的​是​ Xen 核​心​,可​以​跳​過​這​一​步​驟​。​
    1. 將​預​設​核​心​改​為​ Xen 核​心​

      grub.conf 檔​案​設​定​了​開​機​時​使​用​的​核​心​。​要​改​變​預​設​的​核​心​,請​編​輯​ /boot/grub/grub.conf 檔​案​,如​下​所​示​:
      								default=0
      timeout=5
      splashimage=(hd0,0)/grub/splash.xpm.gz
      hiddenmenu
      title Red Hat Enterprise Linux Server (2.6.18-159.el5)
              root (hd0,0)
              kernel /vmlinuz-2.6.18-159.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
              initrd /initrd-2.6.18-159.el5.img
      title Red Hat Enterprise Linux Server (2.6.18-159.el5xen)
              root (hd0,0)
              kernel /xen.gz-2.6.18-159.el5
              module /vmlinuz-2.6.18-159.el5xen ro root=/dev/VolGroup00/LogVol00 rhgb quiet
              module /initrd-2.6.18-159.el5xen.img
      
      請​注​意​ default=0 參​數​。​這​會​讓​ GRUB 開​機​載​入​程​式​啟​動​第​一​個​項​目​,也​就​是​預​設​核​心​。​請​將​其​改​成​預​設​核​心​的​ 1(或​其​他​適​用​於​預​設​核​心​的​值​):
      								default=1
      timeout=5
      splashimage=(hd0,0)/grub/splash.xpm.gz
      hiddenmenu
      title Red Hat Enterprise Linux Server (2.6.18-159.el5)
              root (hd0,0)
              kernel /vmlinuz-2.6.18-159.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
              initrd /initrd-2.6.18-159.el5.img
      title Red Hat Enterprise Linux Server (2.6.18-159.el5xen)
              root (hd0,0)
              kernel /xen.gz-2.6.18-159.el5
              module /vmlinuz-2.6.18-159.el5xen ro root=/dev/VolGroup00/LogVol00 rhgb quiet
              module /initrd-2.6.18-159.el5xen.img
      
  3. 重​新​開​機​,載​入​新​的​核​心​

    重​新​開​機​。​電​腦​會​以​ Xen 核​心​重​新​啟​動​。​請​以​ uname 指​令​檢​查​:
    $ uname -r
    2.6.18-159.el5xen
    
    如​果​其​結​果​有​ xen 字​樣​,那​表​示​現​在​執​行​的​是​ Xen 核​心​。​

32.3. 使​用​ qemu-img

qemu-img 指​令​列​工​具​可​以​用​來​把​ Xen 或​ KVM 所​使​用​的​多​種​檔​案​系​統​格​式​化​。​qemu-img 可​以​用​來​格​式​化​虛​擬​客​座​端​的​映​像​檔​、​額​外​的​儲​存​裝​置​與​網​路​儲​存​裝​置​。​qemu-img 的​選​項​與​用​法​列​於​以​下​。​
格​式​化​與​建​立​新​的​映​像​檔​與​裝​置​
建​立​新​的​磁​碟​映​像​檔​ filename,設​定​大​小​ size 與​格​式​ format。​
# qemu-img create [-6] [-e] [-b base_image] [-f format] filename [size]
如​果​您​指​定​了​ base_image,那​麼​映​像​檔​就​只​會​從​ base_image 紀​錄​不​同​之​處​。​在​這​情​況​下​,您​不​用​指​定​大​小​。​base_image 永​遠​無​法​被​修​改​,除​非​您​使​用​了​「​commit」​監​控​指​令​。​
把​現​有​的​映​像​檔​轉​為​另​一​種​格​式​
這​ convert 選​項​是​用​來​將​可​辨​識​的​一​種​格​式​,轉​為​另​一​種​格​式​。​
指​令​格​式​:
# qemu-img convert [-c] [-e] [-f format] filename [-O output_format] output_filename
將​磁​碟​映​像​檔​ filename 轉​成​格​式​為​ output_format 的​磁​碟​映​像​檔​output_filename。​您​也​可​以​選​用​加​密​(-e)或​壓​縮​(-c)選​項​。​
只​有​「​qcow」​格​式​支​援​加​密​或​壓​縮​功​能​。​壓​縮​是​唯​讀​的​。​這​表​示​如​果​覆​寫​了​一​個​壓​縮​的​磁​區​,那​麼​重​新​寫​入​後​會​變​成​未​壓​縮​的​資​料​。​
加​密​使​用​的​是​非​常​安​全​的​ 128 位​元​加​密​金​鑰​之​ AES 格​式​。​請​使​用​長​一​點​的​密​碼​(十​六​個​字​母​)以​取​得​最​佳​防​護​。​
在​使​用​可​變​換​大​小​的​格​式​(例​如​ qcow 或​ cow)時​,轉​換​映​像​檔​可​以​有​效​地​讓​映​像​檔​更​小​。​程​式​會​偵​測​並​壓​縮​空​的​磁​區​。​
取​得​映​像​檔​的​資​訊​
info 參​數​會​顯​示​磁​碟​映​像​檔​的​資​訊​。​info 選​項​的​格​式​如​下​:
# qemu-img info [-f format] filename
這​會​提​供​關​於​磁​碟​映​像​檔​ filename 的​資​訊​。​利​用​這​項​指​令​可​得​知​磁​碟​的​保​留​空​間​(有​可​能​與​顯​示​的​大​小​不​同​)。​如​果​ vm 的​快​照​是​存​在​磁​碟​映​像​檔​中​,那​快​照​也​會​被​顯​示​出​來​。​
支​援​的​格​式​
映​像​檔​的​格​式​多​半​會​自​動​偵​測​出​來​。​以​下​是​支​援​的​格​式​:
raw
原​始​(raw)磁​碟​映​像​檔​格​式​(預​設​值​)。​這​格​式​的​優​點​是​簡​單​、​容​易​匯​出​到​所​有​其​他​的​模​擬​器​上​。​如​果​您​的​檔​案​系​統​支​援​ hole(例​如​ Linux 上​的​ ext2 或​ ext3;或​是​ Windows 的​ NTFS),那​麼​只​有​寫​入​的​磁​區​會​佔​據​空​間​。​請​使​用​ qemu-image info 或​ Unix/Linux 上​的​ ls -ls 指​令​以​得​知​映​像​檔​所​使​用​的​真​正​大​小​
qcow2
QEMU 映​像​檔​格​式​,也​是​最​精​細​的​格​式​。​這​格​式​的​映​像​檔​比​較​小​(如​果​您​的​檔​案​系​統​並​不​支​援​ holes,例​如​ Windows)、​可​選​用​ AES 加​密​模​式​、​zlib 檔​案​壓​縮​、​並​支​援​多​種​ VM 快​照​。​
qcow
舊​的​ QEMU 映​像​檔​格​式​。​為​了​與​舊​版​本​相​容​,故​包​含​在​此​版​本​中​。​
cow
複​製​即​寫​入​(Copy On Write)映​像​檔​格​式​。​cow 格​式​是​為​了​與​之​前​的​版​本​相​容​,所​以​才​納​入​的​。​這​格​式​並​不​適​用​於​ Windows。​
vmdk
VMware 3 與​ 4 相​容​的​格​式​。​
cloop
Linux 壓​縮​的​ Loop 映​像​檔​,對​於​用​在​壓​縮​的​現​有​光​碟​片​映​像​檔​非​常​有​用​,例​如​ Knoppix 光​碟​片​。​

32.4. Overcommitting Resources

The KVM hypervisor supports overcommitting CPUs and memory. Overcommitting is the process of allocating more virtualized CPUs or memory than there are physical resources on the system. CPU overcommit allows under-utilized virtualized servers or desktops to run on fewer servers which saves power and money.

支​援​ Xen

Memory overcommitting is not supported for the Xen hypervisor, however CPU overcommitting is supported.
超​量​使​用​記​憶​體​
大​部​分​作​業​系​統​與​應​用​程​式​並​不​會​一​直​使​用​ 100% 的​記​憶​體​。​這​可​以​讓​ KVM 為​虛​擬​客​座​端​準​備​更​多​記​憶​體​,甚​至​超​過​實​體​記​憶​體​的​量​。​
When using KVM, virtual machines operate as Linux processes. Guests on the KVM hypervisor do not have blocks of physical RAM assigned to them, instead they function as processes. Each process in a Linux system is allocated memory when it requests more memory. In a similar way, KVM allocates memory for guests when the guest requests more or less memory. The guest only uses slightly more physical memory than the virtualized operating system appears to use.
When physical memory is nearly completely used or a process is inactive for some time, Linux moves the process's memory to swap. Swap is usually a partition on a hard disk drive or solid state drive which Linux uses to extend virtual memory. Swap is significantly slower than RAM.
As KVM virtual machines are Linux processes, memory used by virtualized guests can be put into swap if the guest is idle or not in heavy use. Memory can be committed over the total size of the swap and physical RAM. This can cause issues if virtualized guests use their total RAM. Without sufficient memory and swap space for the virtual machine processes, the system can run completely out of memory, leading to the failure of one or more virtual machine processes.

警​告​

如​果​置​換​空​間​不​足​,客​座​端​作​業​系​統​會​被​強​制​關​機​。​這​樣​可​能​會​讓​客​座​端​無​法​運​作​。​要​避​免​這​問​題​,請​不​要​超​量​使​用​置​換​空​間​所​擁​有​的​記​憶​體​。​
置​換​分​割​區​適​用​來​把​不​常​用​的​記​憶​體​區​塊​,移​到​硬​碟​上​面​去​,以​加​速​記​憶​體​效​能​。​預​設​的​置​換​分​割​區​大​小​是​從​記​憶​體​大​小​,以​及​超​量​使​用​的​比​率​來​計​算​的​。​如​果​您​打​算​使​用​ KVM 的​超​量​使​用​功​能​,建​議​您​加​大​置​換​分​割​區​的​空​間​。​建​議​的​超​量​使​用​比​例​為​ 50%(0.5)。​公​式​為​:
(0.5 * RAM) + (overcommit ratio * RAM) = Recommended swap size
Red Hat 的​知​識​庫​有​一​篇​文​章​,探​討​如​何​安​全​、​有​效​率​地​決​定​置​換​分​割​區​的​大​小​。​
Overcommitting guests by swapping out temporarily unused guest memory can be very slow, due to the IO latency introduced by disk seek times. However, Red Hat Enterprise Linux virtualization with KVM can often avoid this disk IO penalty by merging multiple pages with identical content into the same physical pages. This is done by the KSM (Kernel Samepage Merging) kernel process, which scans memory to find identical pages. The KSM kernel process uses CPU time to avoid disk IO. This tradeoff is often beneficial in workloads with many smaller, similar guests.
要​在​虛​擬​客​座​端​上​執​行​比​實​體​記​憶​體​高​十​倍​的​超​量​使​用​比​例​是​可​能​的​。​但​這​只​能​適​用​於​特​定​的​應​用​程​式​負​載​(例​如​使​用​率​低​於​ 100% 的​桌​面​虛​擬​化​)。​設​定​超​量​使​用​的​比​例​並​沒​有​固​定​的​方​程​式​,您​必​須​在​自​己​的​環​境​中​測​試​,以​自​訂​這​個​比​例​。​
超​量​使​用​虛​擬​處​理​器​
KVM hypervisor 支​援​超​量​使​用​虛​擬​處​理​器​(VCPU)。​只​要​虛​擬​客​座​端​的​負​載​限​制​允​許​,虛​擬​處​理​器​就​可​以​超​量​使​用​。​超​量​使​用​ VCPU 時​請​務​必​小​心​,因​為​負​載​接​近​ 100% 時​,會​導​致​需​求​數​降​低​,或​系​統​暫​時​無​法​回​應​。​
每​個​虛​擬​客​座​端​只​有​一​個​虛​擬​處​理​器​時​,超​量​使​用​的​效​果​最​好​。​Linux 排​程​程​式​對​於​這​種​負​載​,是​非​常​有​效​率​的​。​KVM 可​以​安​全​地​支​援​負​載​低​於​ 100% 的​客​座​端​,與​虛​擬​處​理​器​的​比​例​達​ 5。​超​量​使​用​單​虛​擬​處​理​器​的​虛​擬​客​座​端​並​不​是​問​題​。​
您​不​能​在​處​理​器​核​心​的​實​體​數​量​之​外​,在​客​座​端​裡​超​量​使​用​多​處​理​器​。​舉​例​來​說​,擁​有​四​顆​虛​擬​處​理​器​的​客​座​端​,不​能​在​擁​有​雙​核​處​理​器​的​電​腦​上​執​行​。​超​量​使​用​多​處​理​器​會​導​致​系​統​效​能​顯​著​降​低​。​
虛​擬​處​理​器​的​數​量​若​與​實​體​處​理​器​的​數​量​一​致​,那​運​作​起​來​會​如​預​期​。​例​如​在​四​核​心​的​主​機​上​執​行​擁​有​四​個​虛​擬​處​理​器​的​虛​擬​客​座​端​。​並​非​滿​載​的​客​座​端​應​該​能​在​這​種​環​境​中​運​作​無​礙​。​

一​定​要​先​測​試​

在​密​集​測​試​前​,千​萬​不​要​在​正​式​的​系​統​上​,超​量​使​用​記​憶​體​或​處​理​器​。​滿​載​使​用​記​憶​體​或​處​理​器​的​應​用​程​式​,在​超​量​使​用​的​環​境​中​可​能​會​不​夠​穩​定​。​建​置​之​前​請​務​必​測​試​。​

32.5. 修​改​ /etc/grub.conf

This section describes how to safely and correctly change your /etc/grub.conf file to use the virtualization kernel. You must use the xen kernel to use the Xen hypervisor. Copy your existing xen kernel entry make sure you copy all of the important lines or your system will panic upon boot (initrd will have a length of '0'). If you require xen hypervisor specific values you must append them to the xen line of your grub entry.
下​列​範​例​來​自​執​行​ kernel-xen 套​件​的​系​統​之​ grub.conf。​您​系​統​上​的​ grub.conf 可​能​會​有​所​不​同​。​下​列​範​例​的​重​要​部​份​在​於​ title 那​一​行​。​
#boot=/dev/sda
default=0
timeout=15
#splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console

title Red Hat Enterprise Linux Server (2.6.17-1.2519.4.21.el5xen)
	root (hd0,0)
	kernel /xen.gz-2.6.17-1.2519.4.21.el5 com1=115200,8n1
	module /vmlinuz-2.6.17-1.2519.4.21.el5xen ro root=/dev/VolGroup00/LogVol00
	module /initrd-2.6.17-1.2519.4.21.el5xen.img

有​關​於​編​輯​ grub.conf 上​的​重​點​...

Your grub.conf could look very different if it has been manually edited before or copied from an example. Read 章 28, 設​定​ Xen 核​心​的​開​機​參​數​ for more information on using virtualization and grub.
若​要​設​置​ boot time 時​分​配​給​您​主​機​系​統​ 256MB 的​記​憶​體​數​量​,您​必​須​附​加​ dom0_mem=256M 至​您​的​ grub.conf 中​的​ xen 一​行​上​。​以​下​為​修​改​於​先​前​範​例​中​的​ grub 配​置​檔​案​版​本​:
#boot=/dev/sda
default=0
timeout=15
#splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console

title Red Hat Enterprise Linux Server (2.6.17-1.2519.4.21.el5xen)
	root (hd0,0)
	kernel /xen.gz-2.6.17-1.2519.4.21.el5 com1=115200,8n1 dom0_mem=256MB
	module /vmlinuz-2.6.17-1.2519.4.21.el5xen ro
	root=/dev/VolGroup00/LogVol00
	module /initrd-2.6.17-1.2519.4.21.el5xen.img

32.6. 驗​證​虛​擬​化​延​伸​

請​使​用​本​節​來​判​斷​您​的​硬​體​是​否​擁​有​虛​擬​化​延​伸​功​能​。​虛​擬​化​延​伸​功​能​(Intel VT 或​ AMD-V)是​完​整​虛​擬​化​所​需​的​功​能​。​

沒​有​虛​擬​化​延​伸​的​話​,還​可​以​使​用​虛​擬​化​功​能​嗎​?

如​果​您​的​硬​體​沒​有​虛​擬​化​延​伸​,您​可​以​利​用​ Red Hat kernel-xen 套​件​使​用​ Xen 半​虛​擬​化​功​能​。​
  1. 請​執​行​以​下​指​令​,驗​證​處​理​器​是​否​有​虛​擬​化​延​伸​:
    $ grep -E 'svm|vmx' /proc/cpuinfo
    
  2. Analyze the output.
    • 以​下​輸​出​包​含​了​ vmx 的​一​行​,表​示​擁​有​ Intel VT 延​伸​的​英​特​爾​處​理​器​:
      flags   : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush 
      	dts acpi mmx fxsr sse sse2 ss ht  tm syscall lm constant_tsc pni monitor ds_cpl
      	vmx est tm2 cx16 xtpr lahf_lm
      
    • 以​下​輸​出​包​含​了​ svm 的​一​行​,表​示​擁​有​ AMD-V 延​伸​的​ AMD 處​理​器​:
      flags   :  fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush
      	mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt lm 3dnowext 3dnow pni cx16
      	lahf_lm cmp_legacy svm cr8legacy ts fid vid ttp tm stc
      
    If any output is received, the processor has the hardware virtualization extensions. However in some circumstances manufacturers disable the virtualization extensions in BIOS.
    「​flags:」​的​內​容​可​能​會​因​為​系​統​上​的​超​執​行​緒​、​多​核​心​、​或​多​處​理​器​,而​重​複​出​現​。​
    The virtualization extensions may be disabled in the BIOS. If the extensions do not appear or full virtualization does not work refer to 過程 35.1, “在​ BIOS 中​啟​用​虛​擬​化​延​伸​功​能​”.
  3. For users of the KVM hypervisor

    If the kvm package is installed. I As an additional check, verify that the kvm modules are loaded in the kernel:
    # lsmod | grep kvm
    
    If the output includes kvm_intel or kvm_amd then the kvm hardware virtualization modules are loaded and your system meets requirements. sudo

Additional output

If the libvirt package is installed, the virsh command can output a full list of virtualization system capabilities. Run virsh capabilities as root to receive the complete list.

32.7. Accessing data from a guest disk image

There are various methods for accessing the data from guest image files. One common method is to use the kpartx tool, covered by this section, to mount the guest file system as a loop device which can then be accessed.
The kpartx command creates device maps from partition tables. Each guest storage image has a partition table embedded in the file.
The libguestfs and guestfish packages, available from the EPEL repository, allow advanced modification and access to guest file systems. The libguestfs and guestfish packages are not covered in this section at this time.

警​告​

Guests must be offline before their files can be read. Editing or reading files of an active guest is not possible and may cause data loss or damage.
過程 32.1. Accessing guest image data
  1. Install the kpartx package.
    # yum install kpartx
    
  2. Use kpartx to list partition device mappings attached to a file-based storage image. This example uses a image file named guest1.img.
    # kpartx -l /var/lib/libvirt/images/guest1.img
    loop0p1 : 0 409600 /dev/loop0 63
    loop0p2 : 0 10064717 /dev/loop0 409663
    guest1 is a Linux guest. The first partition is the boot partition and the second partition is an EXT3 containing the root partition.
  3. Add the partition mappings to the recognized devices in /dev/mapper/.
    # kpartx -a /var/lib/libvirt/images/guest1.img
    
    1. Test that the partition mapping worked. There should be new devices in the /dev/mapper/ directory
      # ls /dev/mapper/
      loop0p1
      loop0p2
      
      The mappings for the image are named in the format loopXpY.
  4. Mount the loop device which to a directory. If required, create the directory. This example uses /mnt/guest1 for mounting the partition.
    # mkdir /mnt/guest1
    # mount /dev/mapper/loop0p1 /mnt/guest1 -o loop,ro
  5. The files are now available for reading in the /mnt/guest1 directory. Read or copy the files.
  6. Unmount the device so the guest image can be reused by the guest. If the device is mounted the guest cannot access the image and therefore cannot start.
    # umount /mnt/tmp
  7. Disconnect the image file from the partition mappings.
    # kpartx -d /var/lib/libvirt/images/guest1.img
    
The guest can now be started again.
Accessing data from guest LVM volumes
Many Linux guests use Logical Volume Management (LVM) volumes. Additional steps are required to read data on LVM volumes on virtual storage images.
  1. Add the partition mappings for the guest1.img to the recognized devices in the /dev/mapper/ directory.
    # kpartx -a /var/lib/libvirt/images/guest1.img
    
  2. In this example the LVM volumes are on a second partition. The volumes require a rescan with the vgscan command to find the new volume groups.
    # vgscan
    Reading all physical volumes . This may take a while...
    Found volume group "VolGroup00" using metadata type lvm2
  3. Activate the volume group on the partition (called VolGroup00 by default) with the vgchange -ay command.
    # vgchange -ay VolGroup00
    2 logical volumes in volume group VolGroup00 now active.
  4. Use the lvs command to display information about the new volumes. The volume names (the LV column) are required to mount the volumes.
    # lvs
    LV VG Attr Lsize Origin Snap% Move Log Copy%
    LogVol00 VolGroup00 -wi-a- 5.06G
    LogVol01 VolGroup00 -wi-a- 800.00M
  5. Mount /dev/VolGroup00/LogVol00 in the /mnt/guestboot/ directory.
    # mount /dev/VolGroup00/LogVol00 /mnt/guestboot
  6. The files are now available for reading in the /mnt/guestboot directory. Read or copy the files.
  7. Unmount the device so the guest image can be reused by the guest. If the device is mounted the guest cannot access the image and therefore cannot start.
    # umount /mnt/
  8. Disconnect the volume group VolGroup00
    # vgchange -an VolGroup00
    
  9. Disconnect the image file from the partition mappings.
    # kpartx -d /var/lib/libvirt/images/guest1.img
    
The guest can now be restarted.

32.8. Setting KVM processor affinities

This section covers setting processor and processing core affinities with libvirt for KVM guests.
By default, libvirt provisions guests using the hypervisor's default policy. For most hypervisors, the policy is to run guests on any available processing core or CPU. There are times when an explicit policy may be better, in particular for systems with a NUMA (Non-Uniform Memory Access) architecture. A guest on a NUMA system should be pinned to a processing core so that its memory allocations are always local to the node it is running on. This avoids cross-node memory transports which have less bandwidth and can significantly degrade performance.
On a non-NUMA systems some form of explicit placement across the hosts’​ sockets, cores and hyperthreads may be more efficient.
Identifying CPU and NUMA topology
The first step in deciding what policy to apply is to determine the host’​s memory and CPU topology. The virsh nodeinfo command provides information about how many sockets, cores and hyperthreads there are attached a host.
# virsh nodeinfo
CPU model:           x86_64
CPU(s):              8
CPU frequency:       1000 MHz
CPU socket(s):       2
Core(s) per socket:  4
Thread(s) per core:  1
NUMA cell(s):        1
Memory size:         8179176 kB
This system has eight CPUs, in two sockets, each processor has four cores.
The output shows that that the system has a NUMA architecture. NUMA is more complex and requires more data to accurately interpret. Use the virsh capabilities to get additional output data on the CPU configuration.
# virsh capabilities
<capabilities>
  <host>
    <cpu>
      <arch>x86_64</arch>
    </cpu>
    <migration_features>
      <live/>
      <uri_transports>
        <uri_transport>tcp</uri_transport>
      </uri_transports>
    </migration_features>
    <topology>
      <cells num='2'>
        <cell id='0'>
          <cpus num='4'>
            <cpu id='0'/>
            <cpu id='1'/>
            <cpu id='2'/>
            <cpu id='3'/>
          </cpus>
        </cell>
        <cell id='1'>
          <cpus num='4'>
            <cpu id='4'/>
            <cpu id='5'/>
            <cpu id='6'/>
            <cpu id='7'/>
          </cpus>
        </cell>
      </cells>
    </topology>
    <secmodel>
      <model>selinux</model>
      <doi>0</doi>
    </secmodel>
  </host>

 [ Additional XML removed ]

</capabilities>
The output shows two NUMA nodes (also know as NUMA cells), each containing four logical CPUs (four processing cores). This system has two sockets, therefore we can infer that each socket is a separate NUMA node. For a guest with four virtual CPUs, it would be optimal to lock the guest to physical CPUs 0 to 3, or 4 to 7 to avoid accessing non-local memory, which are significantly slower than accessing local memory.
If a guest requires eight virtual CPUs, as each NUMA node only has four physical CPUs, a better utilization may be obtained by running a pair of four virtual CPU guests and splitting the work between them, rather than using a single 8 CPU guest. Running across multiple NUMA nodes significantly degrades performance for physical and virtualized tasks.
Decide which NUMA node can run the guest
Locking a guest to a particular NUMA node offers no benefit if that node does not have sufficient free memory for that guest. libvirt stores information on the free memory available on each node. Use the virsh freecell command to display the free memory on all NUMA nodes.
# virsh freecell
0: 2203620 kB
1: 3354784 kB
If a guest requires 3 GB of RAM allocated, then the guest should be run on NUMA node (cell) 1. Node 0 only has 2.2GB free which is probably not sufficient for certain guests.
Lock a guest to a NUMA node or physical CPU set
Once you have determined which node to run the guest on, refer to the capabilities data (the output of the virsh capabilities command) about NUMA topology.
  1. Extract from the virsh capabilities output.
    <topology>
      <cells num='2'>
        <cell id='0'>
        <cpus num='4'>
          <cpu id='0'/>
          <cpu id='1'/>
          <cpu id='2'/>
          <cpu id='3'/>
        </cpus>
      </cell>
      <cell id='1'>
        <cpus num='4'>
          <cpu id='4'/>
          <cpu id='5'/>
          <cpu id='6'/>
          <cpu id='7'/>
        </cpus>
      </cell>
      </cells>
    </topology>
  2. Observe that the node 1, <cell id='1'>, has physical CPUs 4 to 7.
  3. The guest can be locked to a set of CPUs by appending the cpuset attribute to the configuration file.
    1. While the guest is offline, open the configuration file with virsh edit.
    2. Locate where the guest's virtual CPU count is specified. Find the vcpus element.
      <vcpus>4</vcpus>
      The guest in this example has four CPUs.
    3. Add a cpuset attribute with the CPU numbers for the relevant NUMA cell.
      <vcpus cpuset='4-7'>4</vcpus>
  4. Save the configuration file and restart the guest.
The guest has been locked to CPUs 4 to 7.
Automatically locking guests to CPUs with virt-install
The virt-install provisioning tool provides a simple way to automatically apply a 'best fit' NUMA policy when guests are created.
The cpuset option for virt-install can use a CPU set of processors or the parameter auto. The auto parameter automatically determines the optimal CPU locking using the available NUMA data.
For a NUMA system, use the --cpuset=auto with the virt-install command when creating new guests.
Tuning CPU affinity on running guests
There may be times where modifying CPU affinities on running guests is preferable to rebooting the guest. The virsh vcpuinfo and virsh vcpupin commands can perform CPU affinity changes on running guests.
The virsh vcpuinfo command gives up to date information about where each virtual CPU is running.
In this example, guest1 is a guest with four virtual CPUs is running on a KVM host.
# virsh vcpuinfo guest1
VCPU:           0
CPU:            3
State:          running
CPU time:       0.5s
CPU Affinity:   yyyyyyyy
VCPU:           1
CPU:            1
State:          running
CPU Affinity:   yyyyyyyy
VCPU:           2
CPU:            1
State:          running
CPU Affinity:   yyyyyyyy
VCPU:           3
CPU:            2
State:          running
CPU Affinity:   yyyyyyyy
The virsh vcpuinfo output (the yyyyyyyy value of CPU Affinity) shows that the guest can presently run on any CPU.
To lock the virtual CPUs to the second NUMA node (CPUs four to seven), run the following commands.
# virsh vcpupin guest1 0 4
# virsh vcpupin guest1 1 5
# virsh vcpupin guest1 2 6
# virsh vcpupin guest1 3 7
The virsh vcpuinfo command confirms the change in affinity.
# virsh vcpuinfo guest1
VCPU:           0
CPU:            4
State:          running
CPU time:       32.2s
CPU Affinity:   ----y---
VCPU:           1
CPU:            5
State:          running
CPU time:       16.9s
CPU Affinity:   -----y--
VCPU:           2
CPU:            6
State:          running
CPU time:       11.9s
CPU Affinity:   ------y-
VCPU:           3
CPU:            7
State:          running
CPU time:       14.6s
CPU Affinity:   -------y

32.9. 產​生​一​個​新​的​獨​特​ MAC 位​址​

In some case you will need to generate a new and unique MAC address for a guest. There is no command line tool available to generate a new MAC address at the time of writing. The script provided below can generate a new MAC address for your guests. Save the script to your guest as macgen.py. Now from that directory you can run the script using ./macgen.py and it will generate a new MAC address. A sample output would look like the following:
$ ./macgen.py 
00:16:3e:20:b0:11
	
#!/usr/bin/python
# macgen.py script to generate a MAC address for virtualized guests on Xen
#
import random
#
def randomMAC():
	mac = [ 0x00, 0x16, 0x3e,
		random.randint(0x00, 0x7f),
		random.randint(0x00, 0xff),
		random.randint(0x00, 0xff) ]
	return ':'.join(map(lambda x: "%02x" % x, mac))
#
print randomMAC()
另​一​個​為​您​的​客​座​端​產​生​新​ MAC 位​址​的​方​式​
您​也​能​使​用​內​建​的​ python-virtinst 模​組​來​產​生​新​的​ MAC 位​址​以​及​使​用​於​客​座​端​配​置​檔​案​中​的​ UUID
# echo  'import virtinst.util ; print\
 virtinst.util.uuidToString(virtinst.util.randomUUID())' | python
# echo  'import virtinst.util ; print virtinst.util.randomMAC()' | python
以​上​ script 也​能​像​下​列​一​般​地​被​以​ script 檔​案​來​實​做​。​
#!/usr/bin/env python
#  -*- mode: python; -*-
print ""
print "New UUID:"
import virtinst.util ; print virtinst.util.uuidToString(virtinst.util.randomUUID())
print "New MAC:"
import virtinst.util ; print virtinst.util.randomMAC()
print ""

32.10. 限​制​ Xen 客​座​端​的​網​路​頻​寬​

In some environments it may be required to limit the network bandwidth available to certain guests. This can be used to implement basic Quality of Service on a host running multiple virtual machines. By default, the guest can use any bandwidth setting available which your physical network card supports. The physical network card must be mapped to one of virtual machine's virtual network interfaces. In Xen the “​rate”​ parameter part of the VIF entries can throttle virtualized guests.
此​清​單​涵​蓋​了​下​列​變​數​
rate
The rate= option can be added to the VIF= entry in a virtual machine configuration file to limit a virtual machine's network bandwidth or specify a specific time interval for a time window.
time window
time window 為​ rate= 選​項​的​非​必​選​變​數​:
預​設​的​ time window 為​ 50ms。​
較​小​的​ time window 可​提​供​較​少​的​猝​發​傳​輸​(burst transmission),不​過​填​充​率​和​等​待​時​間​將​會​增​加​。​
預​設​的​ 50ms 時​窗​可​在​等​待​時​間​和​通​量​之​間​取​得​一​個​平​衡​,並​且​在​大​部​分​情​況​下​無​須​進​行​更​改​。​
rate 參​數​值​和​使​用​方​法​之​範​例​。​
rate=10Mb/s
將​來​自​客​座​端​的​連​外​網​路​流​量​限​制​為​ 10MB/s。​
rate=250KB/s
將​來​自​客​座​端​的​連​外​網​路​流​量​限​制​為​ 250KB/s。​
rate=10MB/s@50ms
將​頻​寬​限​制​為​ 10MB/s 並​每​ 50ms 提​供​客​座​端​ 50KB 的​數​量​。​
在​虛​擬​機​器​的​配​置​中​,範​例​的​ VIF 項​目​會​看​似​:
vif = [ 'rate=10MB/s , mac=00:16:3e:7a:55:1c, bridge=xenbr1']
This rate entry would limit the virtual machine's interface to 10MB/s for outgoing traffic

32.11. 配​置​ Xen 處​理​器​的​關​係​

Xen 能​讓​一​個​網​域​的​虛​擬​中​央​處​理​器​與​一​個​或​更​多​個​主​機​ CPU 聯​繫​。​這​能​用​來​在​虛​擬​客​座​端​之​間​分​配​真​實​的​資​源​。​這​個​方​法​能​讓​ Red Hat Enterprise Linux 在​使​用​雙​核​心​(dual-core)、​超​執​行​緒​(hyperthreading)、​或​是​其​他​先​進​的​ CPU 技​術​時​,能​以​最​佳​的​方​式​使​用​處​理​器​資​源​。​Xen 的​信​用​排​程​器​會​自​動​的​將​虛​擬​中​央​處​理​器​與​實​體​的​ CPU 之​間​重​新​做​一​個​平​衡​來​使​系​統​最​佳​化​。​只​要​虛​擬​ CPU 有​連​接​到​一​個​實​體​的​ CPU,Red Hat Enterprise Linux 能​讓​信​用​排​程​器​隨​著​需​要​來​移​動​ CPU。​
如​果​您​執​行​的​是​ I/O 密​集​的​工​作​,建​議​您​使​用​專​用​的​超​執​行​緒​,或​整​個​處​理​器​核​心​,來​執​行​ domain0。​
請​注​意​,這​對​ KVM 來​說​並​不​是​必​要​的​,因​為​ KVM 使​用​預​設​的​ Linux 核​心​排​程​程​式​。​
處​理​器​之​間​的​關​係​可​以​透​過​ virsh 或​ virt-manager 來​設​定​:
To set CPU affinities using virsh refer to 設​定​虛​擬​ CPU 的​相​似​性​ for more information.
To configure and view CPU information with virt-manager refer to 節 26.11, “顯​示​虛​擬​ CPU” for more information.

32.12. 修​改​ Xen hypervisor

Managing host systems often involves changing the boot configuration file /boot/grub/grub.conf. Managing several or more hosts configuration files quickly becomes difficult. System administrators often prefer to use the 'cut and paste' method for editing multiple grub.conf files. If you do this, ensure you include all five lines in the Virtualization entry (or this will create system errors). Hypervisor specific values are all found on the 'xen' line. This example represents a correct grub.conf virtualization entry:
# boot=/dev/sda/
default=0
timeout=15
#splashimage=(hd0, 0)/grub/splash.xpm.gz

hiddenmenu
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console
title Red Hat Enterprise Linux Server (2.6.17-1.2519.4.21. el5xen)
root (hd0, 0)
kernel /xen.gz-2.6.17-1.2519.4.21.el5 com1=115200,8n1
    module /vmlinuz-2.6.17-1.2519.4.21el5xen ro root=/dev/VolGroup00/LogVol00
    module /initrd-2.6.17-1.2519.4.21.el5xen.img
For example, to change the memory entry on your hypervisor (dom0) to 256MB at boot time, edit the 'xen' line and append it with this entry: 'dom0_mem=256M'. This example is the grub.conf with the hypervisor's memory entry modified.
# boot=/dev/sda
default=0
timeout=15
#splashimage=(hd0,0)/grubs/splash.xpm.gz
hiddenmenu
serial --unit=0 --speed =115200 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console
title Red Hat Enterprise Linux Server (2.6.17-1.2519.4.21. el5xen)
root (hd0,0)
kernel /xen.gz-2.6.17-1.2519.4.21.el5 com1=115200,8n1 dom0_mem=256MB
    module /vmlinuz-2.6.17-1.2519.4.21.el5xen ro root=/dev/VolGroup00/LogVol00
    module /initrd-2.6.17-1.2519.4.21.el5xen.img

32.13. 非​常​安​全​的​ ftpd

vsftpd 提​供​了​半​虛​擬​化​客​座​端​(例​如​ Red Hat Enterprise Linux 5 儲​存​庫​)安​裝​樹​的​存​取​權​限​,或​是​其​他​資​料​。​若​您​在​安​裝​伺​服​器​時​,並​沒​有​安​裝​ vsftpd 的​話​,您​可​透​過​您​安​裝​媒​介​的​ Server 目​錄​中​取​得​該​ RPM 套​件​,並​透​過​使​用​ rpm -ivh vsftpd*.rpm 來​安​裝​它​(請​注​意​,該​ RPM 套​件​必​須​位​於​您​目​前​的​目​錄​中​)。​
  1. To configure vsftpd, edit /etc/passwd using vipw and change the ftp user's home directory to the directory where you are going to keep the installation trees for your para-virtualized guests. An example entry for the FTP user would look like the following:
    ftp:x:14:50:FTP User:/xen/pub:/sbin/nologin
    
  2. 請​使​用​ chkconfig --list vsftpd 來​驗​證​ vsftpd 是​否​並​未​被​啟​用​:
    $ chkconfig --list vsftpd
    vsftpd          0:off   1:off   2:off   3:off   4:off   5:off   6:off
    
  3. 請​執​行​ chkconfig --levels 345 vsftpd on 來​在​ run level 3、​4 和​ 5 之​中​自​動​啟​用​ vsftpd。​
  4. 請​使​用​ chkconfig --list vsftpd 指​令​來​驗​證​ vsftpd 是​否​已​被​設​為​在​系​統​開​機​時​啟​用​:
    $ chkconfig --list vsftpd
    vsftpd          0:off   1:off   2:off   3:on    4:on    5:on    6:off
    
  5. 請​使​用​ service vsftpd start vsftpd 來​啟​用​ vsftpd 服​務​:
    $service vsftpd start vsftpd
    Starting vsftpd for vsftpd:                  [  OK  ]
    

32.14. 配​置​ LUN 的​持​續​性​

This section covers how to implement LUN persistence in guests and on the host machine with and without multipath.
在​沒​有​多​重​路​徑​的​情​況​下​實​施​ LUN 的​持​續​性​
若​您​的​系​統​沒​有​使​用​多​重​路​徑​的​話​,您​可​使​用​ udev 來​實​施​ LUN 的​持​續​性​。​在​您​的​系​統​中​實​施​ LUN 持​續​性​之​前​,請​確​認​您​已​取​得​正​確​的​ UUID。​一​旦​您​取​得​了​這​些​ UUID 之​後​,您​便​可​透​過​編​輯​位​於​ /etc 目​錄​中​的​ scsi_id 檔​案​來​配​置​ LUN 的​持​續​性​。​當​您​在​文​字​編​輯​器​中​開​啟​了​此​檔​案​後​,您​必​須​將​此​行​更​改​為​註​解​:
# options=-b
然​後​使​用​此​參​數​來​替​代​:
# options=-g
這​能​讓​ udev 監​控​所​有​系​統​ SCSI 裝​置​並​取​得​被​回​報​的​ UUID。​若​要​取​得​系​統​的​ UUID,請​使​用​ scsi_id 指​令​:
# scsi_id -g -s /block/sdc
*3600a0b80001327510000015427b625e*
較​長​的​字​串​為​ UUID。​當​您​新​增​裝​置​至​您​的​系​統​時​,UUID 不​會​改​變​。​您​需​取​得​各​個​裝​置​的​ UUID 才​可​為​這​些​裝​置​建​立​規​則​。​若​要​建​立​新​的​裝​置​規​則​,請​編​輯​位​於​ /etc/udev/rules.d/ 目​錄​中​的​ 20-names.rules 檔​案​。​裝​置​的​命​名​規​則​應​採​用​下​列​格​式​:
# KERNEL="sd*",  BUS="scsi",  PROGRAM="sbin/scsi_id", RESULT="UUID", NAME="devicename"
請​將​您​現​有​的​ UUID 和​ devicename 替​換​成​以​上​已​取​得​ UUID 的​項​目​。​您​的​規​則​應​看​似​下​列​:
KERNEL="sd*",  BUS="scsi",  PROGRAM="sbin/scsi_id", RESULT="3600a0b80001327510000015427b625e", NAME="mydevicename"
這​會​讓​系​統​啟​用​所​有​和​ /dev/sd* 模​式​符​合​的​裝​置​檢​查​給​予​的​ UUID。​當​它​發​現​了​符​合​的​裝​置​時​,它​便​會​建​立​一​個​稱​為​ /dev/devicename 的​裝​置​節​點​。​在​此​範​例​中​,裝​置​節​點​為​ /dev/mydevice 。​最​後​,您​需​要​在​ /etc/rc.local 檔​案​中​附​加​這​一​行​:
/sbin/start_udev
在​含​有​多​重​路​徑​的​情​況​下​實​做​ LUN 持​續​性​
若​要​在​多​重​路​徑​的​環​境​下​實​施​ LUN 的​持​續​性​的​話​,您​必​須​為​多​重​路​徑​裝​置​定​義​別​名​名​稱​。​在​此​範​例​中​,您​必​須​透​過​編​輯​位​於​ /etc/ 目​錄​中​的​ multipath.conf 檔​案​來​定​義​四​個​裝​置​別​名​:
multipath  {  
             wwid       3600a0b80001327510000015427b625e
             alias      oramp1
}
multipath  {  
             wwid       3600a0b80001327510000015427b6
             alias      oramp2
}
multipath  {  
             wwid       3600a0b80001327510000015427b625e
             alias      oramp3
}
multipath  {  
             wwid       3600a0b80001327510000015427b625e
             alias      oramp4
}
這​定​義​了​四​個​ LUN:/dev/mpath/oramp1、​/dev/mpath/oramp2、​/dev/mpath/oramp3,以​及​ dev/mpath/oramp4。​裝​置​會​位​於​ /dev/mpath/ 目​錄​中​。​這​些​ LUN 名​稱​在​開​機​後​依​然​具​有​持​續​性​,因​為​它​將​別​名​建​立​於​ LUN 的​ wwid 上​。​

32.15. 停​用​客​座​端​的​ SMART 磁​碟​監​控​

SMART 磁​碟​監​控​可​被​停​用​,因​為​我​們​正​在​虛​擬​磁​碟​上​運​作​並​且​實​體​儲​存​庫​是​由​主​機​來​管​理​的​。​
/sbin/service smartd stop
/sbin/chkconfig --del smartd

32.16. 清​除​舊​的​ Xen 配​置​檔​案​

Over time you will see a number of files accumulate in /var/lib/xen, the usually named vmlinuz.****** and initrd.******. These files are the initrd and vmlinuz files from virtual machines which either failed to boot or failed for some other reason. These files are temporary files extracted from virtual machine's boot disk during the start up sequence. These files should be automatically removed after the virtual machine is shut down cleanly. Then you can safely delete old and stale copies from this directory.

32.17. 配​置​ VNC 伺​服​器​

若​要​配​置​ VNC 伺​服​器​,請​使​用​系​統​ > 偏​好​設​定​中​的​遠​端​桌​面​。​另​外​,您​也​可​執​行​ vino-preferences 這​項​指​令​。​
下​列​步​驟​將​會​設​定​一​個​專​屬​的​ VNC 伺​服​器​ session:
  1. 請​編​輯​ ~/.vnc/xstartup 檔​案​以​便​在​ vncserver 啟​用​時​啟​動​ GNOME session。​您​第​一​次​執​行​ vncserver script 時​,它​會​要​求​您​輸​入​一​組​您​想​要​用​於​您​的​ VNC session 的​密​碼​。​
  2. xstartup 檔​案​的​範​例​:
    #!/bin/sh
    # Uncomment the following two lines for normal desktop:
    # unset SESSION_MANAGER
    # exec /etc/X11/xinit/xinitrc
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    #xsetroot -solid grey
    #vncconfig -iconic &
    #xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    #twm &
    if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
    	eval `dbus-launch --sh-syntax –exit-with-session`
    	echo "D-BUS per-session daemon address is: \
    	$DBUS_SESSION_BUS_ADDRESS"
    fi
    exec  gnome-session
    

32.18. 複​製​客​座​端​配​置​檔​案​

You can copy an existing configuration file to create an all new guest. You must modify the name parameter of the guests' configuration file. The new, unique name then appears in the hypervisor and is viewable by the management utilities. You must generate an all new UUID as well by using the uuidgen command. Then for the vif entries you must define a unique MAC address for each guest (if you are copying a guest configuration from an existing guest, you can create a script to handle it). For the xen bridge information, if you move an existing guest configuration file to a new host, you must update the xenbr entry to match your local networking configuration. For the Device entries, you must modify the entries in the 'disk=' section to point to the correct guest image.
You must also modify these system configuration settings on your guest. You must modify the HOSTNAME entry of the /etc/sysconfig/network file to match the new guest's hostname.
您​必​須​修​改​ /etc/sysconfig/network-scripts/ifcfg-eth0 檔​案​的​ HWADDR 位​址​以​便​符​合​來​自​於​ ifconfig eth0 檔​案​的​輸​出​,並​且​若​您​所​使​用​的​是​靜​態​ IP 位​址​的​話​,您​則​需​要​修​改​ IPADDR 項​目​。​

32.19. 複​製​一​個​現​有​的​客​座​端​以​及​它​的​配​置​檔​案​

This section outlines copying an existing configuration file to create a new guest. There are key parameters in your guest's configuration file you must be aware of, and modify, to successfully duplicate a guest.
name
hypervisor 已​知​,並​顯​示​於​管​理​工​具​程​式​中​的​客​座​端​名​稱​。​此​項​目​在​您​的​系​統​上​應​是​獨​特​的​。​
uuid
客​座​端​的​獨​特​處​理​方​式​,新​的​ UUID 客​透​過​使​用​ uuidgen 指​令​來​產​生​。​以​下​為​ UUID 的​輸​出​範​例​:
$ uuidgen 
a984a14f-4191-4d14-868e-329906b211e5
vif
  • The MAC address must define a unique MAC address for each guest. This is automatically done if the standard tools are used. If you are copying a guest configuration from an existing guest you can use the script 節 32.9, “產​生​一​個​新​的​獨​特​ MAC 位​址​”.
  • 若​您​正​要​將​一​個​現​有​的​客​座​端​配​置​檔​案​移​動​或​複​製​至​一​個​新​的​主​機​上​,您​必​須​確​認​您​已​調​整​了​ xenbr 項​目​以​符​合​您​的​本​地​網​路​配​置​(您​可​透​過​使​用​ brctl show 指​令​來​取​得​橋​接​資​訊​)。​
  • 裝​置​項​目​,請​確​認​您​調​整​了​ disk= 部​份​中​的​項​目​以​便​指​向​正​確​的​客​座​端​映​像​檔​。​
現​在​,請​調​整​您​客​座​端​上​的​系​統​配​置​設​定​:
/etc/sysconfig/network
Modify the HOSTNAME entry to the guest's new hostname.
/etc/sysconfig/network-scripts/ifcfg-eth0
  • 請​將​ HWADDR 位​址​修​改​為​ ifconfig eth0 的​輸​出​
  • 若​使​用​了​靜​態​的​ IP 位​址​請​修​改​ IPADDR 項​目​。​

章 33. 建​立​自​訂​化​的​ libvirt script

此​部​份​提​供​了​一​些​對​於​欲​透​過​使​用​ libvirt 來​編​寫​自​訂​化​ script,以​求​便​利​的​編​程​人​員​與​系​統​管​理​員​有​幫​助​的​資​訊​。​
章 32, 提​示​和​技​巧​ is recommended reading for programmers thinking of writing new applications which use libvirt.

33.1. 搭​配​使​用​ virsh 與​ XML 配​置​檔​案​

virsh can handle XML configuration files. You may want to use this to your advantage for scripting large deployments with special options. You can add devices defined in an XML file to a running para-virtualized guest. For example, to add a ISO file as hdc to a running guest create an XML file:
# cat satelliteiso.xml
<disk type="file" device="disk">
	<driver name="file"/>
	<source file="/var/lib/libvirt/images/rhn-satellite-5.0.1-11-redhat-linux-as-i386-4-embedded-oracle.iso"/>
	<target dev="hdc"/>
	<readonly/>
</disk>
Run virsh attach-device to attach the ISO as hdc to a guest called "satellite" :
# virsh attach-device satellite satelliteiso.xml

部 VIII. 疑​難​排​解​

疑​難​排​解​和​解​決​問​題​的​相​關​介​紹​

以​下​章​節​提​供​的​資​訊​能​幫​助​您​解​決​虛​擬​化​過​程​中​,可​能​會​遇​到​的​問​題​。​

虛​擬​化​的​相​關​重​點​

基​於​ bug 和​相​應​的​修​正​會​不​斷​地​產​生​,因​此​您​的​特​定​問​題​也​許​不​會​出​現​在​此​書​中​。​如​欲​取​得​最​新​的​已​知​ bug、​問​題​和​相​關​修​正​,請​參​閱​和​您​的​版​本​與​硬​體​架​構​相​應​的​ Red Hat Enterprise Linux 發​行​公​告​。​發​行​公​告​可​在​ Red Hat 網​站​的​文​件​部​份​(www.redhat.com/docs/manuals/enterprise/)中​找​到​。​

若​其​它​方​法​都​失​敗​的​話​...

請​與​ Red Hat 全​球​支​援​服​務​中​心​(https://www.redhat.com/apps/support/)聯​絡​。​我​們​的​服​務​人​員​很​樂​於​為​您​解​決​問​題​。​

內容目錄

34. Xen 疑​難​排​解​
34.1. 針​對​於​ Xen 進​行​除​錯​和​疑​難​排​解​
34.2. 日​誌​檔​案​概​述​
34.3. 日​誌​檔​案​描​述​
34.4. 重​要​的​目​錄​位​置​
34.5. 透​過​使​用​日​誌​來​進​行​疑​難​排​解​
34.6. 透​過​使​用​序​列​主​控​台​來​進​行​疑​難​排​解​
34.7. 半​虛​擬​化​客​座​端​的​主​控​台​存​取​
34.8. 完​整​虛​擬​化​客​座​端​的​主​控​台​存​取​
34.9. Xen 的​一​般​問​題​
34.10. 建​立​客​座​端​上​的​錯​誤​
34.11. 透​過​使​用​序​列​主​控​台​來​進​行​疑​難​排​解​
34.11.1. Xen 的​序​列​主​控​台​
34.11.2. 從​半​虛​擬​化​客​座​端​的​ Xen 序​列​主​控​台​輸​出​
34.11.3. 來​自​於​完​整​虛​擬​化​客​座​端​的​序​列​主​控​台​輸​出​
34.12. Xen 的​配​置​檔​案​
34.13. 解​讀​ Xen 的​錯​誤​訊​息​
34.14. 日​誌​目​錄​的​格​式​
35. 疑​難​排​解​
35.1. 找​出​可​用​的​儲​存​裝​置​和​分​割​區​
35.2. 重​新​啟​動​ Xen 的​客​座​端​之​後​,主​控​台​沒​有​回​應​
35.3. 網​路​作​業​工​具​無​法​找​到​虛​擬​化​的​乙​太​網​路​裝​置​
35.4. Loop 裝​置​錯​誤​
35.5. 記​憶​體​短​缺​所​造​成​的​ domain 建​置​失​敗​
35.6. 不​正​確​的​核​心​映​像​檔​
35.7. 不​正​確​的​ kernel 映​像​錯​誤​ - 在​ PAE 平​台​上​的​非​ PAE kernel
35.8. 完​整​虛​擬​化​的​ 64 位​元​客​座​端​無​法​啟​動​
35.9. 缺​少​ localhost(本​地​主​機​)項​目​造​成​了​ virt-manager 失​效​
35.10. 客​座​端​啟​動​時​所​產​生​的​微​程​式​碼​錯​誤​
35.11. 啟​動​虛​擬​機​器​時​所​產​生​的​ Python depreciation 警​告​訊​息​
35.12. 在​ BIOS 中​啟​用​ Intel VT 和​ AMD-V 虛​擬​化​硬​體​延​伸​
35.13. KVM 的​網​路​效​能​
36. Xen 半​虛​擬​化​驅​動​程​式​的​疑​難​排​解​
36.1. Red Hat Enterprise Linux 5 虛​擬​化​日​誌​檔​案​與​目​錄​
36.2. 半​虛​擬​化​客​座​端​在​一​個​ Red Hat Enterprise Linux 3 客​座​端​作​業​系​統​上​無​法​載​入​
36.3. 當​在​ Red Hat Enterprise Linux 3 上​安​裝​半​虛​擬​化​驅​動​程​式​時​,有​個​警​告​訊​息​被​顯​示​了​
36.4. 手​動​式​地​載​入​半​虛​擬​化​驅​動​程​式​
36.5. 驗​證​半​虛​擬​化​驅​動​程​式​是​否​已​成​功​載​入​
36.6. 當​使​用​半​虛​擬​化​驅​動​程​式​時​,系​統​具​有​有​限​的​產​量​

章 34. Xen 疑​難​排​解​

此​章​節​涵​蓋​了​如​何​對​ Xen 的​系​統​進​行​疑​難​排​解​的​相​關​資​訊​。​包​含​於​此​章​節​的​疑​難​排​解​主​題​包​含​:
  • Linux 與​虛​擬​化​的​疑​難​排​解​
  • 找​出​疑​難​問​題​的​技​巧​。​
  • 日​誌​檔​的​位​置​,以​及​日​誌​資​訊​的​解​釋​。​
本​章​為​讀​者​提​供​了​採​用​虛​擬​化​技​術​時​,可​能​會​遇​到​的​問​題​及​其​解​決​方​法​。​疑​難​排​解​需​要​實​務​經​驗​,光​從​書​中​了​解​是​不​夠​的​。​我​們​建​議​您​多​多​實​驗​、​測​試​ Red Hat Enterprise Linux 的​虛​擬​化​功​能​,以​發​展​自​己​的​疑​難​排​解​技​巧​。​
If you cannot find the answer in this document there may be an answer online from the virtualization community. Refer to 節 A.1, “線​上​資​源​” for a list of Linux virtualization websites.

34.1. 針​對​於​ Xen 進​行​除​錯​和​疑​難​排​解​

本​節​概​述​系​統​管​理​員​應​用​程​式​、​網​路​工​具​與​進​階​除​錯​工​具​。​您​可​以​使​用​這​些​標​準​系​統​管​理​員​工​具​與​紀​錄​來​協​助​您​故​障​排​除​:
協​助​進​行​疑​難​排​解​的​有​用​指​令​和​應​用​程​式​
xentop
xentop 會​顯​示​有​關​於​主​系​統​以​及​它​的​網​域​的​即​時​資​訊​。​
xm
使​用​ dmesg 和​ log
  • vmstat
  • iostat
  • lsof
iostat、​mpstat 與​ sar 指​令​都​是​由​sysstat 套​件​所​提​供​。​
您​可​以​使​用​這​些​進​階​除​錯​工​具​與​紀​錄​來​協​助​您​故​障​排​除​:
  • XenOprofile
  • systemtap
  • crash
  • sysrq
  • sysrq t
  • sysrq w
您​可​以​使​用​這​些​網​路​作​業​工​具​來​協​助​您​針​對​於​虛​擬​化​網​路​作​業​的​問​題​進​行​疑​難​排​解​:
  • ifconfig
  • tcpdump
    The tcpdump command 'sniffs' network packets. tcpdump is useful for finding network abnormalities and problems with network authentication. There is a graphical version of tcpdump named wireshark.
  • brctl
    brctl 是​個​網​路​作​業​工​具​,它​可​被​用​來​檢​查​與​設​定​在​虛​擬​化​ linux kernel 中​的​乙​太​網​路​橋​接​設​定​。​您​必​須​能​夠​以​ root 身​份​登​入​,才​能​執​行​下​列​範​例​指​令​:
    # brctl show 
    
    bridge-name    bridge-id          STP  enabled  interfaces  
    -----------------------------------------------------------------------------
    xenbr0             8000.feffffff       no        vif13.0
    xenbr1             8000.ffffefff       yes       pddummy0
    xenbr2             8000.ffffffef       no        vif0.0
    
    # brctl showmacs xenbr0
    
    port-no           mac-addr                  local?       aging timer
    
    1                 fe:ff:ff:ff:ff:           yes            0.00
    2                 fe:ff:ff:fe:ff:           yes            0.00
    
    
    # brctl showstp xenbr0
    xenbr0 
    bridge-id              8000.fefffffffff
    designated-root        8000.fefffffffff
    root-port              0                   path-cost             0
    max-age                20.00               bridge-max-age        20.00
    hello-time             2.00                bridge-hello-time     2.00
    forward-delay          0.00                bridge-forward-delay  0.00
    aging-time            300.01
    hello-timer            1.43                tcn-timer             0.00
    topology-change-timer  0.00                gc-timer              0.02
    
以​下​是​用​來​針​對​在​ Red Hat Enterprise Linux 5 上​的​虛​擬​化​進​行​疑​難​排​解​的​工​具​程​式​。​所​有​提​及​的​工​具​程​式​都​可​在​ Red Hat Enterprise Linux 5 發​行​版​本​中​的​ Server 軟​體​庫​裡​找​到​:
  • strace 是​一​項​可​追​蹤​其​它​程​序​所​收​到​或​使​用​的​系​統​調​用​和​事​件​的​指​令​。​
  • vncviewer: connect to a VNC server running on your server or a virtual machine. Install vncviewer using the yum install vnc command.
  • vncserver:在​您​的​伺​服​器​上​啟​用​一​個​遠​端​桌​面​。​讓​您​可​透​過​遠​端​ session 來​執​行​像​是​ virt-manager 的​圖​形​化​使​用​者​介​面​。​請​透​過​使​用​ yum install vnc-server 指​令​來​安​裝​ vncserver。​

34.2. 日​誌​檔​案​概​述​

When deploying Red Hat Enterprise Linux 5 with Virtualization into your network infrastructure, the host's Virtualization software uses many specific directories for important configuration, log files, and other utilities. All the Xen logs files are standard ASCII files, and accessible with a text editor:
  • Xen 的​主​要​配​置​目​錄​為​ /etc/xen/。​這​個​目​錄​包​括​ xend daemon 以​及​其​它​的​虛​擬​主​機​配​置​檔​案​。​網​路​作​業​的​ script 檔​案​則​位​於​ scripts 目​錄​中​。​
  • 所​有​的​ Xen 日​誌​檔​都​儲​存​在​ /var/log/xen/ 目​錄​中​。​
  • 以​檔​案​為​主​的​映​像​檔​都​儲​存​在​預​設​目​錄​ /var/lib/libvirt/images/ 目​錄​中​。​
  • Xen 核​心​資​訊​儲​存​在​ /proc/xen/ 目​錄​中​。​

34.3. 日​誌​檔​案​描​述​

Xen 有​ xend daemon 與​ qemu-dm 程​序​兩​個​功​能​,這​兩​個​工​具​會​寫​入​多​個​日​誌​檔​於​ /var/log/xen/ 目​錄​:
  • xend.log 為​包​含​了​所​有​由​ xend daemon 所​匯​集​的​資​料​的​日​誌​檔​案​(無​論​是​正​常​的​系​統​事​件​,或​是​操​作​者​所​進​行​的​動​作​)。​所​有​的​虛​擬​機​器​的​作​業​(如​建​立​、​關​機​、​刪​除​等​)都​會​在​此​顯​示​。​當​您​追​蹤​事​件​或​是​效​能​上​的​問​題​時​, xend.log 通​常​應​該​是​您​第​一​個​查​看​的​地​方​。​它​包​含​了​錯​誤​訊​息​的​相​關​詳​細​項​目​與​狀​況​。​
  • xend-debug.log 這​個​日​誌​檔​案​包​含​了​所​有​來​自​於​ xend 和​虛​擬​化​子​系​統​(如​框​架​緩​衝​器​、​Python scripts 等​)的​事​件​錯​誤​紀​錄​。​
  • xen-hotplug-log 為​包​含​著​所​有​來​自​於​ hotplug 事​件​的​日​誌​檔​案​。​如​果​裝​置​或​網​路​ script 無​法​連​上​的​話​,該​事​件​便​會​在​此​顯​示​。​
  • qemu-dm.[PID].log 是​由​ qemu-dm 程​序​為​每​一​個​完​整​虛​擬​化​客​座​端​所​建​立​的​日​誌​檔​案​。​當​您​使​用​該​日​誌​檔​案​時​,您​必​須​擷​取​已​知​的​ qemu-dm 程​序​ PID,並​透​過​使​用​ ps 指​令​來​測​試​程​序​引​數​以​便​隔​離​在​虛​擬​機​器​上​的​ qemu-dm 程​序​。​請​注​意​,您​必​須​使​用​真​正​的​ PID qemu-dm 程​序​來​取​代​ [PID] 符​號​。​
如​果​您​遇​到​由​虛​擬​機​器​管​理​程​式​所​產​生​的​任​何​錯​誤​,您​可​以​檢​閱​位​於​ /.virt-manager 目​錄​中​的​ virt-manager.log 檔​案​內​所​產​生​的​資​料​。​請​注​意​,每​次​您​啟​動​虛​擬​主​機​管​理​程​式​時​,它​便​會​覆​蓋​既​有​的​日​誌​檔​案​內​容​。​當​您​在​系​統​錯​誤​發​生​後​重​新​啟​動​虛​擬​主​機​管​理​程​式​之​前​,請​確​認​您​已​將​ virt-manager.log 檔​案​進​行​備​份​。​

34.4. 重​要​的​目​錄​位​置​

在​您​於​ Xen 虛​擬​化​環​境​下​追​蹤​錯​誤​和​進​行​疑​難​排​解​時​,您​應​注​意​以​下​幾​項​工​具​與​日​誌​檔​案​:
  • 虛​擬​主​機​映​像​檔​位​於​ /var/lib/libvirt/images/ 目​錄​中​。​
  • 當​您​重​新​啟​動​ xend daemon 時​,它​會​更​新​位​於​ /var/lib/xen/xend-db/ 目​錄​的​ xend-database 。​
  • 虛​擬​主​機​傾​印​(在​您​執​行​ xm dump-core 指​令​)位​於​ /var/lib/xen/dumps/ 目​錄​中​。​
  • /etc/xen 目​錄​包​含​您​用​來​管​理​系​統​資​源​的​配​置​檔​。​xend daemon 的​配​置​檔​為​ /etc/xen/xend-config.sxp ,您​可​以​使​用​這​個​檔​案​來​實​做​整​個​系​統​的​更​改​與​配​置​網​路​。​然​而​,我​們​不​建​議​您​手​動​編​輯​ /etc/xen/ 目​錄​中​的​檔​案​。​
  • proc 資​料​夾​是​另​一​項​能​讓​您​取​得​系​統​資​訊​的​資​源​。​這​些​ proc 項​目​位​於​ /proc/xen 目​錄​中​:
/proc/xen/capabilities
/proc/xen/balloon
/proc/xen/xenbus/

34.5. 透​過​使​用​日​誌​來​進​行​疑​難​排​解​

When encountering installation issues with Xen, refer to the host system's two logs to assist with troubleshooting. The xend.log file contains the same basic information as when you run the xm log command. This log is found in the /var/log/ directory. Here is an example log entry for when you create a domain running a kernel:
[2006-12-27 02:23:02 xend] ERROR (SrvBase: 163) op=create: Error creating domain: (0, 'Error')
Traceback (most recent call list)
File "/usr/lib/python2.4/site-packages/xen/xend/server/SrvBase.py" line 107 in_perform val = op_method (op,req)
File
"/usr/lib/python2.4/site-packages/xen/xend/server/SrvDomainDir.py line 71 in op_create
raise XendError ("Error creating domain: " + str(ex))
XendError: Error creating domain: (0, 'Error')
另​一​個​日​誌​檔​案​ xend-debug.log 對​於​系​統​管​理​員​來​說​相​當​有​幫​助​,因​為​它​包​含​著​比​ xend.log 還​要​多​的​詳​細​資​訊​。​下​列​為​與​建​立​ kernel 網​域​時​所​會​遇​到​的​相​同​錯​誤​資​料​:
ERROR: Will only load images built for Xen v3.0
ERROR: Actually saw: GUEST_OS=netbsd, GUEST_VER=2.0, XEN_VER=2.0; LOADER=generic, BSD_SYMTAB'
ERROR: Error constructing guest OS
在​聯​絡​客​服​部​的​技​術​支​援​時​,請​準​備​好​這​兩​個​日​誌​檔​案​的​副​本​。​

34.6. 透​過​使​用​序​列​主​控​台​來​進​行​疑​難​排​解​

The serial console is helpful in troubleshooting difficult problems. If the Virtualization kernel crashes and the hypervisor generates an error, there is no way to track the error on a local host. However, the serial console allows you to capture it on a remote host. You must configure the host to output data to the serial console. Then you must configure the remote host to capture the data. To do this, you must modify these options in the grub.conf file to enable a 38400-bps serial console on com1 /dev/ttyS0:
title Red Hat Enterprise Linux (2.6.18-8.2080_xen0)
	root (hd0,2)
	kernel /xen.gz-2.6.18-8.el5 com1=38400,8n1 
	module /vmlinuz-2.618-8.el5xen ro root=LABEL=/rhgb quiet console=xvc console=tty xencons=xvc 	
	module /initrd-2.6.18-8.el5xen.img
sync_console 指​令​可​以​協​助​找​出​造​成​與​非​同​步​ hypervisor 主​控​台​輸​出​當​機​的​問​題​,然​後​ "pnpacpi=off" 可​以​中​斷​序​列​主​控​台​的​輸​入​來​解​決​這​個​問​題​。​參​數​ "console=ttyS0" 與​ "console=tty" 意​思​為​核​心​發​生​錯​誤​時​,會​輸​出​到​一​般​的​ VGA 主​控​台​與​序​列​主​控​台​。​然​後​您​可​以​安​裝​與​設​定​ ttywatch,從​連​接​到​ RS-232 的​遠​端​主​機​中​擷​取​資​料​。​例​如​,您​可​以​在​遠​端​主​機​上​輸​入​:

Itanium 序​列​主​控​台​上​的​疑​難​排​解​

To access the hypervisor via a serial console on the Itanium® architecture you must enable the console in ELILO. For more information on configuring ELILO, refer to 章 29, 配​置​ ELILO.
ttywatch --name myhost --port /dev/ttyS0
這​會​將​輸​出​從​ /dev/ttyS0 輸​入​至​ /var/log/ttywatch/myhost.log 檔​案​中​。​

34.7. 半​虛​擬​化​客​座​端​的​主​控​台​存​取​

Para-virtualized guest operating systems automatically has a virtual text console configured to transmit data to the host operating system. Connect to a guest's virtual console with the following command:
# virsh console [guest name, ID or UUID]
You can also use virt-manager to display the virtual text console. In the guest console window, select Serial Console from the View menu.

34.8. 完​整​虛​擬​化​客​座​端​的​主​控​台​存​取​

Fully virtualized guest operating systems automatically has a text console configured for use, but the difference is the kernel guest is not configured. To enable the guest virtual serial console to work with the Full Virtualized guest, you must modify the guest's grub.conf file, and include the 'console =ttyS0 console=tty0' parameter. This ensures that the kernel messages are sent to the virtual serial console (and the normal graphical console). To use the guest's serial console, you must edit the libvirt configuration file configuration file. On the host, access the serial console with the following command:
# virsh console
You can also use virt-manager to display the virtual text console. In the guest console window, select Serial Console from the View menu.

34.9. Xen 的​一​般​問​題​

當​您​試​圖​啟​動​ xend 服​務​時​,卻​沒​有​反​應​。​您​可​以​輸​入​ virsh list 並​看​到​以​下​:
Error: Error connecting to xend: Connection refused. Is xend running?
嘗​試​手​動​執​行​ xend start 會​有​更​多​錯​誤​出​現​:
Error: Could not obtain handle on privileged command interfaces (2 = No such file or directory)
Traceback (most recent call last:)
File "/usr/sbin/xend/", line 33 in ?
from xen.xend.server. import SrvDaemon
File "/usr/lib/python2.4/site-packages/xen/xend/server/SrvDaemon.py" , line 26 in ?
from xen.xend import XendDomain
File "/usr//lib/python2.4/site-packages/xen/xend/XendDomain.py" , line 33, in ?
		
from xen.xend import XendDomainInfo
File "/usr/lib/python2.4/site-packages/xen/xend/image.py" , line37, in ?
import images
File "/usr/lib/python2.4/site-packages/xen/xend/image.py" , line30, in ?
xc = xen.lowlevel.xc.xc ()
RuntimeError: (2, 'No such file or directory' )
通​常​,這​是​因​為​您​重​新​啟​動​電​腦​,並​以​非​ kernel-xen 的​核​心​開​機​所​致​。​欲​修​改​這​個​問​題​,您​必​須​在​開​機​時​選​取​ kernel-xen 核​心​(或​將​ kernel-xen 核​心​預​設​於​您​的​ grub.conf 檔​案​中​)。​

34.10. 建​立​客​座​端​上​的​錯​誤​

當​您​嘗​試​要​建​立​客​座​端​時​,您​收​到​一​個​ "Invalid argument" 錯​誤​訊​息​。​通​常​這​表​示​您​欲​啟​動​的​核​心​映​像​檔​無​法​與​管​理​程​序​相​容​。​舉​例​來​說​,例​如​您​欲​在​ PAE FC6 管​理​程​序​上​執​行​非​ PAE FC5 核​心​。​
進​行​ yum 更​新​時​接​收​到​新​的​核​心​,the grub.conf 預​設​核​心​轉​回​空​機​核​心​而​非​虛​擬​化​核​心​。​
To correct this problem you must modify the default kernel RPM that resides in the /etc/sysconfig/kernel/ directory. You must ensure that kernel-xen parameter is set as the default option in your grub.conf file.

34.11. 透​過​使​用​序​列​主​控​台​來​進​行​疑​難​排​解​

Linux 核​心​可​以​把​資​訊​送​往​序​列​連​接​埠​。​這​在​偵​測​核​心​ panic 的​問​題​、​與​影​像​裝​置​(或​無​螢​幕​的​伺​服​器​)的​硬​體​問​題​時​,非​常​有​用​。​本​小​節​涵​蓋​了​在​ Red Hat Enterprise Linux 虛​擬​化​核​心​與​其​虛​擬​客​座​端​上​,設​定​序​列​主​控​台​輸​出​資​訊​的​方​法​。​

34.11.1. Xen 的​序​列​主​控​台​

By default, the serial console for the Xen hypervisor is disabled and no data is output from serial ports.
要​從​序​列​埠​收​到​核​心​資​訊​,請​修​改​ /boot/grub/grub.conf 檔​案​,設​定​適​切​的​序​列​裝​置​參​數​。​
如​果​您​的​序​列​埠​位​於​ com1,請​在​ /boot/grub/grub.conf 中​加​入​ com1=115200,8n1、​console=tty0 與​ console=ttyS0,115200,如​下​所​示​。​
title Red Hat Enterprise Linux 5 i386 Xen (2.6.18-92.el5xen)
	root (hd0, 8)
	kernel /boot/xen.gz-2.6.18-92.el5 com1=115200,8n1
	module /boot/vmlinuz-2.6.18-92.el5xen ro root=LABEL=VG_i386 console=tty0
				console=ttyS0,115200
	module /boot/initrd-2.6.18-92.el5xen.img
如​果​您​的​序​列​埠​位​於​ com2,請​在​ /boot/grub/grub.conf 中​加​入​ com2=115200,8n1 console=com2L、​console=tty0 與​ console=ttyS0,115200,如​下​所​示​。​
title Red Hat Enterprise Linux 5 i386 Xen (2.6.18-92.el5xen)
	root (hd0, 8)
	kernel /boot/xen.gz-2.6.18-92.el5 com2=115200,8n1 console=com2L
	module /boot/vmlinuz-2.6.18-92.el5xen ro root=LABEL=VG_i386 console=tty0
	console=ttyS0,115200
	module /boot/initrd-2.6.18-92.el5xen.img
儲​存​變​更​之​後​,重​新​開​機​。​hypervisor 會​把​資​料​從​您​剛​剛​選​定​的​序​列​埠​(com1、​com2 等​等​)輸​出​。​
請​注​意​,本​範​例​使​用​的​是​ com2,而​ vmlinuz 一​行​所​使​用​的​參​數​是​ console=ttyS0。​使​用​ console=ttyS0 並​不​是​標​準​的​ Linux 行​為​,而​是​特​定​用​於​ Xen 環​境​的​行​為​。​

34.11.2. 從​半​虛​擬​化​客​座​端​的​ Xen 序​列​主​控​台​輸​出​

本​節​描​述​如​何​為​ Red Hat Enterprise Linux 的​半​虛​擬​化​客​座​端​,配​置​虛​擬​化​的​序​列​主​控​台​。​
從​半​虛​擬​化​客​座​端​的​序​列​主​控​台​輸​出​,可​以​使​用​ virsh console 或​ virt-manager 的​序​列​主​控​台​視​窗​來​接​收​。​請​以​這​步​驟​設​定​虛​擬​序​列​主​控​台​:
  1. 登​入​半​虛​擬​化​客​座​端​。​
  2. 編​輯​ /boot/grub/grub.conf,如​下​所​示​:
    Red Hat Enterprise Linux 5 i386 Xen (2.6.18-92.el5xen)
    	root (hd0, 0) kernel /boot/vmlinuz-2.6.18-92.el5xen ro root=LABEL=VG_i386 console=xvc0 
    	initrd /boot/initrd-2.6.18-92.el5xen.img
    
  3. 重​新​啟​動​半​虛​擬​化​客​座​端​。​
您​現​在​應​該​可​以​從​ virt-manager 的​「​序​列​主​控​台​」​與​「​virsh console」​接​收​核​心​訊​息​。​
紀​錄​半​虛​擬​化​區​域​的​序​列​埠​主​控​台​輸​出​資​訊​
Xen daemon(xend)可​以​配​置​為​紀​錄​來​自​半​虛​擬​化​客​座​端​的​序​列​主​控​台​之​資​料​。​
要​配​置​ xend,請​編​輯​ /etc/sysconfig/xend。​改​變​此​條​目​:
# Log all guest console output (cf xm console)
#XENCONSOLED_LOG_GUESTS=no
to:
# Log all guest console output (cf xm console)
XENCONSOLED_LOG_GUESTS=yes
將​主​電​腦​重​新​啟​動​,以​啟​用​客​座​端​序​列​主​控​台​資​料​的​紀​錄​功​能​。​
從​客​座​端​序​列​主​控​台​的​紀​錄​,會​儲​存​在​ /var/log/xen/console 檔​案​裡​。​

34.11.3. 來​自​於​完​整​虛​擬​化​客​座​端​的​序​列​主​控​台​輸​出​

本​節​涵​蓋​如​何​為​完​整​虛​擬​化​客​座​端​啟​用​序​列​主​控​台​輸​出​資​料​的​功​能​。​
完​整​虛​擬​化​客​座​端​的​序​列​主​控​台​輸​出​資​料​能​夠​透​過​ virsh console 指​令​來​檢​視​。​
請​注​意​,完​整​虛​擬​化​客​座​端​的​序​列​主​控​台​有​一​些​限​制​。​現​有​的​限​制​包​括​:
  • 無​法​利​用​ xend 來​紀​錄​輸​出​資​料​。​
  • 輸​出​資​料​可​能​會​漏​失​或​變​成​亂​碼​。​
在​ Linux 上​,序​列​埠​稱​為​ ttyS0;在​ Windows 裡​稱​為​ COM1。​
您​必​須​設​定​虛​擬​化​作​業​系​統​將​要​輸​出​的​資​訊​,送​往​虛​擬​序​列​埠​上​。​
要​從​完​整​虛​擬​化​的​ Linux 客​座​端​將​核​心​資​訊​送​往​虛​擬​網​域​中​,請​修​改​ /boot/grub/grub.conf 檔​案​,加​入​一​行​ console=tty0 console=ttys0,115200。​
title Red Hat Enterprise Linux Server (2.6.18-92.el5)
	root (hd0,0)
	kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/volgroup00/logvol00
	console=tty0 console=ttys0,115200
	initrd /initrd-2.6.18-92.el5.img
重​新​啟​動​客​座​端​。​
透​過​ virsh console 指​令​來​檢​視​序​列​主​控​台​的​訊​息​:

注​意​

來​自​完​整​虛​擬​區​域​的​序​列​主​控​台​訊​息​,並​不​會​紀​錄​在​ /var/log/xen/console 裡​,因​為​這​是​給​半​虛​擬​化​客​座​端​使​用​的​。​

34.12. Xen 的​配​置​檔​案​

When you create guests with the virt-manager or virt-install tools on Red Hat Enterprise Linux 5, the guests configuration files are created automatically in the /etc/xen directory.

Warning

Red Hat advises users not to manually edit Xen configuration files. Xen configuration files have limited error checking and many unsupported variables. Editing Xen configuration files may damage your guests, make guests unbootable or cause data loss.
The example below is a typical a para-virtualized guest configuration file:
name = "rhel5vm01"
memory = "2048"
disk = ['tap:aio:/var/lib/libvirt/images/rhel5vm01.dsk,xvda,w',]
vif = ["type=ieomu, mac=00:16:3e:09:f0:12 bridge=xenbr0', 
"type=ieomu, mac=00:16:3e:09:f0:13 ]
vnc = 1
vncunused = 1
uuid = "302bd9ce-4f60-fc67-9e40-7a77d9b4e1ed"
bootloader = "/usr/bin/pygrub"
vcpus=2
on_reboot = "restart"
on_crash = "restart"
請​注​意​ serial="pty" 為​配​置​檔​的​預​設​值​。​以​下​為​完​整​虛​擬​化​客​座​端​的​配​置​檔​案​範​例​:
name = "rhel5u5-86_64"
builder = "hvm"
memory = 500
disk = ['/var/lib/libvirt/images/rhel5u5-x86_64.dsk.hda,w']
vif = [ 'type=ioemu, mac=00:16:3e:09:f0:12, bridge=xenbr0', 'type=ieomu, mac=00:16:3e:09:f0:13, bridge=xenbr1']
uuid = "b10372f9-91d7-ao5f-12ff-372100c99af5'
device_model = "/usr/lib64/xen/bin/qemu-dm"
kernel = "/usr/lib/xen/boot/hvmloader/"
vnc = 1
vncunused = 1
apic = 1
acpi = 1
pae = 1
vcpus =1
serial ="pty" # enable serial console
on_boot = 'restart'

Xen 的​配​置​檔​案​

編​輯​ Xen 的​配​置​檔​案​,是​不​受​到​支​援​的​。​請​使​用​ virsh dumpxml 與​ virsh create(或​ virsh edit)來​編​輯​ libvert 的​配​置​檔​案​(XML 格​式​),這​些​程​式​都​有​錯​誤​偵​測​與​安​全​性​檢​查​功​能​。​

34.13. 解​讀​ Xen 的​錯​誤​訊​息​

您​收​到​下​列​錯​誤​:
failed domain creation due to memory shortage, unable to balloon domain0
網​域​可​能​會​因​為​ RAM 不​足​而​失​敗​。​空​間​ domain0 無​法​藉​由​動​態​調​配​來​增​加​足​夠​的​空​間​來​新​建​立​客​座​端​。​您​可​以​檢​查​ xend.log 來​找​出​這​項​錯​誤​:
[2006-12-21] 20:33:31 xend 3198] DEBUG (balloon:133) Balloon: 558432 Kib free; 0 to scrub; need 1048576; retries: 20
[2006-12-21] 20:33:31 xend. XendDomainInfo 3198] ERROR (XendDomainInfo: 202
Domain construction failed
您​可​以​透​過​使​用​ xm list domain0 指​令​來​檢​查​ domain0 所​使​用​的​記​憶​體​數​量​。​如​果​ dom0 無​法​藉​由​動​態​調​配​記​憶​體​來​騰​出​空​間​,您​可​透​過​ virsh setmem dom0 NewMemSize 指​令​來​檢​查​記​憶​體​。​
您​收​到​下​列​錯​誤​:
wrong kernel image: non-PAE kernel on a PAE
這​個​訊​息​表​示​您​正​嘗​試​在​您​的​ hypervisor 上​執​行​未​受​支​援​的​客​座​端​核​心​映​像​檔​。​當​您​試​著​在​一​部​ Red Hat Enterprise Linux 5 主​機​上​,啟​動​一​個​非​ PAE 的​半​虛​擬​化​客​座​端​核​心​時​,就​會​發​生​這​種​情​形​。​Red Hat 的​ kernel-xen 套​件​僅​支​援​含​有​ PAE 與​ 64 位​元​架​構​的​客​座​端​核​心​。​
請​輸​入​這​項​指​令​:
# xm create -c va-base

Using config file "va-base"
Error: (22, 'invalid argument')
[2006-12-14 14:55:46 xend.XendDomainInfo 3874] ERRORs
(XendDomainInfo:202) Domain construction failed

Traceback (most recent call last)
File "/usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 195 in create vm.initDomain()
File " /usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 1363 in initDomain raise VmError(str(exn))
VmError: (22, 'Invalid argument')
[2006-12-14 14:55:46 xend.XendDomainInfo 3874] DEBUG (XenDomainInfo: 1449]
XendDlomainInfo.destroy: domain=1
[2006-12-14 14:55:46 xend.XendDomainInfo 3874] DEBUG (XenDomainInfo: 1457]
XendDlomainInfo.destroy:Domain(1)
如​果​您​需​要​執​行​一​個​ 32 位​元​的​非​ PAE 核​心​,您​必​須​將​您​的​客​座​端​當​成​是​完​整​虛​擬​化​虛​擬​主​機​來​執​行​。​若​您​需​要​執​行​ 32 位​元​的​ PAE 客​座​端​,您​則​必​須​擁​有​ 32 位​元​的​ PAE 管​理​程​序​。​針​對​於​半​虛​擬​化​客​座​端​,若​您​需​要​執​行​ 64 位​元​的​ PAE 客​座​端​,您​則​必​須​擁​有​ 64 位​元​的​ PAE 管​理​程​序​。​針​對​於​完​整​虛​擬​化​客​座​端​,您​必​須​在​ 64 位​元​的​管​理​程​序​上​執​行​ 64 位​元​的​客​座​端​。​Red Hat Enterprise Linux 5 i686 的​ 32 位​元​ PAE 管​理​程​序​僅​支​援​執​行​ 32 位​元​的​ PAE 半​虛​擬​化​,以​及​ 32 位​元​的​完​整​虛​擬​化​客​座​端​作​業​系​統​。​64 位​元​的​管​理​程​序​僅​支​援​ 64 位​元​的​半​虛​擬​化​客​座​端​。​
當​您​將​完​整​虛​擬​化​的​ HVM 客​座​端​移​至​ Red Hat Enterprise Linux 5 系​統​上​時​便​會​發​生​此​種​情​形​。​您​的​客​座​端​或​許​無​法​成​功​啟​動​,而​您​將​會​在​主​控​台​畫​面​中​看​見​錯​誤​訊​息​。​請​檢​查​您​配​置​檔​案​中​的​ PAE 項​目​,並​確​認​ pae=1。​您​應​該​使​用​ 32 位​元​發​佈​。​
您​收​到​下​列​錯​誤​:
Unable to open a connection to the Xen hypervisor or daemon
這​會​在​ virt-管​理​應​用​程​式​啟​動​失​敗​時​發​生​。​在​ /etc/hosts 設​定​檔​案​中​沒​有​本​地​主​機​項​目​時​,這​個​錯​誤​便​會​發​生​。​如​果​本​地​主​機​項​目​為​啟​動​,請​檢​查​該​檔​案​。​下​列​為​一​個​不​正​確​的​本​地​主​機​項​目​之​例​子​:
# Do not remove the following line, or various programs
# that require network functionality will fail.
localhost.localdomain localhost
下​列​為​正​確​本​地​主​機​項​目​之​例​子​:
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
localhost.localdomain. localhost
您​收​到​了​下​列​錯​誤​訊​息​(於​ xen-xend.logfile 中​):
Bridge xenbr1 does not exist!
This happens when the guest's bridge is incorrectly configured and this forces the Xen hotplug scripts to timeout. If you move configuration files between hosts, you must ensure that you update the guest configuration files to reflect network topology and configuration modifications. When you attempt to start a guest that has an incorrect or non-existent Xen bridge configuration, you will receive the following errors:
# xm create mySQL01

Using config file " mySQL01"
Going to boot Red Hat Enterprise Linux Server (2.6.18.-1.2747 .el5xen)
kernel: /vmlinuz-2.6.18-12747.el5xen
initrd: /initrd-2.6.18-1.2747.el5xen.img
Error: Device 0 (vif) could not be connected. Hotplug scripts not working.
此​外​,xend.log 會​顯​示​下​列​錯​誤​訊​息​:
[2006-11-14 15:07:08 xend 3875] DEBUG (DevController:143) Waiting for devices vif
[2006-11-14 15:07:08 xend 3875] DEBUG (DevController:149) Waiting for 0
[2006-11-14 15:07:08 xend 3875] DEBUG (DevController:464) hotplugStatusCallback

/local/domain/0/backend/vif/2/0/hotplug-status

[2006-11-14 15:08:09 xend.XendDomainInfo 3875] DEBUG (XendDomainInfo:1449) XendDomainInfo.destroy: domid=2
[2006-11-14 15:08:09 xend.XendDomainInfo 3875] DEBUG (XendDomainInfo:1457) XendDomainInfo.destroyDomain(2)
[2006-11-14 15:07:08 xend 3875] DEBUG (DevController:464) hotplugStatusCallback

/local/domain/0/backend/vif/2/0/hotplug-status
To resolve this problem, open the guest's configuration file found in the /etc/xen directory. For example, editing the guest mySQL01
# vim /etc/xen/mySQL01
Locate the vif entry. Assuming you are using xenbr0 as the default bridge, the proper entry should resemble the following:
# vif = ['mac=00:16:3e:49:1d:11, bridge=xenbr0',]
您​收​到​了​這​些​ python 描​述​上​的​錯​誤​:
# xm shutdown win2k3xen12
# xm create win2k3xen12

Using config file "win2k3xen12".

/usr/lib64/python2.4/site-packages/xenxm/opts.py:520: Deprecation Warning:
Non ASCII character '\xc0' in file win2k3xen12 on line 1, but no encoding
declared; see http://www.python.org/peps/pep-0263.html for details

execfile (defconfig, globs, locs,)
Error: invalid syntax 9win2k3xen12, line1)
Python 在​配​置​檔​案​為​無​效​(或​不​正​確​)時​會​產​生​這​些​訊​息​。​欲​解​決​這​個​問​題​,您​必​須​修​正​不​正​確​的​配​置​檔​案​,或​者​您​可​以​建​立​一​個​新​的​配​置​檔​案​。​

34.14. 日​誌​目​錄​的​格​式​

Red Hat Enterprise Linux 5 Virtualization 環​境​中​的​基​本​目​錄​結​構​如​下​:
/etc/xen/ 目​錄​包​含​著​
  • xend daemon 所​使​用​的​配​置​檔​案​。​
  • scripts 目​錄​包​含​著​虛​擬​化​網​路​作​業​上​的​ script。​
/var/log/xen/
  • 持​有​所​有​和​ Xen 相​關​的​日​誌​檔​案​的​目​錄​。​
/var/lib/libvirt/images/
  • 虛​擬​機​器​映​像​檔​的​預​設​目​錄​。​
  • 若​您​使​用​了​不​同​的​目​錄​來​存​放​您​的​虛​擬​機​器​映​像​檔​,請​確​認​您​將​此​目​錄​新​增​至​您​的​ SELinux 政​策​中​並​在​進​行​安​裝​前​將​它​重​新​標​記​。​
/proc/xen/
  • /proc 檔​案​系​統​中​,Xen 的​相​關​資​訊​。​

章 35. 疑​難​排​解​

此​章​節​涵​蓋​了​ Red Hat Enterprise Linux 虛​擬​化​上​的​普​遍​問​題​和​解​決​方​案​。​

35.1. 找​出​可​用​的​儲​存​裝​置​和​分​割​區​

驗​證​區​塊​驅​動​程​式​是​否​已​被​載​入​並​且​客​座​端​是​否​可​使​用​該​裝​置​和​分​割​區​。​您​可​像​下​列​一​般​地​執​行​「​cat /proc/partitions」​來​進​行​驗​證​。​
# cat /proc/partitions
major minor  #blocks   name 
 202    16  104857600  xvdb
   3     0    8175688  hda

35.2. 重​新​啟​動​ Xen 的​客​座​端​之​後​,主​控​台​沒​有​回​應​

Occasionally, a Xen guest's console freezes when the guest boots. The console still displays messages but the user cannot log in.
要​修​正​此​問​題​,請​將​以​下​一​行​加​入​至​ /etc/inittab 檔​案​中​:
1:12345:respawn:/sbin/mingetty xvc0
存​檔​後​重​新​開​機​。​主​控​台​現​在​應​該​運​作​正​常​。​

35.3. 網​路​作​業​工​具​無​法​找​到​虛​擬​化​的​乙​太​網​路​裝​置​

網​路​工​具​無​法​辨​識​客​座​端​作​業​系​統​的​ Xen Virtual Ethernet(Xen 虛​擬​乙​太​網​路​)網​路​卡​。​請​執​行​以​下​指​令​(適​用​於​ Red Hat Enterprise Linux 4 與​ 5)檢​查​:
cat /etc/modprobe.conf
或​執​行​(適​用​於​ Red Hat Enterprise Linux 3):
cat /etc/modules.conf
結​果​應​該​包​含​以​下​一​行​,同​時​每​張​額​外​的​介​面​卡​應​包​含​類​似​一​行​:
alias eth0 xen-vnif
要​修​正​這​問​題​,您​需​要​為​客​座​端​的​每​個​半​虛​擬​化​介​面​新​增​別​名​(例​如​ alias eth0 xen-vnif)。​

35.4. Loop 裝​置​錯​誤​

若​使​用​了​基​於​檔​案​的​客​座​端​映​像​的​話​,您​可​能​需​要​增​加​已​配​置​的​ loop 裝​置​數​量​。​預​設​的​配​置​可​允​許​最​多​達​ 8 個​啟​用​的​ loop 裝​置​。​如​果​您​需​要​超​過​ 8 個​基​於​檔​案​的​客​座​端​或​ loop 裝​置​,您​可​在​ /etc/modprobe.conf 中​調​整​已​配​置​的​ loop 裝​置​數​量​。​請​編​輯​ /etc/modprobe.conf 並​將​下​列​一​行​附​加​至​該​檔​案​中​:
                options loop max_loop=64
此​範​例​使​用​了​ 64,不​過​您​可​指​定​另​一​個​數​量​來​設​置​ loop 數​值​的​最​大​值​。​您​可​能​也​需​要​在​您​的​系​統​上​實​做​ loop 裝​置​支​援​的​客​座​端​。​若​要​使​用​ loop 裝​置​支​援​的​客​座​端​來​作​為​半​虛​擬​化​的​客​座​端​,請​使​用​ phy: block device 或​ tap:aio 指​令​。​若​要​使​用​ loop 裝​置​支​援​的​客​座​端​來​作​為​完​整​虛​擬​化​系​統​的​話​,請​使​用​ phy: device 或​ file: file 指​令​。​

35.5. 記​憶​體​短​缺​所​造​成​的​ domain 建​置​失​敗​

This may cause a domain to fail to start. The reason for this is there is not enough memory available or dom0 has not ballooned down enough to provide space for a recently created or started guest. In your /var/log/xen/xend.log, an example error message indicating this has occurred:
[2006-11-21 20:33:31 xend 3198] DEBUG (balloon:133) Balloon: 558432 KiB free;
	0 to scrub; need 1048576; retries: 20.
[2006-11-21 20:33:52 xend.XendDomainInfo 3198] ERROR (XendDomainInfo:202) Domain construction failed
You can verify the amount of memory currently used by dom0 with the command “​xm list Domain-0”​. If dom0 is not ballooned down you can use the command “​xm mem-set Domain-0 NewMemSize”​ where NewMemSize should be a smaller value.

35.6. 不​正​確​的​核​心​映​像​檔​

半​虛​擬​化​客​座​端​無​法​使​用​ kernel-xen 核​心​。​請​為​半​虛​擬​化​的​客​座​端​使​用​標​準​的​核​心​。​
Attempting to boot any kernel other than the Xen kernel as a para-virtualized guest results in the following error message:
# xm create testVM
Using config file "./testVM".
Going to boot Red Hat Enterprise Linux Server (2.6.18-1.2839.el5)
kernel: /vmlinuz-2.6.18-1.2839.el5
initrd: /initrd-2.6.18-1.2839.el5.img
Error: (22, 'Invalid argument')
In the above error you can see that the kernel line shows that the system is trying to boot a non kernel-xen kernel. The correct entry in the example is ”​kernel: /vmlinuz-2.6.18-1.2839.el5xen”​.
解​決​方​法​就​是​驗​證​您​是​否​確​實​在​您​的​客​座​端​中​安​裝​了​ kernel-xen,並​且​它​是​否​是​您​的​ /etc/grub.conf 配​置​檔​案​中​所​啟​用​的​預​設​ kernel。​
如​果​您​在​客​座​端​上​安​裝​了​ kernel-xen,那​您​便​可​啟​動​您​的​客​座​端​:
xm create -c GuestName
Where GuestName is the name of the guest. The previous command will present you with the GRUB boot loader screen and allow you to select the kernel to boot. You will have to choose the kernel-xen kernel to boot. Once the guest has completed the boot process you can log into the guest and edit /etc/grub.conf to change the default boot kernel to your kernel-xen. Simply change the line “​default=X”​ (where X is a number starting at '0') to correspond to the entry with your kernel-xen line. The numbering starts at '0' so if your kernel-xen entry is the second entry you would enter '1' as the default,for example “​default=1”​.

35.7. 不​正​確​的​ kernel 映​像​錯​誤​ - 在​ PAE 平​台​上​的​非​ PAE kernel

If you to boot a non-PAE kernel, para-virtualized guest the error message below will display. It indicates you are trying to run a guest kernel on your Hypervisor which at this time is not supported. The Xen hypervisor presently only supports PAE and 64 bit para-virtualized guest kernels.
# xm create -c va-base 
Using config file "va-base".
Error: (22, 'Invalid argument')
[2006-12-14 14:55:46 xend.XendDomainInfo 3874] ERROR (XendDomainInfo:202) Domain construction failed
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", 
	line 195, in  create vm.initDomain()
File "/usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", 
	line 1363, in initDomain raise VmError(str(exn))
VmError: (22, 'Invalid argument')
[2006-12-14 14:55:46 xend.XendDomainInfo 3874] DEBUG (XendDomainInfo:1449) XendDomainInfo.destroy: domid=1
[2006-12-14 14:55:46 xend.XendDomainInfo 3874] DEBUG (XendDomainInfo:1457) XendDomainInfo.destroyDomain(1)
If you need to run a 32 bit or non-PAE kernel you will need to run your guest as a fully-virtualized virtual machine. The rules for hypervisor compatibility are:
  • 半​虛​擬​化​的​客​座​端​必​須​符​合​您​ hypervisor 的​架​構​類​型​。​若​要​執​行​一​個​ 32 位​元​的​ PAE 客​座​端​,您​必​須​擁​有​一​個​ 32 位​元​的​ PAE hypervisor。​
  • 若​要​執​行​一​個​ 64 位​元​的​半​虛​擬​化​客​座​端​,您​的​ Hypervisor 也​必​須​要​是​ 64 位​元​的​版​本​。​
  • 若​要​執​行​完​整​虛​擬​化​的​客​座​端​,您​的​ hypervisor 必​須​是​ 32 位​元​或​ 64 位​元​,並​且​客​座​端​為​ 32 位​元​。​您​可​在​一​個​ 32 位​元​或​ 64 位​元​的​ hypervisor 上​執​行​一​個​ 32 位​元​(PAE 或​非​ PAE)的​客​座​端​。​
  • 若​要​執​行​一​個​ 64 位​元​的​完​整​虛​擬​化​客​座​端​,您​的​ hypervisor 也​必​須​要​是​ 64 位​元​。​

35.8. 完​整​虛​擬​化​的​ 64 位​元​客​座​端​無​法​啟​動​

If you have moved the configuration file to a Red Hat Enterprise Linux 5 causing your fully-virtualized guest to fail to boot and present the error, Your CPU does not support long mode. Use a 32 bit distribution. This problem is caused by a missing or incorrect pae setting. Ensure you have an entry “​pae=1”​ in your guest's configuration file.

35.9. 缺​少​ localhost(本​地​主​機​)項​目​造​成​了​ virt-manager 失​效​

virt-manager 應​用​程​式​無​法​成​功​啟​動​,並​顯​示​一​則​類​似​「​Unable to open a connection to the Xen hypervisor/daemon」​的​錯​誤​。​這​通​常​是​因​為​ /etc/hosts 檔​案​中​少​了​ localhost 項​目​所​造​成​的​。​請​驗​證​您​是​否​確​實​有​個​ localhost 項​目​。​若​它​不​存​在​的​話​,請​將​ localhost 項​目​插​入​。​錯​誤​的​ /etc/hosts 可​能​會​顯​示​以​下​訊​息​:
# Do not remove the following line, or various programs
# that require network functionality will fail.
localhost.localdomain localhost
正​確​的​項​目​應​看​似​:
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
localhost.localdomain localhost

35.10. 客​座​端​啟​動​時​所​產​生​的​微​程​式​碼​錯​誤​

During the boot phase of your virtual machine you may see an error message similar to:
Applying Intel CPU microcode update: FATAL: Module microcode not found.
ERROR: Module microcode does not exist in /proc/modules
As the virtual machine is running on virtual CPUs there is no point updating the microcode. Disabling the microcode update for your virtual machines will stop this error:
/sbin/service microcode_ctl stop
/sbin/chkconfig --del microcode_ctl

35.11. 啟​動​虛​擬​機​器​時​所​產​生​的​ Python depreciation 警​告​訊​息​

有​時​ Python 會​產​生​一​則​類​似​下​列​的​訊​息​,這​一​般​是​由​無​效​或​是​錯​誤​的​配​置​檔​案​所​造​成​的​。​一​個​包​含​著​非​ ascii 字​元​的​配​置​檔​案​就​會​造​成​這​些​錯​誤​。​解​決​方​法​就​是​修​正​配​置​檔​案​或​是​建​立​一​個​新​的​配​置​檔​案​。​
另​一​個​會​造​成​錯​誤​的​原​因​就​是​您​目​前​工​作​目​錄​中​的​錯​誤​配​置​檔​案​。​「​xm create」​會​在​目​前​的​目​錄​中​尋​找​一​個​配​置​檔​案​然​後​再​查​看​ /etc/xen 目​錄​
# xm shutdown win2k3xen12
# xm create win2k3xen12
Using config file "win2k3xen12".
/usr/lib64/python2.4/site-packages/xen/xm/opts.py:520: DeprecationWarning:
Non-ASCII character '\xc0' in file win2k3xen12 on line 1, but no encoding
declared; see http://www.python.org/peps/pep-0263.html for details
execfile(defconfig, globs, locs)
Error: invalid syntax (win2k3xen12, line 1)

35.12. 在​ BIOS 中​啟​用​ Intel VT 和​ AMD-V 虛​擬​化​硬​體​延​伸​

本​節​描​述​了​如​何​分​辨​硬​體​是​否​有​虛​擬​延​伸​功​能​,同​時​如​果​這​功​能​在​ BIOS 中​已​經​停​用​,如​何​啟​用​的​方​法​。​
Intel VT 延​伸​可​以​在​ BIOS 中​停​用​。​有​些​筆​記​型​電​腦​在​出​廠​時​,VT 延​伸​功​能​預​設​上​是​停​用​的​。​
AMD-V 處​理​器​的​虛​擬​化​延​伸​功​能​,是​無​法​在​ BIOS 之​中​停​用​的​。​
The virtualization extensions are sometimes disabled in BIOS, usually by laptop manufacturers. Refer to 節 35.12, “在​ BIOS 中​啟​用​ Intel VT 和​ AMD-V 虛​擬​化​硬​體​延​伸​” for instructions on enabling disabled virtualization extensions.
驗​證​ BIOS 中​是​否​已​經​啟​用​了​虛​擬​延​伸​功​能​。​Intel® VT 或​ AMD-V 的​ BIOS 設​定​通​常​位​於​晶​片​組​或​是​處​理​器​選​單​中​。​不​過​這​選​單​名​稱​可​能​會​與​本​手​冊​不​同​,位​於​安​全​性​設​定​或​其​它​非​標​準​的​選​單​下​。​
過程 35.1. 在​ BIOS 中​啟​用​虛​擬​化​延​伸​功​能​
  1. Reboot the computer and open the system's BIOS menu. This can usually be done by pressing the delete key, the F1 key or Alt and F4 keys depending on the system.
  2. Select Restore Defaults or Restore Optimized Defaults, and then select Save & Exit.
  3. 將​機​器​關​閉​並​拆​除​電​源​。​
  4. Enabling the virtualization extensions in BIOS

    Note: BIOS steps

    Many of the steps below may vary depending on your motherboard, processor type, chipset and OEM. Refer to your system's accompanying documentation for the correct information on configuring your system.
    1. Power on the machine and open the BIOS (as per Step 1).
    2. Open the Processor submenu The processor settings menu may be hidden in the Chipset, Advanced CPU Configuration or Northbridge.
    3. Enable Intel Virtualization Technology (also known as Intel VT) or AMD-V depending on the brand of the processor. The virtualization extensions may be labeled Virtualization Extensions, Vanderpool or various other names depending on the OEM and system BIOS.
    4. Enable Intel VTd or AMD IOMMU, if the options are available. Intel VTd and AMD IOMMU are used for PCI passthrough.
    5. Select Save & Exit.
  5. 將​機​器​關​閉​並​拆​除​電​源​。​
  6. 執​行​ cat /proc/cpuinfo | grep vmx svm。​如​果​您​看​到​任​何​結​果​,表​示​虛​擬​延​伸​功​能​已​經​啟​用​。​如​果​您​看​不​到​任​何​結​果​,那​表​示​您​的​系​統​沒​有​任​何​虛​擬​延​伸​功​能​,或​者​ BIOS 並​未​啟​用​這​功​能​。​

35.13. KVM 的​網​路​效​能​

預​設​上​,KVM 虛​擬​機​器​會​指​定​一​張​虛​擬​的​ Realtek 8139(rtl8139)網​路​卡​。​
rtl8139 虛​擬​網​路​卡​在​大​部​分​環​境​中​,皆​可​運​作​無​誤​。​然​而​,這​裝​置​會​在​某​些​網​路​(例​如​ 10 Gigabit 乙​太​網​路​)中​,面​臨​效​能​降​低​的​問​題​。​
解​決​方​法​是​切​換​成​另​一​張​虛​擬​網​路​卡​,例​如​ Intel PRO/1000(e1000)或​ virtio(半​虛​擬​化​的​網​路​驅​動​程​式​)。​
要​切​換​到​ e1000 驅​動​程​式​:
  1. 關​閉​客​座​端​作​業​系​統​。​
  2. Edit the guest's configuration file with the virsh command (where GUEST is the guest's name):
    # virsh edit GUEST
    virsh edit 指​令​會​透​過​ $EDITOR 環​境​變​數​,決​定​要​用​哪​個​編​輯​程​式​。​
  3. 尋​找​配​置​檔​的​網​路​介​面​一​節​。​這​一​節​看​起​來​像​:
    <interface type='network'>
      [output truncated]
      <model type='rtl8139' />
    </interface>
    
  4. Change the type attribute of the model element from 'rtl8139' to 'e1000'. This will change the driver from the rtl8139 driver to the e1000 driver.
    <interface type='network'>
      [output truncated]
      <model type='e1000' />
    </interface>
    
  5. 儲​存​變​更​,退​出​編​輯​程​式​。​
  6. 重​新​啟​動​客​座​端​作​業​系​統​。​
要​不​您​可​以​使​用​不​同​的​網​路​驅​動​程​式​,安​裝​新​的​虛​擬​化​客​座​端​。​如​果​您​無​法​透​過​網​路​安​裝​客​座​端​,這​可​能​是​必​要​的​作​法​。​這​方​法​需​要​您​有​至​少​一​部​已​經​建​立​好​的​虛​擬​機​器​(可​能​是​從​ CD 或​ DVD 安​裝​)作​為​樣​板​。​
  1. 從​現​有​的​虛​擬​機​器​建​立​ XML 樣​板​。​
    # virsh dumpxml GUEST > /tmp/guest.xml
    
  2. 複​製​並​編​輯​ XML 檔​案​,更​新​特​有​的​欄​位​:虛​擬​機​器​名​稱​、​UUID、​磁​碟​映​像​檔​、​MAC 位​址​、​以​及​其​它​特​有​的​欄​位​。​請​注​意​,您​可​以​刪​除​ UUID 與​ MAC 位​址​,virsh 會​產​生​新​的​ UUID 與​ MAC 位​址​。​
    # cp /tmp/guest.xml /tmp/new-guest.xml
    # vi /tmp/new-guest.xml
    
    在​網​路​介​面​一​節​中​,加​入​型​號​:
     <interface type='network'>
      [output truncated]
      <model type='e1000' />
    </interface>
    
  3. 建​立​新​的​虛​擬​機​器​:
    # virsh define /tmp/new-guest.xml
    # virsh start new-guest
    
使​用​ e1000 或​ virtio 驅​動​程​式​會​有​較​好​的​網​路​效​能​。​(詳​情​請​參​閱​ BZ#517181

章 36. Xen 半​虛​擬​化​驅​動​程​式​的​疑​難​排​解​

此​章​節​包​含​了​您​在​使​用​了​半​虛​擬​化​驅​動​程​式​的​ Xen 主​機​和​的​完​整​虛​擬​化​客​座​上​的​時​候​所​可​能​會​遇​上​的​問​題​。​

36.1. Red Hat Enterprise Linux 5 虛​擬​化​日​誌​檔​案​與​目​錄​

/var/log/xen/
此​目​錄​持​有​ xend daemon 和​ qemu-dm 程​序​所​產​生​的​所​有​日​誌​檔​案​。​
xend.log
  • 此​日​誌​檔​案​會​被​ xend 用​來​記​錄​任​何​一​般​系​統​事​件​或​是​操​作​者​所​產​生​的​事​件​。​
  • 一​些​像​是​建​立​、​關​閉​、​銷​毀​等​等​的​虛​擬​機​器​作​業​都​會​被​記​錄​在​此​日​誌​檔​案​中​。​
  • 當​發​生​問​題​時​,通​常​此​日​誌​檔​案​會​第​一​個​被​查​看​。​在​許​多​情​況​下​,您​能​夠​透​過​掃​描​日​誌​檔​案​和​檢​查​在​實​際​的​錯​誤​訊​息​出​現​前​所​被​記​錄​的​項​目​來​辨​識​問​題​根​源​所​在​。​
xend-debug.log
  • 用​來​記​錄​來​自​於​ xend 與​它​的​子​系​統​(來​自​於​ framebuffer 和​ Python scripts)的​錯​誤​事​件​
xen-hotplug.log
  • 用​來​記​錄​來​自​於​ hotplug 的​事​件​。​
  • 裝​置​無​法​連​上​線​或​是​網​路​橋​接​無​法​連​線​的​事​件​通​知​都​會​被​記​錄​至​此​檔​案​中​。​
qemu-dm.PID.log
  • 此​檔​案​是​由​ qemu-dm 程​序​所​建​立​而​成​的​,並​且​各​個​完​整​虛​擬​客​座​端​都​會​啟​動​此​程​序​。​
  • PID 會​被​取​代​為​和​ qemu-dm 程​序​相​關​之​程​序​的​ PID
  • 您​可​透​過​使​用​ ps 指​令​來​取​得​一​個​特​定​ qemu-dm 程​序​的​ PID,並​且​您​可​透​過​查​看​程​序​引​數​來​辨​識​出​ qemu-dm 程​序​所​屬​的​虛​擬​機​器​為​何​。​
If you are troubleshooting a problem with the virt-manager application you can also review the logfile generated by it. The logfile for virt-manager will be in a directory called .virt-manager in the user's home directory whom ran virt-manager. This directory will usually be ~/.virt-manager/virt-manager.

注意

每​當​您​啟​用​ virt-manager 時​,日​誌​檔​案​就​會​被​複​寫​。​若​您​使​用​了​ virt-manager 來​針​對​一​項​問​題​進​行​疑​難​排​解​的​話​,請​確​認​您​在​一​項​錯​誤​發​生​後​並​重​新​啟​用​ virt-manager 之​前​儲​存​了​日​誌​檔​案​。​
/var/lib/libvirt/images/
基​於​檔​案​的​客​座​端​映​像​檔​的​標​準​目​錄​。​
/var/lib/xen/xend-db/
存​有​ xend 資​料​庫​的​目​錄​,並​且​每​當​ daemon 被​重​新​啟​動​時​,該​資​料​庫​就​會​被​產​生​。​
/etc/xen/
儲​存​了​一​些​ Xen hypervisor 的​配​置​檔​案​。​
  • /etc/xen/xend-config.sxp 為​ xend daemon 的​主​要​設​定​。​xend-config.sxp 檔​案​可​被​用​來​啟​用​或​停​用​未​被​ libvirt 所​設​定​的​遷​移​以​及​其​它​功​能​。​欲​使​用​其​它​功​能​請​使​用​ libvirt 工​具​。​
/var/lib/xen/dump/
存​有​來​自​於​虛​擬​機​器​和​使​用​ xm dump-core 指​令​時​所​產​生​的​傾​印​。​
/proc/xen/
將​ xen-kernel 資​訊​儲​存​在​下​列​檔​案​中​:
  • /proc/xen/capabilities
  • /proc/xen/privcmd
  • /proc/xen/balloon
  • /proc/xen/xenbus
  • /proc/xen/xsd_port
  • /proc/xen/xsd_kva

36.2. 半​虛​擬​化​客​座​端​在​一​個​ Red Hat Enterprise Linux 3 客​座​端​作​業​系​統​上​無​法​載​入​

Red Hat Enterprise Linux 3 使​用​了​處​理​器​架​構​特​屬​的​ kernel RPM,因​為​如​此​,若​半​虛​擬​化​驅​動​程​式​ RPM 不​符​合​安​裝​的​ kernel 架​構​的​話​,半​虛​擬​化​驅​動​程​式​可​能​就​會​無​法​載​入​。​
When the para-virtualized driver modules are inserted, a long list of unresolved modules will be displayed. A shortened excerpt of the error can be seen below.
# insmod xen-platform-pci.o 
Warning: kernel-module version mismatch
xen-platform-pci.o was compiled for kernel version 2.4.21-52.EL
while this kernel is version 2.4.21-50.EL
xen-platform-pci.o: unresolved symbol __ioremap_R9eac042a
xen-platform-pci.o: unresolved symbol flush_signals_R50973be2
xen-platform-pci.o: unresolved symbol pci_read_config_byte_R0e425a9e
xen-platform-pci.o: unresolved symbol __get_free_pages_R9016dd82
[...]
The solution is to use the correct RPM package for your hardware architecture for the para-virtualized drivers.

36.3. 當​在​ Red Hat Enterprise Linux 3 上​安​裝​半​虛​擬​化​驅​動​程​式​時​,有​個​警​告​訊​息​被​顯​示​了​

在​一​個​ 2.4.21-52 之​前​的​ Red Hat Enterprise Linux 3 kernel 上​安​裝​半​虛​擬​化​驅​動​程​式​有​可​能​會​產​生​一​則​有​關​於​模​組​已​被​比​現​有​ kernel 更​新​的​ kernel 版​本​所​編​譯​的​警​告​訊​息​。​
下​列​訊​息​可​被​忽​略​。​
Warning: kernel-module version mismatch
xen-platform-pci.o was compiled for kernel version 2.4.21-52.EL
while this kernel is version 2.4.21-50.EL
Warning: loading xen-platform-pci.o will taint the kernel: forced load
See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module xen-platform-pci loaded, with warnings
以​上​訊​息​的​重​要​部​份​為​最​後​一​行​,它​應​該​會​表​示​模​組​已​在​有​警​告​訊​行​的​情​況​下​被​載​入​。​

36.4. 手​動​式​地​載​入​半​虛​擬​化​驅​動​程​式​

若​基​於​某​些​原​因​導​致​於​半​虛​擬​化​驅​動​程​式​在​開​機​程​序​進​行​時​無​法​自​動​地​載​入​,您​可​嘗​試​透​過​手​動​式​地​來​將​它​們​載​入​。​
這​會​讓​您​能​夠​重​新​配​置​網​路​或​儲​存​實​體​裝​置​,或​辨​識​它​們​到​底​為​何​無​法​載​入​。​下​列​步​驟​應​該​會​將​半​虛​擬​化​驅​動​程​式​模​組​載​入​。​
首​先​,請​找​出​您​系​統​上​的​半​虛​擬​化​驅​動​程​式​模​組​。​
# cd /lib/modules/`uname -r`/
# find . -name 'xen_*.ko' -print
請​記​下​位​置​並​手​動​式​地​載​入​模​組​。​請​將​ {LocationofPV-drivers} 替​換​為​您​由​以​上​指​令​輸​出​所​記​下​的​正​確​位​置​。​
# insmod \
/lib/modules/'uname -r'/{LocationofPV-drivers}/xen_platform_pci.ko
# insmod /lib/modules/'uname -r'/{LocationofPV-drivers}/xen_balloon.ko
# insmod /lib/modules/'uname -r'/{LocationofPV-drivers}/xen_vnif.ko
# insmod /lib/modules/'uname -r'/{LocationofPV-drivers}/xen_vbd.ko

36.5. 驗​證​半​虛​擬​化​驅​動​程​式​是​否​已​成​功​載​入​

您​需​要​進​行​的​第​一​項​工​作​就​是​驗​證​驅​動​程​式​是​否​已​確​切​地​被​載​入​了​您​的​系​統​中​。​
After the para-virtualized drivers have been installed and the guest has been rebooted you can verify that the drivers have loaded. First you should confirm the drivers have logged their loading into /var/log/messages
# grep -E "vif|vbd|xen" /var/log/messages
                    xen_mem: Initialising balloon driver
                    vif vif-0: 2 parsing device/vif/0/mac
                    vbd vbd-768: 19 xlvbd_add at /local/domain/0/backend/vbd/21/76
                    vbd vbd-768: 19 xlvbd_add at /local/domain/0/backend/vbd/21/76
                    xen-vbd: registered block device major 202
You can also use the lsmod command to list the loaded para-virtualized drivers. It should output a list containing the xen_vnif, xen_vbd, xen_platform_pci and xen_balloon modules.
# lsmod|grep xen
xen_vbd                19168  1 
xen_vnif               28416  0 
xen_balloon            15256  1 xen_vnif
xen_platform_pci       98520  3 xen_vbd,xen_vnif,xen_balloon,[permanent]

36.6. 當​使​用​半​虛​擬​化​驅​動​程​式​時​,系​統​具​有​有​限​的​產​量​

If network throughput is still limited even after installing the para-virtualized drivers and you have confirmed they are loaded correctly (refer to 節 36.5, “驗​證​半​虛​擬​化​驅​動​程​式​是​否​已​成​功​載​入​”). To fix this problem, remove the 'type=ioemu' part of 'vif=' line in your guest's configuration file.

Glossary

本​辭​彙​表​定​義​了​使​用​於​本​安​裝​指​南​中​的​專​有​名​詞​和​術​語​。​
dom0
Also known as the host or host operating system.
dom0 refers to the host instance of Red Hat Enterprise Linux running the Xen hypervisor. Domain0 facilitates virtualized devices and virtualization for the guest operating systems. Dom0 runs on and manages the physical hardware and resource allocation for itself and the guest operating systems.
Domains
domU and dom0 are both domains. A domain is a term for a guest or virtual machine on the Xen hypervisor. The term domains has a similar meaning to virtual machines and the two are technically interchangeable.
domU
domU refers to the guest operating systems which run on the host system (the dom0 domain).
Hardware Virtual Machine
See Full virtualization.
Hypervisor
The hypervisor is the software layer that abstracts the hardware from the operating system permitting multiple operating systems to run on the same hardware. The hypervisor runs on a host operating system allowing other virtualized operating systems to run on the host's hardware.
The Kernel-based Virtual Machine (KVM) and Xen) hypervisors are provided with Red Hat Enterprise Linux 5.
I/O
輸​入​/輸​出​的​縮​寫​。​「​I/O」​這​個​名​詞​可​用​來​描​述​任​何​會​將​資​料​在​電​腦​與​週​邊​裝​置​之​間​進​行​傳​輸​的​程​式​、​作​業​或​裝​置​。​每​項​傳​輸​都​是​由​某​個​裝​置​輸​出​並​輸​入​至​另​一​個​裝​置​中​。​鍵​盤​和​滑​鼠​這​類​的​裝​置​都​屬​於​唯​輸​入​的​裝​置​,而​類​似​印​表​機​這​類​的​裝​置​則​屬​於​唯​輸​出​的​裝​置​。​一​部​可​燒​錄​的​光​碟​機​屬​於​可​輸​入​與​輸​出​裝​置​。​
Itanium®
Intel 的​ Itanium® 處​理​器​架​構​。​
Kernel SamePage Merging
Kernel SamePage Merging(KSM)模​組​會​被​ KVM hypervisor 使​用​來​允​許​ KVM 客​座​端​共​享​相​同​的​記​憶​體​分​頁​。​被​共​享​的​分​頁​一​般​為​通​用​函​式​庫​或​其​它​相​同​、​使​用​量​高​的​資​料​。​KSM 可​透​過​將​各​個​客​座​端​的​這​些​函​式​庫​保​留​在​快​取​中​,並​增​加​客​座​端​密​度​來​提​昇​特​定​客​座​端​的​效​能​。​
Kernel-based Virtual Machine
KVM (Kernel-based Virtual Machine) is a Full virtualization solution for Linux on AMD64 and Intel 64 hardware. VM is a Linux kernel module built for the standard Red Hat Enterprise Linux kernel. KVM can run multiple, unmodified virtualized guest Windows and Linux operating systems. KVM is a hypervisor which uses the libvirt virtualization tools (virt-manager and virsh).
KVM 是​一​組​用​來​針​對​於​ Hypervisor 模​組​本​身​管​理​裝​置​、​記​憶​體​以​及​管​理​ API 的​ Linux kernel 模​組​。​虛​擬​化​客​座​端​會​作​為​ Linux 程​序​與​執​行​緒​來​執​行​,並​且​經​由​這​些​模​組​來​進​行​控​制​。​guest density
LUN
邏​輯​單​元​數​量​(Logical Unit Number,LUN)代​表​分​配​至​邏​輯​單​元​(一​個​ SCSI 協​定​實​體​)的​號​碼​。​
MAC 位​址​
媒​體​存​取​控​制​位​址​(Media Access Control Address)為​網​路​介​面​卡​的​硬​體​位​址​。​以​虛​擬​化​的​角​度​來​講​,虛​擬​網​路​介​面​卡​必​須​含​有​ MAC 位​址​並​且​您​本​地​網​域​上​的​各​個​ MAC 必​須​要​是​獨​特​的​。​
PCI passthrough
KVM and Xen hypervisors support attaching PCI devices on the host system to virtualized guests. PCI passthrough allows guests to have exclusive access to PCI devices for a range of tasks. PCI passthrough allows PCI devices to appear and behave as if they were physically attached to the guest operating system.
phy device
The phy device parameter allows guest's to access physical disks. Physical disks includes:
  • LVM volumes (for example, /dev/VolGroup00/LogVol02),
  • disk partitions (for example, /dev/sda5), and
  • whole block devices (for example, /dev/sda).
Physical mode provides the best performance as the hypervisor bypasses extra layers of software on the host at the price of slightly less flexibility in managing the device.
Security Enhanced Linux
安​全​性​增​強​ Linux 的​縮​寫​,SELinux 在​ Linux kernel 中​用​了​ Linux 安​全​性​模​組​(Linux Security Modules,LSM)以​提​供​一​系​列​只​需​要​最​少​權​限​的​安​全​性​政​策​。​
tap:aio
The tap:aio parameter sets the Xen hypervisor to use an advanced access mode designed for safety and performance. File-based, are accessed using a kernel thread and a user-space process. The tap:aio method respects guest flush requests which makes it safer than the file driver. The virtualization tools use tap:aio by default for accessing file-based guest disks on the Xen Hypervisor.
Universally Unique Identifier
通​用​唯​一​識​別​碼​(Universally Unique Identifier,UUID)是​個​在​分​散​式​運​算​環​境​(distributed computing environments)中​使​用​來​為​裝​置​、​系​統​和​特​定​軟​體​物​件​編​號​的​標​準​編​號​方​式​。​虛​擬​化​中​的​ UUID 類​型​包​含​:ext2 和​ ext3 檔​案​系​統​標​識​符​號​、​RAID 裝​置​標​識​符​號​、​iSCSI 和​ LUN 裝​置​標​識​符​號​、​MAC 位​址​以​及​虛​擬​機​器​標​識​符​號​。​
Virtualized CPU
一​部​系​統​所​含​有​的​虛​擬​中​央​處​理​器​(VCPUs)數​量​相​應​於​實​體​處​理​器​核​心​的​數​量​。​虛​擬​ CPU 的​數​量​是​有​限​的​,並​且​代​表​了​可​被​分​配​至​客​座​端​虛​擬​機​器​的​虛​擬​ CPU 總​數​量​。​
Xen
Red Hat Enterprise Linux supports the Xen hypervisor and the KVM hypervisor. Both hypervisors have different architectures and development approaches. The Xen hypervisor runs underneath a Red Hat Enterprise Linux operating system which acts as a host managing system resources and virtualization APIs. The host is sometimes referred to as dom0, or Domain0.
主​機​(Host)
The host operating system, also known as dom0.
The host operating system environment runs the virtualization software for Fully Virtualized and Para virtualized guest systems.
半​虛​擬​化​
Para-virtualization uses a special kernel, sometimes referred to as the Xen kernel or the kernel-xen package. Para-virtualized guest kernels are run concurrently on the host while using the host's libraries and devices. A para-virtualized installation can have complete access to all devices on the system which can be limited with security settings (SELinux and file controls). Para-virtualization is faster than full virtualization. Para-virtualization can effectively be used for load balancing, provisioning, security and consolidation advantages.
從​ Fedora 9 開​始​,有​個​特​殊​的​ kernel 將​已​不​再​被​需​要​。​一​旦​此​修​正​檔​被​併​入​主​要​的​ Linux tree 中​之​後​,所​有​在​那​版​本​之​後​的​ Linux kernel 皆​會​啟​用​或​可​使​用​半​虛​擬​化​。​
半​虛​擬​化​
See Para-virtualization.
半​虛​擬​化​驅​動​程​式​
半​虛​擬​化​驅​動​程​式​是​運​作​於​完​整​虛​擬​化​ Linux 客​座​端​上​的​裝​置​驅​動​程​式​。​這​些​驅​動​程​式​大​幅​增​強​了​完​整​虛​擬​化​客​座​端​的​網​路​和​區​塊​裝​置​ I/O 的​效​能​。​
完​整​虛​擬​化​
Xen and KVM can use full virtualization. Full virtualization uses hardware features of the processor to provide total abstraction of the underlying physical system (bare metal) and create a new virtual machine in which the guest operating systems can run. No modifications are needed in the guest operating system. The guest operating system and any applications on the guest are not aware of the virtualized environment and run normally. Para-virtualization requires a modified version of the Linux operating system.
完​整​虛​擬​化​
See Full virtualization.
客​座​端​系​統​
Also known as guests, virtual machines, virtual servers or domU.
空​機​(Bare-metal)
The term bare-metal refers to the underlying physical architecture of a computer. Running an operating system on bare-metal is another way of referring to running an unmodified version of the operating system on the physical hardware. Examples of operating systems running on bare metal are dom0 or a normally installed operating system.
虛​擬​化​
Virtualization is a broad computing term for running software, usually operating systems, concurrently and isolated from other programs on one system. Most existing implementations of virtualization use a hypervisor, a software layer on top of an operating system, to abstract hardware. The hypervisor allows multiple operating systems to run on the same physical system by giving the guest operating system virtualized hardware. There are various methods for virtualizing operating systems:
  • Hardware-assisted virtualization is the technique used for full virtualization with Xen and KVM.
  • Para-virtualization is a technique used by Xen to run Linux guests.
  • 軟​體​虛​擬​化​或​模​擬​。​軟​體​虛​擬​化​使​用​了​執​行​檔​轉​化​(binary translation)以​及​其​它​模​擬​技​巧​來​執​行​未​經​修​改​的​作​業​系​統​。​軟​體​虛​擬​化​比​硬​體​支​援​的​虛​擬​化​或​半​虛​擬​化​還​要​慢​上​許​多​。​Red Hat Enterprise Linux 不​支​援​格​式​為​ QEMU 的​軟​體​虛​擬​化​。​
Red Hat Enterprise Linux 5 supports hardware-assisted, full virtualization with the Xen and KVM hypervisors and software para-virtualization with the Xen hypervisor for hosting Red Hat Enterprise Linux guests.
虛​擬​機​器​
虛​擬​機​器​是​個​實​體​機​器​或​是​程​式​語​言​(例​如​ Java Runtime Environment 或​是​ LISP)的​軟​體​實​做​。​以​虛​擬​化​的​角​度​來​講​,虛​擬​機​器​屬​於​一​個​執​行​於​虛​擬​硬​體​上​的​作​業​系​統​。​
遷​移​(Migration)
「​遷​移​」​是​個​將​虛​擬​客​座​端​由​一​個​主​機​移​至​另​一​個​主​機​的​程​序​之​名​稱​。​遷​移​程​序​可​離​線​進​行​(客​座​端​將​會​被​暫​停​並​進​行​移​動​)亦​可​即​時​遷​移​(客​座​端​會​在​沒​有​被​暫​停​的​情​況​下​被​移​動​)。​Xen 完​整​虛​擬​化​的​客​座​端​、​Xen 半​虛​擬​化​的​客​座​端​以​及​ KVM 完​整​虛​擬​化​的​客​座​端​皆​可​進​行​遷​移​。​
遷​移​屬​於​虛​擬​化​的​關​鍵​功​能​,因​為​軟​體​與​硬​體​完​全​分​離​了​。​遷​移​主​要​用​於​:
  • 負​載​平​衡​(Load Balancing)- 當​主​機​負​載​過​高​時​,客​座​端​可​被​移​至​使​用​量​較​低​的​主​機​上​。​
  • 硬​體​容​錯​移​轉​(Hardware Failover)- 當​主​機​上​的​硬​體​裝​置​開​始​失​效​時​,客​座​端​可​被​安​全​地​進​行​重​置​,如​此​一​來​主​機​便​能​停​用​並​進​行​修​復​。​
  • 節​能​(Energy Saving)- 當​使​用​量​低​時​,客​座​端​可​被​重​新​發​佈​至​其​它​停​用​中​的​主​機​與​主​機​系​統​上​來​節​省​能​源​並​降​低​成​本​。​
  • 地​理​遷​移​(Geographic Migration)- 在​嚴​重​的​情​況​下​,客​座​端​可​被​遷​移​至​另​一​個​位​置​上​來​達​到​較​低​的​延​遲​時​間​。​
共​享​、​連​接​網​路​的​儲​存​裝​置​可​用​來​儲​存​客​座​端​映​像​檔​。​沒​有​共​享​儲​存​裝​置​的​話​將​無​法​進​行​遷​移​。​
進​行​離​線​遷​移​時​客​座​端​將​會​被​暫​停​,並​且​客​座​端​記​憶​體​的​映​像​檔​會​被​移​至​目​標​主​機​上​。​客​座​端​會​在​目​標​主​機​上​復​原​,如​此​一​來​客​座​端​在​來​源​主​機​上​所​使​用​的​記​憶​體​便​會​被​釋​放​。​
離​線​遷​移​程​序​的​所​需​時​間​取​決​於​網​路​頻​寬​和​延​遲​時​間​。​一​個​擁​有​ 2GB 記​憶​體​的​客​座​端​在​一​個​ 1 Gbit 的​乙​太​網​路​連​結​上​應​該​會​花​上​幾​秒​鐘​。​
A live migration keeps the guest running on the source host and begins moving the memory without stopping the guest. All modified memory pages are monitored for changes and sent to the destination while the image is sent. The memory is updated with the changed pages. The process continues until the amount of pause time allowed for the guest equals the predicted time for the final few pages to be transfer. KVM estimates the time remaining and attempts to transfer the maximum amount of page files from the source to the destination until KVM predicts the amount of remaining pages can be transferred during a very brief time while the virtualized guest is paused. The registers are loaded on the new host and the guest is then resumed on the destination host. If the guest cannot be merged (which happens when guests are under extreme loads) the guest is paused and then an offline migration is started instead.
離​線​遷​移​程​序​的​所​需​時​間​取​決​於​網​路​頻​寬​和​延​遲​時​間​,以​及​客​座​端​上​所​在​進​行​的​活​動​為​何​。​若​客​座​端​正​在​使​用​大​量​的​ I/O 或​ CPU 的​話​,遷​移​程​序​將​會​花​上​較​久​的​時​間​。​

額​外​資​源​

欲​更​進​一​步​地​瞭​解​虛​擬​化​以​及​ Red Hat Enterprise Linux,請​參​閱​下​列​資​源​。​

A.1. 線​上​資​源​

  • http://www.cl.cam.ac.uk/research/srg/netos/xen/ Xen™ 半​虛​擬​化​主​機​管​理​員​的​專​案​網​站​(Red Hat kernel-xen 套​件​就​是​由​此​所​衍​生​的​)。​這​個​網​站​會​維​護​上​游​的​ Xen 專​案​ binary 和​原​始​程​式​碼​,並​且​它​同​時​也​包​含​了​與​ Xen 還​有​和​它​相​聯​技​術​上​相​關​的​資​訊​、​架​構​總​覽​、​文​件​,和​相​關​連​結​。​
  • Xen 社​群​網​站​
  • http://www.libvirt.org/ libvirt 虛​擬​化​ API 的​正​式​網​站​。​
  • http://virt-manager.et.redhat.com/ Virtual Machine Manager(virt-manager)的​專​案​網​站​,是​個​用​來​管​理​虛​擬​機​器​的​圖​形​化​應​用​程​式​。​

A.2. 已​安​裝​的​文​件​

  • /usr/share/doc/xen-<version-number>/ 這​個​目​錄​中​包​含​著​有​關​於​ Xen 半​虛​擬​化​ hypervisor 以​及​相​關​管​理​工​具​的​資​訊​。​它​同​時​也​包​含​著​各​種​不​同​的​配​置​範​例​、​特​定​硬​體​資​訊​,以​及​目​前​的​ Xen 上​游​使​用​者​文​件​。​
  • man virsh and /usr/share/doc/libvirt-<version-number> — 這​裡​面​包​含​著​ virsh 虛​擬​機​器​管​理​公​用​程​式​的​次​指​令​與​選​項​以​及​有​關​於​ libvirt 虛​擬​化​函​式​庫​ API 的​廣​泛​資​訊​。​
  • /usr/share/doc/gnome-applet-vm-<version-number> — 這​裡​面​包​含​著​監​視​與​管​理​本​地​執​行​的​虛​擬​主​機​所​用​的​ GNOME 圖​形​化​面​板​的​獨​立​應​用​程​式​的​文​件​。​
  • /usr/share/doc/libvirt-python-<version-number> — 它​提​供​了​有​關​於​ libvirt 常​式​庫​上​的​ Python 連​結​的​細​節​。​libvirt-python 套​件​能​讓​ python 開​發​者​們​建​立​與​ libvirt 虛​擬​化​管​理​常​式​庫​有​關​的​程​式​。​
  • /usr/share/doc/python-virtinst-<version-number> — 它​提​供​了​virt-install 指​令​的​文​件​。​這​項​指​令​能​在​虛​擬​主​機​中​,幫​助​啟​動​ Fedora 與​ Red Hat Enterprise Linux 相​關​發​行​的​安​裝​。​
  • /usr/share/doc/virt-manager-<version-number> — 它​提​供​了​虛​擬​主​機​管​理​程​式​的​文​件​,虛​擬​主​機​管​理​程​式​則​提​供​了​一​個​用​來​管​理​虛​擬​主​機​的​圖​形​化​工​具​。​

版​權​說​明​

本​指​南​的​格​式​為​ DocBook XML v4.3。​
This book is based on the work of Jan Mark Holzer, Chris Curran and Scott Radvan.
其​他​貢​獻​作​者​包​含​:
  • Don Dutile - 半​虛​擬​化​驅​動​程​式​部​份​的​技​術​編​輯​。​
  • Barry Donahue - 半​虛​擬​化​驅​動​程​式​部​份​的​技​術​編​輯​。​
  • Rick Ring - 虛​擬​機​器​管​理​員​部​份​的​技​術​編​輯​。​
  • Michael Kearey - 使​用​ XML 配​置​檔​案​和​ virsh 以​及​虛​擬​化​磁​碟​片​磁​碟​部​份​的​技​術​編​輯​。​
  • Marco Grigull - 軟​體​相​容​性​與​效​能​部​份​的​技​術​編​輯​。​
  • Eugene Teo - 使​用​ virsh 來​進​行​管​理​客​座​端​部​份​的​技​術​編​輯​。​
Publican,用​來​產​生​本​書​的​發​行​工​具​之​作​者​ - Jeffrey Fearn。​
Red Hat 本​土​化​團​隊​包​含​以​下​成​員​:
  • 簡​體​中​文​
    • 劉​衛​
  • 正​體​中​文​
    • 鄭​中​
    • 莊​佳​儒​
  • 日​文​
    • 橋​田​喜​代​人​
  • 韓​文​
    • 金​銀​珠​
  • 法​文​
    • Sam Friedmann
  • 德​文​
    • Hedda Peters
  • 義​大​利​文​
    • Francesco Valente
  • 巴​西​葡​萄​牙​文​
    • Glaucia de Freitas
    • Leticia de Lima
  • 西​班​牙​文​
    • Angela Garcia
    • Gladys Guerrero
  • 俄​文​
    • Yuliya Poyarkova