redis 不遵循 redis.conf 设置

redis 不遵循 redis.conf 设置

我正在运行 redis 服务器,并在 redis.conf 文件中将 dir 设置为/var/lib/redis并将 dbfilename 设置为 ,dump.rdb但我注意到 redis 开始产生以下错误

120844:C 23 Sep 02:59:31.098 # Failed opening .rdb for saving: Read-only file system
42657:M 23 Sep 02:59:31.198 # Background saving error
42657:M 23 Sep 02:59:37.018 * 1 changes in 900 seconds. Saving...
42657:M 23 Sep 02:59:37.019 * Background saving started by pid 120868
120868:C 23 Sep 02:59:37.019 # Failed opening .rdb for saving: Read-only file system
42657:M 23 Sep 02:59:37.119 # Background saving error
42657:M 23 Sep 02:59:43.035 * 1 changes in 900 seconds. Saving...
42657:M 23 Sep 02:59:43.036 * Background saving started by pid 120869
120869:C 23 Sep 02:59:43.036 # Failed opening .rdb for saving: Read-only file system
42657:M 23 Sep 02:59:43.136 # Background saving error
42657:M 23 Sep 02:59:49.052 * 1 changes in 900 seconds. Saving...
42657:M 23 Sep 02:59:49.052 * Background saving started by pid 120895
120895:C 23 Sep 02:59:49.053 # Failed opening .rdb for saving: Read-only file system
42657:M 23 Sep 02:59:49.153 # Background saving error
42657:M 23 Sep 02:59:55.067 * 1 changes in 900 seconds. Saving...
42657:M 23 Sep 02:59:55.067 * Background saving started by pid 120939

然后我进入 redis-cli 使用以下命令修复此问题

127.0.0.1:6379> config set dbfilename dump.rdb
OK
127.0.0.1:6379> config set dir /var/lib/redis
OK
127.0.0.1:6379> exit

然后我现在检查 redis 日志,它工作正常

42657:M 23 Sep 03:00:43.011 * Background saving started by pid 121168
121168:C 23 Sep 03:00:43.011 # Failed opening .rdb for saving: Read-only file system
42657:M 23 Sep 03:00:43.122 # Background saving error
42657:M 23 Sep 03:00:49.035 * 1 changes in 900 seconds. Saving...
42657:M 23 Sep 03:00:49.036 * Background saving started by pid 121170
121170:C 23 Sep 03:00:49.233 * DB saved on disk
121170:C 23 Sep 03:00:49.233 * RDB: 0 MB of memory used by copy-on-write
42657:M 23 Sep 03:00:49.236 * Background saving terminated with success

几分钟后,redis 又回到了之前的错误,请注意..redis.conf 文件已经设置了 dir 和 dbfilename,所以不确定发生了什么。

我该如何修复这个错误?不确定这是否是一个常见的错误。我正在运行 redis redis-server --version

Redis server v=3.0.6 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=687a2a319020fa42

PS 我正在运行一些使用 gunicorn 运行的 django 应用程序,这些应用程序使用 redis 数据库,因此...只要 redis 工作正常,应用程序就可以正常工作,一旦 redis 开始出现上述错误,应用程序就会开始出现 502 错误,并且我收到以下错误

 [error] 1808#1808: *14662 upstream prematurely closed connection while reading response header from upstream, client: 172.xxx.xxx.xxx, server: xxxxx.com, request: "GET /U/example-url/ HTTP/1.1", upstream: "http://unix:/mnt/http/nginx/xxxxx.com/run/gunicorn.sock:/U/example-url/", host: "xxxxx.com"

所以不确定是应用程序杀死了 redis 还是 redis 杀死了应用程序..无论如何,为什么 redis 设置会被杀死以及如何保留 dir 和 dbfilename 设置?

谢谢

为了解决这个问题,当 redis 再次放弃时,我总是每隔几分钟就这样做一次

:~# redis-cli
127.0.0.1:6379> config set dir /var/lib/redis
OK
127.0.0.1:6379> config set dbfilename dump.rdb
OK
127.0.0.1:6379> exit

那么我该如何持久保存它,以便我不必每次都这样做来使用 redis 数据库来启动 django 网站?

更新:

以下是 redis-cliinfo命令的输出

127.0.0.1:6379> info
# Server
redis_version:3.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:687a2a319020fa42
redis_mode:standalone
os:Linux 4.4.0-133-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:5.3.1
process_id:3957
run_id:dfac396ca05cb307c830abcdcd10b916f536b6fd
tcp_port:6379
uptime_in_seconds:263
uptime_in_days:0
hz:10
lru_clock:10965575
config_file:/etc/redis/redis.conf

# Clients
connected_clients:8
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:4663560
used_memory_human:4.45M
used_memory_rss:7491584
used_memory_peak:4726624
used_memory_peak_human:4.51M
used_memory_lua:36864
mem_fragmentation_ratio:1.61
mem_allocator:jemalloc-3.6.0

# Persistence
loading:0
rdb_changes_since_last_save:84
rdb_bgsave_in_progress:0
rdb_last_save_time:1537691968
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok

# Stats
total_connections_received:44
total_commands_processed:325
instantaneous_ops_per_sec:0
total_net_input_bytes:25453
total_net_output_bytes:652106
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:84
evicted_keys:0
keyspace_hits:88
keyspace_misses:109
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0

# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:0.08
used_cpu_user:0.23
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace
db0:keys=10,expires=0,avg_ttl=0
db5:keys=2,expires=2,avg_ttl=32239229
db6:keys=14432,expires=0,avg_ttl=0
db8:keys=10,expires=10,avg_ttl=1821207715
db9:keys=873,expires=0,avg_ttl=0

相关内容