閑玩Xen

簡述理論

虛擬化的實現

模擬技術:模擬計算機的主要硬件硬件并協調工作,但是效率很低下,所以不常用

完全虛擬化:針對cpu的虛擬來分為,基于BT技術(Guset的特權指令在ring1,Host的特權指令在ring0,Guest的特權指令由Host的ring0來參與邊翻譯邊執行)的完全虛擬化,基于HVM(硬件輔助,Guest的特權指令在ring0,Host的特權指令在ring-1,Guest意識不到自己處于虛擬化環境Intel-VT,AMD-V)的完全虛擬化

半虛擬化:Guest的內核知道自己處于虛擬化環境中,自己的特權指令會變成system call來調用Hpervisor執行

Xen

Dom0:能夠管理控制VMguest,I/O,驅動,結合qemu來虛擬化磁盤,網卡等I/O設備

DomU:運行在Hpervisor上的各個虛機(VMguest)

Hpervisor:運行在物理機上,管理負責CPU和內存的虛擬化

Hardware:物理機

管理工具:xm/xend,xl(輕量級),xe/xapi(提供了管理Xen的api用于cloud環境),virsh(libvirt庫)

實驗過程

實驗目的是利用xen來安裝centos虛機

https://wiki.xen.org/wiki/Xen4CentOS
http://xenbits.xen.org/docs/unstable-staging/
在使用xen4centos時,yum源安裝的Dom0的linux內核版本在配置設置橋ip時,會內核恐慌崩潰,因而轉向參考Xen made easy
 
[root@centos ~]# yum install http://au1.mirror.crc.id.au/repo/kernel-xen-release-latest.noarch.rpm 自動產生Xen yum源配置文件 
[root@centos ~]# yum install xen45 -y   安裝Xen Hpervisor和依賴的包
[root@centos ~]# yum install kernel-xen -y 安裝Dom0 使用的內核
[root@centos ~]# cat /boot/grub/grub.conf 
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (4.4.21-1.el6xen.x86_64)   自動添加Dom0內核引導title
root (hd0,0)
kernel /xen.gz dom0_mem=1024M,max:1024M cpuinfo com1=115200,8n1 console=com1,
tty loglvl=all guest_loglvl=all
module /vmlinuz-4.4.21-1.el6xen.x86_64 ro root=/dev/mapper/vg_centos-lv_root 
rd_NO_LUKS.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD 
SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_centos/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
module /initramfs-4.4.21-1.el6xen.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/vg_centos-lv_root 
rd_NO_LUKS.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD SYSFONT=latarcyrheb-sun16 
crashkernel=auto rd_LVM_LV=vg_centos/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb 
quiet
initrd /initramfs-2.6.32-504.el6.x86_64.img
[root@centos ~]# reboot 選擇剛添加grub.conf Dom0的title,此時本機已為Hpervisor+Dom0
[root@centos ~]# xl list
Name                                        ID   Mem VCPUs State Time(s)
Domain-0                                     0  1024     1     r-----      19.8
[root@centos ~]# xl info
host                   : centos.localdomain
release                : 4.4.21-1.el6xen.x86_64
[root@centos ~]# brctl addbr br0    創建橋設備
[root@centos ~]# ifconfig eth0 0
[root@centos ~]# brctl addif br0 eth0 
[root@centos ~]# cat /etc/sysconfig/network-scripts/{ifcfg-eth0,ifcfg-br0} 永久生效
DEVICE=eth0
TYPE=Ethernet       在做實驗時橋設備的名字改為了xenbr0,用br0時 VMguest 無法啟動
BRIDGE=br0
ONBOOT=yes
NM_CONTROLLED=no
DEVICE=br0
IPADDR=192.168.40.128
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static

在192.168.30.140準備安裝操作系統文件相當于PXE+DHCP+KICKSTART無人職守安裝
利用system-config-kickstart 工具制作ks文件
[root@centos ~]# cat /ks/ks.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=  http://192.168.40.130/    安裝源 掛載到網站根目錄
# Root password
rootpw --iscrypted $1$.bmjihWZ$ZpJnzWFzzEPsR5.cZgq2..
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --enforcing
# Installation logging level
logging --level=info

