#台式机硬件说明 cpu i3-4130  内存 4G  硬盘1T  
#vmware,virtualbox安装 http://bbotte.blog.51cto.com/6205307/1539484
# cat /etc/centos-release 
CentOS release 6.4 (Final) 
 
# uname -a  #这里是安装好的kernel,所以不是2.6.32 此内核版本属于长期维护版
Linux localhost.localdomain 3.14.16-1.el6xen.x86_64 #1 SMP Fri Aug 8 16:33:18 EST 2014 x86_64 x86_64 x86_64 GNU/Linux

安装Xen:


SELINUX=disabled  #关闭selinux
yum install bridge-utils
yum install -y http://au1.mirror.crc.id.au/repo/kernel-xen-release-6-5.noarch.rpm 
yum install -y xen
rpm -e xorg-x11-drv-ati-firmware-6.99.99-1.el6.noarch #没有卸载的话会因为冲突而提示错误
yum install kernel-xen

安装过程虽然只是上面几步,不过安装过程中安装哪些包还是要留意一下


grub自动修改好了的

grep -v ^\# /boot/grub/grub.conf 

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title CentOS (3.14.16-1.el6xen.x86_64)

root (hd0,0)

kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=1 dom0_vcpus_pin

module /vmlinuz-3.14.16-1.el6xen.x86_64 ro root=UUID=39d75778-b819-4ea3-a42b-fc08cbc2a73e rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet

module /initramfs-3.14.16-1.el6xen.x86_64.img

title CentOS (2.6.32-358.el6.x86_64)

root (hd0,0)

kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=39d75778-b819-4ea3-a42b-fc08cbc2a73e rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet

initrd /initramfs-2.6.32-358.el6.x86_64.img

 

chkconfig xend on
reboot
# service xend start
# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     1     r-----     82.7
# xm info
host                   : localhost.localdomain
release                : 3.14.16-1.el6xen.x86_64
version                : #1 SMP Fri Aug 8 16:33:18 EST 2014
machine                : x86_64
nr_cpus                : 4
nr_nodes               : 1
cores_per_socket       : 2
threads_per_core       : 2
cpu_mhz                : 3392
hw_caps                : bfebfbff:2c100800:00000000:00007f40:77dafbbf:00000000:00000021:000027ab
virt_caps              : hvm
total_memory           : 4012
free_memory            : 2937
free_cpus              : 0
xen_major              : 4
xen_minor              : 2
xen_extra              : .4
xen_caps               : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64 
xen_scheduler          : credit
xen_pagesize           : 4096
platform_params        : virt_start=0xffff800000000000
xen_changeset          : unavailable
xen_commandline        : dom0_mem=1024M cpufreq=xen dom0_max_vcpus=1 dom0_vcpus_pin
cc_compiler            : gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
cc_compile_by          : mockbuild
cc_compile_domain      : crc.id.au
cc_compile_date        : Wed Jun 18 01:34:43 EST 2014
xend_config_format     : 4

 

安装guest:

yum install gcc gcc-c++ vim wget lrzsz ntpdate sysstat dstat wget man unzip -y #安装常用包

mkdir /data

cd /data/ 用xshell的Xftp把iso上传过来(大于4G用Xftp,小于4G可以用lrzsz)

wKiom1PlgLXAhRxxAAQosCJDQRI381.jpg

 

mount -o loop -t iso9660 /data/CentOS-6.5-x86_64-bin-DVD1.iso /mnt

 

配置网卡:

 cp /etc/sysconfig/network-scripts/ifcfg-p3p1 /etc/sysconfig/network-scripts/ifcfg-br0

# cat /etc/sysconfig/network-scripts/ifcfg-p3p1
DEVICE=p3p1
TYPE=Ethernet
UUID=875acb88-19d4-457f-967f-5979f39930bf
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=C8:1F:66:44:09:EB
#IPADDR=192.168.22.209
#PREFIX=24
#GATEWAY=192.168.22.253
DNS1=114.114.114.114
DOMAIN=114.114.114.114
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System p3p1"
BRIDGE=br0
# cat /etc/sysconfig/network-scripts/ifcfg-br0 
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.22.209
PREFIX=24
GATEWAY=192.168.22.253
DNS1=114.114.114.114
DOMAIN=114.114.114.114
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System br0"

  

创建guest配置文件并开始安装 

