qemu:kmv的文本管理工具,包括qemu-kvm、qemu-img

libvirt:是一套免费、开源的支持Linux下主流虚拟化工具的C函数库,libvirtd是运行的守护进程的名称。包括GUI: virt-manager, virt-viewer,CLI: virt-install, virsh

使用virsh测试各命令及创建虚拟机

1. 获取各命令帮助

virsh help KEYWORD

#virsh help list

2. 查看域,–all选项可查看关机的虚拟机域,域id每次开关机后可能不一样

root@localhost ~]# virsh list –all

Id    Name                           State

—————————————————-

–     debian8                        shut off

3. 查看虚拟机配置文件

注意为xml格式,可以到处到某处查看或以此为模板创建其他虚拟机

虚拟机以域(domain)为单位创建

# virsh dumpxml debian8 > /tmp/mytemplate.xml

4. 创建域

create

virsh create <file> [–console] [–paused] [–autodestroy] [–pass-fds <string>] [–validate]

[–file] <string>  file containing an XML domain description

–console        attach to console after creation

–paused         leave the guest paused after creation

–autodestroy    automatically destroy the guest when virsh disconnects

–pass-fds <string>  pass file descriptors N,M,… to the guest

–validate       validate the XML against the schema

5. 获取域id

[root@localhost ~]# virsh domid debian8

3

6. 获取域uuid

[root@localhost ~]# virsh domuuid debian8

9332c5a4-4abc-4e7f-bec0-faf394950a55

7. 获取域信息

[root@localhost ~]# virsh dominfo debian8

Id:             3

Name:           debian8

UUID:           9332c5a4-4abc-4e7f-bec0-faf394950a55

OS Type:        hvm

State:          running

CPU(s):         2

CPU time:       428.6s

Max memory:     1047552 KiB

Used memory:    1047552 KiB

Persistent:     yes

Autostart:      disable

Managed save:   no

Security model: selinux

Security DOI:   0

Security label: system_u:system_r:svirt_t:s0:c327,c602 (enforcing)

8. 登录虚拟机控制台

[root@localhost ~]# virsh console debian8

Connected to domain debian8

Escape character is ^]

使用ctrl+],退出console

9. 开启域

[root@localhost ~]# virsh start debian8

Domain debian8 started

10. 重启域

reboot

11. 关闭域

destory

shutdown

12. 删除域

undefine

13. 暂停域并保存域状态至某文件中

# virsh save debian8 /tmp/debian_save1 –running

–running 下次恢复,直接启动

14. 从保存文件中恢复域

# virsh restore /tmp/debian_save1

管理域的命令:

15. 改变内存大小

不能超出预设值,只能调小,可以当前生效,也可以下次生效

# virsh setmem debian8 786m –current

[root@localhost ~]# virsh dominfo debian8

Id:             5

Name:           debian8

UUID:           9332c5a4-4abc-4e7f-bec0-faf394950a55

OS Type:        hvm

State:          running

CPU(s):         2

CPU time:       1471.5s

Max memory:     1047552 KiB

Used memory:    804864 KiB  #此处为改过的值

Persistent:     yes

Autostart:      disable

Managed save:   no

Security model: selinux

Security DOI:   0

Security label: system_u:system_r:svirt_t:s0:c470,c985 (enforcing)

[root@localhost ~]# free -mh

total        used        free      shared  buff/cache   available

Mem:           977M        741M         73M        4.2M        162M         64M

Swap:          1.9G        1.1G        827M

16. 设定内存最大内存

运行中的域不能修改最大内存值

[root@localhost ~]# virsh setmaxmem debian8 900m –config

下次启动有效

17. 设定vcpu数量

# virsh setvcpus debian8 1 –config

不能实时改,下次启动有效

18. 获取vcpu信息

[root@localhost ~]# virsh vcpuinfo debian8

VCPU:           0   #vcpu

CPU:            0    #在宿主机cpu位置

State:          running

CPU time:       675.5s

CPU Affinity:   yyyy

VCPU:           1

CPU:            1

State:          running

CPU time:       694.2s

CPU Affinity:   yyyy

19. 获取域网络接口信息

[root@localhost ~]# virsh domiflist debian8

Interface  Type       Source     Model       MAC

——————————————————-

vnet0      network    default    virtio      52:54:00:82:53:a2

20. 获取域的接口统计信息

[root@localhost ~]# virsh domifstat debian8 vnet0

vnet0 rx_bytes 197810

vnet0 rx_packets 3755

vnet0 rx_errs 0

vnet0 rx_drop 0

vnet0 tx_bytes 13400

vnet0 tx_packets 111

vnet0 tx_errs 0

vnet0 tx_drop 0

21. 获取域块设备信息

[root@localhost ~]# virsh domblklist debian8

Target     Source

————————————————

vda        /var/lib/libvirt/images/debian8.qcow2

hda        –

22. 获取域块设备(存储)统计信息

[root@localhost ~]# virsh domblkstat debian8

rd_req 21908

rd_bytes 670065746

wr_req 1105

wr_bytes 29772800

flush_operations 229

rd_total_times 97947369758

wr_total_times 60546346501

flush_total_times 1534616225

创建及管理磁盘:

23. 创建磁盘

[root@localhost ~]# qemu-img create -f qcow2 -o preallocation=metadata /tmp/test.qcow2 120G 稀疏格式

Formatting '/tmp/test.qcow2', fmt=qcow2 size=128849018880 encryption=off cluster_size=65536 preallocation='metadata' lazy_refcounts=off

[root@localhost ~]# du -lh /tmp/test.qcow2

19M /tmp/test.qcow2

[root@localhost ~]# ll -lh /tmp/test.qcow2

-rw-r–r–. 1 root root 121G Jan 12 13:53 /tmp/test.qcow2

24. 增加磁盘大小

[root@localhost ~]# qemu-img resize /tmp/test.qcow2 150G

Image resized.

[root@localhost ~]# ll -h /tmp/test.qcow2

-rw-r–r–. 1 root root 121G Jan 12 13:57 /tmp/test.qcow2

[root@localhost ~]# du -lh /tmp/test.qcow2

19M /tmp/test.qcow2

25. 附加磁盘到域

# qemu-img create -f qcow2 -o preallocation=metadata /tmp/mytest.img 20G

[root@localhost ~]# virsh attach-disk debian8 /tmp/mytest.img vdb

Disk attached successfully

26. 拆除磁盘

[root@localhost ~]# virsh detach-disk debian8 vdb

Disk detached successfully

网卡管理

网桥查看命令

[root@localhost ~]# brctl show

bridge name bridge id                  STP enabled interfaces

br0 8000.000000000000          no

virbr0 8000.525400571a76  yes virbr0-nic

vnet0

27.添加域网卡到宿主机桥上

[root@localhost ~]# virsh attach-interface debian8 bridge virbr0 为宿主机nat网桥

Interface attached successfully

[root@localhost ~]# virsh domiflist debian8

Interface  Type       Source     Model       MAC

——————————————————-

vnet0      network    default    virtio      52:54:00:82:53:a2

vnet1      bridge     virbr0     rtl8139     52:54:00:ca:04:d3

vnet2      bridge     br0        rtl8139     52:54:00:89:3b:1d

28. 删除域网卡

[root@localhost ~]# virsh detach-interface debian8 bridge –mac 52:54:00:89:3b:1d

Interface detached successfully


使用qemu命令手动创建虚拟机

qemu-kvm为创建工具

kmv 学习笔记 工具的更多相关文章

  1. PowerDesigner16工具学习笔记-工具介绍

    1.初始界面 1.1 .浏览窗口:本地(Local)浏览窗口.知识库(Repository)浏览窗口 Local:用于显示本地模型 Repository:用于显示知识库模型 1.2 .输出窗口:用于显 ...

  2. 20151212jquery学习笔记--工具函数

    工具函数是指直接依附于 jQuery 对象,针对 jQuery 对象本身定义的方法,即全局性 的函数.它的作用主要是提供比如字符串.数组.对象等操作方面的遍历. 一.字符串操作 在 jQuery 中, ...

  3. vue.js 源代码学习笔记 ----- 工具方法 option

    /* @flow */ import Vue from '../instance/index' import config from '../config' import { warn } from ...

  4. vue.js 源代码学习笔记 ----- 工具方法 env

    /* @flow */ /* globals MutationObserver */ import { noop } from 'shared/util' // can we use __proto_ ...

  5. Cesium学习笔记-工具篇20-PrimitiveTexture自定义渲染-贴图【转】

    前几篇博客我们了解了自定义点.线.面绘制,这篇我们接着学习cesium自定义纹理贴图.我们完成点线面的绘制,只是绘制出了对象的框架,没有逼真的外观.逼真外观是需要设置材质来实现:Material . ...

  6. JMeter学习笔记--工具简单介绍

    一.JMeter 介绍 Apache JMeter是纯JAVA桌面应用程序,被设计为用于测试客户端/服务端结构的软件(例如web应用程序).它可以用来测试静态和动态资源的性能,例如:静态文件,Java ...

  7. angularjs学习笔记—工具方法

    angular.bind(self, fn, args) 作用:返回一个新的函数,绑定这个函数的this指向self 参数: self:新函数的上下文对象 fn:需要绑定的函数 args:传递给函数的 ...

  8. vue.js 源代码学习笔记 ----- 工具方法 props

    /* @flow */ import { hasOwn, isObject, isPlainObject, capitalize, hyphenate } from 'shared/util' imp ...

  9. vue.js 源代码学习笔记 ----- 工具方法 share

    /* @flow */ /** * Convert a value to a string that is actually rendered. { .. } [ .. ] 2 => '' */ ...

随机推荐

  1. C# convert between Image and Base64string

    static void ImageMSDemo(string picPath) { byte[] imageArray = System.IO.File.ReadAllBytes(picPath); ...

  2. sql server 查询出整数 (可灵活运用)

    系统辅助用表,常用来获取数字,当然还有其他用途

  3. 关于.Net Core 部署在Linux下连接SqlServer数据库超时解决办法

    .Net Core 在 Linux 下连接 SqlServer 需要 SqlServer2008 SP3或以上版本,或SqlServer2012,或SqlServer2014. 如果SqlServer ...

  4. java基础(23):字节流、字符流

    1. 字节流 在前面的学习过程中,我们一直都是在操作文件或者文件夹,并没有给文件中写任何数据.现在我们就要开始给文件中写数据,或者读取文件中的数据. 1.1 字节输出流OutputStream Out ...

  5. /etc/profile和~/.bash_profile等文件的区别和联系

    对比说明:/etc/profile:为系统的每个用户设置环境信息和启动程序,当用户第一次登录时,该文件被执行,其配置对所有登录的用户都有效.当被修改时,必须重启才会生效.英文描述:”System wi ...

  6. 模仿UIApplication创建单例

    UIApplicationMain: 1.创建UIApplication--应用程序唯一标识:可设置状态栏.识别联网状态.设置数字.打电话.发邮件.发短信.打开网页 2.创建UIApplication ...

  7. hadoop mapreduce求解有序TopN

    利用hadoop的map和reduce排序特性实现对数据排序取TopN条数据. 代码参考:https://github.com/asker124143222/wordcount 1.样本数据,假设是订 ...

  8. 怎么更改當前的USERENV('LANG')返回值

    [php] SQL> ALTER SESSION SET NLS_LANGUAGE='AMERICAN'; Session altered. SQL> select USERENV('LA ...

  9. 比hive快10倍的大数据查询利器presto部署

    目前最流行的大数据查询引擎非hive莫属,它是基于MR的类SQL查询工具,会把输入的查询SQL解释为MapReduce,能极大的降低使用大数据查询的门槛, 让一般的业务人员也可以直接对大数据进行查询. ...

  10. 爬虫 xpath 获取方式

    回顾 bs4 实例化bs对象,将页面源码数据加载到该对象中 定位标签:find('name',class_='xxx') findall() select() 将标签中的文本内容获取 string t ...