zoukankan      html  css  js  c++  java
  • Kvm命令集管理虚拟机

    KVM虚拟机配置文件位置

    [root@localhost ~]# ll /etc/libvirt/qemu/
    总用量 4
    drwxr-xr-x 2 root root   23 12月 14 20:23 autostart
    drwx------ 3 root root   42 12月 14 19:38 networks
    -rw------- 1 root root 4074 12月 14 20:23 test2.xml

    修改KVM虚拟机配置的方法

    [root@localhost ~]#  virsh edit test2

    备份与恢复

    备份虚拟机配置(关机时备份):

    [root@localhost ~]# virsh dumpxml test2 > test2.xml

    删除虚拟机配置

    [root@localhost ~]# virsh list --all
     Id    名称                         状态
    ----------------------------------------------------
     2     test01                         running
     4     test2                          running
    
    [root@localhost ~]# virsh undefine test01

    导入虚拟机

    [root@localhost ~]# virsh define test2.xml 
    定义域 test2(从 test2.xml)

    修改虚拟机名称

    [root@localhost ~]# virsh domrename test2 liujunjun

    虚拟机挂起与恢复

    [root@localhost ~]# virsh suspend test2
    域 test2 被挂起
    
    [root@localhost ~]# virsh list --all
     Id    名称                         状态
    ----------------------------------------------------
     2     test01                         running
     4     test2                          暂停
    
    [root@localhost ~]# virsh resume test2
    域 test2 被重新恢复

    查询虚拟机vnc端口

    [root@localhost ~]# virsh vncdisplay test2
    :10050

    开机自启动设置

    [root@localhost ~]# systemctl is-enabled libvirtd.service 
    enabled

    设置宿主机开机虚拟机开机

    [root@localhost ~]# virsh autostart test2
    域 test2标记为自动开始

    取消开机自启动

    [root@localhost ~]# virsh autostart --disable test2
    域 test2取消标记为自动开始

    kvm虚拟机console登录

    CentOS 7.X 版本console登录

    配置console登录

    在test2虚拟机内操作(该操作仅限centos7):

    [root@localhost ~]# grubby --update-kernel=ALL --args="console=ttyS0,115200n8"
    [root@localhost ~]# reboot
    [root@localhost ~]# virsh console test2
    连接到域 test2
    换码符为 ^]

    创建一块qcow2的虚拟硬盘为2GB

    [root@localhost ~]# qemu-img create -f qcow2 qcow2-ceshi 2GB
    qemu-img: Invalid image size specified! You may use k, M, G, T, P or E suffixes for 
    qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.

    查看当前虚拟机硬盘信息

    [root@localhost kvm-bak2]# qemu-img info /home/kvm-bak2/test2.img 
    image: /home/kvm-bak2/test2.img
    file format: qcow2
    virtual size: 10G (10737418240 bytes)
    disk size: 1.2G
    cluster_size: 65536
    Format specific information:
        compat: 1.1
        lazy refcounts: true
  • 相关阅读:
    【转载】10个Web3D可视化精彩案例
    基于react的audio组件
    如何开发一款堪比APP的微信小程序(腾讯内部团队分享)
    CSS3 用border写 空心三角箭头 (两种写法)
    浅谈微信小程序对于创业者,意味着什么?
    左手Cookie“小甜饼”,右手Web Storage
    css3中user-select的用法详解
    个人感觉一些比较有用的特效例子
    纯css模拟电子钟
    蓝桥杯 ALGO-2:最大最小公倍数
  • 原文地址:https://www.cnblogs.com/liujunjun/p/12041038.html
Copyright © 2011-2022 走看看