Redhat 5.4KVM 安装文档

  • 格式:doc
  • 大小:211.50 KB
  • 文档页数:14

RHEL5.4 KVM虚拟机安装使用说明目录一RHEL5.4 KVM版本说明 (2)二硬件需求 (3)三测试环境描述 (3)四系统安装 (3)五KVM初期配置 (3)5.1 grub.conf配置 (3)5.2 vncserver配置 (3)5.3 网桥搭建 (4)5.4 NFS存储搭建: (5)5.5 字符下安装虚机操作: (6)5.6 Clone 服务器操作 (7)5.7 服务器迁移 (8)5.8 调整cpu ,mem (12)六测试结论 (13)七问题汇总 (13)八简单的虚机系统故障修复 (13)一RHEL5.4 KVM版本说明Redhat 5.4的kvm版本为83-105.e15 英文版,版本性能还算稳定,但是服务图形界面不支持克隆,由于版本较低不支持半虚拟化,只能支持全虚拟,内存在使用后,不能自动释放。

所依赖的包:kvm-83-105.el5etherboot-zroms-kvm-5.4.4-10.el5kmod-kvm-83-105.el5etherboot-roms-kvm-5.4.4-10.el5kvm-qemu-img-83-105.el5kvm-tools-83-105.el5二硬件需求处理器需求:需要一台可以运行最新linux内核的Intel处理器(含VT虚拟化技术)或AMD处理器(含SVM安全虚拟机技术的AMD处理器, 也叫AMD-V).注: 一些厂商禁止了机器BIOS中的VT选项, 这种方式下不能使用KVM.目前Redhat 还无针对小型机的虚拟化版本,只针对x86系列支持虚拟化的Pc-server 服务器。

所以在安装操作系统时,需要在服务器启动时进入boss界面,把相应的虚拟化开关打开。

判断服务器是否开启虚拟化可以使用如下命令判断:lsmod | grep kvm三测试环境描述正常至少三台服务器或者两台服务器一台存储,以便完成数据迁移测试。

目前测试环境两台DELL R710 硬件配置简单描述:16G内存,2颗4核cpu。

服务器资源分配:218.246.34.160 安装redhat5.4企业版,部署nfs服务,对应内网地址192.168.1.74。

192.168.1.75 安装redhat5.4企业版。

四系统安装宿主服务器系统的安装注意事项,主要是安装包的选择,第一步选择自定义虚拟化里面的包全部都选上,每一项都打钩并选择Select all optional packeges开发库除了Eclipse 都打上钩,不用选择Select all其他的选项都默认即可,图形界面选择性安装。

五KVM初期配置5.1 grub.conf配置登陆两台服务器进入/etc/grub.conf文件中,手动注释掉以下内容:#title Red Hat Enterprise Linux Server (2.6.18-164.el5xen)# root (hd0,0)# kernel /xen.gz-2.6.18-164.el5 crashkernel=128M@32M# module /vmlinuz-2.6.18-164.el5xen ro root=/dev/rootvg/lv_root rhgb quiet# module /initrd-2.6.18-164.el5xen.img5.2 vncserver配置确定服务器安装vnc的相关软件包:vnc-server-4.1.2-14.el5_3.1gtk-vnc-0.3.8-3.el5vnc-4.1.2-14.el5_3.1gtk-vnc-python-0.3.8-3.el5所需修改的文件:/etc/sysconfig/vncservers 修改相应的vnc分辨率。

修改下面文件为:cat /root/.vnc/xstartup#!/bin/sh# Uncomment the following two lines for normal desktop:unset SESSION_MANAGERexec /etc/X11/xinit/xinitrc[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresourcesxsetroot -solid greyvncconfig -iconic &xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &twm &然后执行vncserver ,修改密码执行vncpasswd。

