• 617888.com九五至尊_617888.com九五至尊唯一官网

  • 发布时间:2016-01-13 14:54 | 作者:yc | 来源:互联网 | 浏览:1200 次
  • 617888.com九五至尊_617888.com九五至尊唯一官网另处linux 发行版别必须在64bit 情况中才气运用KVM

    一.kvm虚拟化情况建立预备

    1.硬件情况

    kvm只能部署在物理机上面

    2.BIOS洞开VT

    Virtualization Tech [Enabled]

    3.反省cpu 是不是支撑kvm 全虚拟化

    # grep "flags" /proc/cpuinfo|uniq

    flags : fpu vme de pse tsc msr pae mce cx8 apic sepmtrr pge mca cmov pat

    pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tmsyscall nx pdpe1gb rdtscp lm

    constant_tsc nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16xtpr sse4_1 sse4_2 popcnt lahf_lm

    要是输出的成果包括VMX,它是Intel 处置惩罚器虚拟机技能象征,要是包括SVM,它是AMD 处

    理器虚拟机技能的象征,看到VMX 或SVM,说明支撑全虚拟化

    二.虚拟化情况部署

    1.装配kvm 和虚拟化解决软件包

    yum -y install kvm virt-* libvirts bridge-utils qemu-img

    kvm 软件包kvm 软件包中含有 KVM 内核模块,它可在默许 Linux 内核中

    提供 KVM 解决法度榜样

    libvirts 装配虚拟机解决对象,运用virsh 等指令来解决和操控虚拟机

    bridge-utils 装配收集支撑,设置桥接

    virt-* 创立、克隆虚拟机等指令,以及图形化解决对象virt-manager

    qemu-img 装配qemu 组件,运用qemu 指令来创立磁盘等

    2.加载kvm 模块

    # modprobe kvm-intel

    3.反省kvm 模块是不是被加载

    # lsmod |grep kvm

    kvm_intel 85256 0

    kvm 1 kvm_intel

    4.reboot 并承认

    承认kvm 模块是不是被加载

    # lsmod |grep kvm

    kvm_intel 85256 0

    kvm 2 ksm,kvm_intel

    #如出现以上内容,说明kvm 模块准确加载

    kvm 有关模块的道路

    # cd /lib/modules/2.6.18-348.1.1.el5/weak-updates/kmod-kvm/

    # pwd

    /lib/modules/2.6.18-348.1.1.el5/weak-updates/kmod-kvm

    [root@wg-vm-s2 kmod-kvm]# ls

    ksm.ko kvm-amd.ko kvm-intel.kokvm.ko

    5.反省物理主机虚拟化完结状况

    # virsh list

    Id Name State

    ----------------------------------

    #如出现以上提示说明虚拟化被准确装配

    6.封闭防火墙和selinux

    由于防火墙和selinux会阻止libvirt为虚拟机创立收集设备

    封闭防火墙

    # /etc/init.d/iptables stop

    617888.com九五至尊_617888.com九五至尊唯一官网

    封闭selinux

    [root@test22~]# cat /etc/selinux/config

    #This file controls the state of SELinux on the system.

    #SELINUX= can take one of these three values:

    #enforcing - SELinux security policy isenforced.

    #permissive - SELinux prints warningsinstead of enforcing.

    #disabled - No SELinux policy is loaded.

    SELINUX=disabled#变动为disabled

    #SELINUXTYPE= can take one of these two values:

    #targeted - Targeted processes areprotected,

    #mls - Multi Level Security protection.

    SELINUXTYPE=targeted

    然后指令行实行:setenforce0

    7.设置设备摆设收集桥接

    # cat /etc/sysconfig/network-scripts/ifcfg-eth0

    # Broadcom Corporation NetXtreme BCM5720 GigabitEthernet PCIe

    DEVICE=eth0

    HWADDR=90:B1:1C:2A:A4:40

    ONBOOT=yes

    BOOTPROTO=none

    TYPE=Ethernet

    BRIDGE=br0

    #把稳不要写错

    # cat /etc/sysconfig/network-scripts/ifcfg-br0

    # Broadcom Corporation NetXtreme BCM5720 GigabitEthernet PCIe

    DEVICE=br0

    #HWADDR=90:B1:1C:2A:A4:40

    ONBOOT=yes

    BOOTPROTO=static

    TYPE=Bridge

    IPADDR=192.168.3.200

    NETMASK=255.255.255.0

    GATEWAY=192.168.3.254

    设置设备摆设完eth0 和br0 重启网卡:serivce network restart

    反省已有桥接:

    # brctl show

    bridge name bridge id STP enabled interfaces

    br0 8000.90b11c2aa440 no eth0(设置设备摆设准确的桥接是有mac地址的)

    br1 8000.90b11c2aa441 no eth1

    同伴桥接:

    # brctl show

    bridge name bridge id STP enabled interfaces

    br0 8000.00 no eth0

    8.修正vnc 监听端口

    # cd /etc/libvirt/

    # ls

    libvirtd.conf nwfilter qemu qemu.conf

    # cp qemu.conf qemu.conf.panglu-$(date +%F)

    # vi qemu.conf+12

    11 #

    12 # vnc_listen ="0.0.0.0" #把前面的#注释去掉落,洞开vnc 监听

    13

    14

    15 # Enable use of TLS encryption on the VNC server.This requires

    16 # a VNC client which supports the VeNCryptprotocol extension.

    17 # Examples include vinagre, virt-viewer,virt-manager and vencrypt

    9.洞开响应的效劳

    # /etc/init.d/messagebusstart #linux ICP 效劳

    Starting system message bus:[ OK ]

    # /etc/init.d/libvirtd restart#发动virbr0

    libvirtd (pid 3665) is running...

    增添到开机发动

    # chkconfig messagebus on

    617888.com九五至尊_617888.com九五至尊唯一官网

    echo “/etc/init.d/libvirtdstart”>>/etc/rc.local

    到此,kvm 效劳端装配完结

    三.装配虚拟机

    1.创立虚拟机磁盘目录

    #mkdir /data/vmdisk -p

    2.创立iso文件目录

    #mkdir /iso

    把光盘放入到光驱,dd 指令把iso 文件复制到/iso目录下

    # dd if=/dev/cdromof=/iso/centos5.iso

    3.创立虚拟磁盘文件

    qemu-img create -f qcow2 -opreallocation=metadatadev_5931.img 300G

    主要参数:-opreallocation=metadata 预分配磁盘,硬盘空间不会当即占用

    把稳:ext3不支撑此参数,ext4支撑

    4.装配虚拟机指令及参数

    virt-install --name=dev_5934_44 --ram 8192--vcpus=2 -f dev_5934_44.img--cdrom../iso/CentOS-6.4-x86_64-bin-DVD1to2/CentOS-6.4-x86_64-bin-DVD1.iso--graphics vnc,listen=0.0.0.0,port=5934, --force--autostart

    把稳端口号设定值,用vnc毗连时需求用

    5.接下来客户端vnc去毗连

    650) this.width=650;" id="aimg_43757" src="http://www.iyunv.com/data/attachment/forum//03/hqa799iq58zt8k9q.jpg" class="zoom"www.5imx.com width="1" style="margin:0px;padding:0px;border:0px;" alt="hqa799iq58zt8k9q.jpg" />

    #192.168.3.200 是宿主机IP,5900 是装配指令指定的vnc 端口

    四. 虚拟机硬件设置设备摆设变动篇

    1.处置惩罚kvm情况下能够运用shutdown指令让虚拟机关机,但不见效

    进入不能关机的虚拟机中:

    [root@localhost ~]# yum -yinstallacpid;装配acpid效劳

    [root@localhost ~]# service acpid restart;发动效劳

    [root@localhost ~]# chkconfig acpid on;参加开机发动

    颠末以上历程后就能够让虚拟机呼应shutdown 和reboot指令了

    2.修正kvm中虚拟机的内存巨细及cpu数量

    a.反省虚拟机

    virsh # list --all

    Id名称状况

    ----------------------------------------------------

    2test_centosrunning

    4qishirunning

    13qishi2running

    14cloud_monitor_5921running

    20test22running

    -test33封闭

    b.变动要修正的设置设备摆设文件

    [root@nfs ~]# virsh edittest22##把稳vi直接修正不见效

    test22

    eb342f67-e70c-194b-5291-e91010ed996f

    #à为内存巨细,单位为K 修正此数字,例如要调剂为8G 则设置为

    4 #4à为cpu数量,变动为5个则将4修正为5

    hvm

    修正完保留à封闭虚拟机à发动虚拟机(把稳直接重启不见效)

    [root@nfs ~]# virshshutdown test22

    Domain vm01 is being shutdown

    [root@nfs ~]# virshstart test22

    反省:

    发动后登录虚拟机,反省内存及cpu,发明现已变动

    反省内存:# free -m

    反省cpu数量 # cat/proc/cpuinfo

    3.虚拟机网卡mac矛盾的处置惩罚法子:

    a.毗连上虚拟机

    b.关掉落矛盾主机

    #ifdown eth0

    c.修正eth0的mac

    #sbin/ifconfig eth0 hw ether 00:AA:BB:CC:11:22 ##-->分一个只管即便不易出现的mac

    d.修正eth0设置设备摆设文件中的mac

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

    Hwaddr: 00:AA:BB:CC:11:22

    e.重启网卡

    service network restart

    f.咱们用指令行变动的mac在当前见效,重启后掉效,以是需求参加到开机发动

    echo “ifdown eth0”>>/etc/rc.local

    echo “sbin/ifconfig eth0 hw ether 00:AA:BB:CC:11:22”

    echo “ifup eth0”

    好了,网卡mac矛盾处置惩罚了!

    4.给虚拟机增添硬盘

    1、给当前磁盘扩容

    a.找到需求扩容的磁盘文件

    [root@qishi_test qemu]# cd /data/VHOST/

    [root@qishi_test VHOST]# ll

    总用量

    -rw-r--r-- 1 qemu qemu44 6月2 12:33 cloud_monitor_5921.img

    -rw-r--r-- 1 root root0 5月30 16:54 jia_qishi2.img

    -rw-r--r-- 1 qemu qemu4 6月2 12:33 test2.img

    -rwxr-xr-x 1 root root4 6月2 10:05 test33.img

    -rw-r--r-- 1 qemu qemu0 5月30 18:53 test_jia.img

    b.咱们现在给test22增添10G空间,他的磁盘文件对应的test2.img

    qemu-img resize test2 +10G

    c.封闭虚拟机test22à发动虚拟机test22(把稳:重启不见效)

    反省:

    登入虚拟机,fdisk -l 发明磁盘增添了10G的空间,咱们能够对其进行分区挂载等操作了

    2、给虚拟机增添一块磁盘

    a.创立文件硬盘的镜像

    qemu-img create -f raw /disk/sdb6/c1d6.img 10G #指定道路、名称、及巨细

    Formatting '/disk/sdb6/c1d6.img', fmt=raw size=0

    b.翻开虚拟机列表

    virsh # list --all

    Id名称状况

    ----------------------------------------------------

    2test_centosrunning

    4qishirunning

    13qishi2running

    14cloud_monitor_5921running

    20test22running

    -test33封闭

    c.在此test22硬盘扩容

    virsh # edit test22

    #找到硬盘设置设备摆设(原先的体系硬盘)

    #新加磁盘设置设备摆设

    把稳:dev 名称设定不能一样 bus不能一样平日源为“0”则加一个数字+1,即1,2,3….

    #保留退出

    d.封闭虚拟机à发动虚拟机(把稳:重启不能见效)

    [root@nfs ~]# virshshutdown test22

    Domain vm01 is being shutdown

    [root@nfs ~]# virshstart test22

    反省:

    虚拟机发动后,登入进入运用指令#fdisk -l 反省新加的磁盘

    以下为磁盘分区挂载历程,若不注重纰漏!

    在c1中,进行硬盘查检并分区

    ~sudo fdisk -l

    Disk /dev/vda: 42.9 GB, 0 bytes

    16 heads, 63 sectors/track, 83220 cylinders, total sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0xaa

    Device BootStartEndBlocksIdSystem

    /dev/vda1*Linux

    /dev/vda1375Extended

    /dev/vda1368eLinux LVM

    Disk /dev/vdb: 10.7 GB, 0 bytes

    16 heads, 63 sectors/track, 20805 cylinders, total sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0x

    Disk /dev/vdb doesn't contain a valid partition table

    Disk /dev/mapper/u1210-root: 38.4 GB, 6 bytes

    255 heads, 63 sectors/track, 4667 cylinders, total sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0x

    Disk /dev/mapper/u1210-root doesn't contain a valid partition table

    Disk /dev/mapper/u1210-swap_1: 4294 MB, bytes

    255 heads, 63 sectors/track, 522 cylinders, total sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0x

    Disk /dev/mapper/u1210-swap_1 doesn't contain a valid partition table

    /dev/vdb现已被辨认,接下来 分区,款式化,挂载,运用

    硬盘分区

    ~ sudo fdisk /dev/vdb

    Command (m for help): p

    Disk /dev/vdb: 161.1 GB, 12 bytes

    16 heads, 63 sectors/track, cylinders, total sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (lowww.tbplay777.c0mgical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0x3b49c6a0

    Device BootStartEndBlocksIdSystem

    Command (m for help): n

    Partition type:

    pprimary (0 primary, 0 extended, 4 free)

    eextended

    Select (default p): p

    Partition number (1-4, default 1):

    Using default value 1

    First sector (2048-, default 2048):

    Using default value 2048

    Last sector, +sectors or +size{K,M,G} (2048-, default ):

    Using default value

    Command (m for help): w

    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    Syncing disks.

    #分区见效

    ~ sudo partprobe

    ~ sudo fdisk -l

    Disk /dev/vdb: 10.7 GB, 0 bytes

    2 heads, 17 sectors/track, cylinders, total sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0xf0432cd6

    Device BootStartEndBlocksIdSystem

    /dev/vdb683Linux

    款式化

    ~sudo mkfs -t ext4 /dev/vdb1

    mke2fs 1.42.5 (29-Jul-2012)

    Filesystem label=

    OS type: Linux

    Block size=4096 (log=2)

    Fragment size=4096 (log=2)

    Stride=0 blocks, Stripe width=0 blocks

    inodes, blocks

    blocks (5.00%) reserved for the super user

    First data block=0

    Maximum filesystem blocks=

    1200 block groups

    32768 blocks per group, 32768 fragments per group

    8192 inodes per group

    Superblock backups stored on blocks:

    32768, 98304, , , ,, , , ,

    , , , ,

    Allocating group tables: done

    Writing inode tables: done

    Creating journal (32768 blocks): done

    Writing superblocks and filesystem accounting information: done

    挂载

    ~ sudo mount /dev/vdb1 /home/cos/hadoopb

    ~ df -h

    FilesystemSizeUsed Avail Use% Mounted on

    /dev/mapper/u1210-root36G1.1G33G4% /

    udev2.0G4.0K 2.0G1% /dev

    tmpfs791M232K 791M1% /run

    none5.0M0 5.0M0% /run/lock

    none2.0G0 2.0G0% /run/shm

    none100M0 100M0% /run/user

    /dev/vda1228M29M 188M14% /boot

    /dev/vdb19.9G151M 9.2G2% /home/cos/hadoopb

    五 centos 6.0 克隆虚拟机历程

    宿主机:192.168.3.100

    模版机web-1:192.168.3.102

    克隆机web-5:192.168.3.110

    1) 封闭/停息模版虚拟机进行克隆,(把稳新克隆的虚拟磁盘文件的姓名不能与模版机一样)

    virt-clone -o web-1 -n web-5 -f /data/vmdisk/web-5.qcow2

    2)然背工动变动xml 设置设备摆设文件的vnc 端口

    vi /etc/libvirt/qemu/web-5.xml

    3)重启libvirtd 效劳使变动的端口见效

    /etc/init.d/libvirtd restart

    4)发动新克隆的虚拟机

    virsh start web-5

    5)然后客户端vnc 去连

    6)变动web-5 的eth0 的ip

    7)重启network效劳

    六复制xml 文件措施装配新虚拟机

    装配新虚机web-10

    1)制造虚拟机镜像

    cd /data/vmdisk/

    cp web-1.qcow2web-10.qcow2

    2)创立xml 文件

    Cd/etc/libvirt/qemu

    cp web-1.xmlweb-10.xml

    修正响应的参数

    uuid mac vnc 硬盘文件方位 虚拟机姓名

    uuid:随意变动,确保仅有

    mac:随意变动,确保仅有

    vnc:指定端口号,别和其余虚拟机矛盾

    虚拟磁盘文件方位:/data/vmdisk/web-10.qcow2

    #

    虚拟机姓名:web-10

    vi web-10.xml

    :%S/web-1/web-10/g

    3)创立虚拟机

    virsh defineweb-10.xml

    4)发动虚拟机

    virsh start web-10

    七 设置虚拟机自发动

    #virsh autostart 虚拟机名(例如web-1)

    在/etc/libvirt/qemu/network/autostart目录下会出现 web-1.xml

    此刻,要是重启宿主机,web-1 虚拟机是不会主动发动的,需求重启libvirtd 效劳

    以是记得把libvirtd 效劳设置成开机自发动,这么宿主机重启,虚拟机就会自发动

  • 相关内容

友情链接: