Qemu-KVM管理

1.KVM基本配置

由于我安装RHEL6.4的时候选择的是base server,所以却了虚拟化的包!

安装之:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # virsh list --all     //查看现有的所有虚拟机  
  2. 错误:Failed to reconnect to the hypervisor  //不能链接到libvirtd服务  
  3. 错误:无效的连接  
  4. 错误:内部错误 Unable to locate libvirtd daemon in /usr/sbin (to override, set $LIBVIRTD_PATH to the name of the libvirtd binary)  
  5.   
  6. # yum -y install libvirt virt-viewer libpk-gtk-module.so     //安装libvir服务  
  7.   
  8. # /etc/init.d/libvirtd start  //启动libvir服务  
  9. 启动 libvirtd 守护进程:                                   [确定]  
  10. # virsh list --all       //此处验证 OK  
  11.  Id    名称                         状态  
  12. ----------------------------------------------------  
  13.   
  14.   
  15. # chkconfig --list|grep libvirtd  
  16. libvirtd           0:关闭    1:关闭    2:关闭    3:启用    4:启用    5:启用    6:关闭  


2.KVM网络的桥接

移步至此处

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost ~]# ifconfig br0  
  2. br0       Link encap:Ethernet  HWaddr E2:27:EE:C9:53:73    
  3.           inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0  
  4.           inet6 addr: fe80::e027:eeff:fec9:5373/64 Scope:Link  
  5.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
  6.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  7.           TX packets:12 errors:0 dropped:0 overruns:0 carrier:0  
  8.           collisions:0 txqueuelen:0   
  9.           RX bytes:0 (0.0 b)  TX bytes:720 (720.0 b)  


3.创建虚拟机

不管是安装linux图形界面还是windows都要起勇x界面,这里先不研究url连接

用ssh的x11转发功能实现图形界面,链接方式移步至此处

创建虚拟机:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # virt-install --name=test4 --ram=1024 --cdrom=/usr/src/CentOS-6.4-x86_64-bin-DVD1.iso --os-type=linux --disk=/opt/kvm/test4.img,size=20 --graphics vnc  --network bridge=br0  
  2.   
  3. 开始安装......  
  4. 创建域......   //此处会弹出安装系统的窗口  
  5. # virsh list --all  
  6.  Id    名称                         状态  
  7. ----------------------------------------------------  
  8.  5     test4                          running  

参数name虚拟机名字,ram内存大小,cdroom安装介质,os-type系统类型,disk磁盘,graphics显示,network指向网桥br0

更多参数请查看:virt-install --help


4.虚拟机的关闭和启动

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost ~]# virsh shutdown test4  #关闭test域  
  2. 域 test4 被关闭  
  3.   
  4. [root@localhost ~]# virsh list #查看开启的域  
  5.  Id    名称                         状态  
  6. ----------------------------------------------------  
  7.  7     test4                          running  
  8.   
  9. [root@localhost ~]# ps -ef|grep qemu  #查看qemu的进程 进行强制关闭虚拟机  
  10. qemu      3273     1 11 13:47 ?        00:00:11 /usr/libexec/qemu-kvm -name test4 -S -M rhel6.4.0 -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -uuid 5132f755-fd6d-49f2-e4d0-e82ef327eb37 -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/test4.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-reboot -no-shutdown -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/opt/kvm/test4.img,if=none,id=drive-ide0-0-0,format=raw,cache=none -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=2 -drive file=/usr/src/CentOS-6.4-x86_64-bin-DVD1.iso,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,bootindex=1 -netdev tap,fd=23,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:71:1a:1d,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -vnc 127.0.0.1:0 -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4  
  11. root      3306 32058  0 13:49 pts/0    00:00:00 grep qemu  
  12. [root@localhost ~]# kill -9 3273 #强制关闭虚拟机  
  13. [root@localhost ~]# virsh list #查看开启的域  
  14.  Id    名称                         状态  
  15. ----------------------------------------------------  
  16.   
  17. [root@localhost ~]# virsh list --all #查看所有的域  
  18.  Id    名称                         状态  
  19. ----------------------------------------------------  
  20.  -     test4                          关闭  
  21. [root@localhost ~]# virsh start test4  
  22. 域 test4 已开始  
  23.   
  24. [root@localhost ~]# virsh list --all #查看所有的域  
  25.  Id    名称                         状态  
  26. ----------------------------------------------------  
  27.  8     test4                          running  

5.删除虚拟机


[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost ~]# virsh shutdown test4 #必须将域关掉才能删除  
  2. 域 test4 被关闭  
  3.   
  4.   
  5. [root@localhost ~]# virsh undefine --managed-save test4  
  6. 域 test4 已经被取消定义  
  7.   
  8. [root@localhost ~]# virsh list --all #查看所有的域  
  9.  Id    名称                         状态  
  10. ----------------------------------------------------  

virsh的所有参数

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # virsh help  

6.克隆

将mysql1克隆到mysql2,-o参数是原先的机器名字,-n是新机器的名字,--force-copy克隆牢老机器的那些磁盘,-f克隆后的磁盘名字。

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. virt-clone -o mysql1 -n mysql2 --force-copy=vda -f mysql2.img  
  2. 正在克隆 mysql1.img                                                                                        |  40 GB     01:59       
  3.   
  4. Clone 'mysql2' created successfully.  

7.打开虚拟机的控制台

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@CWG 桌面]# ssh -XY 192.168.10.55  
  2. root@192.168.10.55's password:   
  3. Last login: Mon Feb 24 09:21:10 2014 from 192.168.10.5  
  4. [root@localhost ~]# virsh list --all  
  5.  Id    名称                         状态  
  6. ----------------------------------------------------  
  7.  1     mysql1                         running  
  8.  2     mysql2                         running  
  9.  3     mysql3                         running  
  10.  4     mysql4                         running  
  11.  10    mysql4-zujia                   running  
  12.  -     mysql1-zujia                   关闭  
  13.  -     mysql2-zujia                   关闭  
  14.  -     mysql3-zujia                   关闭  
  15.  -     mysql5                         关闭  
  16.   
  17. [root@localhost ~]# virt-viewer mysql1  

用ssh的X11转发功能所以ssh加上X参数

如果是windows的话可以用xmanager

列出所有虚拟机,然后用工具virt-viewer工具连接到虚拟机的控制台!


后续需要做一下mysql cluster所以温习一下kvm的cmd,小做笔记

virsh的命令有:

# vir
virsh               virt-convert        virt-image          virt-pki-validate   virt-what           
virt-clone          virt-host-validate  virt-install        virt-viewer         virt-xml-valid

可以根据需求自行help

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值