温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Redis哨兵sentinel

发布时间:2020-08-14 09:30:51 来源:ITPUB博客 阅读:151 作者:dmcatding 栏目:关系型数据库

########哨兵sentinel   

配置3个redis(1主2从),1个哨兵。步骤如下:

cp redis.conf redis1.conf

cp redis.conf redis2.conf

cp redis.conf redis3.conf



#创建了 3个redis配置文件,1个哨兵配置文件:redis01设置为master,将redis02,redis03设置为slave

vi redis01.conf

port 6380

requirepass beijing           -----配置redis Master密码为beijing

masterauth  beijing


vi redis02.conf

port 6381

requirepass beijing           -----配置redis Slave密码为beijing

masterauth  beijing           -----由于slave需要和master交互,在slave上需配置

slaveof 127.0.0.1 6380


vi redis03.conf

port 6382

requirepass beijing           -----配置redis Slave密码为beijing

masterauth  beijing           -----由于slave需要和master交互,在slave上需配置

slaveof 127.0.0.1 6380


vi sentinel.conf

daemonize yes

port 26379

sentinel monitor mymaster 127.0.0.1 6380 1   # 下面解释含义

sentinel auth-pass mymaster beijing

pidfile "/var/run/sentinel_26379.pid"

logfile "/usr/local/redis/bin/sentinel_26379.log"

protected-mode no



上面的主从配置都熟悉,只有哨兵配置 sentinel.conf,需要解释一下:

mymaster        为主节点名字,可以随便取,后面程序里边连接的时候要用到

127.0.0.1 63790 为主节点的 ip,port

1               后面的数字 1 表示选举主节点的时候,投票数。1表示有一个sentinel同意即可升级为master



redis Sentinel

如果系统中使用了redis 哨兵集群,由于在切换master的时候,原本的master可能变成slave,故也需要在原本redis master上配置masterauth:

# vi /path/to/conf/6379.conf

masterauth beijing            ---在哨兵的配置中,也需要填入获取到的master密码:

# vi /path/to/conf/sentinel.conf

sentinel auth-pass master beijing         ----master为你的自定义哨兵集群maste


#启动哨兵,使用jedis连接哨兵操作redis

./redis-server redis1.conf

./redis-server redis2.conf

./redis-server redis3.conf

./redis-server sentinel.conf --sentinel


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI