Configuring Sanlock on KVM Centos 6

Introduction

The purpose of this document, is set some instructions about how to configure libvirt-sanlock with Abiquo KVM on Centos 6. This will prevent the situation where two hypervisors with shared datastore are running two virtual machines using the same hard disk file, which can lead to data corruption.This setup with the provided packages has been approved by quality team and it's supported by Abiquo.

1.1 Setup introduction

First of all, for configure libvirt-sanlock, we will need to set various requirements:

  • All KVM hypervisors connected to the shared datastore must be running on Centos 6 with the libvirt version provided by Abiquo
  • You will need to export an extra NFS folder for save the lock files of sanlock. This NFS MUST be mounted with a certain options that we will explain later

1.2. Impact

You will notice that a restart of abiquo-aim makes libvirt to not respond for round a minute. This is because when restarting libvirt (aim restart makes libvirt restart), sanlock must adquire the locks status before let libvirt work properly. So virsh commands will take a minute to work after that restart. Normal performance of the hypervisor should not be affected.

1.3 HA configuration

If you want to configure sanlock with HA on Abiquo, keep in mind that Sanlock needs certain time to "realize" that the hypervisor has died and release the lock. In our tests, we have seen problems with HA when the HA check is configured to be performed every 30 seconds. We recommend to set the HA check at least every 120 seconds to ensure the correct HA execution.

Configuration

2.1 Previous steps

First of all, we need to create a NFS share where we are going to save the sanlock lock files. Once it's created, we must mount it with the next options on fstab:

<ip>:/sanlock /sanlock nfs    hard,nointr        0 0

If it's mounted with other options, you may see sanlock with problems to acquire the lock status after a restart of the hypervisor, what would make libvirt unable to use hard disks that are not currently used.

2.2 Install the required packages

The required packages for install sanlock can be found on Abiquo repository. For install it then, we just need to execute:

#> yum sanlock sanlock-lib sanlock-python sanlock-devel sanlock-debuginfo

#> yum --disablerepo=* --enablerepo=abiquo-base install libvirt-lock-sanlock

2.3 Disable watchdog for Sanlock

All the tests performed by Abiquo have been without using watchdog, as this functionality would be quite implemented by HA.

For disable watchdog on sanlock, edit the file vim /etc/sysconfig/sanlock and set:

SANLOCKOPTS="-w 0"

2.4 Configure Sanlock

Now, we need to configure sanlock. For that, we edit the file /etc/libvirt/qemu-sanlock.conf and set:

auto_disk_leases = 1

disk_lease_dir = "/sanlock" # set the path of the NFS export from step 2.1

host_id = 2 # This ID should be different for each KVM node

2.5 Configure libvirt to use sanlock

We need to tell libvirt that he is going to use sanlock. For this, we need to edit the file /etc/libvirt/qemu.conf and set:

lock_manager = "sanlock"

2.6 Start Sanlock service and register with libvirt

This step needs to be performed separately for each hypervisor. If you need to connect two hypervisors, you will need to ensure that the lock is properly registered for first hypervisor before start the services on the second hypervisor.

#> /etc/init.d/sanlock start

You can check sanlock is properly started with command:

#> sanlock status

daemon 48aaf6fa-e8ad-4589-95ad-a4626101f47a.bc3blade7.

p -1 helper

p -1 listener

p -1 status

Once you see response of that command, you must restart aim. Once aim is properly restarted, you must wait until you can see how sanlock have been registered with libvirt properly:

[root@bc3blade7 ~]# sanlock status

daemon 48aaf6fa-e8ad-4589-95ad-a4626101f47a.bc3blade7.

p -1 helper

p -1 listener

p -1 status

s __LIBVIRT__DISKS__:2:/sanlock/__LIBVIRT__DISKS__:0

Unable to render {include} The included page could not be found.