openstack高可用集群20-openstack计算节点宕机迁移方案

openstack计算节点宕机迁移方案
 
情景一:/var/lib/nova/instances/ 目录不共享的处理方法(相似手动迁移云主机到其余节点)
查看正在运行的云主机xml
[root@node3 ~]# virsh dumpxml d045e4dd-5598-40b4-82e7-bddc0fcde14c
<domain type='kvm' id='1'>
  <name>instance-000001b6</name>
  <uuid>d045e4dd-5598-40b4-82e7-bddc0fcde14c</uuid>
  <metadata>
    <nova:instance xmlns:nova="http://openstack.org/xmlns/libvirt/nova/1.0">
      <nova:package version="17.0.13-1.el7"/>
      <nova:name>tomcat-vm2</nova:name>
      <nova:creationTime>2020-02-21 01:28:16</nova:creationTime>
      <nova:flavor name="1c2g">
        <nova:memory>2024</nova:memory>
        <nova:disk>40</nova:disk>
        <nova:swap>0</nova:swap>
        <nova:ephemeral>0</nova:ephemeral>
        <nova:vcpus>1</nova:vcpus>
      </nova:flavor>
      <nova:owner>
        <nova:user uuid="51ffe09d0ed342f4bf4e443e454055cc">admin</nova:user>
        <nova:project uuid="75aed7016c86445198356e78dddde4ba">admin</nova:project>
      </nova:owner>
      <nova:root type="image" uuid="75398b9c-5cd6-4936-a093-eba02984f7f0"/>
    </nova:instance>
  </metadata>
  <memory unit='KiB'>2072576</memory>
  <currentMemory unit='KiB'>2072576</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <cputune>
    <shares>1024</shares>
  </cputune>
  <resource>
    <partition>/machine</partition>
  </resource>
  <sysinfo type='smbios'>
    <system>
      <entry name='manufacturer'>RDO</entry>
      <entry name='product'>OpenStack Compute</entry>
      <entry name='version'>17.0.13-1.el7</entry>
      <entry name='serial'>4a7258d2-f86c-af77-106d-598ffd558b8e</entry>
      <entry name='uuid'>d045e4dd-5598-40b4-82e7-bddc0fcde14c</entry>
      <entry name='family'>Virtual Machine</entry>
    </system>
  </sysinfo>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.6.0'>hvm</type>
    <boot dev='hd'/>
    <smbios mode='sysinfo'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='custom' match='exact' check='full'>
    <model fallback='forbid'>IvyBridge-IBRS</model>
    <vendor>Intel</vendor>
    <topology sockets='1' cores='1' threads='1'/>
    <feature policy='require' name='ss'/>
    <feature policy='require' name='vmx'/>
    <feature policy='require' name='pcid'/>
    <feature policy='require' name='hypervisor'/>
    <feature policy='require' name='arat'/>
    <feature policy='require' name='tsc_adjust'/>
    <feature policy='require' name='umip'/>
    <feature policy='require' name='stibp'/>
    <feature policy='require' name='ssbd'/>
    <feature policy='require' name='xsaveopt'/>
    <feature policy='require' name='pdpe1gb'/>
  </cpu>
  <clock offset='utc'>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
       <source file='/var/lib/nova/instances/d045e4dd-5598-40b4-82e7-bddc0fcde14c/disk'/>
      <backingStore type='file' index='1'>
        <format type='raw'/>
         <source file='/var/lib/nova/instances/_base/138d5db2b1f3dec2e4d41721505aede7454d7cd2'/>
        <backingStore/>
      </backingStore>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='piix3-uhci'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <interface type='bridge'>
      <mac address='fa:16:3e:93:1a:23'/>
      <source bridge='brq5ac5c948-90'/>
      <target dev='tap22a81bb2-3a'/>
      <model type='virtio'/>
      <mtu size='1500'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='fa:16:3e:cb:2a:67'/>
      <source bridge='brq85ae5035-20'/>
      <target dev='tap14a1350e-51'/>
      <model type='virtio'/>
      <mtu size='1450'/>
      <alias name='net1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/0'/>
      <log file='/var/lib/nova/instances/d045e4dd-5598-40b4-82e7-bddc0fcde14c/console.log' append='off'/>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/0'>
      <source path='/dev/pts/0'/>
      <log file='/var/lib/nova/instances/d045e4dd-5598-40b4-82e7-bddc0fcde14c/console.log' append='off'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <input type='tablet' bus='usb'>
      <alias name='input0'/>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'>
      <alias name='input1'/>
    </input>
    <input type='keyboard' bus='ps2'>
      <alias name='input2'/>
    </input>
    <graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0' keymap='en-us'>
      <listen type='address' address='0.0.0.0'/>
    </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'>
      <stats period='10'/>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
  </devices>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+107:+107</label>
    <imagelabel>+107:+107</imagelabel>
  </seclabel>
</domain>
 
1.1迁移xml文件和云主机镜像
[root@node3 ~]# scp /var/lib/nova/instances/_base/138d5db2b1f3dec2e4d41721505aede7454d7cd2 root@node4:/var/lib/nova/instances/_base/
[root@node3 ~]# ssh node4 mkdir -pv /var/lib/nova/instances/d045e4dd-5598-40b4-82e7-bddc0fcde14c/
[root@node3 ~]# scp /var/lib/nova/instances/d045e4dd-5598-40b4-82e7-bddc0fcde14c/disk root@node4:/var/lib/nova/instances/d045e4dd-5598-40b4-82e7-bddc0fcde14c/
[root@node3 ~]# virsh dumpxml d045e4dd-5598-40b4-82e7-bddc0fcde14c >d045e4dd-5598-40b4-82e7-bddc0fcde14c.xml
[root@node3 ~]# scp d045e4dd-5598-40b4-82e7-bddc0fcde14c.xml root@node4:/root/
 
1.2控制器上修改数据库
mysql -Dnova -e "update instances set host='node4' where uuid='d045e4dd-5598-40b4-82e7-bddc0fcde14c'"
mysql -Dnova -e "update instances set launched_on='node4' where uuid='d045e4dd-5598-40b4-82e7-bddc0fcde14c'"
1.3初始化迁移后的XML文件及启动云主机
[root@node4 data]# virsh define d045e4dd-5598-40b4-82e7-bddc0fcde14c.xml
[root@node4 data]# virsh start d045e4dd-5598-40b4-82e7-bddc0fcde14c
1.4验证是否成功
情景二:/var/lib/nova/instances/ 目录共享的处理方法
2.1控制器上修改数据库
mysql -Dnova -e "update instances set host='node3' where uuid='d045e4dd-5598-40b4-82e7-bddc0fcde14c'"
mysql -Dnova -e "update instances set launched_on='node4' where uuid='d045e4dd-5598-40b4-82e7-bddc0fcde14c'"
2.2修改完数据库之后在horizon界面硬重启这台虚拟机就ok了