一、需求
公司近一台DELL T460机器回来,虚拟30台来跑hadoop集群测试的,虚拟化用的KVM技术,这当中第一次使用,在部署安装过程,入了不少坑。故把整个过程写下来。
二、部署步聚
1、所需要软件
[root@KVM qemu]# rpm -qa | grep -E 'qemu|libvirt|virt' virt-what-1.11-1.2.el6.x86_64 libgovirt-0.3.2-1.el6_7.2.x86_64 libvirt-0.10.2-54.el6_7.6.x86_64 virt-viewer-2.0-7.el6.x86_64 libvirt-python-0.10.2-54.el6_7.6.x86_64 qemu-kvm-0.12.1.2-2.479.el6_7.4.x86_64 virt-manager-0.9.0-29.el6_7.1.x86_64 virt-top-1.0.4-3.15.el6.x86_64 python-virtinst-0.600.0-29.el6.noarch gpxe-roms-qemu-0.9.7-6.14.el6.noarch qemu-kvm-tools-0.12.1.2-2.479.el6_7.4.x86_64 libvirt-client-0.10.2-54.el6_7.6.x86_64 qemu-img-0.12.1.2-2.479.el6_7.4.x86_64
在KVM环境上,以上rpm包都是必需的。
2、安装图形化其他组件
#yum groupinstall "Desktop" "Desktop Platform" "Desktop Platform Development" "Fonts" "General Purpose Desktop" "Graphical Administration Tools" "Grahics Creation Tools" "Input Methods" "X Window System" "Chinese Support[zh]" "Internet Browser" # yum install libvirt-client # yum install gpxe-roms-qemu -y # yum install libvirt-python python-virtinst qemu-kvm
3、安装桥工具并配置桥接网卡
yum install bridge-utils
root@KVM ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0 DEVICE="br0" ONBOOT="yes" NM_CONTROLLED=no BOOTPROTO="static" TYPE="Bridge" IPADDR=10.1.2.218 NETMASK=255.255.255.0 GATEWAY=10.1.2.254 DNS1=114.114.114.114
[root@KVM ~]# cat /etc/sysconfig/network-scripts/ifcfg-em1 DEVICE=em1 HWADDR=14:18:77:54:2F:A4 TYPE=Ethernet UUID=9183c4ff-432c-4141-ae6a-74c40d58732d ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none BRIDGE=br0
3、安装VNC
#yum install -y tigervnc #yum install -y tigervnc-server
在这里注意了,安装tigervnc,那么用到pc连接过去时,自然也需要要安装tigervnc电脑版
配置文件
[root@KVM ~]# cat /etc/sysconfig/vncservers # The VNCSERVERS variable is a list of display:user pairs. # # Uncomment the lines below to start a VNC server on display :2 # as my 'myusername' (adjust this to your own). You will also # need to set a VNC password; run 'man vncpasswd' to see how # to do that. # # DO NOT RUN THIS SERVICE if your local area network is # untrusted! For a secure way of using VNC, see this URL: # https://access.redhat.com/knowledge/solutions/7027 # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP. # Use "-localhost" to prevent remote VNC clients connecting except when # doing so through a secure tunnel. See the "-via" option in the # `man vncviewer' manual page. # VNCSERVERS="2:myusername" # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost" VNCSERVERS="1:root" VNCSERVERARGS[1]="-geometry 800x600 -depth 32"
4、创建磁盘
qemu-img create -f qcow2 -o size=200G,preallocation="metadata" /data1/hadoop/images/kvmhadoop222.qcow2
5、使用virt-install创建虚拟机并安装GuestOS
virt-install --virt-type kvm --name kvmhadoop222 --ram 16384 --cdrom=/root/CentOS-6.7-x86_64-LiveDVD.iso --disk path=/data1/hadoop/hadoop2/kvmhadoop202.qcow2 --graphics vnc,listen=0.0.0.0 ,port=5903--noautoconsole --os-type=linux --os-variant=rhel6 --network bridge=br0,model=virtio
6、用vnc连接
7、接下来就是安装操作系统了(省略)
8、虚拟机列表
[root@KVM ~]# virsh list Id Name State ---------------------------------------------------- 19 kvmhadoop223 running 21 kvmhadoop228 running 22 kvmhadoop229 running 23 kvmhadoop230 running 24 kvmhadoop231 running 25 kvmhadoop232 running 30 kvmhadoop221 running 31 kvmhadoop222 running 36 kvmhadoop233 running 37 kvmhadoop234 running 38 kvmhadoop235 running 39 kvmhadoop236 running 40 kvmhadoop224 running
9、修改端口号,到配置文件
[root@KVM qemu]# pwd /etc/libvirt/qemu [root@KVM qemu]# ls kvmhadoop202.xml.bak kvmhadoop222.xml kvmhadoop223.xml kvmhadoop228.xml kvmhadoop230.xml kvmhadoop232.xml kvmhadoop234.xml kvmhadoop236.xml kvmhadoop221.xml kvmhadoop222.xml.bak kvmhadoop224.xml kvmhadoop229.xml kvmhadoop231.xml kvmhadoop233.xml kvmhadoop235.xml networks
10、修改端口,记得从XML配置文件定义一个domian,相当于注册一个domain但是不启动。
#virsh define /etc/libvirt/qemu/kvmhadoop222.xml
11、然后就是启动了
12、宿主机开机自动启动虚拟机设置
#/bin/bash #Program # Automatic virtual machine command # History #2016/04/1 qingyun first release Array=(222 223 224 228 229 230 231 232 233 234 235 236) for i in ${Array[@]} do virsh autostart kvmhadoop$i done
13、开机启动虚拟机脚本
#/bin/bash #Program # Automatic virtual machine command # History #2016/04/1 qingyun first release Array=(222 223 224 228 229 230 231 232 233 234 235 236) for i in ${Array[@]} do virsh start kvmhadoop$i done