Redis篇3 -- 主从复制

环境:

redis版本:redis-3.2.11.tar.gz    包已上传至博客可直接下载

centos 7.5 :192.168.253.130

1.配置基础环境(编译安装redis)

[root@hya src]# ls
redis-3.2.11.tar.gz
[root@hya src]# yum -y install gcc gcc-c++   编译所需的依赖包
[root@hya src]# tar xzf redis-3.2.11.tar.gz 
[root@hya src]# cd redis-3.2.11
[root@hya redis-3.2.11]# make 

2.配置主上的配置文件

[root@hya src]# cp /usr/local/src/redis-3.2.11/redis.conf /etc/
[root@hya src]# vim /etc/redis.conf 
128 daemonize yes

3.配置从上的配置文件

[root@hya src]# cp /usr/local/src/redis-3.2.11/redis.conf /etc/redis-slave.conf 
[root@hya src]# vim /etc/redis-slave.conf   
84   port 6380
128 daemonize yes
266 slaveof 192.168.253.130 6379
61 bind 192.168.253.130

############
slaveof 192.168.5.110 6379 #指定主redis的ip及端口
修改:
bind 127.0.0.1(删掉) 改成 bind 192.168.152.130 (本机IP)
保存退出
############

4.启动测试

[root@hya src]# ./redis-server /etc/redis.conf   指定配置文件启动
[root@hya src]# ./redis-server /etc/redis-slave.conf 
[root@hya src]# ss -tnl
State       Recv-Q Send-Q       Local Address:Port                      Peer Address:Port              
LISTEN      0      128              127.0.0.1:6379                                 *:*                  
LISTEN      0      128        192.168.253.130:6380                                 *:*
###############测试
[root@hya src]# ./redis-cli   主上
127.0.0.1:6379> get hya hhh
127.0.0.1:6379> set hya hhh
OK
127.0.0.1:6379> get hya
"hhh"

[root@hya src]# ./redis-cli -h 192.168.253.130 -p 6380  从上
192.168.253.130:6380> slaveof 127.0.0.1 6379     同步一下主上的数据
OK
192.168.253.130:6380> get hya
"hhh"
######
192.168.253.130:6380> slaveof no one    在从上执行这一步是删除从库
OK

猜你喜欢

转载自blog.csdn.net/yeyslspi59/article/details/108095208