项目需要迁移redis缓存 需要从服务器 A 将 redis缓存数据迁到B
只需在B(从) redis.conf 配置文件中添加:
205 # slaveof <masterip> <masterport>
206 slaveof 10.3.0.25 7369
207 # If the master is password protected (using the "requirepass" configuration
208 # directive below) it is possible to tell the slave to authenticate before
209 # starting the replication synchronization process, otherwise the master will
210 # refuse the slave request.
211 #
212 # masterauth <master-password>
213 masterauth 5vwJ4AghYNH&W4RWejfieo69C2ZPp%r@
数据量比较到350多万条 修改超时时间
302 # repl-timeout 60
303 repl-timeout 600
否则会报以下错误:
[96842] 20 Dec 10:50:04.013 * Connecting to MASTER 10.3.0.25:7369
[96842] 20 Dec 10:50:04.014 * MASTER <-> SLAVE sync started
[96842] 20 Dec 10:50:04.014 * Non blocking connect for SYNC fired the event.
[96842] 20 Dec 10:50:04.014 * Master replied to PING, replication can continue...
[96842] 20 Dec 10:50:04.014 * (Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.
[96842] 20 Dec 10:50:04.015 * Partial resynchronization not possible (no cached master)
[96842] 20 Dec 10:50:04.015 # Unexpected reply to PSYNC from master: -NOAUTH Authentication required.
[96842] 20 Dec 10:50:04.015 * Retrying with SYNC...
[96842] 20 Dec 10:50:04.015 # MASTER aborted replication with an error: NOAUTH Authentication required.
正常的日志:
[qjzh@Logsvr bin]$ ./redis-server /etc/redis/7369.config &
[1] 98824
[qjzh@Logsvr bin]$ _._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.19 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 7369
| `-._ `._ / _.-' | PID: 98824
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[98824] 20 Dec 11:05:24.341 # Server started, Redis version 2.8.19
[98824] 20 Dec 11:05:24.341 # 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.
[98824] 20 Dec 11:05:24.341 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
[98824] 20 Dec 11:05:24.341 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[98824] 20 Dec 11:05:24.341 * The server is now ready to accept connections on port 7369
[98824] 20 Dec 11:05:25.341 * Connecting to MASTER 10.3.0.25:7369
[98824] 20 Dec 11:05:25.342 * MASTER <-> SLAVE sync started
[98824] 20 Dec 11:05:25.343 * Non blocking connect for SYNC fired the event.
[98824] 20 Dec 11:05:25.344 * Master replied to PING, replication can continue...
[98824] 20 Dec 11:05:25.344 * Partial resynchronization not possible (no cached master)
[98824] 20 Dec 11:05:25.362 * Full resync from master: c15d7e34c96d2e79cae4180498fe747f6b66fda6:1
[98824] 20 Dec 11:05:41.674 * MASTER <-> SLAVE sync: receiving 659986364 bytes from master
[98824] 20 Dec 11:05:52.763 * MASTER <-> SLAVE sync: Flushing old data
[98824] 20 Dec 11:05:52.764 * MASTER <-> SLAVE sync: Loading DB in memory
[98824] 20 Dec 11:06:02.723 * MASTER <-> SLAVE sync: Finished with success
[98824] 20 Dec 11:10:25.091 * 10 changes in 300 seconds. Saving...
[98824] 20 Dec 11:10:25.094 * Background saving started by pid 99147
[99147] 20 Dec 11:10:41.719 * DB saved on disk
[99147] 20 Dec 11:10:41.720 * RDB: 174 MB of memory used by copy-on-write
[98824] 20 Dec 11:10:41.765 * Background saving terminated with success
[98824] 20 Dec 11:15:42.051 * 10 changes in 300 seconds. Saving...
[98824] 20 Dec 11:15:42.054 * Background saving started by pid 99515
[99515] 20 Dec 11:15:59.061 * DB saved on disk
[99515] 20 Dec 11:15:59.061 * RDB: 350 MB of memory used by copy-on-write
[98824] 20 Dec 11:15:59.136 * Background saving terminated with success
redis客户端工具:
RedisDesktopManager
#缓存文件名
# The filename where to dump the DB
dbfilename portal_cache.rdb
#文件保存的路径
# Note that you must specify a directory here, not a file name.
dir /data/redisdb_7369