Quick Summary: Deep dive into a highly specific NFSv4 statd issue on /var/log leading to inode exhaustion and systemd-journald deadlocks during high service rest...
Alright, listen up. You've hit that special hell where your systemd services are failing to start, journalctl is showing 'No space left on device' for /var/log, but df -h says you've got *plenty* of disk space. Your application logs stop mid-sentence, and everything just… grinds to a halt. You restart systemd-journald and it *seems* okay for a bit, then BAM, same issue. If df -i reveals 100% inode usage on /var/log and you're running NFSv4 mounts, congratulations, you've found the ghost in the machine.
This isn't theoretical; this is a hard-earned lesson from environments where historical architectural choices clash violently with modern system behavior. Specifically, the dance between systemd-journald, NFSv4 client-side locking, and inode management on older CentOS/RHEL 7.x systems. It’s nasty.
Trigger Environments
| Operating System | NFS Version | Problem Trigger | Observed Symptoms |
|---|---|---|---|
| CentOS 7.x, RHEL 7.x, Fedora (older kernel/systemd) | NFSv4 (especially with statd running on client) |
High frequency of systemd service restarts, especially those writing heavily to STDOUT/STDERR (e.g., microservices in unstable states, rapid CI/CD deployments). |
|
Initial Troubleshooting: Verify the Obvious (and not-so-obvious)
First, rule out the simple stuff:
- Verify Inode Exhaustion: Run
df -i /var/log. If it's 100%, you're on the right track. If not, this isn't your problem. Also, checklsof +L1to find deleted files still held open by processes. This can sometimes free up inodes, but it's often a symptom, not the root cause here. - Check
journaldStatus:systemctl status systemd-journald. Is it dead? Restarting? Spewing errors? Dig deeper withjournalctl -xeu systemd-journald. Look for clues like 'Failed to write entry' or 'Disk full'. - NFS Client State: This is where it gets spicy. Check
rpcinfo -p localhost | grep statdandsystemctl status nfs-statd. Thestatddaemon keeps track of server/client states for NFSv4 file locking. If it's unstable, you're in for a ride. - Identify Open Files:
lsof | grep "/var/log" | wc -lgives you a count. More importantly,lsof | grep -E "(statd|nfsd|lockd)"might show NFS-related processes holding a disproportionate number of file handles, especially to journal files. When you runlsof | grep "/var/log", don't just count. Look for *why* files are open. Are they processes that are supposed to be long-running, or orphaned child processes?systemd-journalditself should have files open, but a massive number of small.journalfiles, especially if they're marked as(deleted)but still held, is a red flag. This points directly tojournaldstruggling to unreference files, often due to underlying filesystem issues – in this case,NFSv4locking.
The Root Cause
This is where the architecture bites you. Shipping /var/log over NFSv4 on CentOS 7.x or similar, especially with default journald settings, is a recipe for disaster. The systemd-journald process, under high logging load or during frequent service restarts, creates and rotates journal files at a frantic pace. Each journal file, even small ones, consumes an inode. The critical flaw lies in how NFSv4 client-side locking (managed by statd and lockd) interacts with journald's rapid file creation/deletion and fdatasync calls.
statd (the status monitor daemon) maintains state between clients and servers. When journald creates or removes many files, or when it hits an error trying to write to the NFS mount, statd can get overwhelmed trying to synchronize file locks and states. This isn't just about disk space; it's about the metadata operations. Each file operation needs to be tracked. If the statd process on the client side (or server, but usually client-side nfs-statd or rpc.statd) falls behind or enters an unresponsive state, it delays journald's ability to finalize file operations. This can lead to a backlog of open file descriptors or temporary files not being properly cleaned up, even if journald *thinks* it's done with them. Result? inode exhaustion, because the filesystem reports them as "in use" by processes that are effectively deadlocked with statd.
The CentOS 7.x systemd/NFSv4 stack had particular quirks. Newer systemd versions and kernels have improved NFS interaction, but if you're stuck on an older version, you're inheriting this mess. The problem escalates when services go into a crash-loop. Each restart cycle forces journald to re-initialize and potentially create new logging contexts, exacerbating the inode pressure. This isn't just a nuisance; it's a stability nightmare that can propagate. Critical services fail to log, making debugging impossible, leading to further cascading failures. It’s a systemic breakdown, often manifesting deceptively as a ‘disk full’ error. This is akin to the challenges faced with shared storage in Kubernetes environments, especially when NFSv4 client-side issues manifest as LOCKD_OVERLOAD errors, a topic explored in "NFSv4 LOCKD_OVERLOAD on K8s Pod Eviction with CentOS 7 & SELinux: The Ghost in the Machine". Understanding the nuances of NFSv4 locking is crucial.
Immediate Mitigation & The REAL Fix
You need to stabilize the system NOW, and then fix it properly. Stop patching bullet holes with duct tape.
Step-by-step resolution (Use with extreme caution!):
# WARNING: EXECUTE THESE COMMANDS WITH CAUTION AND UNDERSTANDING.
# ONLY USE IF /VAR/LOG IS ON NFSv4 AND YOU'RE EXPERIENCING INODE EXHAUSTION.
# THIS ASSUMES YOU HAVE IDENTIFIED THE ISSUE AS DESCRIBED.
# 1. Stop systemd-journald to prevent further writes and attempt to clear locks.
# This is critical to prevent new file creations and allow the system to breathe.
sudo systemctl stop systemd-journald
# 2. Restart NFS client-side daemons to clear their state (especially statd).
# This can sometimes unstick stale file handles/locks. If your system is heavily
# reliant on NFS, this might cause temporary disruption to other NFS mounts.
sudo systemctl restart nfs-client.target # Restarts all NFS client services including statd, lockd
sudo systemctl restart rpcbind # Ensure rpcbind is healthy, often a prerequisite for statd
# 3. Clean up old journal files to free inodes (move, don't delete initially).
# Identify the journal directory for your system (usually /var/log/journal/<uuid>)
JOURNAL_DIR=$(find /var/log/journal -maxdepth 1 -type d -name "????????????????????????????????")
if [ -n "$JOURNAL_DIR" ] && [ -d "$JOURNAL_DIR" ]; then
echo "Found journal directory: $JOURNAL_DIR"
sudo mkdir -p /tmp/journal_backup # Create a temporary local backup location
# Move older journal files. Adjust 'mmin +1440' (older than 24 hours) as needed.
# This example moves files older than 1 day to free up inodes. This is a temporary measure.
sudo find "$JOURNAL_DIR" -type f -name "*.journal" -mmin +1440 -exec mv {} /tmp/journal_backup/ \;
echo "Moved old journal files to /tmp/journal_backup/"
else
echo "Could not find journal directory. Manual cleanup might be needed."
fi
# 4. Reconfigure journald to be less aggressive (important for immediate relief & long-term stability).
# Ensure these lines are present/modified in /etc/systemd/journald.conf.
# These settings limit the total disk space and number of files journald will use.
sudo sed -i '/^#\?SystemMaxUse=/c\SystemMaxUse=1G' /etc/systemd/journald.conf
sudo sed -i '/^#\?SystemKeepFree=/c\SystemKeepFree=500M' /etc/systemd/journald.conf
sudo sed -i '/^#\?MaxFiles=/c\MaxFiles=5' /etc/systemd/journald.conf
echo "Updated /etc/systemd/journald.conf settings."
# 5. Start systemd-journald again.
sudo systemctl start systemd-journald
# 6. Verify inode usage and system state.
echo "Current inode usage on /var/log after remediation attempt:"
df -i /var/log
echo "Monitor journald and application services for stability."
journalctl -f -u systemd-journald
The Permanent Solution (No Excuses):
- NEVER put
/var/logon NFS. This cannot be stressed enough. It introduces unnecessary complexity and potential for deadlocks and performance issues. Local storage for logs is non-negotiable for system stability. - If centralized logging is required: Implement a robust log shipping solution. Tools like Fluentd, Filebeat, Vector, or a dedicated
rsyslogclient-server setup should forward logs from local disk to a central logging cluster (ELK Stack, Loki, Splunk). This decouples your application and system logging from the underlying filesystem. - Migrate
/var/logto local storage: Provision anext4or XFS partition specifically for/var/log. Carefully move existing logs and reconfigure mounts. This is the only proper fix for this specific architectural flaw.
The lesson here is profound: architecture matters. Shortcuts on critical infrastructure components, like putting /var/log on NFS, inevitably lead to complex, opaque failures. Building resilient systems often means making pragmatic choices about where data lives and how it's accessed, principles that are equally vital whether you're dealing with NFSv4 deadlocks or optimizing data retrieval for large language models, as discussed in "Ollama: Local LLMs Unleashed – A Pragmatic Technical Review", where local resource management is key to performance. Don't let your systems become another cautionary tale.
Comments
Post a Comment