安装部署KVM虚拟机(四)

Libvirt提供了用户空间的命令行和编程语言绑定来管理虚拟机的build, configure, start, stop,migrate, terminate,etc.

OpenStack的组件中也做了集成。

https://blog.csdn.net/xxfigo/article/details/7590229

Nova是OpenStack云中的计算组织控制器。支持OpenStack云中实例(instances)生命周期的所有活动都由Nova处理。这样使得Nova成为一个负责管理计算资源、网络、认证、所需可扩展性的平台。但是,Nova自身并没有提供任何虚拟化能力,相反它使用libvirt API来与被支持的Hypervisors交互。

安装和配置libvirt

jahentao:qemu$ sudo apt install gir1.2-libvirt-glib-1.0 libvirt-bin libvirt-clients libvirt-daemon libvirt-daemon-system libvirt-dev libvirt-glib-1.0-0 libvirt0 python-libvirt virt-manager virt-top virt-viewer virtinst

查看libvirt的守护进程是否在执行

jahentao:qemu$  pgrep -lfa libvirtd
1895 /usr/sbin/libvirtd

修改配置/etc/libvirt/libvirtd.conf

查看配置

jahentao:~$ cat /etc/libvirt/libvirtd.conf | grep -vi "#" | sed '/^$/d'
listen_tls = 0
listen_tcp = 1
listen_addr = "127.0.0.1"
auth_tcp = "sasl"

Qemu默认用的Selinux策略

查看SELinux状态

/usr/sbin/sestatus -v

如果SELinux status参数为enabled即为开启状态,也可以用getenforce命令检查

我的机器上没有使用SeLinux。

警用QEMU的安全驱动,如果有selinux在运行。

jahentao:qemu$ sudo cat /etc/libvirt/qemu.conf | grep -vi '#' | sed '/^$/d'
security_driver = "none"

配置监听

jahentao:~$ sudo cat /etc/default/libvirtd | grep -vi '#' | sed '/^$/d'
start_libvirtd="yes"
libvirtd_opts=" --listen"

重启libvirt守护进程。

jahentao:~$ systemctl restart libvirtd
jahentao:~$ 

验证配置文件

jahentao:~$ ls -la /etc/libvirt/
总用量 140
drwxr-xr-x   8 root root  4096 3月   9 09:05 .
drwxr-xr-x 153 root root 12288 3月   9 09:00 ..
drwxr-xr-x   2 root root  4096 5月  16  2018 hooks
-rw-r--r--   1 root root   450 5月  16  2018 libvirt-admin.conf
-rw-r--r--   1 root root   642 2月  27 13:17 libvirt.conf
-rw-r--r--   1 root root   547 2月  21 19:00 libvirt.conf.bak
-rw-r--r--   1 root root 16047 2月  26 22:48 libvirtd.conf
-rw-r--r--   1 root root  2268 5月  16  2018 libxl.conf
-rw-r--r--   1 root root  2169 5月  16  2018 libxl-lockd.conf
drwxr-xr-x   2 root root  4096 3月   4 21:39 lxc
-rw-r--r--   1 root root  1175 5月  16  2018 lxc.conf
drwxr-xr-x   2 root root  4096 2月  21 17:29 nwfilter
-rw-r-----   1 root root 12288 2月  27 12:31 passwd.db
drwxr-xr-x   3 root root  4096 3月   6 19:17 qemu
-rw-------   1 root root 29195 3月   9 09:05 qemu.conf
-rw-r--r--   1 root root  2169 5月  16  2018 qemu-lockd.conf
-rw-r--r--   1 root root  2465 5月  16  2018 qemu-sanlock.conf
drwx------   2 root root  4096 2月  21 17:29 secrets
drwxr-xr-x   3 root root  4096 3月   4 21:22 storage
-rw-r--r--   1 root root  2003 5月  16  2018 virtlockd.conf
-rw-r--r--   1 root root  2101 5月  16  2018 virtlogd.conf
-rw-r--r--   1 root root  1883 5月  16  2018 virt-login-shell.conf
  • libvirt.conf是客户端的配置文件
  • libvirtd.conf是服务器端的配置文件
  • qemu.conf是libvirt使用QEMU的配置文件
  • QEMU/KVM虚拟机一经创建 /etc/libvirt/qemu/目录下就会出现定义相应实例的XML配置文件,/etc/libvirt/qemu/networks/包含网络配置

还有其他配置文件位置

