Monitoring Ceph cluster health and handling a failed OSD

  1. Goal
  2. Preparation
  3. Steps
  4. 1. Read the overall picture
  5. 2. Read the OSD state
  6. 3. Read the PG state
  7. 4. Planned maintenance: use `noout`
  8. 5. Replace a failed OSD (keeping the ID)
  9. Verification
  10. Common mistakes
  11. Summary
  12. References

Goal

After this article you can read the state of a Ceph cluster, understand the common OSD and PG states, and know the steps to replace a failed OSD disk without losing data.

The background on OSDs, PGs and pools is in Ceph architecture: MON, OSD, MGR and how CRUSH places data; if you do not yet tell RBD, CephFS and RGW apart, see Ceph's three storage types: RBD, CephFS and RGW, and which to choose.

Preparation

Steps

Steps

1. Read the overall picture

ceph -s              # cluster state: health, MON, MGR, OSD, PG
ceph health detail   # list each warning in detail

The Ceph documentation notes that HEALTH_OK is not always available immediately, for example right after restarting the cluster or adding or removing an OSD; a temporary state is normal.

Persistent problems, such as inconsistent PG data, raise the PG_DAMAGED and OSD_SCRUB_ERRORS warnings at HEALTH_ERR level and need repair.

2. Read the OSD state

ceph osd stat   # total OSDs, how many are up, how many are in
ceph osd tree   # the OSD tree, to find which machine has a down OSD

Each OSD has two independent pairs of states: up (the process is running) or down; in (used to hold data) or out.

According to the documentation, an OSD that is down but still in means the cluster is not healthy.

A down OSD is marked out by the Monitors only after a delay, by default mon_osd_down_out_interval of 600 seconds. This delay avoids a mass rebuild just because a machine restarted briefly.

3. Read the PG state

ceph pg stat

The desired state is active+clean. The degraded state means some objects do not yet have as many copies as the pool requires, usually because an OSD is down.

According to the documentation, an active+degraded PG can still serve reads and writes; the cluster is running with less redundancy, so this is the time to act quickly, but it is not yet data loss.

4. Planned maintenance: use `noout`

If you deliberately shut a machine down for short maintenance, tell Ceph in advance so it does not rebuild data:

ceph osd set noout     # stop the Monitors from marking OSDs out automatically
# ... maintenance, reboot the machine ...
ceph osd unset noout   # remember to clear the flag when done

Forgetting unset noout is a common mistake: later, when an OSD really fails, the cluster will not rebuild the data on its own.

5. Replace a failed OSD (keeping the ID)

The following steps follow the "Replacing an OSD" section of the Ceph documentation for clusters not managed by cephadm. Instead of removing the OSD entirely, we keep its ID and its CRUSH entry.

# a) if the OSD is still "in", mark it out so data moves away
ceph osd out {id}

# b) wait until it is safe to destroy the OSD
while ! ceph osd safe-to-destroy osd.{id} ; do sleep 10 ; done

# c) stop the process on the host (destroy requires the OSD to be down)
sudo systemctl stop ceph-osd@{id}

# d) destroy the OSD but keep the ID
ceph osd destroy {id}

Warning: ceph osd destroy removes the OSD's CephX keys and configuration data; for an encrypted OSD, the data on the old disk can never be read again.

Run it only after safe-to-destroy reports it is safe.

After inserting the new disk (for example /dev/sdX), prepare and activate it with ceph-volume:

# WARNING: zap erases all data on the disk; check the device name very carefully
ceph-volume lvm zap --destroy /dev/sdX

# create the new OSD with the destroyed ID, combining prepare and activate
ceph-volume lvm create --osd-id {id} --data /dev/sdX

If you need to remove an OSD entirely instead of replacing it, the documentation describes: ceph osd out {id}, stop the daemon, then ceph osd purge {id}.

The purge command checks safe-to-destroy first; the --force flag skips that check and can cause permanent data loss, so do not use it unless you fully understand the consequences.

Verification

Common mistakes

Summary

Check regularly with ceph -s and ceph health detail, understand the up/down and in/out states, use noout for planned maintenance, and replace disks in the order out → safe-to-destroy → destroy.

To be alerted automatically instead of checking by hand, enable the MGR prometheus module (command ceph mgr module enable prometheus;

according to the documentation it listens on port 9283 at the /metrics path by default) and set up alerts as in Alerting with Prometheus and Alertmanager:how metrics differ from logs.

This article only explains the procedure according to the documentation; on a real cluster, check the documentation for your exact Ceph release and rehearse in a non-critical environment first.

References

Monitoring Ceph cluster health and handling a failed OSD