Essential tasks and commands for maintaining a healthy Linux server
System Health Check
System Resources
Running Processes
Check System Resources
Monitor CPU, memory, and disk usage:
# Check memory usage
free -h
# Check disk usage
df -h
# Check CPU usage (interactive)
top
# Alternative to top
htop
Monitor Running Processes
Identify resource-intensive processes:
# Show processes sorted by CPU usage
ps aux --sort=-%cpu | head -10
# Show processes sorted by memory usage
ps aux --sort=-%mem | head -10
# Real-time process monitoring
top
# Find processes by name
pgrep -l nginx
Tip: Set up monitoring tools like Nagios, Zabbix, or Prometheus for automated health checks.
# Check UFW status
ufw status
# Check iptables rules
iptables -L -n -v
# Check open ports
netstat -tuln
ss -tuln
Important: Regularly review security logs and investigate any suspicious activity.
Service Management
Check Critical Services
Ensure essential services are running:
# Check service status
systemctl status nginx
systemctl status mysql
systemctl status apache2
# List all running services
systemctl list-units --type=service --state=running
# Check if service is enabled on boot
systemctl is-enabled nginx
Service Management Commands
# Restart a servicebr>
systemctl restart nginx
# Stop a servicebr>
systemctl stop nginx
# Start a servicebr>
systemctl start nginx
# Enable service on bootbr>
systemctl enable nginx
# Reload service configuration
systemctl reload nginx
Note: Use reload instead of restart when possible to avoid downtime.
Backup Verification
Check Backup Status
Ensure backups are running successfully:
# Check backup logs
tail -n 20 /var/log/backup.log
# Verify backup file integrity
sha256sum /backup/server-backup.tar.gz
# Check backup disk space
df -h /backup
# List recent backups
ls -la /backup
Test Restoration Process
Periodically verify backups can be restored:
# Extract test file from backup
tar -tzf /backup/server-backup.tar.gz | head -10
# Test restore to temporary location
mkdir /tmp/restore-test
tar -xzf /backup/server-backup.tar.gz -C /tmp/restore-test --strip-components=1 ./important-file.txt
Warning: Backups are useless if they can't be restored. Test regularly!
# Check logrotate status
logrotate --debug /etc/logrotate.conf
# Force log rotation
logrotate -f /etc/logrotate.conf
# Check disk usage of logs
du -sh /var/log/
# Find large log files
find /var/log -type f -size +100M
Tip: Set up log aggregation with tools like ELK Stack or Graylog for better log management.