假设cloud-compute-b10-03.cloud.cn 节点需要停机维护,并且已经配置了shared storage
[root@cloud-control-b13-01 ~]# nova host-evacuate --target_host cloud-compute-b10-04.cloud.cn cloud-compute-b10-03.cloud.cn
+--------------------------------------+-------------------+---------------+
| Server UUID | Evacuate Accepted | Error Message |
+--------------------------------------+-------------------+---------------+
| c5a884e7-a13d-49a6-81ff-e91fe331cea0 | True | |
| fb6a5295-23a4-491b-a6ce-55f8e9a980fe | True | |
+--------------------------------------+-------------------+---------------+
该命令的输出为Instances 是否接受evacuate, 效果是cloud-compute-b10-03上的Instances都迁移到cloud-compute-b10-04上。
--target_host参数视具体情况而定。
why not live migrate
live migrate 不保险, 有时会失败,所以在虚拟机允许停业务的情况下,用host-evacuate 是最好的方法。
Notice
host-evacuate命令的前提是节点上的nova-compute服务处于down的状态, 节点停机必然是满足该条件的,如果不想停机, 将该节点上的nova-compute服务stop也是可以的。
[root@cloud-control-b13-01 tmp]# nova service-list |grep compute
| 97 | nova-compute | cloud-compute-b10-03.cloud.cn | nova | enabled | down | 2018-01-23T08:53:46.000000 | - |
| 100 | nova-compute | cloud-compute-b10-04.cloud.cn | nova | enabled | up | 2018-01-23T08:49:14.000000 | - |
模拟停机
[root@cloud-compute-b10-03 ~]# docker stop nova_compute
nova_compute
[root@cloud-compute-b10-03 ~]# machinectl list
MACHINE CLASS SERVICE
qemu-1-instance-00000075 vm libvirt-qemu
qemu-2-instance-0000002e vm libvirt-qemu
2 machines listed.
[root@cloud-compute-b10-03 ~]# ps aux |grep qemu
42427 31730 0.8 0.1 5009896 809736 ? Sl 16:49 0:29 /usr/libexec/qemu-kvm -name guest=instance-00000075,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-1-instance-00000075/master-key.aes -machine pc-i440fx-rhel7.3.0,accel=kvm,usb=off -cpu Broadwell,+vme,+ds,+acpi,+ss,+ht,+tm,+pbe,+dtes64,+ds_cpl,+vmx,+smx,+est,+tm2,+xtpr,+pdcm,+dca,+osxsave,+f16c,+rdrand,+arat,+tsc_adjust,+xsaveopt,+pdpe1gb,+abm,+rtm,+hle -m 4096 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid c5a884e7-a13d-49a6-81ff-e91fe331cea0 -smbios type=1,manufacturer=RDO,product=OpenStack Compute,version=15.0.4-1.el7,serial=c5e75cce-0425-83cc-e711-cd25f6d44577,uuid=c5a884e7-a13d-49a6-81ff-e91fe331cea0,family=Virtual Machine -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-1-instance-00000075/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=discard -no-hpet -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/dev/disk/by-id/dm-uuid-mpath-3600a09803830434972244a78424b336b,format=raw,if=none,id=drive-virtio-disk0,serial=fd1ffcad-c8cd-47d7-8ad5-e038146ac254,cache=none,aio=native -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,fd=27,id=hostnet0,vhost=on,vhostfd=28 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=fa:16:3e:e0:5e:f9,bus=pci.0,addr=0x3 -chardev file,id=charserial0,path=/var/lib/nova/instances/c5a884e7-a13d-49a6-81ff-e91fe331cea0/console.log -device isa-serial,chardev=charserial0,id=serial0 -chardev pty,id=charserial1 -device isa-serial,chardev=charserial1,id=serial1 -device usb-tablet,id=input0,bus=usb.0,port=1 -vnc 10.54.12.14:0 -k en-us -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 -msg timestamp=on
42427 31745 2.0 0.0 1151464 302960 ? Sl 16:49 1:10 /usr/libexec/qemu-kvm -name guest=instance-0000002e,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-2-instance-0000002e/master-key.aes -machine pc-i440fx-rhel7.3.0,accel=kvm,usb=off -cpu Broadwell,+vme,+ds,+acpi,+ss,+ht,+tm,+pbe,+dtes64,+ds_cpl,+vmx,+smx,+est,+tm2,+xtpr,+pdcm,+dca,+osxsave,+f16c,+rdrand,+arat,+tsc_adjust,+xsaveopt,+pdpe1gb,+abm,+rtm,+hle -m 256 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid fb6a5295-23a4-491b-a6ce-55f8e9a980fe -smbios type=1,manufacturer=RDO,product=OpenStack Compute,version=15.0.4-1.el7,serial=c5e75cce-0425-83cc-e711-cd25f6d44577,uuid=fb6a5295-23a4-491b-a6ce-55f8e9a980fe,family=Virtual Machine -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-2-instance-0000002e/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=discard -no-hpet -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/var/lib/nova/instances/fb6a5295-23a4-491b-a6ce-55f8e9a980fe/disk,format=qcow2,if=none,id=drive-virtio-disk0,cache=none -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=/dev/disk/by-id/dm-uuid-mpath-3600a09803830434972244a78424a7958,format=raw,if=none,id=drive-virtio-disk1,serial=909086ba-7002-476b-9b67-b1202d1c052d,cache=none,aio=native -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk1,id=virtio-disk1 -netdev tap,fd=30,id=hostnet0,vhost=on,vhostfd=31 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=fa:16:3e:d4:4d:31,bus=pci.0,addr=0x3 -chardev file,id=charserial0,path=/var/lib/nova/instances/fb6a5295-23a4-491b-a6ce-55f8e9a980fe/console.log -device isa-serial,chardev=charserial0,id=serial0 -chardev pty,id=charserial1 -device isa-serial,chardev=charserial1,id=serial1 -device usb-tablet,id=input0,bus=usb.0,port=1 -vnc 10.54.12.14:1 -k en-us -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on
root 68566 0.0 0.0 112648 964 pts/15 S+ 17:48 0:00 grep --color=auto qemu
注意把vm停掉
[root@cloud-compute-b10-03 ~]# kill -9 31730 31745
[root@cloud-compute-b10-03 ~]# machinectl list
MACHINE CLASS SERVICE
0 machines listed.
[root@cloud-compute-b10-03 ~]#
迁移虚拟机
[root@cloud-control-b13-01 tmp]# nova service-list |grep compute
| 97 | nova-compute | cloud-compute-b10-03.cloud.cn | nova | enabled | down | 2018-01-23T09:45:05.000000 | - |
| 100 | nova-compute | cloud-compute-b10-04.cloud.cn | nova | enabled | up | 2018-01-23T09:49:04.000000 | - |
| 103 | nova-compute | cloud-control-b13-02-ironic | nova | enabled | up | 2018-01-23T09:49:06.000000 | - |
| 106 | nova-compute | cloud-control-b13-01-ironic | nova | enabled | up | 2018-01-23T09:49:03.000000 | - |
| 160 | nova-compute | cloud-control-b13-03-ironic | nova | enabled | up | 2018-01-23T09:49:04.000000 | -
[root@cloud-control-b13-01 tmp]# nova host-evacuate cloud-compute-b10-03.cloud.cn
+--------------------------------------+-------------------+---------------+
| Server UUID | Evacuate Accepted | Error Message |
+--------------------------------------+-------------------+---------------+
| fb6a5295-23a4-491b-a6ce-55f8e9a980fe | True | |
| c5a884e7-a13d-49a6-81ff-e91fe331cea0 | True | |
+--------------------------------------+-------------------+---------------+
模拟恢复
[root@cloud-compute-b10-03 ~]# docker start nova_compute
nova_compute
[root@cloud-compute-b10-03 ~]#