jahentao:~$ sudo !!
sudo tree /var/lib/libvirt/
/var/lib/libvirt/
├── boot
├── dnsmasq
│   ├── default.addnhosts
│   ├── default.conf
│   ├── default.hostsfile
│   ├── virbr0.macs
│   └── virbr0.status
├── images
├── qemu
│   ├── channel
│   │   └── target
│   ├── dump
│   ├── nvram
│   ├── ram
│   │   └── libvirt
│   │       └── qemu
│   ├── save
│   └── snapshot
└── sanlock
/usr/lib/libvirt
├── connection-driver
│   ├── libvirt_driver_interface.so
│   ├── libvirt_driver_libxl.so
│   ├── libvirt_driver_lxc.so
│   ├── libvirt_driver_network.so
│   ├── libvirt_driver_nodedev.so
│   ├── libvirt_driver_nwfilter.so
│   ├── libvirt_driver_qemu.so
│   ├── libvirt_driver_secret.so
│   ├── libvirt_driver_storage.so
│   ├── libvirt_driver_uml.so
│   └── libvirt_driver_vbox.so
├── libvirt-guests.sh
├── libvirt_iohelper
├── libvirt_leaseshelper
├── libvirt_lxc
├── libvirt_parthelper
├── libvirt_sanlock_helper
├── lock-driver
│   └── lockd.so
├── storage-backend
│   ├── libvirt_storage_backend_disk.so
│   ├── libvirt_storage_backend_fs.so
│   ├── libvirt_storage_backend_iscsi.so
│   ├── libvirt_storage_backend_logical.so
│   ├── libvirt_storage_backend_mpath.so
│   └── libvirt_storage_backend_scsi.so
└── virt-aa-helper
/usr/lib/libvirt-admin.so [error opening dir]
/usr/lib/libvirt-admin.so.0 [error opening dir]
/usr/lib/libvirt-admin.so.0.4003.0 [error opening dir]
/usr/lib/libvirt-lxc.so [error opening dir]
/usr/lib/libvirt-lxc.so.0 [error opening dir]
/usr/lib/libvirt-lxc.so.0.4003.0 [error opening dir]
/usr/lib/libvirt-qemu.so [error opening dir]
/usr/lib/libvirt-qemu.so.0 [error opening dir]
/usr/lib/libvirt-qemu.so.0.4003.0 [error opening dir]
/usr/lib/libvirt.so [error opening dir]
/usr/lib/libvirt.so.0 [error opening dir]
/usr/lib/libvirt.so.0.4003.0 [error opening dir]

定义KVM实例

列出宿主机上所有的虚拟机

jahentao:~$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     ubuntu14.04                    shut off
jahentao:qemu$ cp debian.img debian2.img

编写XML配置文件,定义KVM实例

<boot dev>指定了虚拟机的启动设备
有关domain XML的文档 https://libvirt.org/formatdomain.html

virsh从XML创建虚拟机

jahentao:~$ sudo virsh define kvm1.xml
Domain kvm1 defined from kvm1.xml
jahentao:qemu$ ls /etc/libvirt/qemu/
kvm1.xml  networks  ubuntu14.04.xml

查看虚拟机列表

jahentao:qemu$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     kvm1                           shut off
 -     ubuntu14.04                    shut off

取消定义,即删除

jahentao:qemu$ sudo virsh undefine kvm1
Domain kvm1 has been undefined
jahentao:qemu$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     ubuntu14.04                    shut off

自己编写XML定义很容易出错,参考使用 virt-install 命令

启动、停止、移除KVM实例

启动

jahentao:qemu$ sudo virsh start kvm1
Domain kvm1 started

查看运行状态

jahentao:qemu$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 3     kvm1                           running
 -     ubuntu14.04                    shut off

验证

jahentao:qemu$ pgrep -lfa qemu
9138 qemu-system-x86_64 -enable-kvm -name guest=kvm1,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-3-kvm1/master-key.aes -machine pc-i440fx-2.12,accel=kvm,usb=off,dump-guest-core=off -cpu Nehalem -m 1024 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid 2616fd23-18e6-4e14-90c3-8042b890344c -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-3-kvm1/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=delay -no-hpet -no-shutdown -global PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -boot strict=on -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x4.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x4 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x4.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x4.0x2 -drive file=/pan/qemu/debian2.img,format=raw,if=none,id=drive-ide0-0-0 -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -netdev tap,fd=27,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:ce:2c:a2,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -vnc 127.0.0.1:0 -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny -msg timestamp=on

可以看见同xml中读取传递了大量参数.

停止KVM实例

jahentao:qemu$ sudo virsh destroy kvm1
Domain kvm1 destroyed
jahentao:qemu$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     kvm1                           shut off
 -     ubuntu14.04                    shut off

移除实例

jahentao:qemu$ sudo virsh undefine kvm1
Domain kvm1 has been undefined
jahentao:qemu$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     ubuntu14.04                    shut off

查看和编辑KVM配置

确保虚拟机正在运行