# service network restart
Shutting down interface p3p1:  bridge br0 does not exist!
                                                           [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface p3p1:                                [  OK  ]
Bringing up interface br0:                                 [  OK  ]
 
# brctl show
bridge name	bridge id		STP enabled	interfaces
br0		8000.c81f664409eb	no		p3p1
 
cd /data   #创建磁盘文件
# qemu-img create -f raw centos65.img 40G
Formatting 'centos65.img', fmt=raw size=42949672960
# qemu-img create -f raw centos65.swp 512M
Formatting 'centos65.swp', fmt=raw size=536870912
  
# cp /mnt/isolinux/initrd.img /data/
# cp /mnt/isolinux/vmlinuz /data/
  
  
# vim centos65   #编辑配置文件

kernel = "/data/vmlinuz"
ramdisk = "/data/initrd.img"
name = "centos1"
memory = "1024"
disk = [ "file:/data/centos65.img,xvda,w","file:/data/centos65.swp,xvdb,w" ]
vif = [ "bridge=br0" ]
vcpus = 2
on_reboot = "destroy"
on_crash = "destroy" 
 
 
cp -r /mnt/ /data/centosiso
yum install httpd
vim /etc/httpd/conf/httpd.conf  #修改292,318两行即可
292 DocumentRoot "/data/centosiso"
293 #DocumentRoot "/var/www/html"
  
318 <Directory "/data/centosiso">
319 #<Directory "/var/www/html">
 
vim /etc/httpd/conf.d/welcome.conf #修改第8行,-改为+ 
 8     Options +Indexes
 
service httpd start
  
修改这个文件,需要强制保存 wq!
vim /root/centos/.treeinfo  
[images-x86_64]
initrd = images/pxeboot/initrd.img  
  
[images-x86_64]
kernel = isolinux/vmlinuz
initrd = isolinux/initrd.img    
  
vim /etc/sysconfig/iptables #开启80端口,添加一行
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
service iptables restart
   
# xm create centos65 -c  #创建centos65虚拟机,-c 参数直接console DomU
Using config file "./centos65".
Started domain centos1 (id=3)

# xm console centos1    #连接,开始安装系统
 
  
                    ┌────────┤ Choose a Language ├────────┐
                    │                                     │
                    │ What language would you like to use │
                    │ during the installation process?    │
                    │                                     │
                    │      Catalan                ↑       │
                    │      Chinese(Simplified)           │
                    │      Chinese(Traditional)          │
                    │      Croatian                      │
                    │      Czech                         │
                    │      Danish                        │
                    │      Dutch                         │
                    │      English                ↓       │
                    │                                     │
                    │               ┌────┐                │
                    │               │ OK │                │
                    │               └────┘                │
                    │                                     │
# 到下面大家应该知道怎么操作了,选择URL
┌───┤ Installation Method ├───┐
                        │                             │
                        │ What type of media contains │
                        │ the installation image?     │
                        │                             │
                        │       Local CD/DVD          │
                        │       Hard drive            │
                        │       NFS directoryy        │
                        │       URL                   │
                        │                             │
                        │   ┌────┐       ┌──────┐     │
                        │   │ OK │       │ Back │     │
                        │   └────┘       └──────┘

接下来一步配置ip地址,xen的ip是192.168.22.209
───. │          Please enter the URL containing the CentOS          │
        │          installation image on your server.                  │
        │                                                              │
        │http://192.168.22.209________________________________________ │
        │                                                              │
        │ [ ] Enable HTTP proxy                                        │────│.                                                             │
        │ Proxy URL        ___________________________________         │
        │ Username         _______________                             │
        │                                                              │────│ Password.────_______________                             │
        │                                                              │
        │            ┌────┐                       ┌──────┐             │
        │            │ OK │                       │ Back │             │
        │            └────┘                       └──────┘
下一步开启vnc "Start VNC",(其实字符界面也可以,至少速度快)步骤可以参考我博客KVM里面系统安装的操作

wKiom1Pl1APCNfCHAAF1tjnV-V8695.jpg

这里一步步 安装后,重启的时候会关机(因为配置文件 on_reboot = "destroy") 

现在修改配置文件

# cat centos65
#kernel = "/data/vmlinuz"
#ramdisk = "/data/initrd.img"
name = "centos1"
memory = "1024"
disk = [ "file:/data/centos65.img,xvda,w","file:/data/centos65.swp,xvdb,w" ]
vif = [ "bridge=br0" ]
#bootloader = "/usr/bin/pygrub"
vcpus = 2
on_reboot = "restart"
on_crash = "destroy"
# xm create centos65
Using config file "./centos65".
Started domain centos1 (id=8)
# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     1     r-----    496.5
centos1                                      8  1024     2     r-----      2.9


# xm console centos1
root
Password: 
Last login: Sat Aug  9 15:59:32 on hvc0
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda2       40G  3.8G   34G  11% /
tmpfs           497M     0  497M   0% /dev/shm
/dev/xvda1      194M   30M  155M  16% /boot

查看现在的状态

# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     1     r-----    500.2
centos1                                      8  1024     2     -b----      6.5


xm list                          #查看已有guest

xm destroy centos1      #停止

xm shutdown centos1  #关闭电源

xm start centos1          #启动