redis系列-redis哨兵安装步骤

Redis哨兵安装步骤

----------------------------------

之前的redis6379.conf的配置不变,做为主节占,并且复制出两个配置文件redis6380.conf, redis6381.conf,这两个配置文件启动后的redis做为6379节点的从节点。:

 

注意:redis6380.conf和redis6381.conf 加上slaveof 127.0.0.1 6379

        修改 requirepass 12345678 ,注释掉bind 127.0.0.1, 加上masterauth 12345678

 

redis sentinel哨兵机制配置(也是3个节点):

   /usr/local/bin/conf/sentinel_26379.conf 

   /usr/local/bin/conf/sentinel_26380.conf

   /usr/local/bin/conf/sentinel_26381.conf

将三个文件的端口改成: 26379   26380   26381

然后:sentinel monitor mymaster 127.0.0.1 6379 2  //监听主节点6379

          sentinel auth-pass mymaster 12345678     //连接主节点时的密码

三个配置除端口外,其它一样。

启动sentinel服务:

            ./redis-sentinel conf/sentinel_26379.conf &

            ./redis-sentinel conf/sentinel_26380.conf &

            ./redis-sentinel conf/sentinel_26381.conf &

 

 

杀掉进程

ps -ef|grep redis-server |grep 6379 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-server |grep 6380 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-server |grep 6381 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-sentinel |grep 26379 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-sentinel |grep 26380 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-sentinel |grep 26381 | grep -v grep | awk '{print $2}' | xargs kill -9

启动进程
../redis-server redis6379.conf &
../redis-server redis6380.conf &
../redis-server redis6381.conf &
../redis-sentinel sentinel_26379.conf &
../redis-sentinel sentinel_26380.conf &
../redis-sentinel sentinel_26381.conf &

 

测试:

kill -9 6379  杀掉6379的redis服务

看日志是分配6380 还是6381做为主节点,当6379服务再启动时,已变成从节点

如果6380升级为主节点:进入6380>info replication     可以看到role:master

打开sentinel_26379.conf等三个配置,sentinel monitor mymaster 127.0.0.1 6380 2

外部应用连接sentinel时, sentinel.conf的protected-mode no改成no

./redis-cli -p 26380 shutdown //关闭

 

资源位置

https://download.csdn.net/download/xsxy0506/19118094

 

上一篇:kill、killall发送信号命令


下一篇:mysql查看当前正在运行的任务_MySQL运行时监测