Installing ZFS on CentOS
Tags: zfs, centos, azure
Published: 2019-06-04 13:44:34

---
title: Installing ZFS on CentOS
published: true
description: Upgrading the filesystem on CentOS to take advantage of ZFS snapshots on Azure
tags: ZFS, CentOS, Azure
---

_**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._

# Article series

1. **Installing ZFS on CentOS**
1. [Creating a RAID-Z Drive for MySQL with ZFS on CentOS](https://dev.to/rgeraldporter/creating-a-raid-z-drive-with-zfs-on-centos-3484)
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)

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

# Creating the VM

First, create a VM in Azure using the CentOS image. It needs to be a minimum of 2 cores to be set up with RAID-Z.

Make sure it is inside the Cloud Service of the application server VMs you wish to connect it to.

User name for the initial user should be `azureadmin`, but you should be sure to change the password and document it somewhere safe.

If you wish to make use of Load Balancing, be sure to create an Availability Set when asked, or select one that it will be used with if we're adding another load balanced instance.

# After logging in via SSH...

First we need to be sudo.

```sh
sudo su
```

Next we're going to need to get ZFS installed, which will require some set up. First, we need to disable SELinux for this to work, at least until ZFS software gets updated to support it (or visa versa). First command disables it for now, second disables it for good.

```sh
echo 0 >/selinux/enforce
vim /etc/selinux/config
```

And change `SELINUX=` to `permissive`.

Next we need some new kernel libraries in yum so we need to edit the config file to remove kernel exceptions.

```sh
vim /etc/yum.conf
```

Find the line with `exclude=kernel*` and comment it out with a hash (`#`).

Then we're going to install some stuff.

```sh
yum groupinstall "Development Tools"
yum install kernel-devel zlib-devel libuuid-devel libblkid-devel libselinux-devel parted lsscsi nano mdadm bc
```

Next go to [zfsonlinux.org](zfsonlinux.org) and click on CentOS link, which should have commands like these two:

```sh
sudo yum localinstall --nogpgcheck http://archive.zfsonlinux.org/epel/zfs-release-1-3.el6.noarch.rpm
sudo yum install zfs
```

This will take a few minutes.

Now we'll load the module.

```sh
modprobe zfs
```

To make sure it's there and working, we'll check using this command.

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

Let's set it up so it'll load on boot.

```sh
vim /etc/sysconfig/modules/zfs.modules
```

Paste into this file:

```sh
#!/bin/sh

if [ ! -c /dev/zfs ] ; then
        exec /sbin/modprobe zfs >/dev/null 2>&1
fi
```

Save the file (:wq) and then we'll do this:

```sh
chmod +x /etc/sysconfig/modules/zfs.modules
```

Let's now test that it works, and reboot.

```sh
reboot
```

Then make sure we get output from:

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

If so, ZFS is installed!

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