5.3 网桥搭建KVM支持两种模式NAT模式和网桥模式,但NAT主机与虚机处于不同网段;桥接模式虚机与物理机共用一块物理网卡出口,所以为方便测试直接登陆虚机,配置为桥接,具体方法见下:宿主服务器安装完后先要设定网络,选择bridge模式,即桥接模式桥接模式需要手动设置,很简单^_^,在eth0配置文件中加一行即可[dave@localhost network-scripts]# pwd/etc/sysconfig/network-scriptsDEVICE=eth0HW ADDR=00:22:19:6b:64:bbNNMM_CCOONNTTRROOLLLLEEDD==yyeessONBOOT=yesIPADDR=192.168.60.11BOOTPROTO=noneNETMASK=255.255.255.0DNS2=202.106.0.20TYPE=EthernetGA TEWAY=192.168.60.254DNS1=202.106.196.115IPV6INIT=noUSERCTL=noBRIDGE=br0 #指定桥接设备为br0拷贝eth0配置文件给br0用[dave@localhost network-scripts]# cp ifcfg-eth0 ifcfg-br0[dave@localhost network-scripts]# cat ifcfg-br0DEVICE=br0 #修改设备名为br0NM_CONTROLLED=yesONBOOT=yesIPADDR=192.168.60.11BOOTPROTO=noneNETMASK=255.255.255.0DNS2=202.106.0.20TYPE=Bridge #类型改为BridgeGA TEWAY=192.168.60.254DNS1=202.106.196.115IPV6INIT=noUSERCTL=no注意不要保留MAC地址。

配置好后重启网络如果一切无误的话br0 会接替eth0 的ip[dave@localhost network-scripts]# service network restartShutting down interface br0: [ OK ]Shutting down interface eth0: [ OK ]Shutting down loopback interface: [ OK ]Bringing up loopback interface: [ OK ]Bringing up interface eth0: [ OK ]Bringing up interface br0: [ OK ][dave@localhost network-scripts]# ifconfigbr0 Link encap:Ethernet HWaddr 00:22:19:6B:64:BBinet addr:192.168.1.74 Bcast:192.168.60.255 Mask:255.255.255.0inet6 addr: fe80::222:19ff:fe6b:64bb/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:225269 errors:0 dropped:0 overruns:0 frame:0TX packets:36082 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:13732285 (13.0 MiB) TX bytes:30387309 (28.9 MiB)eth0 Link encap:Ethernet HWaddr 00:22:19:6B:64:BBinet6 addr: fe80::222:19ff:fe6b:64bb/64 Scope:LinkUP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1 RX packets:127 errors:0 dropped:0 overruns:0 frame:0TX packets:43 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:10391 (10.1 KiB) TX bytes:8730 (8.5 KiB)Interrupt:36 Memory:d6000000-d60128005.4 NFS存储搭建:修改 /etc/exports 文件,添加/images75 *(rw,sync,no_root_squash)rw:可读写的权限;ro:只读的权限;no_root_squash:登入到 NFS 主机的用户如果是 ROOT 用户,他就拥有 ROOT 权限,此参数很不安全,建议不要使用。

sync:资料同步写入存储器中。

async:资料会先暂时存放在内存中,不会直接写入硬盘。

