This page is for Dedicated Servers on which you have root access and AlmaLinux or Rocky Linux on a software RAID, for example RAID 1: two disks hold the same data, so the server keeps running when one of them fails. That only helps if you notice the failure and get the disk replaced before the second one fails too. We checked the RAID of a dedicated server installed with AlmaLinux 9 and software RAID 1, and tested the alerts with a test RAID 1 in test machines with Rocky Linux 9 and AlmaLinux 10; run the commands as root.


1. Is My RAID Healthy?

cat /proc/mdstat

Each array is one block. [2/2] [UU] means: two of two disks work, both are Up. After a disk failure, an array shows for example [2/1] [_U] and the failed disk with (F). More details for one array (use the names from /proc/mdstat):

mdadm --detail /dev/md5

A healthy array shows State : clean and lists all its disks as active sync; after a failure it shows clean, degraded and the disk as faulty.

A line such as check = 5.4% is not a fault: AlmaLinux and Rocky Linux compare the disks of each array every Sunday at 01:00 (raid-check.timer, settings in /etc/sysconfig/raid-check). On big disks this check takes some hours.

2. The RAID Monitor Needs a Settings File

The monitor mdmonitor sends the alerts. It only starts if the file /etc/mdadm.conf exists. Check both:

cat /etc/mdadm.conf
systemctl status mdmonitor

The file must list your arrays in ARRAY lines. After an installation of AlmaLinux 9 with software RAID 1, it lists all arrays (for example md2 to md5), and mdmonitor is already running: it writes every event to the system log (journalctl -t mdadm), but sends no e-mail until you set an address in step 3. If the file does not exist, create it from the running arrays:

mdadm --detail --scan > /etc/mdadm.conf

If the file exists, do not overwrite it; keep a copy before you change it: cp /etc/mdadm.conf /root/mdadm.conf.backup.

3. Send the Alerts by E-mail

Your server needs a way to send mail. The simplest is msmtp, which sends through an ordinary e-mail account, for example the one of your e-mail provider. You need its SMTP server, port, user name and password; your provider lists them in its help pages. msmtp comes from EPEL (see Install and Update Software on AlmaLinux and Rocky Linux):

dnf install epel-release
dnf install msmtp

The package also makes msmtp the server's sendmail, which mdadm uses to send its alerts. Create /etc/msmtprc with nano, with your own details:

defaults
auth on
tls on
tls_trust_file /etc/pki/tls/certs/ca-bundle.crt
logfile /var/log/msmtp.log

account alerts
host smtp.example.com
port 465
tls_starttls off
from server@example.com
user server@example.com
password your-mailbox-password

account default : alerts

For port 587, write port 587 and tls_starttls on instead. The file holds a password, so let only root read it:

chmod 600 /etc/msmtprc

Then add two lines at the end of /etc/mdadm.conf, with nano and each on a line of its own: where the alerts go, and from which address:

MAILADDR you@example.com
MAILFROM server@example.com

Send one test e-mail for one array, look at the log of msmtp, and start the monitor:

mdadm --monitor --oneshot --test /dev/md5
tail /var/log/msmtp.log
systemctl restart mdmonitor

The log line of a delivered e-mail ends with exitcode=EX_OK. When a disk fails, the running monitor sends e-mails such as Fail event on /dev/md9 and FailSpare event on /dev/md9. It checks the arrays every 60 seconds, so an alert can take up to about a minute. Every event is also written to the system journal: journalctl -t mdadm.

ℹ Your own alert script

On Ubuntu, mdadm can also run a script of your own for every event (PROGRAM in mdadm.conf). On AlmaLinux and Rocky Linux SELinux limits what such a script may do: a script started by the monitor is not allowed to write its own log file in /var/log, although the same script started by hand can. E-mail through sendmail works without any change, so we recommend it here.

4. After a Disk Was Replaced

Our support replaces a failed disk in your dedicated server. Tell them which one has failed: lsblk -d -o NAME,SIZE,SERIAL lists the serial numbers. Taking the failed disk out of the arrays, copying the partition layout to the new disk and adding it back work as on Ubuntu: Check the Software RAID of Your Linux Server and Replace a Failed Disk, step 5. The tool sgdisk used there is in the package gdisk: dnf install gdisk.


Good to Know


Related Guides

View all AlmaLinux and Rocky Linux guides

Was this answer helpful? 0 Users Found This Useful (0 Votes)