ITS-Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login

    VM mit drbd und pacemaker

    Scheduled Pinned Locked Moved Technik
    1 Posts 1 Posters 369 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      admin
      last edited by admin

      Heute geht es darum in KVM eine VM mit Hoch verfügbarkeit einzurichten.

      Zu erst legen wir ein Volume an auf beiden Hosts mit 15 Gigabyte:

      lvcreate -n ubuntu-lts -L 15G cl
      

      anschließend müssen wir die Config im DRBD anlegen /etc/drbd.d wichtig hier ist jedes Volume liegt auf einem eigenen Port:

      resource ubuntu-lts {
              startup {
                      wfc-timeout 20;
                      degr-wfc-timeout 10;
              }
              net {
                      cram-hmac-alg sha1;
                      shared-secret "Passwort";
                      protocol C;
              }
              on kvmtest1.nwe.de {
                      device    /dev/drbd9;
                      disk      /dev/cl/ubuntu-lts;
                      address   172.16.200.142:7809;
                      meta-disk  internal;
              }
              on kvmtest2.nwe.de {
                      device    /dev/drbd9;
                      disk      /dev/cl/ubuntu-lts;
                      address   172.16.200.143:7809;
                      meta-disk  internal;
              }
      }
      

      anschließend können wir auf beiden Hosts das DRBD anlegen mit:

      drbdadm create-md ubuntu-lts
      

      Jetzt nehmen wir beide Volumes up auf beiden Hosts:

      drbdadm up ubuntu-lts
      

      Zu letzt müssen wir nocheinem Host sagen das er jetzt Master ist.

      drbdadm primary --force ubuntu-lts
      

      mit dem folgendem Befehl können wir prüfen was drbd gerade macht:

      drbdadm status
      

      Jetzt haben wir ein Volume was zwischen beiden Hosts gesynct wird. Jetzt müsen wir die KVM config selber anlegen in

      <domain type='kvm'>
        <name>ubuntu-lts</name>
        <uuid>952cdef1-dfc2-4599-8310-8ced312abdc2</uuid>
        <memory unit='KiB'>2194304</memory>
        <currentMemory unit='KiB'>2194304</currentMemory>
        <vcpu placement='static'>2</vcpu>
        <resource>
          <partition>/machine</partition>
        </resource>
        <os>
          <type arch='x86_64' machine='pc-i440fx-rhel7.6.0'>hvm</type>
          <boot dev='hd'/>
          <boot dev='cdrom'/>
        </os>
        <features>
          <acpi/>
          <apic/>
          <pae/>
        </features>
        <cpu mode='custom' match='exact' check='full'>
          <model fallback='forbid'>qemu64</model>
          <feature policy='require' name='x2apic'/>
          <feature policy='require' name='hypervisor'/>
          <feature policy='require' name='lahf_lm'/>
          <feature policy='disable' name='svm'/>
        </cpu>
        <clock offset='utc'/>
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>restart</on_reboot>
        <on_crash>restart</on_crash>
        <devices>
          <emulator>/usr/libexec/qemu-kvm</emulator>
          <disk type='block' device='disk'>
            <driver name='qemu' type='raw' cache='none' io='native'/>
            <source dev='/dev/drbd/by-res/ubuntu-lts/0'/>
            <backingStore/>
            <target dev='vda' bus='virtio'/>
            <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
          </disk>
          <disk type='file' device='cdrom'>
            <driver name='qemu' type='raw'/>
            <target dev='hdc' bus='ide'/>
            <readonly/>
            <address type='drive' controller='0' bus='1' target='0' unit='0'/>
          </disk>
          <controller type='ide' index='0'>
            <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
          </controller>
          <controller type='usb' index='0' model='piix3-uhci'>
            <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
          </controller>
          <controller type='pci' index='0' model='pci-root'/>
          <interface type='bridge'>
            <mac address='52:54:00:9d:81:29'/>
            <source bridge='br-enp3s4f0'/>
            <vlan>
              <tag id='199'/>
            </vlan>
            <virtualport type='openvswitch'>
              <parameters interfaceid='8a4ab6e9-e1fd-4921-95fe-65097be92391'/>
            </virtualport>
            <model type='virtio'/>
            <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
          </interface>
          <serial type='pty'>
            <target type='isa-serial' port='0'>
              <model name='isa-serial'/>
            </target>
          </serial>
          <console type='pty'>
            <target type='serial' port='0'/>
          </console>
          <input type='tablet' bus='usb'>
            <address type='usb' bus='0' port='1'/>
          </input>
          <input type='mouse' bus='ps2'/>
          <input type='keyboard' bus='ps2'/>
          <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='de'>
            <listen type='address' address='127.0.0.1'/>
          </graphics>
          <video>
            <model type='cirrus' vram='16384' heads='1' primary='yes'/>
            <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
          </video>
          <memballoon model='virtio'>
            <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
          </memballoon>
        </devices>
        <seclabel type='none' model='none'/>
        <seclabel type='dynamic' model='dac' relabel='yes'/>
      </domain>
      

      Wir benutzen hier im Beispiel csync2 um die configs von Host 1 auf Host 2 zu pushen. Dies kann man auch manuell mit scp durchführen.

      Um eine Iso zu Mounten kann folgender Befehl verwendet werden.

      virsh attach-disk ubuntu-lts /tmp/ubuntu-lts.iso hdc --type cdrom
      

      Oder mit virsh edit ubuntu-lts von Hand einfügen:

      <source file='/tmp/ubuntu-lts.iso'/>
      

      Mit folgendem Befehl bekommen wir den consolen Port über den wir uns dann mit VNC verbinden können.

      virsh vncdisplay ubuntu-lts
      

      Im prizip ist die VM jetzt fertig, jetzt müssen wir noch den Pacemaker einrichten.Zu erst setzen wir diesen in den Maintenance Mode:

      pcs property set maintenance-mode=true
      

      Dann erstellen wir eine Überwachung für das DRBD:

      pcs resource create drbd_ubuntu-lts ocf:linbit:drbd drbd_resource=ubuntu-lts op monitor interval=15s
      

      Jetzt aktivieren wir die Einstellung mit:

      pcs resource promotable drbd_ubuntu-lts meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true target-role=Master
      

      Aufräumen des Pacemaker mit:

      pcs resource cleanup drbd_ubuntu-lts-clone
      

      Nun erstellen wir die Verknüpfung zum liebvirt, damit der Pacemaker die Resource auch starten und verschieben kann mit:

      pcs resource create kvm_ubuntu-lts ocf:heartbeat:VirtualDomain config=/etc/libvirt/qemu/ubuntu-lts.xml meta allow-migrate=false target-role=Started op monitor interval=10s timeout=30s stop interval=0 timeout=120s start interval=0 timeout=30s
      

      Pacemaker muss noch in welcher Reihenfolge er die aktionen durchführen soll mit:

      pcs constraint order promote drbd_ubuntu-lts-clone then start kvm_ubuntu-lts
      

      Zusamenführen der beiden Konfigurationen

      pcs constraint colocation add kvm_ubuntu-lts with Master drbd_ubuntu-lts-clone
      

      Pacemaker wieder in den Normalbetrieb setzen.

      pcs property unset maintenance-mode
      

      Wir haben somit auf beiden Hosts dein Volume was gesynct wird und auf einem Host läuft nun die VM, man kann die VM auf den anderen Host schieben mit:

      resource move ubuntu-lts gate2
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB | Contributors