1、环境准备(部署redis看前面的文档):
master节点 192.168.56.11 slave节点 192.168.56.12 slave节点 192.168.56.13
2.master修改配置文件
egrep 'dir|bind|daemonize|logfile|requirepass|appendonly' /usr/local/redis/etc/redis.conf |egrep -v '^#' bind 192.168.56.11 # 绑定本台机器的IP daemonize yes # 允许后台启动 logfile "/data/redis/redis.log" #日志路径
dir /data/redis/ #存放数据 requirepass 123456 #设置master连接密码,slave可省略 appendonly yes #在/data/redis/目录生成appendonly.aof文件,将每一次写操作请求都追加到appendonly.aof 文件中 appendfilename "appendonly.aof"
3、slave修改配置文件
egrep 'dir|bind|daemonize|logfile|masterauth|appendonly|replicaof|slaveof' /usr/local/redis/etc/redis.conf |egrep -v '^#' bind 192.168.56.12 daemonize yes logfile "/data/redis/redis.log" slaveof 192.168.56.11 6379 # 绑定master的ip和port
dir /data/redis/ masterauth 123456 # slave连接master密码,master可省略 appendonly yes appendfilename "appendonly.aof"
4、master、slave 启动redis
redis-server /usr/local/redis/etc/redis.conf
5、验证
master
slave
数据演示: