redis单机器多实例哨兵集群

下载安装包

yum -y install wget
wget http://download.redis.io/releases/redis-5.0.8.tar.gz

开始安装

#将安装包,解压到指定位置
tar xf redis-5.0.8.tar.gz -C /usr/src/
#安装编译工具
yum -y install gcc gcc-c++ make
#切换到Redis的安装包目录
cd /usr/src/redis-5.0.8/
#如果不知道怎么安装,可以查看README的文件
cat README.md
#编译
make

配置多实例

mkdir -p /usr/local/redis
cd /usr/local/redis/
mkdir redis{1,2,3}
cd /usr/src/redis-5.0.8/
cp redis.conf /usr/local/redis/redis1/redis_6380.conf
cp redis.conf /usr/local/redis/redis2/redis_6381.conf
cp redis.conf /usr/local/redis/redis3/redis_6382.conf
cp sentinel.conf /usr/local/redis/redis1/sentinel_26380.conf
cp sentinel.conf /usr/local/redis/redis2/sentinel_26381.conf
cp sentinel.conf /usr/local/redis/redis3/sentinel_26382.conf

主配置

vim redis_6380.conf 
bind 0.0.0.0 
daemonize yes 
port 6380

--------------sentinel_26380.conf -------------------
port 26380
daemonize yes
pidfile /var/run/redis-sentinel_26380.pid
logfile "/usr/local/redis/log/sentinel_26380.log"`
dir /tmp
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

从配置


redis_6381.conf

bind 0.0.0.0 
daemonize yes  后台守护
port 6381
replica-priority 100  优先级
replicaof 127.0.0.1 6380

----------------sentinel_26381.conf ----------------------
port 26381
daemonize yes
pidfile /var/run/redis-sentinel-26381.pid
logfile "/usr/local/redis/log/sentinel_26381.log"
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes


redis_6382.conf

bind 0.0.0.0 
daemonize yes  后台守护
port 6382
replicaof 127.0.0.1 6380
replica-priority 90 优先级 

----------------sentinel_26382.conf ----------------------
port 26382
daemonize yes
pidfile /var/run/redis-sentinel-26382.pid
logfile "/usr/local/redis/log/sentinel_26381.log"
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

sentinel monitor mymaster 127.0.0.1 6380 2
告诉sentinel去监听地址为ip:port的一个master,这里的master-name可以自定义,quorum是一个数字,指明当有多少个sentinel认为一个master失效时,master才算真正失效
 
sentinel down-after-milliseconds mymaster 30000
这个配置项指定了需要多少失效时间,一个master才会被这个sentinel主观地认为是不可用的。 单位是毫秒,默认为30秒
 
sentinel parallel-syncs mymaster 1
这个配置项指定了在发生failover主备切换时最多可以有多少个slave同时对新的master进行 同步。
这个数字越小,完成failover所需的时间就越长,但是如果这个数字越大,就意味着越 多的slave因为replication而不可用。
可以通过将这个值设为 1 来保证每次只有一个slave 处于不能处理命令请求的状态。
 
sentinel failover-timeout mymaster 180000
当进行failover故障转移时,配置所有slaves指向新的master所需的最大时间
 
sentinel deny-scripts-reconfig yes
避免脚本重置,默认值yes

配置启动程序

cd /usr/src/redis-5.0.8/src/
cp redis-server /usr/local/redis/
cp redis-sentinel /usr/local/redis/
cp redis-cli /usr/local/redis/
cd /usr/local/redis/
mkdir log

启动多实例

./redis-sentinel redis1/sentinel_26380.conf &

./redis-sentinel redis2/sentinel_263801.conf &

./redis-sentinel redis3/sentinel_26382.conf &


./redis-sentinel redis1/sentinel_26380.conf &

./redis-sentinel redis2/sentinel_26381.conf &

./redis-sentinel redis3/sentinel_26382.conf &

验证

./redis-cli -p 26380 info Sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6380,slaves=2,sentinels=3

#################关闭master#######################
./redis-cli -p 26381 info Sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6382,slaves=2,sentinels=3
#可以看到address=127.0.0.1:6382换成了6382

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值