Redis+Sentinel集群安装与配置

1、安装环境

集群机器                                    redis服务                             哨兵(sentinel)                描述

虚拟机:10.202.107.207    redis服务端口6379          sentinel服务端口26379           主节点

虚拟机:10.202.107.208    redis服务端口6379          sentinel服务端口26379           从节点

虚拟机:10.202.107.209    redis服务端口6379           sentinel服务端口26379          从节点

即:3个redis服务(1主2从),3个sentinel服务

2、Redis安装(请参照Redis安装)

3、Redis主从配置

  3.1、创建目录

mkdir conf
mkdir run
mkdir logs
mkdir data
mkdir sentinel

 虚拟机:10.202.107.207 redis.conf配置文件:

daemonize yes
pidfile /usr/dev/redis/redis-4.0.1/run/redis.pid
port 6379
tcp-backlog 511
bind 10.202.107.207
timeout 180
tcp-keepalive 60
loglevel notice
logfile /usr/dev/redis/redis-4.0.1/logs/redis.log
databases 16
save 900 1
save 300 10
save 60 100
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename its_redis.rdb
dir /usr/dev/redis/redis-4.0.1/data
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 123456
maxclients 1000
maxmemory 4096mb
maxmemory-policy volatile-lru
maxmemory-samples 3
appendonly no
appendfilename its_redis.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
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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
masterauth 123456

  虚拟机:10.202.107.208 redis.conf配置文件:

daemonize yes
pidfile /usr/dev/redis/redis-4.0.1/run/redis.pid
port 6379
tcp-backlog 511
bind 10.202.107.208
timeout 180
tcp-keepalive 60
loglevel notice
logfile /usr/dev/redis/redis-4.0.1/logs/redis.log
databases 16
save 900 1
save 300 10
save 60 100
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename its_redis.rdb
dir /usr/dev/redis/redis-4.0.1/data
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 123456
maxclients 1000
maxmemory 4096mb
maxmemory-policy volatile-lru
maxmemory-samples 3
appendonly no
appendfilename its_redis.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
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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
masterauth 123456
slaveof 10.202.107.207 6379

   虚拟机:10.202.107.209 redis.conf配置文件:

 

daemonize yes
pidfile /usr/dev/redis/redis-4.0.1/run/redis.pid
port 6379
tcp-backlog 511
bind 10.202.107.209
timeout 180
tcp-keepalive 60
loglevel notice
logfile /usr/dev/redis/redis-4.0.1/logs/redis.log
databases 16
save 900 1
save 300 10
save 60 100
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename its_redis.rdb
dir /usr/dev/redis/redis-4.0.1/data
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 123456
maxclients 1000
maxmemory 4096mb
maxmemory-policy volatile-lru
maxmemory-samples 3
appendonly no
appendfilename its_redis.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
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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
masterauth 123456
slaveof 10.202.107.207 6379

  相关命令:

 

1.查看redis进程
ps -ef|grep redis
2.启动redis server
./src/redis-server redis.conf 
3.启动redis Client
./src/redis-cli -h 10.202.107.207 -p 6379 -a 123456
4.输入密码
10.202.107.207:6379> auth 123456 
5.查看信息
info

 

查看主从关系

./src/redis-cli -h 10.202.107.207 -p 6379 -a 123456

 

10.202.107.207:6379> info replication

主从切换

主服务挂掉了后从执行,将从切换为主:

./src/redis-cli -p 6380 slaveof NO ONE

主恢复后从执行:

./src/redis-cli -p 6380 slaveof 10.202.107.207 6379

4、Sentinel主从配置

 虚拟机:10.202.107.207 sentinel.conf配置文件:

 

# 守护进程模式,即后台模式
daemonize yes
port 26379
bind 10.202.107.207
sentinel monitor its_sentinel 10.202.107.207 6379 2#2表示在sentinel集群中只要有两个节点检测到redis主节点出故障就进行切换,单sentinel节点无效
#指定工作目录  
dir "/usr/dev/redis/redis-4.0.1/sentinel"
pidfile "/usr/dev/redis/redis-4.0.1/run/sentinel.pid"
#日志级别
loglevel notice
logfile "/usr/dev/redis/redis-4.0.1/logs/sentinel.log"

#如果6秒后,master仍没活过来,则启动failover  
sentinel failover-timeout its_sentinel 60000
#redis主节点密码  
sentinel auth-pass its_sentinel 123456
#选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就
sentinel config-epoch its_sentinel 0
sentinel leader-epoch its_sentinel 0
sentinel current-epoch 1
sentinel announce-ip "10.202.107.207"

 

 虚拟机:10.202.107.208 sentinel.conf配置文件:

 

# 守护进程模式,即后台模式
daemonize yes
port 26379
bind 10.202.107.208
sentinel monitor its_sentinel 10.202.107.207 6379 2#2表示在sentinel集群中只要有两个节点检测到redis主节点出故障就进行切换,单sentinel节点无效
#指定工作目录  
dir "/usr/dev/redis/redis-4.0.1/sentinel"
pidfile "/usr/dev/redis/redis-4.0.1/run/sentinel.pid"
#日志级别
loglevel notice
logfile "/usr/dev/redis/redis-4.0.1/logs/sentinel.log"

#如果6秒后,master仍没活过来,则启动failover  
sentinel failover-timeout its_sentinel 60000
#redis主节点密码  
sentinel auth-pass its_sentinel 123456
#选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就
sentinel config-epoch its_sentinel 0
sentinel leader-epoch its_sentinel 0
sentinel current-epoch 1
sentinel announce-ip "10.202.107.208"

 

 虚拟机:10.202.107.209 sentinel.conf配置文件:

 

# 守护进程模式,即后台模式
daemonize yes
port 26379
bind 10.202.107.209
sentinel monitor its_sentinel 10.202.107.207 6379 2#2表示在sentinel集群中只要有两个节点检测到redis主节点出故障就进行切换,单sentinel节点无效
#指定工作目录  
dir "/usr/dev/redis/redis-4.0.1/sentinel"
pidfile "/usr/dev/redis/redis-4.0.1/run/sentinel.pid"
#日志级别
loglevel notice
logfile "/usr/dev/redis/redis-4.0.1/logs/sentinel.log"

#如果6秒后,master仍没活过来,则启动failover  
sentinel failover-timeout its_sentinel 60000
#redis主节点密码  
sentinel auth-pass its_sentinel 123456
#选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就
sentinel config-epoch its_sentinel 0
sentinel leader-epoch its_sentinel 0
sentinel current-epoch 1
sentinel announce-ip "10.202.107.209"

   启动sentinel服务: ./src/redis-sentinel ./conf/sentinel.conf

 

 

你可能感兴趣的:(Redis)