查看redis.log,出现的具体错误如下:

1127:M 22 Apr 10:50:05.195 # Background saving error
12479:C 22 Apr 10:50:11.010 # Failed opening .rdb for saving: Permission denied
1127:M 22 Apr 10:50:11.109 # Background saving error
12485:C 22 Apr 10:50:17.024 # Failed opening .rdb for saving: Permission denied
1127:M 22 Apr 10:50:17.123 # Background saving error
12497:C 22 Apr 10:50:23.043 # Failed opening .rdb for saving: Permission denied
1127:M 22 Apr 10:50:23.142 # Background saving error
12504:C 22 Apr 10:50:29.058 # Failed opening .rdb for saving: Permission denied
1127:M 22 Apr 10:50:29.158 # Background saving error
12510:C 22 Apr 10:50:35.074 # Failed opening .rdb for saving: Permission denied
1127:M 22 Apr 10:50:35.173 # Background saving error
12518:C 22 Apr 10:50:41.088 # Failed opening .rdb for saving: Permission denied
1127:M 22 Apr 10:50:41.187 # Background saving error
12524:C 22 Apr 10:50:47.102 # Failed opening .rdb for saving: Permission denied
1127:M 22 Apr 10:50:47.201 # Background saving error
12533:C 22 Apr 10:50:53.015 # Failed opening .rdb for saving: Permission denied
1127:M 22 Apr 10:50:53.114 # Background saving error
12540:C 22 Apr 10:50:59.028 # Failed opening .rdb for saving: Permission denied

这个原因很诡异!

用我自己写的/etc/init.d/redis_init_script stop 结束进程会提示,

"pid XXXX does not exist, process is not running"

我的/etc/init.d/redis_init_script 脚本文件的配置如下:

#!/bin/sh
#
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/redis/run/redis_${REDISPORT}.pid
CONF="/etc/redis/redis_${REDISPORT}.conf"

case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac

开始怀疑是权限的问题,于是就将之前的/etc/redis/redis_6379.conf 配置中

关于dir /var/redis/data的目录进行粗暴的 chomd 777 操作,具体目录如下:

pidfile /var/redis/run/redis.pid
logfile "/var/redis/log/redis.log"
dbfilename dump.rdb
dir /var/redis/data

一顿操作后,发现错误仍在,赋权操作无效!

附上我的 /etc/redis/redis_6379.conf  配置文件吧!

[root@leekwen ~]# cat /etc/redis/redis_6379.conf
daemonize yes
pidfile /var/redis/run/redis.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel warning
logfile "/var/redis/log/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/redis/data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass wodemimanibuzhidaoisleekwen
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 200
auto-aof-rewrite-min-size 128mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

如果你也遇到这样的问题,赋权操作无效后,你可以尝试这个解决方法!

具体如下:

1、一定要使用 kill -9 来,关闭redis-server进程;

[root@leekwen ~]# ps aux |grep redis
root 13174 0.1 0.2 149084 9272 ? Ssl 11:00 0:02 redis-server *:6379
root 15402 0.0 0.0 112712 960 pts/1 R+ 11:32 0:00 grep --color=auto redis
[root@leekwen ~]# kill -9 13174

2、不要再用你的配置文件加载方法加载进程了。

直接输入命令来加载你的配置文件:# 具体目录根据你的配置文件不同,进行适当修改!

[root@test ~]# redis-server -h
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>

Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --slaveof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel

# 具体目录根据你的配置文件不同,进行适当修改!

[root@test ~]# redis-server /etc/redis/redis_6379.conf

3、再次查看redis的启动日志,应该就OK了。

问题可能出现在redis错误后,无法正常加载自定义的配置文件,而加载了默认的配置,导致数据持久化的写入权限失效!