版 5.8
1801 Varsity Drive
Raleigh, NC 27606-2072 USA
Phone: +1 919 754 3700
Phone: 888 733 4281
Fax: +1 919 754 3701
/etc/grub.conf
ftpd
固定粗體字型(Mono-spaced Bold)
若要查看位於您目前工作目錄中的my_next_bestselling_novel
檔案的話,請在 shell 提示中輸入cat my_next_bestselling_novel
指令並按下 Enter 來執行該指令。
請按下 Enter 來執行指令。請按下 Ctrl+Alt+F2 來切換至第一個虛擬終端機。按下 Ctrl+Alt+F1 來返回您的 X-Windows session。
固定粗體字型
顯示。例如:
和檔案相關的 class,其中包含了filesystem
(檔案系統)、file
(檔案)以及dir
(目錄)。各個 class 都有著與它關聯的權限組。
由主選單選取滑鼠偏好設定。請在按鈕分頁中點選左手操作滑鼠核取方塊並按下 來將主要滑鼠按鍵由左邊切換至右邊(這可讓滑鼠適合以左手使用)。→ → 來啟動若要將特殊字元插入一個 gedit 檔案中的話,請由主選單中選擇 → → 。接下來,請由字元對應表的選單中選擇 → ,並在搜尋欄位中輸入字元的名稱,然後按下 。您所選擇的字元將會顯示於字元表中。在被選定的字元上點兩下滑鼠便可將它放置在準備複製的文字欄位中,接下來請按下旁邊的 按鈕。現在,請切換回您的文件並由 gedit 的選單上選擇 → 。
Mono-spaced Bold Italic
(固定粗體斜體字型)或是 Proportional Bold Italic
(相稱粗體斜體字型)
若要透過使用 ssh 來連至一部遠端機器,請在 shell 提示中輸入ssh
。若遠端機器為用戶名稱
@網域.名稱
example.com
而您在該機器上的用戶名稱為 john 的話,請輸入ssh john@example.com
。mount -o remount
指令會將 named 檔案系統重新掛載。比方說,若要重新掛載檔案系統
/home
檔案系統的話,該指令就會是mount -o remount /home
。使用rpm -q
指令來查看目前已安裝套件的版本。系統將會回傳此結果:套件
。
套件發行版本
Publican 是個 DocBook 發佈系統。
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")); } }
5
.
NFS
、FTP
或是 HTTP
通訊協定,來使用 Red Hat Enterprise Linux 5 的安裝目錄樹。
/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.
yum
來安裝 Xen hypervisor for more information.
grub.conf
file.
virtio
驅動程式。目前用戶端最多只能使用 32 組 PCI 裝置。有些 PCI 裝置對客座端來說,是極為重要且不能被移除的。預設的必要裝置有:
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.
/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.
phy
裝置的數目沒有限制。
/etc/modprobe.conf
檔案中,加入以下一行:
options loop max_loop=64
# rmmod loop # modprobe loop
yum
與 Red Hat Network(RHN)來安裝。
virt-manager
、libvirt
、virt-viewer
、以及所有相依性套件。。
自訂套件(視需要而定)
%packages
一節裡,加入以下套件群組:
%packages @xen
xen-ia64-guest-firmware
rhn_register
指令並依照提示進行。
yum
來安裝 Xen hypervisorxen
和 kernel-xen
套件。xen
套件包含著 hypervisor 與基本的虛擬化工具。kernel-xen
套件包含著修改過的 Linux 核心,作為執行在 hypervisor 上的虛擬機器客座端。
xen
和 kernel-xen
套件,請執行:
# yum install xen kernel-xen
xen-ia64-guest-firmware
)。此套件也可透過 yum
指令來由 RHN 進行安裝:
# yum install xen-ia64-guest-firmware
python-virtinst
virt-install
指令。
libvirt
libvirt
是與 hypervisor 互動的 API 函式庫。libvert
使用的是 xm
虛擬化架構;而 virsh
是用來管理與控制虛擬機器的命令列工具。
libvirt-python
libvirt
API 所提供的介面。
virt-manager
virt-manager
,又稱虛擬機器管理員,提供了一個用來管理虛擬機器的圖形化工具。它使用了 libvirt
函式庫為進行管理用的 API。
# yum install virt-manager libvirt libvirt-python python-virtinst
virt-manager
、libvirt
與 virt-viewer
。
自訂套件(視需要而定)
%packages
一節裡,加入以下套件群組:
%packages @kvm
rhn_register
指令並依照提示進行。
yum
來安裝 KVM hypervisorkvm
套件。kvm
套件包含著 KVM 核心模組,為預設的 Red Hat Enterprise Linux 核心提供 KVM hypervisor。
kvm
套件,請執行:
# yum install kvm
python-virtinst
virt-install
指令。
libvirt
libvirt
是與 hypervisor 互動的 API 函式庫。libvert
使用的是 xm
虛擬化架構;而 virsh
是用來管理與控制虛擬機器的命令列工具。
libvirt-python
libvirt
API 所提供的介面。
virt-manager
virt-manager
,又稱虛擬機器管理員,提供了一個用來管理虛擬機器的圖形化工具。它使用了 libvirt
函式庫為進行管理用的 API。
# yum install virt-manager libvirt libvirt-python python-virtinst
virt-install
來建立客座端。本章將提及這兩種方法。
virt-install
指令來建立虛擬化客座端。您可以藉由互動式方式來使用 virt-install
,或用於一個 script 中來自動化虛擬機器的建置。當使用 virt-install
和 kickstart 檔案時,您可進行無人式的虛擬機器安裝程序。
virt-install
工具提供了幾個您可傳送至指令列上的選項。要看完整的選項,請執行:
$ virt-install --help
virt-install
的 man page 也為每個選項與重要的變數,提供了詳細資訊。
qemu-img
是相關指令,可以在使用 virt-install
之前,設定儲存選項。
--vnc
option which opens a graphical window for the guest's installation.
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
# virt-install --name fedora11 --ram 512 --file=/var/lib/libvirt/images/fedora11.img \ --file-size=3 --vnc --cdrom=/var/lib/libvirt/images/fedora11.iso
virt-manager
為虛擬機器管理員,適用來建立、管理虛擬客座端的圖形工具。
Open virt-manager
virt-manager
. Launch the application from the menu and submenu. Alternatively, run the virt-manager
command as root.
Optional: Open a remote hypervisor
Create a new guest
New guest wizard
Name the virtual machine
Choose virtualization method
kernel-xen
不是正在執行的核心,半虛擬化選項就無法選擇。
Select the installation method
.iso
file).
HTTP
, FTP
or NFS
.
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
.
Installation media selection
ISO image or physical media installation
Network install tree installation
NFS
, FTP
or HTTP
. Optionally, a kickstart file can be specified to automated the installation. Kernel parameters can also be specified if required.
Network boot (PXE)
Storage setup
/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/
. 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).
Network setup
Memory and CPU allocation
Verify and start guest installation
virt-manager
. 章 8, 客座端作業系統的安裝程序 contains step-by-step instructions to installing a variety of common operating systems.
建立新的橋接裝置
/etc/sysconfig/network-scripts/
目錄裡建立新的網路 script 檔。這範例建立了名為 ifcfg-installation
的檔案,並建立一組名為 installation
的橋接裝置。
# cd /etc/sysconfig/network-scripts/ # vim ifcfg-installation DEVICE=installation TYPE=Bridge BOOTPROTO=dhcp ONBOOT=yes
TYPE=Bridge
, is case-sensitive. It must have uppercase 'B' and lower case 'ridge'.
ifup installation
command can start the individual bridge but it is safer to test the entire network restarts properly.
# service network restart
brctl show
指令,來檢視系統上關於橋接裝置的詳細資料。
# brctl show bridge name bridge id STP enabled interfaces installation 8000.000000000000 no virbr0 8000.000000000000 yes
virbr0
橋接裝置是 libvirt
的預設橋接裝置,用在預設乙太網路的 NAT(網路位址轉譯)功能上。
將介面加至新的橋接裝置上
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
安全配置
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
在安裝之前重新啟動 libvirt
libvirt
daemon:
# service libvirtd reload
virt-install
裡,新增 --network=bridge:installation
安裝參數,其中 installation
是橋接裝置的名稱。要透過 PXE 來安裝,請使用 --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 \
選擇 PXE
選擇橋接裝置
開始安裝
virsh update-device Guest1 ~/Guest1.xml
(substituting your guest's name and XML file), and select OK to continue past this step.
kernel-xen
核心。
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 -nrhel5PV
-r 500 \ -f /var/lib/libvirt/images/rhel5PV.dsk
-s 3 --vnc -p \ -lftp://10.1.1.1/trees/RHEL5-B2-Server-i386/
DHCP
(as shown below) or a static IP address:
安裝號碼
」欄位中:
rhn_register
指令,在安裝完成過後確認您的 Red Hat Network 帳號詳情。rhn_register
指令需要 root 存取權限。
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
、選擇您客座端的名稱、按下「 」,然後按下「 」。
kdump
. The use of kdump
is unsupported on para-virtualized guests.
yum
command or RHN. Click .
開啟 virt-manager
virt-manager
。請透過 選單和 子選單來啟用 。此外,您也能夠以 root 身份執行 virt-manager
指令。
選擇 hypervisor
qemu
。
啟用新增虛擬機器精靈
為虛擬機器命名
選擇虛擬化方式
選擇安裝方式
選擇安裝媒介的位置
/var/lib/libvirt/images/
directory. Any other location may require additional configuration for SELinux, refer to 節 18.2, “SELinux 和虛擬化” for details.
儲存裝置設定
/var/lib/libvirt/images/
directory. Assign sufficient space for your virtualized guest and any applications the guest requires.
網路設定
記憶體和 CPU 配置
驗證和啟動客座端安裝程序
安裝 Red Hat Enterprise Linux
啟動 virt-manager
為虛擬系統命名
選擇虛擬化的方法
選擇安裝方法
/var/lib/libvirt/images/
directory. Any other location may require additional configuration for SELinux, refer to 節 18.2, “SELinux 和虛擬化” for details.
Choose installation image
/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 政策的相關資訊)。
設定網路
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.
# virsh start WindowsGuest
WindowsGuest
是虛擬機器的名稱。
virsh reboot WindowsGuestName
指令來重新啟動客座端。當您重新啟動虛擬機器時,您將會看見一則 Setup is being restarted
的訊息:
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 客座端為完整的虛擬化客座端”.
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.
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
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
標準 PC
」作為您的電腦類型。選擇「標準 PC
」是安裝 Windows Server 2003 虛擬化客座端的必要步驟。
開啟 virt-manager
virt-manager
。請在「 」選單中點選「 」,然後再點選「 」,或以 root 身份值 virt-manager
指令。
選擇 hypervisor
qemu
。
啟動新虛擬機器的精靈介面
為虛擬機器命名
選擇虛擬化的方法
請選擇安裝方法
找到安裝媒體
/var/lib/libvirt/images/
directory. Any other location may require additional configuration for SELinux, refer to 節 18.2, “SELinux 和虛擬化” for details.
設定儲存空間
/var/lib/libvirt/images/
directory. Assign sufficient space for your virtualized guest and any applications the guest requires.
設定網路
分配記憶體與處理器
檢查並開始安裝客座端
安裝 Windows
內容目錄
/dev/xvd[a to z][1 to 15]
/dev/xvdb13
/dev/xvd[a to i][a to z][1 to 15]
/dev/xvdbz13
/dev/sd[a to p][1 to 15]
/dev/sda1
/dev/hd[a to t][1 to 63]
/dev/hdd3
dd
command. Replace /dev/fd0
with the name of a floppy device and name the disk appropriately.
# dd if=/dev/fd0 of=~/legacydrivers.img
virt-manager
所建立的,它的映像檔位於 /var/lib/libvirt/images/rhel5FV.img
。範例中使用了 Xen hypervisor。
virsh
指令,來為您的客座端映像檔建立 XML 配置檔案。
# virsh dumpxml rhel5FV > rhel5FV.xml
# dd if=/dev/zero of=/var/lib/libvirt/images/rhel5FV-floppy.img bs=512 count=2880
<disk type='file' device='floppy'> <source file='/var/lib/libvirt/images/rhel5FV-floppy.img'/> <target dev='fda'/> </disk>
virsh shutdown
command instead.
# virsh destroy rhel5FV
# virsh create rhel5FV.xml
dd
指令來建立一個 sparse 檔案。基於資料完整性以及效能上的考量,我們不建議您使用 sparse 檔案。Sparse 檔案可快速地建立,並且可被使用來進行測試,不過不該使用於生產環境中。
# dd if=/dev/zero of=/var/lib/libvirt/images/FileName.img bs=1M seek=4096 count=0
# dd if=/dev/zero of=/var/lib/libvirt/images/FileName.img bs=1M count=4096
Guest1
並且檔案儲存在使用者的家目錄中。
# virsh dumpxmlGuest1
> ~/Guest1
.xml
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>
<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>
# virsh create Guest1.xml
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.
n
來建立新分割區。
# fdisk /dev/sdb Command (m for help):
p
來選擇主要分割區。
Command action e extended p primary partition (1-4)
1
來選取。
Partition number (1-4): 1
Enter
來輸入預設的第一個磁柱。
First cylinder (1-400, default 1):
Enter
來分配整個磁碟。
Last cylinder or +size or +sizeM or +sizeK (2-400, default 400):
t
來設定分割區類型。
Command (m for help): t
1
。
Partition number (1-4): 1
83
。
Hex code (type L to list codes): 83
Command (m for help):w
Command (m for help):q
ext3
檔案系統來格式化新的分割區。
# mke2fs -j /dev/sdb1
# mount /dev/sdb1 /myfiles
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.
/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.
multipath
來設定裝置以及主機上的一致性。
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.
--type cdrom
parameter to the command for CD-ROM or DVD devices.
--type floppy
參數至指令。
# virsh attach-diskmyguest
/dev/sdb1
sdc
--driver tap --mode readonly
/dev/sdb
on Linux or D: drive
, or similar, on Windows. This device may require formatting.
multipath
must use 單路徑設定. Systems running multipath
can use 多路徑的配置.
udev
. Only use this procedure for hosts which are not using multipath
.
/etc/scsi_id.config
檔案。
options=-b
一行已被標為註解。
# options=-b
options=-g
udev
設定為假設所有連接的 SCSI 裝置都會回傳一組 UUID。
scsi_id -g -s /block/sd*
這項指令。例如:
# scsi_id -g -s /block/sd* 3600a0b800013275100000015427b625e
/dev/sdc
裝置的 UUID。
scsi_id -g -s /block/sd*
指令所得到的 UUID 輸出與存取該裝置的電腦的 UUID 是相同的。
/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
。
/etc/rc.local
:
/sbin/start_udev
/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)以及增強的效能。
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
/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 } }
/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.
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.
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
# 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
<interface type='network'> <source network='default'/> </interface>
<interface type='network'> <source network='default'/> <mac address='00:16:3e:1a:b3:4a'/> </interface>
/etc/xen/xend-config.sxp
並更改下列一行來停用預設的 Xen 網路橋接:
(network-script network-bridge)
(network-script /bin/true)
/etc/sysconfig/network-scripts/
directory):
# chkconfig NetworkManager off # chkconfig network on # service NetworkManager stop # service network start
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.
/etc/sysconfig/network-scripts
目錄:
# cd /etc/sysconfig/network-scripts
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
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
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.
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
規則處理。請在 /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)連結性。
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.
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
/etc/xen/scripts/network-bridge
檔案複製至 /etc/xen/scripts/network-bridge.xen
。
/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
network-xen-multi-bridge
parameter to enable multiple network bridges.
#network-script network-bridge network-script network-xen-multi-bridge
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
# chmod +x /etc/xen/scripts/network-xen-multi-bridge.sh
# service network restart
virt-manager
來建立客座端時請使用「虛擬網路」卡。就預設值來說,在 Red Hat Enterprise Linux 5.1 或更新版本中,NetworkManager 可適用於虛擬網路裝置。
<interface type='network'> <mac address='AA:AA:AA:AA:AA:AA'/> <source network='default'/> <target dev='vnet0'/> <model type='virtio'/> </interface>
xm
配置檔案中,虛擬網路裝置會被標記為「vif
」。
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.
dummy0
. This will also allow you to use a hidden IP address space for your guests.
/etc/modprobe.conf
alias dummy0 dummy options dummy numdummies=1
/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
xenbr0
綁定至 dummy0
,如此一來就算未連至一個實體網路,您也還是能夠使用網路作業。請編輯 /etc/xen/xend-config.sxp
並使其包含 netdev=dummy0
這個項目:
(network-script 'network-bridge bridge=xenbr0 netdev=dummy0')
/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
/etc/init.d/xenLaptopNAT
並建立一個連至 /etc/rc3.d/S99xenLaptopNAT
的捷徑。這會使 NAT 在開機時自動地啟動。
#!/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
dnsmasq
的簡短指南:
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 映像檔。
/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
。
xenDNSmasq
至 /etc/init.d
。
chkconfig
來註冊它:
chkconfig --add xenDNSmasq
chkconfig --levels 345 xenDNSmasq on
dnsmasq
配置成每當 NetworkManager 偵測到連接性上的改變時,就會重新啟動的話,您可使用提供的 script:nm-dnsmasq
。
nm-dnsmasq
script 複製至 /etc/NetworkManager/dispatcher.d/
dnsmasq
也會偵測您 /etc/resolv.conf
中的變更並自動地(在您啟用了一個 VPN session 時)將它們重新載入。
nm-dnsmasq
和 xenDNSmasq
這兩個 script 也會設定 NAT,以允許它們存取公共網路。
pv-on-hvm
模組。這代表 Red Hat Enterprise Linux 4.7 和更新版本以及 5.3 與更新版本的客座端皆可使用半虛擬化驅動程式。
kmod-xenpv
.
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
.
kmod-xenpv
.
/lib
file system.
# rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' 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) | 已支援 |
# rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' kernel
kernel-PAE-2.6.18-53.1.4.el5.i686
GRUB
GRUB
),或是一個包含著 kernel initrd
映像的磁碟。也就是說所有包含著 /boot
目錄或是分割區的磁碟,都無法使用半虛擬化區塊裝置的驅動程式。
xen-pci-platform
模組的載入便會失敗。
客座端 kernel 類型 | 必要的主機 kernel 類型 |
---|---|
ia32e(UP 和 SMP) | x86_64 |
i686 | i686 |
i686-SMP | i686 |
i686-HUGEMEM | i686 |
客座端 kernel 類型 | 必要的主機 kernel 類型 |
---|---|
athlon | i686 |
athlon-SMP | i686 |
x86_64 | x86_64 |
x86_64-SMP | x86_64 |
MBR
和開機載入程式(GRUB
),以及 /boot
分割區使用半虛擬化驅動程式。這個磁碟的容量不用很大,因為它只需要擁有足夠的空間來容納 /boot
分割區即可。
/
、/usr
)或是邏輯卷冊。
/boot
分割區後,才可使用虛擬化區塊裝置的驅動程式。
rpm
指令或是 yum
指令來安裝套件。rpm
工具程式會將以下的四個新 kernel 模組安裝至 /lib/modules/[%kversion][%kvariant]/extra/xenpv/%release
中:
xen_platform_pci.ko
,
xen_balloon.ko
,
xen_vbd.ko
,
xen_vnif.ko
.
xen-vbd
) disk driver.
<disk type='file' device='disk'> <driver name='file'/> <source file='/dev/hda6'/> <target dev='hda'/> </disk>
<disk type='file' device='disk'> <driver name='tap' type='aio'/> <source file='/dev/hda6'/> <target dev='xvda'/> </disk>
# xm start YourGuestName
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.
kernel-2.4.21-60.EL
for all the required headers.
kmod-xenpv
rpm 複製到您的客座端作業系統上。
rpm
工具來安裝 RPM 套件。請確認您已正確地辨識了您客座端作業系統類型與架構所需的套件為何。
[root@rhel3]# rpm -ivh kmod-xenpv*
[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
insmod
會產生警告訊息。您可忽略這些警告訊息。
/etc/modules.conf
並確認 eth0
擁有一組類似下列的別名。若您計畫設定多張網路卡,請為各個網路卡附加額外一行。
alias eth0 xen-vnif
/etc/rc.local
並新增一行:
insmod /lib/modules/'uname -r'/extra/xenpv/%release/xen-vbd.o
#shutdown -h now
」)。
/etc/xen/YourGuestName
with a text editor, performing the following changes:
type=ioemu
」項目由「vif=
」項目中移除。
xen-vbd
)的磁碟驅動程式來被存取。
<disk type='file' device='disk'> <driver name='file'/> <source file='/dev/hda6'/> <target dev='hda'/> </disk>
<disk type='file' device='disk'> <driver name='tap' type='aio'/> <source file='/dev/hda6'/> <target dev='xvda'/> </disk>
# xm start YourGuestName
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.
weak-modules
與 modversions
,因此半虛擬化驅動程式不會被自動地新增並載入系統中。若要插入模組,請執行下列指令。
insmod xen_vbd.ko
xen-vbd
的區塊裝置建立特殊檔案。下列步驟將會涵蓋如何建立與註冊半虛擬化區塊裝置。
#!/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*
# mknod /dev/xvdc b $major 16 # mknod /dev/xvdc1 b $major 17
# 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
」可使用於系統。
[root@rhel3]# mkdir /mnt/pvdisk_p1 [root@rhel3]# mkdir /mnt/pvdisk_p2
[root@rhel3]# mount /dev/xvdb1 /mnt/pvdisk_p1 [root@rhel3]# mount /dev/xvdb2 /mnt/pvdisk_p2
[root@rhel3]# df /mnt/pvdisk_p1 Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvdb1 32000 15 31985 1% /mnt/pvdisk_p1
/etc/fstab
檔案,在開機時掛載這些裝置。請新增以下幾行:
/dev/xvdb1 /mnt/pvdisk_p1 ext3 defaults 1 2 /dev/xvdb2 /mnt/pvdisk_p2 ext3 defaults 1 2
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
kmod-xenpv
、modules-init-tools
和 modversions
RPM 複製至您的客座端系統上。
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*
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
#shutdown -h now
」)。
/etc/xen/YourGuestsName
中的客座端配置檔案:
type=ioemu
」項目由「vif=
」項目中移除。
xen-vbd
)的磁碟驅動程式來存取。
disk=
」部份。原本的「disk=
」項目也有可能看似下列項目。
disk = [ "file:/var/lib/libvirt/images/rhel4_64_fv.dsk,hda,w"]
disk = [ "file:/var/lib/libvirt/images/rhel3_64_fv.dsk,hda,w", "tap:aio:/var/lib/libvirt/images/UserStorage.dsk,xvda,w" ]
tap:aio
」使用於半虛擬化的裝置。
virsh
指令來啟動虛擬機器:
# virsh start YourGuestName
kudzu
會詢問您「Keep or Delete the Realtek Network device(保留或刪除 Realtek 網路裝置)」和「Configure the xen-bridge device(配置 xen-bridge 裝置)」。您應該配置 xen-bridge
並刪除 Realtek 網路裝置。
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
[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
」可用於系統。
[root@rhel4]# mkdir /mnt/pvdisk_p1 [root@rhel4]# mkdir /mnt/pvdisk_p2
[root@rhel4]# mount /dev/xvdb1 /mnt/pvdisk_p1 [root@rhel4]# mount /dev/xvdb2 /mnt/pvdisk_p2
[root@rhel4]# df /mnt/pvdisk_p1 Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvdb1 32000 15 31985 1% /mnt/pvdisk_p1
/etc/fstab
檔案,在開機時掛載這些裝置。請新增以下幾行:
/dev/xvdb1 /mnt/pvdisk_p1 ext3 defaults 1 2 /dev/xvdb2 /mnt/pvdisk_p2 ext3 defaults 1 2
xen-vbd
驅動程式可能無法自動載入。若是如此,請在客座端上輸入下列指令,將 %release 更改為半虛擬化驅動程式的正確發行版本。
# insmod /lib/modules/'uname -r'/weak-updates/xenpv/%release/xen_vbd.ko
#shutdown -h now
」)。
/etc/xen/<Your GuestsName>
中的客座端配置檔案:
type=ioemu
」項目由「vif=
」項目中移除。
xen-vbd
)的磁碟驅動程式來存取。
disk=
」部份。原本的「disk=
」項目也有可能看似下列項目。
disk = [ "file:/var/lib/libvirt/images/rhel4_64_fv.dsk,hda,w"]
disk = [ "file:/var/lib/libvirt/images/rhel3_64_fv.dsk,hda,w", "tap:aio:/var/lib/libvirt/images/UserStorage.dsk,xvda,w" ]
tap:aio
」使用於半虛擬化的裝置。
virsh
指令來啟動虛擬機器:
# virsh start YourGuestName
[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
」可用於系統。
[root@rhel5]# mkdir /mnt/pvdisk_p1 [root@rhel5]# mkdir /mnt/pvdisk_p2
[root@rhel5]# mount /dev/xvdb1 /mnt/pvdisk_p1 [root@rhel5]# mount /dev/xvdb2 /mnt/pvdisk_p2
[root@rhel5]# df /mnt/pvdisk_p1 Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvdb1 32000 15 31985 1% /mnt/pvdisk_p1
/etc/fstab
檔案,在開機時掛載這些裝置。請新增以下幾行:
/dev/xvdb1 /mnt/pvdisk_p1 ext3 defaults 1 2 /dev/xvdb2 /mnt/pvdisk_p2 ext3 defaults 1 2
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
/etc/modprobe.d/blacklist
file. Blacklist 8139cp
and 8139too
for the RealTek 8139 and e1000
for the virtualized Intel e1000 NIC.
8139cp
8139too
e1000
/etc/sysconfig/network-scripts
directory.
xen_emul_unplug=never
virt-manager
中開啟客座端的主控台視窗並以 root
身份登入。
/etc/modprobe.conf
中是否含有「alias eth0 xen-vnif
」這一行。
# cat /etc/modprobe.conf alias eth0 xen-vnif
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)
# system-config-network
”. Click on the “ ” button to start the network card configuration.
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)
/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" ]
# echo 'import virtinst.util ; print virtinst.util.randomMAC()' | python
/etc/modules.conf
,或是 Red Hat Enterprise Linux 4 與 Red Hat Enterprise Linux 5 的 /etc/modprobe.conf
中。請為您所新增的各個新介面卡加上一個新的別名。
alias eth1 xen-vnif
# ifconfig eth1
redhat-config-network
,或在 Red Hat Enterprise Linux 4 和 Red Hat Enterprise Linux 5 上使用 system-config-network
來配置新的網路介面卡。
/etc/xen/YourGuestName
中的客座端配置檔案,並將 YourGuestName
替換為您客座端的名稱。原本的項目會看似下列範例。
disk = [ "file:/var/lib/libvirt/images/rhel5_64_fv.dsk,hda,w"]
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=
」部份為逗號區隔的清單。
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
下載驅動程式
yum
command.
# yum install virtio-win
/usr/share/virtio-win/
目錄中安裝一個光碟映像檔 virtio-win.iso
。
安裝半虛擬化驅動程式
virt-manager
來掛載光碟映像檔。” to add a CD-ROM image with virt-manager
and then install the drivers.
virt-manager
來掛載光碟映像檔。Open virt-manager and the virtualized guest
virt-manager
, select your virtualized guest from the list by double clicking the guest name.
Open the hardware tab
Select the device type
Select the ISO file
/usr/share/virtio-win/virtio-win.iso
.
Disc assigned
Reboot
Open My Computer
Select the correct installation files
RHEV-Block.msi
for 32-bit guests or RHEV-Block64.msi
for 64-bit guests),
RHEV-Network.msi
for 32-bit guests or RHEV-Block64.msi
for 64-bit guests),
Install the block device driver
Start the block device driver installation
RHEV-Block.msi
or RHEV-Block64.msi
.
Confirm the exception
Finish
Install the network device driver
Start the network device driver installation
RHEV-Network.msi
or RHEV-Network64.msi
.
Performance setting
Value | Action |
---|---|
0 | Disable TCP timestamps and window scaling. |
1 | Enable TCP window scaling. |
2 | Enable TCP timestamps. |
3 | Enable TCP timestamps and window scaling. |
Confirm the exception
Finish
Reboot
viostor.vfd
附加為一片磁碟片。
Windows Server 2003
Windows Server 2008
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 半虛擬化驅動程式於新裝置上”.
<disk type='file' device='disk'> <source file='/var/lib/libvirt/images/disk1.img'/> <target dev='vda' bus='ide'/> </disk>
virtio
來使用半虛擬化裝置。
<disk type='file' device='disk'>
<source file='/var/lib/libvirt/images/disk1.img'/>
<target dev='vda' bus='virtio'/>
</disk>
virt-manager
來新建裝置。
virsh attach-disk
或 virsh attach-interface
指令皆可被使用來連接使用了半虛擬化驅動程式的裝置。
virt-manager
中的客座端名稱,來開虛擬化客座端。
Enable the Intel VT-d extensions
Activate Intel VT-d in the kernel
intel_iommu=on
parameter to the kernel line of the kernel line in the /boot/grub/grub.conf
file.
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
Ready to use
Enable AMD IOMMU extensions
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
pci_8086_3a6c
, and a fully virtualized guest named win2k3
.
Identify the device
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
# virsh nodedev-list | grep pci
****
is a four digit hexadecimal code):
pci_8086_****
lspci
output to lspci -n
(which turns off name resolution) output can assist in deriving which device has which device identifier code.
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>
# virsh nodedev-dettach pci_8086_3a6c Device pci_8086_3a6c dettached
$ printf %x 0 0 $ printf %x 26 1a $ printf %x 7 7
bus='0x00' slot='0x1a' function='0x7'
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>
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
$ virsh nodedev-dettach pci_8086_3a6c
$ readlink /sys/bus/pci/devices/0000\:00\:1d.7/driver ../../../bus/pci/drivers/pci-stub
# setsebool -P virt_use_sysfs 1
# virsh start win2k3
virt-manager
tool. The following procedure adds a 2 port USB controller to a virtualized guest.
Identify the device
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
# virsh nodedev-list | grep pci
****
is a four digit hexadecimal code):
pci_8086_****
lspci
output to lspci -n
(which turns off name resolution) output can assist in deriving which device has which device identifier code.
Detach the PCI device
# virsh nodedev-dettach pci_8086_3a6c Device pci_8086_3a6c dettached
Power off the guest
Open the hardware settings
Add the new device
Select a PCI device
Confirm the new device
--host-device
parameter.
Identify the PCI device
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
# virsh nodedev-list | grep pci
****
is a four digit hexadecimal code):
pci_8086_****
lspci
output to lspci -n
(which turns off name resolution) output can assist in deriving which device has which device identifier code.
Add the device
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
Complete the installation
/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)
/etc/modprobe.conf
to hide multiple devices.
options pciback hide=(0000:09:00.0)(0000:0a:04.1)
virsh
(節 14.1, “Adding a PCI device with virsh” - Step 5);
virt-manager
(節 14.2, “Adding a PCI device with virt-manager”); or
virt-install
(節 14.3, “PCI passthrough with virt-install”)
/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
Enable Intel VT-d in BIOS and in the kernel
Verify support
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)
Start the SR-IOV kernel modules
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
Activate Virtual Functions
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
.
# modprobe -r igb
max_vfs
set to 1
or any number of Virtual Functions up to the maximum supported by your device.
# modprobe igb max_vfs=1
Inspect the new Virtual Functions
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)
-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
.
Find the devices with virsh
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]
Get advanced details
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>
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.
Add the Virtual Function to the guest
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.
printf
utility to convert decimal values to hexadecimal values.
$ printf %x 3 3 $ printf %x 16 10 $ printf %x 1 1
bus='0x03' slot='0x10' function='0x01'
virsh edit
command. This example edits a guest named MyGuest
.
# virsh edit MyGuest
devices
section of the XML configuration file.
<hostdev mode='subsystem' type='pci' managed='yes'> <source> <address bus='0x03' slot='0x10' function='0x01'/> </source> </hostdev>
Restart
# virsh start MyGuest
# 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
ntpd
服務:
# service ntpd start
# chkconfig ntpd on
ntpd
服務便能有效降低所有時鐘偏移(clock skew)情況下所造成的影響。
constant_tsc
旗標存在的話,您的 CPU 便擁有一致的時間戳記計數器。若要檢查您的 CPU 是否擁有 constant_tsc
旗標,請執行下列指令:
$ cat /proc/cpuinfo | grep constant_tsc
constant_tsc
。若沒有得到任何結果的話,請依照下列步驟進行。
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
檔案中找到。
/boot/grub/grub.conf
檔案中的 /kernel
一行尾端來設定。
Red Hat Enterprise Linux | 額外的客座端 kernel 參數 |
---|---|
含有半虛擬化時鐘的 5.4 AMD64/Intel 64 | 無須額外的參數 |
無半虛擬化時鐘的 5.4 AMD64/Intel 64 | divider=10 notsc lpj=n |
含有半虛擬化時鐘的 5.4 x86 | 無須額外的參數 |
沒有半虛擬化時鐘的 5.4 x86 | divider=10 clocksource=acpi_pm lpj=n |
5.3 AMD64/Intel 64 | divider=10 notsc |
5.3 x86 | divider=10 clocksource=acpi_pm |
4.8 AMD64/Intel 64 | notsc divider=10 |
4.8 x86 | clock=pmtmr divider=10 |
3.9 AMD64/Intel 64 | 無須額外的參數 |
3.9 x86 | 無須額外的參數 |
boot.ini
檔案中:
/use pmtimer
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.
{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
# setenforce 1
AutoFS
、NFS
、FTP
、HTTP
、NIS
、telnetd
、sendmail
等等)。
/var/lib/libvirt/images/
下。若您的虛擬機器映像檔處於一個不同的目錄中,請確認您有將該目錄附加至您的 SELinux 政策中,並在啟動安裝程序之前將它重新標記。
vsftpd
伺服器的位置。
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.
/dev/sdb
). Use partitions (for example, /dev/sdb1
) or LVM volumes.
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
.
volumegroup
的卷冊群組上建立了一個 5GB 的邏輯卷冊,名為 NewVolumeName
。
# lvcreate -nNewVolumeName
-L5G volumegroup
NewVolumeName
邏輯卷冊。
# mke2fs -j /dev/volumegroup/NewVolumeName
/etc
、/var
、/sys
)或是家目錄中(/home
或 /root
)。此範例使用了一個名為 /virtstorage
的目錄。
# mkdir /virtstorage
# mount /dev/volumegroup/NewVolumeName /virtstorage
semanage fcontext -a -t xen_image_t "/virtstorage(/.*)?"
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
/dev/volumegroup/NewVolumeName
with the correct label:
# semanage fcontext -a -t xen_image_t /dev/volumegroup/NewVolumeName # restorecon /dev/volumegroup/NewVolumeName
# 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
。
SELinux Boolean | Description |
---|---|
allow_unconfined_qemu_transition | Default: off. This boolean controls whether KVM guests can be transitioned to unconfined users. |
qemu_full_network | Default: on. This boolean controls full network access to KVM guests. |
qemu_use_cifs | Default: on. This boolean controls KVM's access to CIFS or Samba file systems. |
qemu_use_comm | Default: off. This boolean controls whether KVM can access serial or parallel communications ports. |
qemu_use_nfs | Default: on. This boolean controls KVM's access to NFS file systems. |
qemu_use_usb | Default: on. This boolean allows KVM to access USB devices. |
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.
xend
來管理客座端/etc/xen/xend-config.sxp
來指定作業參數。下列為能在 xend-config.sxp
配置檔案中啟用與停用的參數:
項目 | 描述 |
---|---|
(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 伺服器所綁定至的位址。預設值可允許所有的連線。
|
service xend start
service xend stop
service xend restart
service xend status
xend
chkconfig
指令來將 xend
附加至 initscript
。
chkconfig --level 345 xend
xend
現在會在 runlevel 3、4 和 5 模式下啟動。
virsh migrate
指令。
# virsh migrateGuestName
libvirtURI
virsh migrate
指令的 --live
選項。
# virsh migrate--liveGuestName
libvirtURI
/etc/xen/xend-config.sxp
配置檔案。基於對主機安全性上持有潛在的有害影響,因此遷移就預設值來講會是停用的。開啟遷移連接埠時可能會導致未經授權的主機實施遷移,或是連至重定位連接埠。因為遷移請求並不需要特定的授權,並且唯一的控制機制是基於主機名稱和 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
連線所應監聽的位址。
(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 '')
(xend-relocation-hosts-allow 'hosts')
parameter controls which hostnames can communicate on the relocation port.
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$')
# service xend restart
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)
# 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
[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 '')
[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)
/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 starttestvm1
Domaintestvm1
started
[et-virt07 ~]# virsh list
Id Name State
----------------------------------
Domain-0 running
testvm1
blocked
[et-virt07 images]# time virsh savetestvm1
testvm1
.sav real 0m15.744s user 0m0.188s sys 0m0.044s
[et-virt07 images]# ls -lrttestvm1
.sav -rwxr-xr-x 1 root root 1075657716 Jan 12 06:46testvm1
.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
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
et-virt08
[et-virt08 ~]# virsh list Id Name State ---------------------------------- Domain-0 running
et-virt07
:
[et-virt07 ~]# virsh list
Id Name State
----------------------------------
Domain-0 running
testvm1
running
#!/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
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
# ./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
# ./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
xm migrate
指令)。即時遷移可以使用相同指令來完成。但您必須在 xend-config
配置檔案上作進一步的修改。這個例子顯示您必須修改的項目,以確保遷移成功:
(xend-relocation-server yes)
(xend-relocation-port 8002)
xend
用來移動的連接埠。除非您的網路環境需要自訂連接埠,否則使用這個值即可。請移除這一行之前的註解符號,以啟用連接埠。
(xend-relocation-address )
xend-relocation-server
後,這個參數為接收重定位槽連接的位置。Xen hypervisor 只會聆聽特定介面卡上的遷移網路交通。
(xend-relocation-hosts-allow )
(xend-relocation-hosts-allow- '^localhost\\.localdomain$' )>
virsh
指令來將客座端遷移至另一部主機上。migrate
指令接受下列參數格式:
# virsh migrate --live GuestName DestinationURL
GuestName
參數代表您希望遷移的客座端之名稱。
DestinationURL
參數代表目標系統的 URL 或主機名稱。目標系統必須執行相同版本的 Red Hat Enterprise Linux、使用相同的 hypervisor 並且皆需要執行 libvirt
。
test1.example.com
遷移至 test2.example.com
。請更改您環境的主機名稱。此範例遷移了一部名為 RHEL4test
的虛擬機器。
驗證客座端是否正在運作
test1.example.com
上驗證 RHEL4test
是否正在運作:
[root@test1 ~]# virsh list Id Name State ---------------------------------- 10 RHEL4 running
遷移客座端
test2.example.com
。請將 /system
附加至目標 URL 的尾端來讓 libvirt 知道您需要完整的存取權限。
# virsh migrate --live RHEL4test qemu+ssh://test2.example.com/system
等待
virsh
只會回報錯誤。客座端會繼續在來源主機上執行直到完全被遷移。
驗證客座端已到達目標主機
test2.example.com
上驗證 RHEL4test
是否有在運作:
[root@test2 ~]# virsh list Id Name State ---------------------------------- 10 RHEL4 running
virt-manager
來遷移基於 KVM 的客座端。
ssh
或是 TLS 與 SSL 來遠端管理您的虛擬化客座端。
libvirt
管理連線並安全地通過了一個 SSH 連線來管理遠端機器。所有認證都是透過使用 SSH 公共金鑰加密,以及透過您本機 SSH 代理程式所蒐集的密碼或密語來進行的。此外,各個客座端虛擬機器的 VNC 主控台都會通過 SSH。
virt-manager
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.
virt-manager
.
Optional: Changing user
$ su -
Generating the SSH key pair
virt-manager
is used. This example uses the default key location, in the ~/.ssh/
directory.
$ ssh-keygen -t rsa
Coping the keys to the remote hosts
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
Optional: Add the passphrase to the ssh-agent
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
libvirt
daemon(libvirtd
)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
來存取您的客座端。
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.
libvirt
伺服器設定/etc/xen/xend-config.sxp
這個配置檔案來啟用 TLS。請將配置檔案中的 (vnc-tls 1)
設定參數的註解符號移除掉。
/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
(vnc-x509-verify 1)
parameter.
virt-manager
和 virsh
客戶端設定libvirt
管理 API,CA 與客戶端憑證就必須被放置在 /etc/pki
中。如欲取得更多相關資訊,請參閱 http://libvirt.org/remote.html。
virt-manager
user interface, use the ' ' transport mechanism option when connecting to a host.
virsh
的話 URI 的格式會如下:
qemu://hostname.guestname/system
。
xen://hostname.guestname/
。
$HOME/.pki
之中,也就是以下的三個檔案:
ca-cert.pem
- CA 憑證。
libvirt-vnc
或 clientcert.pem
- CA 所簽署的客戶端憑證。
libvirt-vnc
或 clientkey.pem
- 客戶端私密金鑰。
libvirt
支援下列傳輸模式:
/var/run/libvirt/libvirt-sock
以及 /var/run/libvirt/libvirt-sock-ro
(唯讀連線)。
libvirtd
)必須在遠端機器上執行。通訊埠 22 必須開啟才可進行 SSH 存取。您應該使用某種 ssh 金鑰管理(例如 ssh-agent
工具),否則系統會提示您輸入密碼。
ext
參數用於任何能夠連至遠端機器,libvirt
所無法處理的外部程式。這參數並不支援。
virsh
和 libvirt
使用來連至遠端主機。URI 亦可與 --connect
參數搭配使用,讓 virsh
指令在遠端主機上執行單獨的指令或遷移。
driver[+transport]://[username@][hostname][:port]/[path][?extraparameters]
ccurran
,連至遠端 Xen hypervisor 上名為 towada
的主機。
xen+ssh://ccurran@towada/
towada
的遠端 Xen hypervisor。
xen://towada/
towada
using TLS. The no_verify=1
tells libvirt not to verify the server's certificate.
xen://towada/?no_verify=1
towada
上的遠端 KVM hypervisor。
qemu+ssh://towada/system
qemu+unix:///system?socket=/opt/libvirt/run/libvirt/libvirt-sock
test+tcp://10.1.1.10:5000/default
名稱 | 傳輸模式 | 描述 | 使用範例 |
---|---|---|---|
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 指令:
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 |
內容目錄
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
ps
pstree
top
kvmtrace
kvm_stat
xentop
xm dmesg
xm log
virsh
是個用來管理客座端和 hypervisor(管理程序)的指令列介面工具。
virsh
這項工具建置於 libvirt
管理 API 上,並且可作為替代 xm
工具和圖形化客座端管理程式(virt-manager
)的額外選項來進行作業。無權限的使用者只可使用 virsh
的唯讀模式。您可使用 virsh
來執行客座端機器的 script。
指令 | 描述 |
---|---|
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 資源:
指令 | 描述 |
---|---|
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
指令:
指令 | 描述 |
---|---|
version
|
顯示 virsh 的版本
|
nodeinfo
| 輸出有關於 hypervisor 的相關資訊 |
virsh
來連至一個 hypervisor session:
# virsh connect {hostname OR URL}
<name>
為 hypervisor 的機器名稱。若您希望進行唯讀的連線,請搭配使用上述指令與 -readonly
。
virsh
:
# virsh dumpxml {domain-id, domain-name or domain-uuid}
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 dumpxmlThis fileGuestID
>guest.xml
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>
dumpxml
option (refer to 建立一個虛擬機器的 XML 傾印(配置檔案)). To create a guest with virsh
from an XML file:
# virsh create configuration_file.xml
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}
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
restore
(復原客座端) option. Save is similar to pause, instead of just pausing a guest the present state of the guest is saved.
# virsh restore filename
virsh
指令來關閉客座端:
# virsh shutdown {domain-id, domain-name or domain-uuid}
on_shutdown
parameter in the guest's configuration file.
virsh
指令來重新啟動客座端:
#virsh reboot {domain-id, domain-name or domain-uuid}
on_reboot
element in the guest's configuration file.
virsh
指令來停止客座端:
# virsh destroy {domain-id, domain-name or domain-uuid}
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.
# virsh domid {domain-name or domain-uuid}
# virsh domname {domain-id or domain-uuid}
# virsh domuuid {domain-id or domain-name}
virsh domuuid
指令輸出的範例:
# virsh domuuid r5b2-mySQL01 4a4c59a7-ee3f-c781-96e4-288f2862f011
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
的客座端在執行時發生了錯誤並且已不再運作了。此狀態只可能在客座端被設為當機時不會重新啟動的情況下才會發生。
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
# virsh vcpupin domain-id vcpu cpulist
domain-id
parameter is the guest's ID number or name.
vcpu
參數表示分配給客座端的虛擬處理器數目。您必須提供 vcpu
參數。
cpulist
參數是實體處理器的識別號碼之清單,這些號碼會以逗號隔開。cpulist
參數會決定何種實體處理器是 VCPU 可以在其上執行的。
virsh
來修改指定給客座端的 CPU 數量:
# virsh setvcpus {domain-name, domain-id or domain-uuid} count
count
計數值不可超過當您建立客座端時所指定的數值。
virsh
:
# virsh setmem {domain-id or domain-name} count
virsh domblkstat
來顯示啟用中的客座端的區塊裝置數據。
# virsh domblkstat GuestName block-device
virsh domifstat
來顯示執行中的客座端的網路介面卡數據。
# virsh domifstat GuestName interface-device
virsh
來被遷移至另一部主機上。將網域遷移至另一部主機上。附加 --live 來進行即時遷移。migrate
指令接受下列格式的參數:
# virsh migrate --live GuestName DestinationURL
--live
參數為可選用的參數。請附加 --live
參數來進行即時遷移。
GuestName
參數代表您希望遷移的客座端之名稱。
DestinationURL
參數代表目標系統的 URL 或主機名稱。目標系統需要:
libvirt
服務必須要啟動。
virsh
指令來管理虛擬網路。若要列出虛擬網路請輸入:
# virsh net-list
# virsh net-list Name State Autostart ----------------------------------------- default active yes vnet1 active yes vnet2 active yes
# virsh net-dumpxml NetworkName
# 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 未啟用的網路之名稱
— 將未啟用的網路的定義移除。
virt-manager
)視窗、對話方塊與各種不同的 GUI 控制。
virt-manager
提供了您系統上以及許端機器上的 hypervisor 和客座端的圖形化視點。您可使用 virt-manager
來定義半虛擬化和完整虛擬化的客座端。virt-manager
可進行虛擬化管理工作,這包含了:
virt-manager
. The UUID field displays the globally unique identifier for the virtual machines.
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.
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'.
virt-manager
, it is not possible to use this sticky key feature to send a Sysrq key combination to a guest.
virt-manager
session,請開啟 選單、 選單,然後再點選 (virt-manager
)
virt-manager
的主視窗將會出現。
virt-manager
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 來進行遠端管理”.
virt-manager
's preferences window.
DHCP
範圍xm
指令可管理 Xen hypervisor。大部分的作業都可透過 virt-manager 應用程式或是 virsh
指令這些 libvirt 工具來進行。xm
指令沒有檢查 libvirt 工具錯誤的功能,因此不該被使用來進行 libvirt 工具所支援的工作。
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
目前尚未受到支援。
/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
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
mem
com1=115200, 8n1
dom0_mem
dom0_max_vcpus
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
/etc/elilo.conf
的 ELILO 配置檔案,包含著全域選項和映像的資料清單。當您安裝 kernel-xen
RPM 時,有個安裝後執行的描述檔會將適當的映像資料新增至 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"
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
.
read-only
參數轉換至核心指令列選項 ro
,這會使 root 檔案系統以唯讀掛載,直到 initscripts
將 root 檔案系統掛載為可讀寫為止。ELILO 會將「root
」這一行複製至核心指令列上。這些會被合併於「append
」一行以建立一個完整的指令列:
"-- root=/dev/VolGroup00/rhel5_2 ro rhgb quiet"
--
可被用來界定 hypervisor 和核心引數。首先是 hypervisor 引數,接著便是 --
界定符號,然後才是核心引數。Hypervisor 通常不會有任何引數。
--
之前輸入參數。以下為 hypervisor 記憶體(mem
)參數和核心的 quiet
參數之範例:
append="dom0_mem=2G -- quiet"
參數 | 描述 |
---|---|
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= | com1= 可設置第一個序列線路的參數(例如 com1=9600,8n1,0x408,5 )。io_base 和 irq 選項可被省略以將它們保留為標準的預設值。baud 參數可被設為 auto 來表示開機載入程式設定應被保留。若是序列參數在 ELILO 或 EFI 配置中被設為了全域選項的話,com1 參數就可被省略掉。 |
com2= | 請設置第二個序列線路的參數。請參閱以上 com1 參數的描述。 |
console= | console 是個以逗號來區隔開的 Xen 主控台選項的偏好清單。這些選項包含 vga、com1 和 com2。此設定應被省略掉,因為 hypervisor 會嘗試繼承 EFI 主控台的設定。 |
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 引數。
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.
|
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.
xm create --help_config
.
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=
vnclisten=
xauthority=
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=
script= =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 位址一樣。這個值在整個叢集上必須是獨一無二的。 |
剖析器函式 | 有效的引數 |
---|---|
set_bool
|
接受的值:
|
set_float
|
Accepts a floating point number with Python's float(). For example:
|
set_int
|
Accepts an integer with Python's int().
|
set_value
|
接受任何 Python 的值。
|
append_value
|
接受任何 Python 的值,並且會將它附加至先前儲存在陣列中的值。
|
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
|
內容目錄
/etc/grub.conf
ftpd
/etc/grub.conf
ftpd
virsh
來設定客座端 TestServer
,使其在主系統開機時自動啟動。
# virsh autostart TestServer
Domain TestServer marked as autostarted
--disable
參數
# virsh autostart --disable TestServer
Domain TestServer unmarked as autostarted
安裝 KVM 套件
# yum install kvm
檢查使用中的核心版本
uname
指令來確定正在執行的是哪個核心:
$ uname -r 2.6.18-159.el5xen
2.6.18-159.el5xen
」。如果您執行的是預設的核心「2.6.18-159.el5
」,您可以跳過這個子步驟。
將 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
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
重新開機,載入新的核心
$ lsmod | grep kvm kvm_intel 85992 1 kvm 222368 2 ksm,kvm_intel
kvm
模組與 kvm_intel
或 kvm_amd
模組之一。
安裝 Xen 套件
# yum install kernel-xen xen
檢查使用中的核心版本
uname
指令,確定執行中的套件為何。
$ uname -r 2.6.18-159.el5
2.6.18-159.el5
」。這是預設的核心。如果核心的檔名最後有 xen
字樣(例如 2.6.18-159.el5xen
),那表示您現在執行的是 Xen 核心,可以跳過這一步驟。
將預設核心改為 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
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
重新開機,載入新的核心
uname
指令檢查:
$ uname -r 2.6.18-159.el5xen
xen
字樣,那表示現在執行的是 Xen 核心。
qemu-img
指令列工具可以用來把 Xen 或 KVM 所使用的多種檔案系統格式化。qemu-img
可以用來格式化虛擬客座端的映像檔、額外的儲存裝置與網路儲存裝置。qemu-img
的選項與用法列於以下。
filename
,設定大小 size
與格式 format
。
# qemu-img create [-6] [-e] [-b base_image] [-f format] filename [size]
convert
選項是用來將可辨識的一種格式,轉為另一種格式。
# qemu-img convert [-c] [-e] [-f format]filename
[-Ooutput_format
]output_filename
filename
轉成格式為 output_format
的磁碟映像檔output_filename
。您也可以選用加密(-e
)或壓縮(-c
)選項。
qcow
」格式支援加密或壓縮功能。壓縮是唯讀的。這表示如果覆寫了一個壓縮的磁區,那麼重新寫入後會變成未壓縮的資料。
qcow
或 cow
)時,轉換映像檔可以有效地讓映像檔更小。程式會偵測並壓縮空的磁區。
info
參數會顯示磁碟映像檔的資訊。info
選項的格式如下:
# qemu-img info [-f format] filename
filename
的資訊。利用這項指令可得知磁碟的保留空間(有可能與顯示的大小不同)。如果 vm
的快照是存在磁碟映像檔中,那快照也會被顯示出來。
raw
qemu-image info
或 Unix/Linux 上的 ls -ls
指令以得知映像檔所使用的真正大小
qcow2
qcow
cow
cow
格式是為了與之前的版本相容,所以才納入的。這格式並不適用於 Windows。
vmdk
cloop
(0.5 * RAM) + (overcommit ratio * RAM) = Recommended swap size
/etc/grub.conf
/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.
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
上的重點...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.
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
$ grep -E 'svm|vmx' /proc/cpuinfo
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
flags:
」的內容可能會因為系統上的超執行緒、多核心、或多處理器,而重複出現。
For users of the KVM hypervisor
kvm
modules are loaded in the kernel:
# lsmod | grep kvm
kvm_intel
or kvm_amd
then the kvm
hardware virtualization modules are loaded and your system meets requirements. sudo
virsh
command can output a full list of virtualization system capabilities. Run virsh capabilities
as root to receive the complete list.
kpartx
tool, covered by this section, to mount the guest file system as a loop device which can then be accessed.
kpartx
command creates device maps from partition tables. Each guest storage image has a partition table embedded in the file.
# yum install kpartx
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.
/dev/mapper/
.
# kpartx -a /var/lib/libvirt/images/guest1.img
# ls /dev/mapper/ loop0p1 loop0p2
loopXpY
.
/mnt/guest1
for mounting the partition.
# mkdir /mnt/guest1
# mount /dev/mapper/loop0p1
/mnt/guest1 -o loop,ro
/mnt/guest1
directory. Read or copy the files.
# umount /mnt/tmp
# kpartx -d /var/lib/libvirt/images/guest1.img
guest1.img
to the recognized devices in the /dev/mapper/
directory.
# kpartx -a /var/lib/libvirt/images/guest1.img
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
VolGroup00
by default) with the vgchange -ay
command.
# vgchange -ay VolGroup00 2 logical volumes in volume group VolGroup00 now active.
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
/dev/VolGroup00/LogVol00
in the /mnt/guestboot/
directory.
# mount /dev/VolGroup00/LogVol00 /mnt/guestboot
/mnt/guestboot
directory. Read or copy the files.
# umount /mnt/
VolGroup00
# vgchange -an VolGroup00
# kpartx -d /var/lib/libvirt/images/guest1.img
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
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>
virsh freecell
command to display the free memory on all NUMA nodes.
# virsh freecell 0: 2203620 kB 1: 3354784 kB
virsh capabilities
command) about NUMA topology.
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>
<cell id='1'>
, has physical CPUs 4 to 7.
cpuset
attribute to the configuration file.
virsh edit
.
vcpus
element.
<vcpus>4</vcpus>
cpuset
attribute with the CPU numbers for the relevant NUMA cell.
<vcpus cpuset='4-7'>4</vcpus>
virt-install
provisioning tool provides a simple way to automatically apply a 'best fit' NUMA policy when guests are created.
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.
--cpuset=auto
with the virt-install
command when creating new guests.
virsh vcpuinfo
and virsh vcpupin
commands can perform CPU affinity changes on running guests.
virsh vcpuinfo
command gives up to date information about where each virtual CPU is running.
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
virsh vcpuinfo
output (the yyyyyyyy
value of CPU Affinity
) shows that the guest can presently run on any CPU.
# virsh vcpupinguest1
0 4 # virsh vcpupinguest1
1 5 # virsh vcpupinguest1
2 6 # virsh vcpupinguest1
3 7
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
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()
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
#!/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 ""
rate
” parameter part of the VIF
entries can throttle virtualized guests.
rate
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.
rate=
選項的非必選變數:
rate
參數值和使用方法之範例。
rate=10Mb/s
rate=250KB/s
rate=10MB/s@50ms
VIF
項目會看似:
vif = [ 'rate=10MB/s , mac=00:16:3e:7a:55:1c, bridge=xenbr1']
rate
entry would limit the virtual machine's interface to 10MB/s for outgoing traffic
virsh
或 virt-manager
來設定:
virsh
refer to 設定虛擬 CPU 的相似性 for more information.
virt-manager
refer to 節 26.11, “顯示虛擬 CPU” for more information.
/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
'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
ftpd
vsftpd
提供了半虛擬化客座端(例如 Red Hat Enterprise Linux 5 儲存庫)安裝樹的存取權限,或是其他資料。若您在安裝伺服器時,並沒有安裝 vsftpd
的話,您可透過您安裝媒介的 Server
目錄中取得該 RPM 套件,並透過使用 rpm -ivh vsftpd*.rpm
來安裝它(請注意,該 RPM 套件必須位於您目前的目錄中)。
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
chkconfig --list vsftpd
來驗證 vsftpd
是否並未被啟用:
$ chkconfig --list vsftpd vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
chkconfig --levels 345 vsftpd on
來在 run level 3、4 和 5 之中自動啟用 vsftpd
。
chkconfig --list vsftpd
指令來驗證 vsftpd
是否已被設為在系統開機時啟用:
$ chkconfig --list vsftpd vsftpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
service vsftpd start vsftpd
來啟用 vsftpd 服務:
$service vsftpd start vsftpd Starting vsftpd for vsftpd: [ OK ]
udev
來實施 LUN 的持續性。在您的系統中實施 LUN 持續性之前,請確認您已取得正確的 UUID。一旦您取得了這些 UUID 之後,您便可透過編輯位於 /etc
目錄中的 scsi_id
檔案來配置 LUN 的持續性。當您在文字編輯器中開啟了此檔案後,您必須將此行更改為註解:
# options=-b
# options=-g
scsi_id
指令:
# scsi_id -g -s /block/sdc *3600a0b80001327510000015427b625e*
/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
/etc/
目錄中的 multipath.conf
檔案來定義四個裝置別名:
multipath { wwid 3600a0b80001327510000015427b625e alias oramp1 } multipath { wwid 3600a0b80001327510000015427b6 alias oramp2 } multipath { wwid 3600a0b80001327510000015427b625e alias oramp3 } multipath { wwid 3600a0b80001327510000015427b625e alias oramp4 }
/dev/mpath/oramp1
、/dev/mpath/oramp2
、/dev/mpath/oramp3
,以及 dev/mpath/oramp4
。裝置會位於 /dev/mpath/
目錄中。這些 LUN 名稱在開機後依然具有持續性,因為它將別名建立於 LUN 的 wwid 上。
/sbin/service smartd stop /sbin/chkconfig --del smartd
/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.
vino-preferences
這項指令。
~/.vnc/xstartup
檔案以便在 vncserver 啟用時啟動 GNOME session。您第一次執行 vncserver script 時,它會要求您輸入一組您想要用於您的 VNC session 的密碼。
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
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.
/etc/sysconfig/network
file to match the new guest's hostname.
/etc/sysconfig/network-scripts/ifcfg-eth0
檔案的 HWADDR
位址以便符合來自於 ifconfig eth0
檔案的輸出,並且若您所使用的是靜態 IP 位址的話,您則需要修改 IPADDR
項目。
name
uuid
uuidgen
指令來產生。以下為 UUID 的輸出範例:
$ uuidgen a984a14f-4191-4d14-868e-329906b211e5
vif
xenbr
項目以符合您的本地網路配置(您可透過使用 brctl show
指令來取得橋接資訊)。
disk=
部份中的項目以便指向正確的客座端映像檔。
/etc/sysconfig/network
HOSTNAME
entry to the guest's new hostname
.
/etc/sysconfig/network-scripts/ifcfg-eth0
HWADDR
位址修改為 ifconfig eth0
的輸出
IPADDR
項目。
libvirt
來編寫自訂化 script,以求便利的編程人員與系統管理員有幫助的資訊。
libvirt
.
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
內容目錄
xentop
xentop
會顯示有關於主系統以及它的網域的即時資訊。
xm
dmesg
和 log
vmstat
iostat
lsof
iostat
、mpstat
與 sar
指令都是由sysstat
套件所提供。
XenOprofile
systemtap
crash
sysrq
sysrq t
sysrq w
ifconfig
tcpdump
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
Server
軟體庫裡找到:
yum install vnc
command.
yum install vnc-server
指令來安裝 vncserver。
/etc/xen/
。這個目錄包括 xend
daemon 以及其它的虛擬主機配置檔案。網路作業的 script 檔案則位於 scripts
目錄中。
/var/log/xen/
目錄中。
/var/lib/libvirt/images/
目錄中。
/proc/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
檔案進行備份。
/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/
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
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 的遠端主機中擷取資料。例如,您可以在遠端主機上輸入:
ttywatch --name myhost --port /dev/ttyS0
/dev/ttyS0
輸入至 /var/log/ttywatch/myhost.log
檔案中。
# virsh console [guest name, ID or UUID]
virt-manager
to display the virtual text console. In the guest console window, select Serial Console from the View menu.
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
virt-manager
to display the virtual text console. In the guest console window, select Serial Console from the View menu.
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
檔案中)。
"Invalid argument"
錯誤訊息。通常這表示您欲啟動的核心映像檔無法與管理程序相容。舉例來說,例如您欲在 PAE FC6 管理程序上執行非 PAE FC5 核心。
grub.conf
預設核心轉回空機核心而非虛擬化核心。
/etc/sysconfig/kernel/
directory. You must ensure that kernel-xen
parameter is set as the default option in your grub.conf
file.
/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.el5com1=115200,8n1
module /boot/vmlinuz-2.6.18-92.el5xen ro root=LABEL=VG_i386console=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
com1
、com2
等等)輸出。
com2
,而 vmlinuz
一行所使用的參數是 console=ttyS0
。使用 console=ttyS0
並不是標準的 Linux 行為,而是特定用於 Xen 環境的行為。
virsh console
或 virt-manager
的序列主控台視窗來接收。請以這步驟設定虛擬序列主控台:
/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
virt-manager
的「序列主控台」與「virsh console
」接收核心訊息。
xend
)可以配置為紀錄來自半虛擬化客座端的序列主控台之資料。
xend
,請編輯 /etc/sysconfig/xend
。改變此條目:
# Log all guest console output (cf xm console) #XENCONSOLED_LOG_GUESTS=no
# Log all guest console output (cf xm console) XENCONSOLED_LOG_GUESTS=yes
/var/log/xen/console
檔案裡。
virsh console
指令來檢視。
xend
來紀錄輸出資料。
ttyS0
;在 Windows 裡稱為 COM1
。
/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
裡,因為這是給半虛擬化客座端使用的。
virt-manager
or virt-install
tools on Red Hat Enterprise Linux 5, the guests configuration files are created automatically in the /etc/xen
directory.
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'
virsh dumpxml
與 virsh create
(或 virsh edit
)來編輯 libvert
的配置檔案(XML 格式),這些程式都有錯誤偵測與安全性檢查功能。
failed domain creation due to memory shortage, unable to balloon 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
# 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)
Unable to open a connection to the Xen hypervisor or daemon
/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!
# 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
/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',]
# 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)
/etc/xen/
目錄包含著xend
daemon 所使用的配置檔案。
scripts
目錄包含著虛擬化網路作業上的 script。
/var/log/xen/
/var/lib/libvirt/images/
/proc/xen/
/proc
檔案系統中,Xen 的相關資訊。
cat /proc/partitions
」來進行驗證。
# cat /proc/partitions major minor #blocks name 202 16 104857600 xvdb 3 0 8175688 hda
/etc/inittab
檔案中:
1:12345:respawn:/sbin/mingetty xvc0
Xen Virtual Ethernet
(Xen 虛擬乙太網路)網路卡。請執行以下指令(適用於 Red Hat Enterprise Linux 4 與 5)檢查:
cat /etc/modprobe.conf
cat /etc/modules.conf
alias eth0 xen-vnif
alias eth0 xen-vnif
)。
/etc/modprobe.conf
中調整已配置的 loop 裝置數量。請編輯 /etc/modprobe.conf
並將下列一行附加至該檔案中:
options loop max_loop=64
phy: block device
或 tap:aio
指令。若要使用 loop 裝置支援的客座端來作為完整虛擬化系統的話,請使用 phy: device
或 file: file
指令。
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 failedYou 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.
kernel-xen
核心。請為半虛擬化的客座端使用標準的核心。
# 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
”.
/etc/grub.conf
配置檔案中所啟用的預設 kernel。
kernel-xen
,那您便可啟動您的客座端:
xm create -c GuestName
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
”.
# 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:
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.
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
Applying Intel CPU microcode update: FATAL: Module microcode not found. ERROR: Module microcode does not exist in /proc/modulesAs 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
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)
Enabling the virtualization extensions in BIOS
cat /proc/cpuinfo | grep vmx svm
。如果您看到任何結果,表示虛擬延伸功能已經啟用。如果您看不到任何結果,那表示您的系統沒有任何虛擬延伸功能,或者 BIOS 並未啟用這功能。
e1000
)或 virtio
(半虛擬化的網路驅動程式)。
e1000
驅動程式:
virsh
command (where GUEST
is the guest's name):
# virsh edit GUEST
virsh edit
指令會透過 $EDITOR
環境變數,決定要用哪個編輯程式。
<interface type='network'>
[output truncated]
<model type='rtl8139' />
</interface>
'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>
# virsh dumpxml GUEST > /tmp/guest.xml
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>
# virsh define /tmp/new-guest.xml # virsh start new-guest
/var/log/xen/
xend
daemon 和 qemu-dm 程序所產生的所有日誌檔案。
xend.log
xend-debug.log
xen-hotplug.log
qemu-dm.PID
.log
qemu-dm
程序所建立而成的,並且各個完整虛擬客座端都會啟動此程序。
PID
會被取代為和 qemu-dm 程序相關之程序的 PID
ps
指令來取得一個特定 qemu-dm
程序的 PID
,並且您可透過查看程序引數來辨識出 qemu-dm
程序所屬的虛擬機器為何。
.virt-manager
in the user's home
directory whom ran virt-manager. This directory will usually be ~/.virt-manager/virt-manager
.
/var/lib/libvirt/images/
/var/lib/xen/xend-db/
/etc/xen/
/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
# 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.
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
# cd /lib/modules/`uname -r`/ # find . -name 'xen_*.ko' -print
# 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
/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 202You 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]
type=ioemu
' part of 'vif
=' line in your guest's configuration file.
domU
refers to the guest operating systems which run on the host system (the dom0 domain).
/dev/VolGroup00/LogVol02
),
/dev/sda5
), and
/dev/sda
).
tap:aio
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.
ext2
和 ext3
檔案系統標識符號、RAID 裝置標識符號、iSCSI 和 LUN 裝置標識符號、MAC 位址以及虛擬機器標識符號。
libvirt
虛擬化 API 的正式網站。
/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>
— 它提供了虛擬主機管理程式的文件,虛擬主機管理程式則提供了一個用來管理虛擬主機的圖形化工具。