redis 主从同步配置方案 博客分类: 数据库
程序员文章站
2024-03-06 18:49:08
...
今天研究了redis主从同步部分的配置,在这里留个备忘!
闲话少续,上配置!
这是redis-master.conf
这是redis-slave.conf
主要有几点需要注意:
1、 memory设置问题
需要执行脚本
2、要保证主配置中 slave-serve-stale-data yes
3、slaveof 127.0.0.1 6379
masterauth ooxxoo
密码一定要设置正确哦!
另外:由于redis rdb模式下会有部分数据处于未落地状态,停redis前最好执行
/usr/local/redis/redis-cli -h 127.0.0.1 -p 6379 -a pwd bgsave 保存下数据,然后再停止redis线程
闲话少续,上配置!
这是redis-master.conf
daemonize yes pidfile /var/run/redis-master.pid port 6379 timeout 0 loglevel verbose logfile stdout databases 16 save 60 100 rdbcompression yes dbfilename dump-master.rdb dir /usr/local/redis/data slave-serve-stale-data yes requirepass ooxxoo appendonly no appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb slowlog-log-slower-than 10000 slowlog-max-len 128 maxclients 128 maxmemory 1gb vm-enabled no vm-swap-file /tmp/redis.swap vm-max-memory 0 vm-page-size 32 vm-pages 134217728 vm-max-threads 4 hash-max-zipmap-entries 512 hash-max-zipmap-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 activerehashing yes
这是redis-slave.conf
daemonize no pidfile /var/run/redis-slave.pid port 7379 timeout 0 loglevel verbose logfile stdout databases 16 save 60 100 rdbcompression yes dbfilename dump-slave.rdb dir /usr/local/redis/data slave-serve-stale-data yes slaveof 127.0.0.1 6379 masterauth ooxxoo appendonly no appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb slowlog-log-slower-than 10000 slowlog-max-len 128 maxclients 128 maxmemory 1gb vm-enabled no vm-swap-file /tmp/redis.swap vm-max-memory 0 vm-page-size 32 vm-pages 134217728 vm-max-threads 4 hash-max-zipmap-entries 512 hash-max-zipmap-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 activerehashing yes
主要有几点需要注意:
1、 memory设置问题
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
需要执行脚本
# echo vm.overcommit_memory=1 >> /etc/sysctl.conf # sysctl vm.overcommit_memory=1
2、要保证主配置中 slave-serve-stale-data yes
3、slaveof 127.0.0.1 6379
masterauth ooxxoo
密码一定要设置正确哦!
另外:由于redis rdb模式下会有部分数据处于未落地状态,停redis前最好执行
/usr/local/redis/redis-cli -h 127.0.0.1 -p 6379 -a pwd bgsave 保存下数据,然后再停止redis线程