# System timezone
timezone  Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel           最小化安裝
把ks文件放在 /ks目錄下,在httpd主配置添加目錄別名訪問,請測試能否訪問,如下
Alias /kss/ "/ks/"
<Directory "/ks">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
將welcome.conf重命名避免其生效,必須關閉selinux
[root@centos ~]# cd /etc/httpd/conf.d/
[root@centos conf.d]# ls
mod_dnssd.conf  README  welcome.conf.bak
掛在光盤到/var/www/html/下,請測試訪問網站根目錄是否為光盤內容
配置DHCP服務
subnet 192.168.40.0 netmask 255.255.255.0 {
  range 192.168.40.10 192.168.40.20;
 option subnet-mask 255.255.255.0;
   next-server 192.168.40.130; tftp服務器ip
   filename "pxelinux.0"; pxe引導程序文件
}

[root@centos ~]# vim /etc/dhcp/dhcpd.conf 
[root@centos ~]# service dhcpd restart
Starting dhcpd:                                            [  OK  ]
[root@centos ~]# yum install tftp-server

[root@centos xinetd.d]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@centos xinetd.d]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@centos xinetd.d]# cd /mnt/
[root@centos mnt]# cp images/pxeboot/vmlinuz /var/lib/tftpboot/
[root@centos mnt]# cp images/pxeboot/initrd.img /var/lib/tftpboot/
[root@centos mnt]# cp isolinux/* /var/lib/tftpboot/
cp: overwrite `/var/lib/tftpboot/initrd.img'? n
cp: overwrite `/var/lib/tftpboot/vmlinuz'? n
[root@centos mnt]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@centos ~]# cp isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@centos ~]# chmod +wx /var/lib/tftpboot/pxelinux.cfg/default
label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel vmlinuz  ks= "http://192.168.40.130/kss/ks.cfg" 指定ks文件位置 
  append initrd=initrd.img 
[root@centos ~]# grep "disable" /etc/xinetd.d/tftp  更改disable項為no
	disable			= no
[root@centos ~]# service xinetd start   啟動xinetd服務
回到192.168.40.128
[root@centos ~]# man xl.cfg
xl.cfg(5)                             Xen                            xl.cfg(5)
NAME
       xl.cfg - XL Domain Configuration File Syntax 關于VMguest配置文件中各個指令的幫助
[root@centos ~]# cat /etc/xen/xlexample.pvlinux 
# =====================================================================
# Example PV Linux guest configuration
# =====================================================================
#
# This is a fairly minimal example of what is required for a
# Paravirtualised Linux guest. For a more complete guide see xl.cfg(5)
# Guest name
name = "example.pvlinux"
# 128-bit UUID for the domain as a hexadecimal number.
# Use "uuidgen" to generate one if required.
# The default behavior is to generate a new UUID each time the guest is started.
#uuid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
# Kernel image to boot
kernel = "/boot/vmlinuz"
# Ramdisk (optional)
#ramdisk = "/boot/initrd.gz"
# Kernel command line options
extra = "root=/dev/xvda1"
# Initial memory allocation (MB)
memory = 128
# Maximum memory (MB)
# If this is greater than `memory' then the slack will start ballooned
# (this assumes guest kernel support for ballooning)
#maxmem = 512
# Number of VCPUS
vcpus = 2
# Network devices
# A list of 'vifspec' entries as described in
# docs/misc/xl-network-configuration.markdown
vif = [ '' ]
# Disk Devices
# A list of `diskspec' entries as described in
# docs/misc/xl-disk-configuration.txt
disk = [ '/dev/vg/guest-volume,raw,xvda,rw' ]
[root@centos xen]# cp xlexample.pvlinux centos
[root@centos xen]# mkdir -p /images/xen
[root@centos xen]# qemu-img create -o size=100G /images/xen/centos.img 創建VMguest磁盤文件
Formatting '/images/xen/centos.img', fmt=raw size=107374182400
[root@centos xen]# mkdir /images/kernel
[root@centos xen]# cd /mnt/
[root@centos mnt]# cd isolinux/
[root@centos isolinux]# cp vmlinuz initrd.img /images/kernel/
[root@centos xen]# grep -v "^#" centos | grep -v "^$"
name = "centos6.6"
kernel = "/images/kernel/vmlinuz"  臨時內核引導
ramdisk = "/images/kernel/initrd.img"
extra = "ks=http://192.168.40.130/kss/ks.cfg" 指定ks文件位置
memory = 512
vcpus = 2
vif = [ 'xenbr0' ]
disk = [ '/images/xen/centos.img,raw,xvda,rw' ]
on_boot="shutdown"
[root@centos xen]# xl create centos -c 根據VMguest的配置文件啟動VM并連接登錄
Parsing config from centos
[root@centos xen]# xl list
Name                                        ID   Mem VCPUs	State	Time(s)
Domain-0                                     0  1022     1     r-----      54.4
centos6.6                                    5   512     2     -b----      10.7

