Redis 简单主从架构缺点:主节点出现故障,无法继续写数据
上传Redis安装包到/usr/local/src/redis-6.2.6/,并解压缩
cd /usr/local/src/redis-6.2.6/
tar -zxvf redis-6.2.6.tar.gz
rm -rf redis-6.2.6.tar.gz
cd redis-6.2.6
# 编译后redis 默认是安装在 /usr/local/bin/
make && make install
3个配置文件对映3个实例
cp /usr/local/src/redis-6.2.6/redis.conf /tmp/7001/redis.conf
cp /usr/local/src/redis-6.2.6/redis.conf /tmp/7002/redis.conf
cp /usr/local/src/redis-6.2.6/redis.conf /tmp/7003/redis.conf
准备3个配置文件,并设置7002、7003 为7001 的从节点
bind 0.0.0.0
port 7001
daemonize yes
dir /tmp/7001/
bind 0.0.0.0
port 7002
daemonize yes
dir /tmp/7002/
replicaof 192.168.208.131 7001
bind 0.0.0.0
port 7003
daemonize yes
dir /tmp/7003/
replicaof 192.168.208.131 7001
启动实例
redis-server /tmp/7001/redis.conf
redis-server /tmp/7002/redis.conf
redis-server /tmp/7003/redis.conf
验证数据同步
redis-cli -h 192.168.208.131 -p 7001
> set name zhangsan
redis-cli -h 192.168.208.131 -p 7002
> get name
redis-cli -h 192.168.208.131 -p 7003
> get name