三台机器:
master:192.168.111.4
slave1:192.168.111.7
slave2:192.168.111.8
- # mkdir -p /data/application #创建工作目录
- # wget https://download.redis.io/releases/redis-6.2.7.tar.gz
- # tar xzf redis-6.2.7.tar.gz -C /data/application/
- # mv /data/application/redis-6.2.7 /data/application/redis
- # cd /data/application/redis
- # yum install -y gcc make #安装编译工具
- # make
- 注:如果报错请将刚才解压的安装包删除掉,再次重新解压并进行make安装即可
- # mv /data/application/redis/redis.conf /data/application/redis/redis.conf.bak
- # vim /data/application/redis/redis.conf #修改以下内容
- bind 0.0.0.0
- port 6379
- daemonize yes
- dbfilename dump.rdb
- dir /data/application/redis/data
- save 900 1
- save 300 10
- save 60 10000
- stop-writes-on-bgsave-error yes
- rdbcompression yes
-
- # mkdir /data/application/redis/data
master :
- # vim /data/application/redis/redis.conf #增加以下内容
- protected-mode no #将加密保护关闭
-
- # cd /data/application/redis/src
- # ./redis-server ../redis.conf & #启动redis服务
slave1:
- # vim /data/application/redis/redis.conf #增加以下内容
- protected-mode no
- replicaof 192.168.111.4 6379 #指定主服务是谁
-
- # cd /data/application/redis/src
- # ./redis-server ../redis.conf &
slave2:
- # vim /data/application/redis/redis.conf #增加以下内容
- protected-mode no
- replicaof 192.168.111.4 6379
-
- # cd /data/application/redis/src
- # ./redis-server ../redis.conf &
瞅一眼端口:
到这里主从同步就完成了,可以在master里登录测试一下
/data/application/redis/src/redis-cli -h 192.168.111.4 -p 6379
Sentinel(哨兵)是用于监控Redis集群中Master状态的工具 。
作用:
1、Master状态检测
2、如果Master异常,则会进行Master-Slave切换,将其中一个Slave作为Master,将之前的Master作为Slave
3、Master-Slave切换后,sentinel.conf的监控目标会随之调换
每台机器都配置与启动哨兵
- # vim /data/application/redis/sentinel.conf
- sentinel monitor mymaster 192.168.111.4 6379 2
- sentinel down-after-milliseconds mymaster 3000
- sentinel failover-timeout mymaster 10000
- protected-mode no
-
- # /data/application/redis/src/redis-sentinel sentinel.conf & #启动哨兵
完毕!