1. 系统规划
主机 | 操作系统 | ip地址 | 安装包 |
master | centos7 | 172.30.234.65 | redis-3.2.4.tar.gz |
slave1 | centos7 | 172.30.234.65 | redis-3.2.4.tar.gz |
slave2 | centos7 | 172.30.234.66 | redis-3.2.4.tar.gz |
slave3 | centos7 | 172.30.234.67 | redis-3.2.4.tar.gz |
2. 下载安装
下载解压redis-3.2.4.tar.gz,目录结构如图:
3. 更改配置
3.1 在172.30.234.65节点编辑配置文件:redis-master.conf
protected-mode yes
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass "pms.redis"
masterauth "pms.redis"
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
logfile "/data/prod/redis-3.2.4/logs/master.log"
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
daemonize yes
# Generated by CONFIG REWRITE
port 6379
dir "/data/prod/redis-3.2.4/data/master"
timeout 10
3.2 在所有服务器编辑配置文件:redis-slave.conf
protected-mode yes
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass "pms.redis"
masterauth "pms.redis"
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
logfile "/data/prod/redis-3.2.4/logs/slave.log"
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
daemonize yes
# Generated by CONFIG REWRITE
port 6380
bind 0.0.0.0
dir "/data/prod/redis-3.2.4/data/slave"
slaveof $your_ip 6379
3.3 在所有服务器编辑配置文件:sentinel.conf
port 26379
dir "/data/prod/redis-3.2.4/data/sentinel"
daemonize yes
protected-mode no
logfile "/data/prod/redis-3.2.4/logs/sentinel.log"
4. 启动redis主从
在redis-3.2.4所在目录下执行如下命令:
# 在主节点所在服务器上执行
bin/redis-server config/redis-master.conf
# 在从节点所在服务器上执行
bin/redis-server config/redis-slave.conf
5. 启动sentinel
在redis-3.2.4所在目录下执行如下命令:
# 在所有服务器上执行
bin/redis-sentinel config/sentinel.conf
6.模拟主备切换
查找到redis master进程的pid,结束进程
ps -ef | grep redis
kill $redis_master_pid
查看sentinel的日志