码迷,mamicode.com
首页 > 其他好文 > 详细

kvm初体验之三:vm的安装及管理

时间:2015-05-27 08:29:57      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

Host: CentOS release 6.4 (Final)

Guest: CentOS release 6.6 (Final)

全程以root身份操作

 

1. host上创建桥br0

参考《KVM Virtualization in RHEL 6 Made Easy2.6 Networking

我的/etc/sysconfig/network-scripts/ifcfg-br0文件内容为:

 

DEVICE=br0
BOOTPROTO=dhcp
IPV6INIT=yes
IPV6_AUTOCONF=yes
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Bridge
DELAY=0

 

我的/etc/sysconfig/network-scripts/ifcfg-eth0文件内容为:

 

DEVICE=eth0
TYPE=Ethernet
UUID=20008b30-343b-4150-b908-af2b0ca5b545
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp
HWADDR=3C:97:0E:5C:E4:2E
DNS1=192.168.1.1
BRIDGE=br0

 

重启network服务后,ifconfig出现br0接口,并且br0获取到了IP

 

[root@tanghuimin ~]# ifconfig 
br0       Link encap:Ethernet  HWaddr 3C:97:0E:5C:E4:2E  
          inet addr:192.168.1.6  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::3e97:eff:fe5c:e42e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:30252 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17512 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:41222923 (39.3 MiB)  TX bytes:1501305 (1.4 MiB)

eth0      Link encap:Ethernet  HWaddr 3C:97:0E:5C:E4:2E  
          inet6 addr: fe80::3e97:eff:fe5c:e42e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:30272 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17525 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:41647651 (39.7 MiB)  TX bytes:1502123 (1.4 MiB)
          Interrupt:20 Memory:f2500000-f2520000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1040 (1.0 KiB)  TX bytes:1040 (1.0 KiB)

virbr0    Link encap:Ethernet  HWaddr 52:54:00:25:90:C1  
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

 

ping一下网关及外网,可以连通:

 

[root@tanghuimin ~]# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.978 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.861 ms
^C
--- 192.168.1.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1080ms
rtt min/avg/max/mdev = 0.861/0.919/0.978/0.065 ms
[root@tanghuimin ~]# ping www.baidu.com
PING www.a.shifen.com (115.239.210.25) 56(84) bytes of data.
64 bytes from 115.239.210.25: icmp_seq=1 ttl=54 time=7.46 ms
64 bytes from 115.239.210.25: icmp_seq=2 ttl=54 time=7.37 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 9850ms
rtt min/avg/max/mdev = 7.372/7.416/7.460/0.044 ms
[root@tanghuimin ~]# 

 

brctl show可以看到host上存在的桥:

 

[root@tanghuimin ~]# brctl show
bridge name    bridge id        STP enabled    interfaces
br0        8000.3c970e5ce42e    no        eth0
virbr0        8000.5254002590c1    yes        virbr0-nic

 


2. 设置SELinux

参考KVM Virtualization in RHEL 6 Made Easy2.7 SELinux


3. 安装vm

参考《KVM Virtualization in RHEL 6 Made Easy3. Creating VMs

 

virt-install --name vm1 --ram=1024 --vcpus=1 --disk path=/vm-images/vm1,size=2 --cdrom /root/iso/CentOS-6.6-x86_64-minimal.iso --network bridge:br0

 

关于virt-install参数的详细解释参考:

Installing a KVM Guest OS from the Command-line (virt-install)

安装过程同linux系统的正常安装过程。

技术分享

安装完成之后输入用户名密码可以进入vm

技术分享

4. 管理vm

常用的vm管理命令有:

列出所有vmvirsh list –all

挂起:virsh suspend

恢复:virsh resume

关机:virsh shutdown

启动:virsh start

强制关机:virsh destroy

销毁:virsh undefine

查看vm信息:virsh dominfo

查看virsh全部的管理命令:virsh help

查看virsh某个管理命令的用法:virsh help xxx

技术分享

技术分享

注:virsh shutdown命令执行后vm往往仍处于running状态,这时可以用virsh destroy强制关机。

virsh undefine销毁一个vm前,要先将vm关机。

 

 

 

 

 

 

 

 

 

kvm初体验之三:vm的安装及管理

标签:

原文地址:http://www.cnblogs.com/tanghuimin0713/p/4532397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!