标签:kvm
初探KVM-第一个虚拟机
一、准备环境 主板是否支持虚拟化技术: egrep ‘(vmx|svm)‘ --color=always /proc/cpuinfo 检查kvm是否加载: # lsmod |grep kvm 配置文件: /etc/libvirt/libvirtd.conf 管理方式 1) 安装vnc用GUI工具(Virtual Machine Manager)管理: Virtual Machine Manager 由 Red Hat 使用 Python 语言开发,用于控制虚拟机的生命周期,包括配给、虚拟网络管理,统计数据收集和报告,以及提供对虚拟机本身的简单图形访问。 http://www.ibm.com/developerworks/cn/cloud/library/cl-managingvms/ 2) 命令行工具 3) 图形化工具 二、尝试安装一个虚拟机 1. 安装kvm相关的包(也可以在安装宿主机时选择virtual相关包) [root@200-70 ~]# yum groupinstall -y "Virtualization Client" "Virtualization Platform" "Virtualization Tools" [root@200-70 ~]# yum install -y libvirt-python python-virtinst virt-viewer 启动服务: [root@200-70 kvm]# service libvirtd start 2. 关闭selinux [root@200-70 ~]# setenforce 0 [root@200-70 ~]# sed -i ‘s/=enforcing/=disabled/g‘ /etc/selinux/config 3. 增加bridge类型的虚拟网卡br0,调整物理网卡em1的配置 [root@200-70 network-scripts]# cat ifcfg-br0 DEVICE=br0 TYPE=Bridge ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none IPADDR=10.0.200.70 PREFIX=20 GATEWAY=10.0.192.1 DNS1=223.5.5.5 DNS2=8.8.8.8 DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="System br0" [root@200-70 network-scripts]# cat ifcfg-em1 DEVICE=em1 TYPE=Ethernet UUID=7dcae5ce-d611-4628-bcab-aacb77fc9e28 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none HWADDR=00:26:B9:36:E9:A0 BRIDGE="br0" #IPADDR=10.0.200.70 #PREFIX=20 #GATEWAY=10.0.192.1 #DNS1=223.5.5.5 #DNS2=8.8.8.8 #DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="System em1" 重启network服务: [root@200-70 network-scripts]# service network restart Shutting down interface em1: bridge br0 does not exist! [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface em1: [ OK ] Bringing up interface br0: Determining if ip address 10.0.200.70 is already in use for device br0... [ OK ] [root@200-70 network-scripts]# ip a |grep -E ‘(br0|em1)‘ 2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP qlen 1000 6: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 7: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master virbr0 state DOWN qlen 500 10: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP inet 10.0.200.70/20 brd 10.0.207.255 scope global br0 4、第一个虚拟机 1)创建一个虚拟磁盘 [root@200-70 os]# qemu-img create -f qcow2 /data/kvm/hosts/node1.img 20G 2)创建一个虚拟机 [root@200-70 os]# virt-install --name node1 --vnc --vncport=5900 --vnclisten 0.0.0.0 --noautoconsole -r 1024 --arch x86_64 --vcpus=1 -w bridge:br0 --os-type=linux --os-variant=rhel6 --cdrom /data/kvm/os/CentOS-6.5-x86_64-bin-DVD1.iso --disk path=/data/kvm/hosts/node1.img,device=disk,bus=virtio,size=20,sparse=true,format=qcow2 Starting install... Creating domain... | 0 B 00:00 Domain installation still in progress. You can reconnect to the console to complete the installation process. 上面提示要重新连接到console来继续完成安装os的过程(通过vnc方式) 3)检查vnc的状态 [root@200-70 os]# ss -antp src :5900 State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 1 *:5900 *:* users:(("qemu-kvm",5107,13)) 打开防火墙:5900端口 调整客户端的vnc配置: vnc-options-expert-colourlevel 改为 full,解决vnc客户端连接时,一闪就不见的问题。 用VNC连接 10.0.200.70:5900 在VNC下安装虚拟机(略) 4)启动这个虚拟机 [root@200-70 ~]# virsh start node1 Domain node1 started [root@200-70 ~]# virsh list Id Name State ---------------------------------------------------- 4 node1 running 三、备注 1、如何删除该虚拟机: [root@200-70 ~]# virsh destroy node1 Domain node1 destroyed [root@200-70 ~]# virsh undefine node1 Domain node1 has been undefined
本文仅作为入门测试,生产环境通常是通过平台来管理,例如,下面是kvm群里的一个小调查:
标签:kvm
原文地址:http://nosmoking.blog.51cto.com/3263888/1672481