QQ截圖20160921210923.jpgQQ截圖20160921211013.jpg

安裝完成后更改centos配置文件注釋掉kernel,initrd, 指明disk文件,extra為空,
加bootloader=pygrub即可,筆記本做實驗很吃力,無法驗證結果了,,,,

總結

Xen支持PV(front-backend I/O分段虛擬化)和HVM的虛擬化,VMguest磁盤也可以是Dom0的物理分區,內核也可以使用Dom0的內核,實驗關于VMguest的管理管理命令xl,網卡vif,磁盤disk的配置參數涉及的比較少,需要多xl help ,參考相關文檔來進一步熟悉記憶,在Xen虛擬化平臺上安裝操作系統也可以使用virt-manager 圖形化來管理配置VMguest.

原創文章,作者:Snoo,如若轉載,請注明出處:http://www.www58058.com/48079

(0)
SnooSnoo
上一篇 2016-09-26 07:43
下一篇 2016-09-26 07:44

相關推薦

  • Linux文件系統總結(7.4課上作業)

    一、什么是文件系統         文件系統是對一個存儲設備上的數據和元數據進行組織的機制。它使用文件和樹形目錄的抽象邏輯概念代替了硬盤和光盤等物理設備使用的數據塊的概念,用戶使用文件系統來保存數據而不必關心數據實際保存在硬盤(or光盤)的地址為多少數據塊上,只需要記住這個文件的…

    Linux干貨 2016-07-10
  • 文本處理工具(一)

    文本處理工具 查看工具 cat;tac;rev;more cat 連接文件,并打印到標準輸出上。 注意:當文件比較大的時候,文本在屏幕上一閃而過,導致無法看清內容,所以對于較大的文件建議結合著more,less等命令結合來用。 使用方法: -E: 顯示行結束符$ -n: 對顯示出的每一行進行編號 空行也加行號 -A:顯示所有控制符 相當于-ETV -b:非空…

    2017-06-01
  • 通過fast-cgi方式在三臺主機部署phpwind并設置為https站點

    通常來說httpd用來處理靜態的網頁請求,動態的資源請求以前是通過CGI的方式進行處理的,但是CGI的方式的處理過程是這樣:有動態資源請求,服務器會fork一個CGI進程進行資源處理,處理完成后這個進程會退出,當再有新的動態資源請求,又會fork一個進程,這樣的效率是很低的。后來就有了通過加載php模塊的方式,即:httpd服務器啟動之后會自動加載php動態…

    2017-06-04
  • PXE

    BootStraping 系統提供 PXE 簡介 PXE(preboot execute environment,預啟動執行環境)是由Intel公司開發的最新技術,工作于Client/Server的網絡模式,支持工作站通過網絡從遠端服務器下載映像,并由此支持通過網絡啟動操作系統,在啟動過程中,終端要求服務器分配IP地址,再用TFTP(trivial file…

    Linux干貨 2016-11-05
  • 優云軟件老司機:如何讓運維操作更輕松、高效

    講師介紹 龐輝富 ?廣通軟件技術總監 ?擁有10多年IT運維管理軟件研發經驗 ?致力于自動化運維解決方案的研究和推廣 ?主導研發的產品廣泛應用于海關、公安、能源等多個行業 技術發展給運維帶來的挑戰 當前的IT建設在這些新技術的演進下,我們看到的是呈現“雙態IT”特征。Gartner也提出雙模IT理論,與現在談的雙態IT是異曲同工的,不再是一種單純的形態,而是…

    系統運維 2017-01-09
  • 第八周

    1、寫一個腳本,使用ping命令探測172.16.250.1-172.16.250.254之間的所有主機的在線狀態;      在線的主機使用綠色顯示;      不在線的主使用紅色顯示; #!/bin/bash # for i in 172.16.250.{…

    Linux干貨 2017-05-23
欧美性久久久久