vim /redis_node_test/6382/redis.conf
requirepass 123456 //主服务器连接密码
vim /redis_node_test/6383/redis.conf
slaveof 127.0.0.1 6382
masterauth 123456
redis-server /redis_node_test/6382/redis.conf
redis-server /redis_node_test/6383/redis.conf
redis-cli -p 6382
127.0.0.1:6382> info
NOAUTH Authentication required.
报错
redis-cli -p 6382 -a 123456
127.0.0.1:6382> info
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6383,state=online,offset=729,lag=0
这样就不报错了
有时候主从数据可能会不一致,因为redis是异步写入磁盘的,此时有可能部分数据还在内存中,没有同步到磁盘,要想现在强制同步到磁盘,需要执行如下命令
redis-cli -p 6382 save
redis-cli -p 6383 save
如果想让redis变成内存型数据库只需要做如下操作
去掉配置文件的如下内容
# Save the DB on disk:
#
# save <seconds> <changes>
#
# Will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
# In the example below the behaviour will be to save:
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changed
#
# Note: you can disable saving completely by commenting out all "save" lines.
#
# It is also possible to remove all the previously configured save
# points by adding a save directive with a single empty string argument
# like in the following example:
#
# save ""
save 900 1
save 300 10
save 60 10000
改成如下格式
save 10000000000 10000000000 前面一个数字是表示数据发生改变后多久写入硬盘,后面数字表示有多少个key发生改变才写入硬盘