Ubuntu16.04下Redis3.0.6无法启动:无法打开AOF文件(只读文件系统)
Let's break down this error—it means either Redis doesn't have write permissions to the directory where your redis-test.aof file lives, or the underlying file system is mounted as read-only. Here's how to fix it step by step:
1. Locate Redis's working directory
First, find where Redis is trying to create/write the AOF file. Check your Redis config file (usually /etc/redis/redis.conf) for the dir directive—this is the directory Redis uses for all data files.
If you want to quickly find it, use grep:
grep "^dir" /etc/redis/redis.conf
On Ubuntu 16.04, this will typically output dir /var/lib/redis (the default data directory).
2. Fix directory and file permissions
Redis runs as the redis user by default on Ubuntu. Make sure the data directory and any existing redis-test.aof file are owned by this user:
- First, check current ownership:
ls -ld /var/lib/redis # Replace with your actual dir path from step 1 ls -l /var/lib/redis/redis-test.aof # Run this only if the file already exists - If the owner is not
redis:redis, fix it with:sudo chown -R redis:redis /var/lib/redis - Ensure the directory has proper read/write permissions for the Redis user:
sudo chmod 750 /var/lib/redis
3. Check if the file system is read-only
If permissions look correct, verify that the partition hosting Redis's data directory isn't mounted as read-only. Run this command to view mount details:
mount | grep -v tmpfs
Look for the partition corresponding to your Redis directory (e.g., / if /var/lib/redis is on the root partition). If you see ro in the mount options, remount it as read-write:
sudo mount -o remount,rw / # Replace with your partition path if different
4. Verify Redis service configuration
If you're starting Redis via systemd (the default on Ubuntu 16.04), make sure the service runs Redis as the correct user. Open the service file:
sudo nano /lib/systemd/system/redis-server.service
Confirm there's a line that reads User=redis. If you made changes, reload systemd and restart Redis:
sudo systemctl daemon-reload sudo systemctl restart redis-server
If Redis still fails to start after these steps, check the Redis logs (usually /var/log/redis/redis-server.log) for more specific details—sometimes hidden issues like low disk space can trigger this error too.
内容的提问来源于stack exchange,提问作者Дмитрий Смирнов

