redis集群和哨兵搭建
2019-05-29 15:09
176 查看
为了实现redis高可用,考虑主从复制,哨兵模式
安装和开机自启省略本文版本为4.0.10,可参考
https://www.geek-share.com/detail/2727783003.html
https://www.geek-share.com/detail/2692689282.html
主从配置
[code][root@localhost redis]# cd /usr/local/redis [root@localhost redis]# vi redis.conf 主的配置 # Redis使用后台模式 daemonize yes # 关闭保护模式 protected-mode no # 开启远程访问 bind 0.0.0.0 # 修改启动端口为6379 port 6379 从的配置 # Redis使用后台模式 daemonize yes # 关闭保护模式 protected-mode no # 开启远程访问 bind 0.0.0.0 # 修改启动端口为6379 port 6379 #配置主的地址端口 slaveof 192.168.255.111 6379 #配置主的密码(如果有) masterauth 123456
启动redis
[code][root@localhost redis]# src/redis-server ./redis.conf #查看主从节点信息 [root@localhost redis]# src/redis-cli 127.0.0.1:6379> info replication 主节点信息: # Replication role:master connected_slaves:2 slave0:ip=192.168.255.113,port=6379,state=online,offset=2563538,lag=1 slave1:ip=192.168.255.112,port=6379,state=online,offset=2563538,lag=0 master_replid:58abe37473712e06efca0f4d598de56792b42953 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:2563538 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1514963 repl_backlog_histlen:1048576 次节点信息 # Replication role:slave master_host:192.168.255.111 master_port:6379 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_repl_offset:2577991 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:58abe37473712e06efca0f4d598de56792b42953 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:2577991 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1529416 repl_backlog_histlen:1048576 master_link_status:up 为up则表示连接成功
哨兵配置
[code][root@localhost redis]# vi sentinel.conf 3台实例均修改如下: #本机地址 port 26379 bind 192.168.255.111 #本机地址 dir /usr/local/redis/tmp sentinel monitor mymaster 192.168.1.132 6379 2 #mymaster是集群的名称可自定义,IP地为集群中master的地址,注意与bind的区别 6379表示端口 2表示 需要多少哨兵同意才能执行故障转移操作 sentinel down-after-milliseconds mymaster 30000 #超过多少毫秒跟一个redis实例断了连接,哨兵就可能认为这个redis实例挂了 sentinel failover-timeout mymaster 60000 #failover转移时间,超出此时间认为master转移失效,重新开始转移 sentinel parallel-syncs mymaster 1 #新的master别切换之后,同时有多少个slave被切换到去连接新master,重新做同步,数字越低,花费的时间越多 protected-mode no #关闭安全模式,否则会报错 sentinel auth-pass mymaster redis-pass #如果集群设置了密码,需要添加 daemonize yes #后台进程 logfile /usr/local/redis/logs/sentinal.log #日志路径
启动哨兵
[code]#设置为后台启动 [root@localhost redis]# src/redis-sentinel ./sentinel.conf &
查看状态
[code][root@redis-master 26379]# redis-cli -h 192.168.255.111 -p 26379 192.168.255.112:26379> sentinel master mymaster #查看master的信息 192.168.255.112:26379> SENTINEL slaves mymaster #查看slave的信息 192.168.255.112:26379> SENTINEL sentinels mymaster #查看sentinel的信息,本机sentinel信息不显示 192.168.255.112:26379> SENTINEL get-master-addr-by-name mymaster #查看redis集群master的IP地址和端口
测试宕机
kill掉主节点
相关文章推荐
- 搭建redis-sentinel(哨兵机制)集群
- 基于哨兵(Sentinel)模式搭建Redis集群搭建
- 基于Centos7系统搭建Redis集群之哨兵机制(新手教程)
- 搭建redis-sentinel(哨兵机制)集群
- Redis高可用集群-哨兵模式(Redis-Sentinel)搭建配置教程【Windows环境】
- redis主从集群搭建及容灾部署(哨兵sentinel)
- redis主从集群搭建及容灾部署(哨兵sentinel)
- [置顶] 搭建一个简单的redis-sentinel(哨兵机制)集群
- Redis学习总结(6)之高可用(主从、哨兵、集群)搭建
- 从docker入门到使用docker搭建redis哨兵集群
- redis系列07--redis哨兵集群搭建
- redis主从集群搭建及容灾部署(哨兵sentinel)
- Redis高可用集群-哨兵模式(Redis-Sentinel)搭建配置教程【Windows环境】
- Redis+Sentinel哨兵模式集群方案配置与搭建
- 基于Sentinel(哨兵)搭建实现Redis高可用集群
- redis主从集群搭建及容灾部署(哨兵sentinel)
- redis主从集群搭建及容灾部署(哨兵sentinel)
- 搭建redis-sentinel(哨兵机制)集群
- Docker 搭建redis哨兵、cluster集群
- redis sentinel哨兵模式集群搭建教程