# Performing Live Migration with Platform9 Managed OpenStack

Platform9 Managed OpenStack supports live migration on KVM.

## What is live migration?

Live migration means migrating or transferring a virtual machine (VM) from one physical hypervisor (host) to another, while the VM is still running. The VM might have applications running on it.

The VM or application downtime during a live migration is very small or negligible.

The host from which a live or running VM is transferred, is called the source host. The host to which the running VM is transferred, is called the destination host.

## When is live migration performed?

Live migration is performed in the following scenarios.

* It is not possible to bring down the running applications or VMs and have downtime for a cold migration.
* It is necessary to redistribute the load of multiple VMs running on the same physical machine.

## Prepare hosts for live migration

You must be an administrator to perform live migration.

{% hint style="info" %}
**Info**

**Note:** When the instance storage is not shared between the source host and the destination host, block migration must be used. This type of migration can be slower, since it copies data and requires that both hosts have compatible CPU architectures.
{% endhint %}

The following steps must be performed on the source host and the destination host **before** you start with the live migration.

* TCP port 16509 must be open on both the source and the destination hosts. Run the following command to add the text in the command to the end of /etc/libvirt/libvirtd.conf.

{% tabs %}
{% tab title="Bash" %}

```bash
cat<<-EOF>> /etc/libvirt/libvirtd.conf
listen_tcp=1
listen_tls=0
auth_tcp="none"
tcp_port="16509"
EOF
```

{% endtab %}
{% endtabs %}

* Run the following command to allow traffic for port 16509 on the host.

{% tabs %}
{% tab title="Bash" %}

```bash
iptables -I INPUT 1 -p tcp --dport 16509 -j ACCEPT
```

{% endtab %}
{% endtabs %}

* Run the following command to disable host key checking between the source host and destination host.

{% tabs %}
{% tab title="Bash" %}

```bash
cat <<-EOF>> /etc/ssh/ssh_config
Host <host ip address>
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOF
```

{% endtab %}
{% endtabs %}

* Run the following command to enable a shell for the pf9 user.

{% tabs %}
{% tab title="Bash" %}

```bash
chsh -s /bin/bash pf9
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Info**

**Note:** After running the chsh command, you might get the message, ‘shell not changed’. You can safely ignore this message.
{% endhint %}

* Configure all hypervisors to authenticate with each other via SSH Keys:
* Register the private ssh key in /opt/pf9/home/.ssh/id\_rsa on the host.
* Add the corresponding public ssh key to /opt/pf9/home/.ssh/authorized\_keys on the host.
* Change the permissions on the public ssh key and the private ssh key such that both files are owned by the user pf9:pf9group. The permissions for both of the public ssh key and the private ssh key must be "600" or read and write by owner only.
* Follow the operating system specific steps given below, based on your operating system:
* **Steps for CentOS**

1. Configure libvirtd such that it is able to listen for migration requests and able to connect to other libvirtd services.
2. Run the following command to add the text *LIBVIRTD\_ARGS="--listen"* to the end of /etc/sysconfig/libvirtd.

{% tabs %}
{% tab title="Bash" %}

```bash
cat <<-EOF >> /etc/sysconfig/libvirtd
LIBVIRTD_ARGS="--listen"
EOF
```

{% endtab %}
{% endtabs %}

3. Run the following command to restart the libvirtd service.

{% tabs %}
{% tab title="Bash" %}

```bash
service libvirtd restart
```

{% endtab %}
{% endtabs %}

* **Steps for Ubuntu**

1. Configure *libvirtd* such that it is able to listen for migration requests and is able to connect to other *libvirtd* services.
2. Run the following command to add the ***-l***&#x6F;ption to the *libvirtd\_opts*.

{% tabs %}
{% tab title="Bash" %}

```bash
vi /etc/default/libvirtd
libvirtd_opts="-l"
```

{% endtab %}
{% endtabs %}

3. Run the following command to restart the *libvirtd* service.

{% tabs %}
{% tab title="Bash" %}

```bash
systemctl restart libvirtd
```

{% endtab %}
{% endtabs %}

* Install the **sysfsutils** package. This is useful for resizing a VM or while performing a block migration.

Once the host preparation is complete, you are ready to perform a live migration of VM instances on Platform9 Managed OpenStack.

## How to perform a live migration?

Live migration can be done in one of the following two ways.

* Using Clarity
* Using OpenStack Command Line Interface (CLI)

The steps for each of the above-mentioned ways are explained in the sections below.

### Live Migration using Clarity

Live migration is a simple two-step process when it is performed by using the Clarity UI.

{% hint style="info" %}
**Info**

**Note:** Live migration through the Clarity UI is not enabled, by default. Contact Platform9 support to enable live migration in the Clarity UI, after you have completed the steps given above in this article.
{% endhint %}

Follow the steps given below to perform live migration through the Clarity UI.

1. Log in to Clarity as an administrator.
2. Click Instances and select the check box for the instance to migrate.
3. Click More on the toolbar above the list of instances.
4. Click the Migrate Instance option.

<figure><img src="https://2491133324-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTp3vmrOuO3dQilOzN2fE%2Fuploads%2Fgit-blob-0f58eb6b732f2e3b4740b581b0b2bc7fc20f3c24%2F1605215873.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2491133324-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTp3vmrOuO3dQilOzN2fE%2Fuploads%2Fgit-blob-60947e156507311594b9bf110c5ef68d7af6289e%2F1605215928.png?alt=media" alt=""><figcaption></figcaption></figure>

5. Select the host to migrate the instance and click Migrate VM.

When the migration is successful, the destination host name appears as the host for the migrated VM instance.

<figure><img src="https://2491133324-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTp3vmrOuO3dQilOzN2fE%2Fuploads%2Fgit-blob-7b1a550865e7d90ddab6d9e72ae51be0ae33a032%2F1605215943.png?alt=media" alt=""><figcaption></figcaption></figure>

### Live Migration using OpenStack (CLI)

Run the following command on the OpenStack CLI, to perform live migration.

{% tabs %}
{% tab title="Bash" %}

```bash
openstack server migrate --live <destination-host> <vm-name>
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Info**

**Note:** The destination host is the UUID or OpenStack ID of the compute node. It can be obtained from Clarity.
{% endhint %}
