Redis 主从搭建
将redis.conf配置文件复制三份
分别为 命名为:
redis6380.conf
redis6381.conf
redis6382.conf
需要修改的配置文件内容如下
-
redis6380.conf
bind 0.0.0.0 # (配置文件69行) protected-mode:no # (配置文件88行) prot 6380 # (配置文件92行) pidfile /var/run/redis_6380.pid # (配置文件158行)
-
redis6381.conf
bind 0.0.0.0 # (配置文件69行) protected-mode:no # (配置文件88行) prot 6381 # (配置文件92行) pidfile /var/run/redis_6381.pid # (配置文件158行) slaveof 127.0.0.1 6380 # (配置文件21行) replicaof 192.168.218.130 6380 # (配置文件286行) masterauth 123456 # (配置文件293行)
-
redis6382.conf
bind 0.0.0.0 # (配置文件69行) protected-mode:no # (配置文件88行) prot 6382 # (配置文件92行) pidfile /var/run/redis_6382.pid # (配置文件158行) slaveof 127.0.0.1 6380 # (配置文件21行) replicaof 192.168.218.130 6380 # (配置文件286行) masterauth 123456 # (配置文件293行)
然后通过配置文件分别启动3个服务:
分别启动三个服务:
[root@Test1 redis-5.0.3]# src/redis-server redis6380.conf
[root@Test1 redis-5.0.3]# src/redis-server redis6381.conf
[root@Test1 redis-5.0.3]# src/redis-server redis6382.conf
分别进入三个服务的客户端:
从服务器 能获取到 主服务器 的key则为配置成功
- 启动主服务器:
[root@Test1 redis-5.0.3]# src/redis-cli -p 6380 -a 123456
127.0.0.1:6380> set name wll
OK
127.0.0.1:6380> get name
"wll"
- 启动从服务器客户端:
[root@Test1 redis-5.0.3]# src/redis-cli -p 6381 -a 123456
127.0.0.1:6381> get name
"wll"
- 启动第二台从服务器客户端:
[root@Test1 redis-5.0.3]# src/redis-cli -p 6382 -a 123456
127.0.0.1:6382> get name
"wll"