jahentao:qemu$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 5     kvm1                           running
 -     ubuntu14.04                    shut off

将配置文件dump到标准输出

jahentao:qemu$ sudo virsh dumpxml kvm1
<domain type='kvm' id='5'>
  <name>kvm1</name>
  <uuid>87efed27-be55-43f3-a5a1-ea523679c90c</uuid>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='custom' match='exact' check='full'>
    <model fallback='forbid'>Nehalem</model>
    <feature policy='require' name='vme'/>
    <feature policy='require' name='x2apic'/>
    <feature policy='require' name='hypervisor'/>
  </cpu>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/pan/qemu/debian2.img'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <alias name='usb'/>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <alias name='usb'/>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <alias name='usb'/>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <controller type='ide' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:9c:9b:06'/>
      <source network='default' bridge='virbr0'/>
      <target dev='vnet0'/>
      <model type='rtl8139'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/1'/>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/1'>
      <source path='/dev/pts/1'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <input type='mouse' bus='ps2'>
      <alias name='input0'/>
    </input>
    <input type='keyboard' bus='ps2'>
      <alias name='input1'/>
    </input>
    <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='cirrus' vram='16384' heads='1' primary='yes'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </memballoon>
  </devices>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+64055:+64055</label>
    <imagelabel>+64055:+64055</imagelabel>
  </seclabel>
</domain>

Dump到文件

jahentao:qemu$ sudo virsh dumpxml kvm1 > kvm1_dump.xml

编辑kvm1配置

jahentao:qemu$ sudo virsh edit kvm1
Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny
  4. /usr/bin/code
Choose 1-4 [1]:
Domain kvm1 XML configuration not changed.

管理KVM中的CPU和内存资源

获取运行实例的信息

jahentao:~$ sudo virsh dommemstat kvm1
actual 1048576
swap_in 0
swap_out 0
major_fault 155
minor_fault 27761
unused 959200
available 1020300
usable 903764
last_update 1552137455
rss 219708

更新可用内存大小

jahentao:~$ sudo virsh setmem kvm1 --size 1049000
error: invalid argument: cannot set memory higher than max memory

关闭虚拟机

jahentao:~$ sudo virsh destroy kvm1
Domain kvm1 destroyed

调整最大可用内存为2G

jahentao:~$ sudo virsh setmaxmem kvm1 --size 2097152

重新启动虚拟机

jahentao:~$ sudo virsh start kvm1
Domain kvm1 started

查看更新后的信息

jahentao:~$ sudo virsh dommemstat kvm1
actual 1048576
swap_in 0
swap_out 0
major_fault 150
minor_fault 25073
unused 1992768
available 2052492
usable 1932580
last_update 1552138163
rss 258580

检查XML内存配置

jahentao:~$ sudo virsh dumpxml kvm1 | grep memory
  <memory unit='KiB'>2097152</memory>

获取CPU信息

jahentao:~$ sudo virsh vcpuinfo kvm1
VCPU:           0
CPU:            6
State:          running
CPU time:       18.8s
CPU Affinity:   yyyyyyyy

列出被客户机使用的CPU

jahentao:~$ sudo virsh vcpucount kvm1
maximum      config         1
maximum      live           1
current      config         1
current      live           1

修改vCPU数目

jahentao:~$ sudo virsh edit kvm1
[sudo] jahentao 的密码:
Domain kvm1 XML configuration edited.
<vcpu placement='static'>4</vcpu>

查看修改后的CPU信息

jahentao:~$ sudo virsh vcpucount kvm1
maximum      config         4
maximum      live           1
current      config         4
current      live           1
jahentao:~$ sudo virsh dumpxml kvm1 | grep -i cp
  <vcpu placement='static'>1</vcpu>
    <acpi/>
  <cpu mode='custom' match='exact' check='full'>
  </cpu>

只是配置值改变了,为什么live值不变呢?

重启之后好了。

给虚拟机增加块设备

给虚拟机添加块设备,可以是iSCSI、LVM逻辑卷或者镜像文件

创建1G的镜像文件

jahentao:qemu$ dd if=/dev/zero of=/tmp/new_disk.img bs=1M count=1024
记录了1024+0 的读入
记录了1024+0 的写出
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.909218 s, 1.2 GB/s

将镜像文件作为磁盘,挂载到虚拟机

jahentao:qemu$ sudo virsh attach-disk kvm1 /tmp/new_disk.img vda --live
Disk attached successfully

连接到KVM实例

jahentao:~$ sudo virsh console kvm1
Connected to domain kvm1
Escape character is ^]
Debian GNU/Linux 9 jahentao-PC ttyS0
jahentao-PC login: root
Password:
Last login: Sun Mar 10 00:44:03 UTC 2019 on tty1
Linux jahentao-PC 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3 (2019-02-02) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@jahentao-PC:~# 

查看磁盘信息

root@jahentao-PC:~# fdisk -l /dev/vda
Disk /dev/vda: 1 GiB, 1073741824 bytes, 2097152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
jahentao:qemu$ sudo virsh dumpxml kvm1
……
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/pan/qemu/debian2.img'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/tmp/new_disk.img'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>
……

查看新磁盘的信息

jahentao:qemu$ sudo virsh domblkstat kvm1 vda
vda rd_req 48
vda rd_bytes 1081344
vda wr_req 0
vda wr_bytes 0
vda flush_operations 0
vda rd_total_times 6797296
vda wr_total_times 0
vda flush_total_times 0

删除磁盘

jahentao:qemu$ sudo virsh detach-disk kvm1 vda --live
Disk detached successfully

虚拟机和宿主机共享文件夹

在宿主机上创建共享目录

jahentao:qemu$ mkdir /tmp/shared
jahentao:qemu$ touch /tmp/shared/file

停止客户机后,编辑配置文件

jahentao:qemu$ sudo virsh destroy kvm1
Domain kvm1 destroyed
jahentao:qemu$ sudo virsh edit kvm1
Domain kvm1 XML configuration edited.
……
    <filesystem type='mount' accessmode='passthrough'>
        <source dir='/tmp/shared' />
        <target dir='tmp_shared' />
    </filesystem>

accessmode有三种:

  • passthrough,默认,使用的客户机中用户的权限
  • mapped,继承自宿主机QEMU用户的权限
  • squash,与passthrough类似,但禁用chmod

登录后查看9p和virto模块都在

jahentao:qemu$ sudo virsh console kvm1
Connected to domain kvm1
Escape character is ^]
Debian GNU/Linux 9 jahentao-PC ttyS0
jahentao-PC login: root
Password:
Last login: Sun Mar 10 01:03:56 UTC 2019 on ttyS0
Linux jahentao-PC 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3 (2019-02-02) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@jahentao-PC:~# lsmod | grep 9p
9pnet_virtio           20480  0
9pnet                  86016  1 9pnet_virtio
virtio_ring            24576  3 9pnet_virtio,virtio_balloon,virtio_pci
virtio                 16384  3 9pnet_virtio,virtio_balloon,virtio_pci

如果没有加载,则加载

modprobe 9p virtio

将共享目录挂载到/mnt

root@jahentao-PC:~# mount -t 9p -o trans=virtio tmp_shared /mnt

查看宿主机中共享的文件

root@jahentao-PC:~# ls -la /mnt/
total 8
drwxr-xr-x  2 1000 1000 4096 Mar 10 01:31 .
drwxr-xr-x 22 root root 4096 Mar  7 11:56 ..
-rw-r--r--  1 1000 1000    0 Mar 10 01:31 file

如何取消挂载呢?重启之后报错。

设置自动启动KVM实例

默认情况下,KVM实例要等宿主机操作系统启动之后,才能运行。

当宿主机操作系统重启时,即使libvirt守护进程运行着,libvirt创建的实例并不会自动运行。

可以设置libvirt守护进程启动时,即启动KVM实例。

jahentao:qemu$ sudo virsh autostart kvm1
[sudo] jahentao 的密码:
Domain kvm1 marked as autostarted
jahentao:qemu$ sudo virsh dominfo kvm1
Id:             3
Name:           kvm1
UUID:           87efed27-be55-43f3-a5a1-ea523679c90c
OS Type:        hvm
State:          running
CPU(s):         4
CPU time:       29.6s
Max memory:     2097152 KiB
Used memory:    1048576 KiB
Persistent:     yes
Autostart:      enable
Managed save:   no
Security model: none
Security DOI:   0

停止运行的实例

jahentao:qemu$ sudo virsh destroy kvm1
Domain kvm1 destroyed
jahentao:qemu$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     kvm1                           shut off
 -     kvm2                           shut off
 -     ubuntu14.04                    shut off

停止libvirtd守护进程

jahentao:qemu$ /etc/init.d/libvirtd stop
[ ok ] Stopping libvirtd (via systemctl): libvirtd.service.
jahentao:qemu$ pgrep -lfa libvirtd

启动守护进程

jahentao:qemu$ /etc/init.d/libvirtd start
[ ok ] Starting libvirtd (via systemctl): libvirtd.service.

查看实例是否自动启动

jahentao:qemu$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     kvm1                           running
 -     kvm2                           shut off
 -     ubuntu14.04                    shut off

取消实例自动启动

jahentao:qemu$ sudo virsh autostart kvm1 --disable
Domain kvm1 unmarked as autostarted

发布者

jahentao

挖掘概念,创造工具