Creating a RAID-Z Drive for MySQL with ZFS on CentOS
Tags: zfs, raidz, centos, mysql
Published: 2019-06-05 13:38:49

---
title: Creating a RAID-Z Drive for MySQL with ZFS on CentOS
published: true
description: Get the reliability of RAID with the fast-restore snapshotting of ZFS
tags: ZFS, RAID-Z, CentOS, MySQL
---

_**Notes**: I wrote this documentation around 2013 as internal documentation at [Weever Apps](https://weeverapps.com/) for setting up RAID-Z as a method of making very quick backups of MySQL. Since we no longer use this setup and the documentation will never be used again, I felt it might be a good idea to post it out there for those who might find some use in it. Using RAID-Z for MySQL was amazing, and never failed us, and allowed hourly snapshot-based backups with no downtime. We've since moved to AWS RDS instances though._

_This will be part of multiple posts that combined will allow one to build a RAID-Z setup for MySQL. Or, at least it used to be able to! While this is geared towards Azure, I'm sure it would work anywhere._

_As I add more parts over the next few days I'll add links here._

# Article series

1. [Installing ZFS on CentOS](https://dev.to/rgeraldporter/installing-zfs-on-centos-2fkl)
1. **Creating a RAID-Z Drive for MySQL with ZFS on CentOS**
1. [Setting up RAID-Z for use in a MySQL Master-Master Replicator Pattern](https://dev.to/rgeraldporter/setting-up-raid-z-for-use-in-a-mysql-master-master-replicator-pattern-4eme)
1. [Creating a ZFS Image of a MySQL Data Directory](https://dev.to/rgeraldporter/creating-a-zfs-image-of-a-mysql-data-directory-dad)

# Instructions

First, let's make sure we have ZFS installed.

```sh
sudo su
lsmod | grep -i zfs
```

Next, in Azure, shut down the server then attach all the disks you'd like to use for RAID-Z; minimum should be a 2-core machine using the max 4 disks. All disks should be the same size, though this may not be a requirement for RAID-Z.

For this example, I'll be making 4 disks with 300 GB each. Give them names so it is clear that they are RAID-Z disks, by making sure raid-z is somewhere in the name.

Each disk should take about a minute to set up.

Start the machine up when the final disk is added.

Once booted back up, check the status of the disks (be sure to `sudo su`):

```sh
fdisk -l | grep GB
```

The following command will create a zpool called `sqlstorage` and mount it to `/etc/mysql`:

```sh
zpool create -m /var/lib/mysql sqlstorage raidz -f sdc sdd sde sdf
```

Note that the minimum for `raidz` is two disks. For double-parity `raidz` known as `raidz2`, you need a minimum of 3 disks. For triple, 4 disks are required. Use the highest level RAID-Z possible with the setup.

To check the zpool status:

```sh
zpool status
```

To make sure it's mounted:

```sh
mount | grep zfs
```

And to confirm the storage size:

```sh
df -h | grep sqlstorage
```

We also want to make sure the drive will mount on bootup:

```sh
echo "zfs mount sqlstorage" >> /etc/rc.local
```

Reboot, and you can then repeat the above checks to ensure it is working on boot.

_Is something badly out of date? Did this work for you? Please post a comment to help others who might use this for guidance._