重新启动 nfs 服务# service nfsrestart5.5 字符下安装虚机操作:为了方便安装定义一些变量(非必须)[dave@localhost ~]# name=test1 #虚拟机名字[dave@localhost ~]# port=6900 #vnc监听端口[dave@localhost ~]# img=/var/lib/libvirt/images/test1.img #虚拟机硬盘文件[dave@localhost ~]# os=rhel6 #操作系统类型[dave@localhost ~]# ram=2048 #内存大小[dave@localhost ~]# cpu=8 #虚拟机使用CPU数量[dave@localhost ~]# sizeG=20 #虚拟硬盘大小[dave@localhost ~]# eth=br0 #虚拟机网卡接口[dave@localhost ~]# iso=/opt/rhel-server-6.0-x86_64-dvd.iso #安装光盘镜像文件[dave@localhost ~]# ip=192.168.1.74 #vnc监听IP用virt-install 在字符下安装虚拟机(红帽开发的libvrit工具包)[dave@localhost ~]# virt-install \--name $name \--ram $ram \--vcpus=$cpu \--disk path=$img,size=$sizeG \--network bridge=$eth \--os-variant=$os \--cdrom $iso--vnclisten=$ip \--vncport=$port --vncStarting install...Creating domain... Cannot open display:Run 'virt-viewer --help' to see a full list of available command line optionsDomain installation still in progress. You can reconnect tothe console to complete the installation process.执行完成后看看VNC监听端口有没有起来,如果起来了赶紧用vnc客户端连上去体验一下吧:-)[dave@localhost ~]# netstat -anp | grep 6900tcp 0 0 192.168.60.11:6900 0.0.0.0:* LISTEN 10182/qemu-kvm[dave@localhost ~]#O(∩_∩)O哈哈~ 熟悉的界面又出来了,接下来安装过程大家都轻车熟路了所以略过:)虚拟机系统装完后,安装的时候没有加--autostart参数,所以默认没有启动接下来用virsh 工具来操作虚拟机[dave@localhost ~]# virsh list #列出已运行的虚拟机Id Name State----------------------------------1 yunwei2 running[dave@localhost ~]# virsh start test1 #启动刚安装的虚拟机Domain test1 started[dave@localhost ~]# virsh listId Name State----------------------------------1 yunwei2 running8 test1 running #test1已经在运行了virsh 工具命令简单示例[dave@localhost ~]# virsh list #列出在运行的虚拟机[dave@localhost ~]# virsh start test1 #启动test1虚拟机[dave@localhost ~]# virsh shutdown test1 #关闭test1虚拟机[dave@localhost ~]# virsh destroy test1#强制关闭test1虚拟机[dave@localhost ~]# virsh autostart test1 #设置test1为自启动[dave@localhost ~]# virsh undefine test1 #删除test1虚拟机[dave@localhost ~]# virsh suspend test1 #暂停test1虚拟机[dave@localhost ~]# virsh resume test1#从暂停状态还原test1虚拟机5.6 Clone 服务器操作[dave@localhost ~]# virt-clone \--connect qemu:///system --original=test1 --name=test2--file=/var/lib/libvirt/images /test2.imgERROR Domain with devices to clone must be paused or shutoff.#源虚拟机须暂停或关闭[dave@localhost ~]# virsh suspend test1Domain test1 suspended[dave@localhost ~]# virsh listId Name State----------------------------------8 test1 paused[dave@localhost ~]# virt-clone \--connect qemu:///system --original=test1 --name=test2--file=/ var/lib/libvirt/images/test2.imgCloning test1.img | 20 GB 01:19Clone 'vm2' created successfully. #克隆虚拟机test2成功克隆完成后启动虚拟机试试,出错了~!宿主服务器的6900端口已经给test1用了[dave@localhost ~]# virsh start test2error: Failed to start domain test2error: internal error process exited while connecting to monitor:char device redirected to /dev/pts/5inet_listen_opts: bind(ipv4,192.168.60.11,6900): Address already in useinet_listen_opts: FAILED所以我们要修改vm2虚拟机的配置文件,把vnc端口改一下[dave@localhost /]# vi /etc/libvirt/qemu/test2.xml #修改配置文件<graphics type='vnc' port='7900' autoport='no' ……略#把port改为7900[dave@localhost ~]# service libvirtd restart #先重启libvirtd服务,不然改动不能生效Stopping libvirtd daemon: [ OK ]Starting libvirtd daemon: [ OK ][dave@localhost ~]# virsh start test2Domain vm2 started[dave@localhost ~]# virsh listId Name State----------------------------------8 test1 paused9 test2 running #克隆虚拟机起来了用vnc客户端连接192.168.60.11:7900 修改虚拟机网卡配置并启动网路会遇到如下问题Bringing up interface eth0: Device eth0 does not seem to be present, delayinginitialization. [FAILED][dave@localhost ~]#sed -i '/^SUBSYSTEM==/d' /etc/udev/rules.d/70-persistent-net.rules#删除该文件内关于网卡的记录[dave@localhost ~]# reboot #重启系统后,网路就正常了针对克隆说明:克隆操作必须在服务器暂停或者中断后进行操作。