Knowledge
Monitoring Ceph cluster health and handling a failed OSD
- Start every check with
ceph -sandceph health detail; the goal isHEALTH_OKand PGs in theactive+cleanstate. - An OSD that is
downbut stillinsignals a problem; after 600 seconds by default the Monitors mark itoutand the data starts to be rebuilt elsewhere. - Replace a failed disk in the right order (
out→safe-to-destroy→destroy→ prepare the new disk) and do not use--forceuntil you understand the consequences.
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
- A machine with cluster admin rights (the admin keyring), for example inside
cephadm shellon an admin node. - Know what the cluster was deployed with: this article describes the manual procedure from the Ceph documentation for clusters not managed by cephadm. For cephadm clusters, the documentation tells you to use the orchestrator to remove OSDs; read that section first.
- Physical access or someone on site at the data center to swap the disk.
- Check capacity: removing an OSD pushes its data onto the other OSDs, so the cluster must not be near its
full_ratio.
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
ceph osd tree: the new OSD appears on the right host and isupandin.ceph -sorceph -w: watch the data being rebuilt; when finished, the PGs return toactive+clean.ceph health detail: no remaining warnings about the OSD you just replaced.
Common mistakes
- Forgetting to clear the
nooutflag: the cluster does not self-heal when an OSD really fails. - Cluster too full when removing an OSD: data moving to other OSDs can push them past the full threshold; check capacity first.
- PGs stuck in
active+remappedon a small cluster: the documentation suggests runningceph osd in {id}and thenceph osd crush reweight osd.{id} 0instead of leaving the OSDout. - Using
--forceorzapon the wrong disk: unrecoverable data loss. - Looking only at
HEALTH_OK: also follow capacity trends and the number ofupandinOSDs.
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.