zoukankan      html  css  js  c++  java
  • 创建Linux下Xen虚拟机

    mkdir /domU

    1.创建虚拟机映像

    dd if=/dev/zero of=xen.img bs=1M count=16000

    dd if=/dev/zero of=xen2.img bs=1M count=16000

    mkfs -t ext3 xen.img

    mkfs -t ext3 xen2.img

    mount -o loop /domU/xen.img /mnt

    cp -ax /{bin,dev,etc,lib,lib64,opt,root,sbin,usr,var} /mnt

    mkdir /mnt/{home,proc,selinux,srv,sys,tmp}

    创建swap盘

    mkswap /slview/swap1.img

    vi /mnt/etc/fstab

    /dev/hda1               /                       ext3    defaults        1 1

    tmpfs                   /dev/shm                tmpfs   defaults,size=1024m        0 0

    devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

    sysfs                   /sys                    sysfs   defaults        0 0

    proc                    /proc                   proc    defaults        0 0

    /dev/sdg           swap                    swap   defaults         0 0

    ---edit network

    vi /mnt/etc/sysconfig/network

    ---edit ifcfg-eth0

    vi /mnt/etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE=eth0
    BOOTPROTO=static
    ONBOOT=yes
    IPADDR=192.168.24.210
    NETMASK=255.255.255.0
    NETWORK=192.168.24.0
    BROADCAST=192.168.24.255

    -----gen   initrd

    mkinitrd -v -f --fstab /mnt/etc/fstab --with xenblk \

    --with xennet --preload xenblk --preload xennet \

    initrd-2.6.18-194.el5xen.wd.img `uname -r`

    umount /mnt

    ---在/etc/inittab

    co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav

    >init q

    >ln -s /dev/console /dev/xvc0

    ---创建内网网桥

    vi ifcfg-xenbr2
    DEVICE=xenbr2
    BOOTPROTO=static
    ONBOOT=yes
    TYPE=Bridge
    启动网桥
    ifup xenbr2

    ----编辑虚拟机配置文件

    name="oradb1"
    kernel="/boot/vmlinuz-2.6.18-238.el5xen"
    ramdisk="/boot/initrd-2.6.18-238.el5xen.wd.img"
    memory="2048"
    vcpus = 2
    vif=['mac=00:16:3e:2e:40:cf,bridge=xenbr0','mac=00:16:3e:2e:a9:41,bridge=xenbr1']
    disk=['tap:aio:/slview/db1.img,sda1,w','tap:aio:/slview/vot1.img,sdb,w!','tap:aio:/slview/vot2.img,sdc,w!','tap:aio:/slview/ocr1.img
    ,sdd,w!','tap:aio:/slview/ocr2.img,sde,w!','tap:aio:/root/data1.img,sdf,w!','tap:aio:/slview/swap1.img,sdg,w','tap:aio:/slview/ocr3.
    img,sdh,w!','tap:aio:/slview/flash1.img,sdi,w!','tap:aio:/slview/flash2.img,sdj,w!','tap:aio:/root/data2.img,sdk,w!']
    root="/dev/sda1 rw"

    网桥配置:

    修改 Xend 配置文件 /etc/xen/xend-config.sxp ,取消下面两行的注释:

    (network-script network-bridge)

    (vif-script vif-bridge)

    使用brctl show来查看网桥

    DomU的config中设置vif = ['bridge=xenbr0']

    存储配置

    [root@db6 xen]# cat oralinux

    name    = "oravm1"

    kernel  = "/boot/vmlinuz-2.6.18-194.el5xen"

    ramdisk = "/boot/initrd-2.6.18-194.el5xen.wd.img"

    memory  = "256"

    vcpus   = 2

    vif     = [ 'ip=192.168.1.140,bridge=xenbr0','ip=192.168.100.140,bridge=xenbr1' ]

    disk    = [ 'file:/domU/xen.img,hda1,w','file:/domU/sdb.img,sdb,w!','file:/domU/sdc.img,sdc,w!','phy:/dev/mapper/oradata1,sdn,w!' ]

    root    = "/dev/hda1 ro "

    ------------------------------------------------------虚拟机-----------------

    强制多虚拟机共享存储

    phy:/dev/sda,sda,w!  加叹号

    需要让xend为两块网卡创建bridge,需要修改/etc/xen/xend-config.sxp,将(network-script 'network-bridge')

    改为:

    (network-script 'my_network_script')

    my_network_script是我们自己的脚本,创建/etc/xen/scripts/my_network_script内容如下:

    #!/bin/sh

    dir=$(dirname "$0")

    "$dir/network-bridge" "$@" vifnum=0 netdev=eth0 bridge=xenbr0

    "$dir/network-bridge" "$@" vifnum=1 netdev=eth1 bridge=xenbr1

    将my_network_script加上执行权限:

    chmod a+x /etc/xen/scripts/my_network_script

    重启服务器,可以用ifconfig看到xend创建的4个网络接口

    可以看到虚拟交换机上的连接如下:
    [root@rac2 xen]# brctl show
    bridge name     bridge id               STP enabled     interfaces
    xenbr0          8000.feffffffffff       no              vif1.0  dom1的eth0
                                                            peth0  主机的物理网卡0
                                                            vif0.0  Dom0的eth0
    xenbr1          8000.feffffffffff       no              vif1.1  Dom1的eth1
                                                            peth1  主机的物理网卡1
                                                            vif0.1  Dom0的eth1

    编辑虚拟机配置文件:

    Error: Device 2048 (vbd) could not be connected. Failed to find an unused loop device

    Error: Device 2064 (vbd) could not be connected. losetup -r /dev/loop8 /domU/sdb.img failed

    >losetup -a 查看loop设备使用情况

    再卸载 loop 模块  rmmod loop

    >vi /etc/modprobe.conf

    options loop max_loop=16

    再重新加载 loop 模块检查是否生效

    modprobe loopdmesg | grep loop               # 应当能见到 loop: loaded (max 16 devices)

    最后建立 loop 设备文件

    ls -d /dev/loop*

    mknod -m0660 /dev/loop9 b 7 8   

    chown root:disk /dev/loop9

    mknod loop8 b 7 8

    mknod loop9 b 7 9

    Q: ADDRCONF(NETDEV_UP): vif1.0: link is not ready

    A: 将/dev/sda1改为/dev/hda1

    Q: 使用vnc报以下错误
    [root@db1 ~]# su - grid
    -bash-3.2$ xclock
    Xlib: connection to ":1.0" refused by server
    Xlib: No protocol specified
    Error: Can't open display: :1.0

    A: 用root帐号执行下列命令既可
    xhost + localhost

    Q:fdisk分区表无法保存
    A:
    chmod 755 *.img
    file:/slview/db1.img 改成tape:aio:/slview/db1.img

    Q:mkrootdev: expected fs options
        mount: missing mount point
        setuproot: moving /dev failed No such file or directory
        setuproot: error mounting /proc: No such file or directory
        setuproot: error mounting /sys: No such file or directory
        switchroot: mount failed: No such file or directory
    A:mkinitrd, /fstab内容

    Q: /sbin/hwclock: error while loading shared libraries: libaudit.so.0: cannot open shared object file: Permission denied

    A: 关闭selinux

  • 相关阅读:
    XML(学习笔记)
    css样式学习笔记
    Request(对象)
    sql一些错误修改的总结
    转载(如何学习C#)
    sql server(学习笔记2 W3Cschool)
    sql sqrver(学习笔记1 W3Cschool)
    关于 flutter开发碰到的各种问题,有的已经解决有的一直没解决或者用其他方法替代
    关于 Flutter IOS build It appears that your application still contains the default signing identifier.
    关于 flutter本地化问题 The getter 'pasteButtonLabel' was called on null
  • 原文地址:https://www.cnblogs.com/itfriend/p/2009786.html
Copyright © 2011-2022 走看看