Redis学习之路(11)- 主从同步

2018-09-18  本文已影响9人  William_Wei007

首先安装2个redis服务器:安装过程见 。各个网络博文。。。

安装完毕之后,修改redis从服务器的配置文件 redis_conf:

找到 slaveof 主库ip 主库端口

我主从都在同一个服务器安装了,所有是同一个地址: 直接就用了 localhost 了

设置为

slaveof localhost 6379

在安装路径bin文件夹下执行 ./redis-server 启动redis主库:

主库_20180918114319.png

在安装路径bin文件夹下执行 ./redis-server 启动redis从库:


从库_20180918115410.png

此时,准备工作完成,让我们验证一下:

主库操作之前先验证一下从库的数据:

查询key= rediskey 的redis数据,主库为空

127.0.0.1:6379> get rediskey
(nil)

-- 先启动从库客户端  然后 查询  db1 中 key = rediskey 
[root@xxx bin]# ./redis-cli -h localhost -p 6389 
localhost:6389> select 1
OK
localhost:6389[1]> get rediskey
(nil)
发现为空, 

此时主服務器執行:

127.0.0.1:6379> set rediskey "hello word"
OK
127.0.0.1:6379> get rediskey
"hello word"

在從庫查詢

localhost:6389[1]> get rediskey
"hello word"

验证成功,在主库设置值之后,从库自动同步过来了。

上一篇 下一篇

猜你喜欢

热点阅读