redis的主从和哨兵模式(一主二从)

Redis的主从及哨兵模式的搭建(一主二从)

一.搭建主从模式

  1. 首先在linux中安装好redis(这里就不详细介绍)
  2. 然后复制redis.conf复制出两份(我们这里用16379,26379作为从节点
    cp redis.conf redis-16379.conf

    cp redis.conf redis-26379.conf    
  • 修改redis-16379.conf文件
vi redis-16379.conf

bind 127.0.0.1          服务器ip

daemonize yes             

pidfile "/var/run/redis16379.pid"

port 16379              从redis端口

logfile "16379.log"

dbfilename "dump16379.rdb"

# Generated by CONFIG REWRITE

dir "/tpsys/redis-409/conf"   


slaveof 127.0.0.1 6379  主节点

(修改redis-26379.conf同上,对应的日志文件要名字要做修改,然后启动即完成配置,使用redis-cli -p 6379 -h 127.0.0.1进入对应的端口后使用info命令可查看是否配置成功)

二.哨兵模式

1.创建sentinel-6379.conf文件

2.编辑sentinel-6379.conf

daemonize yes

bind 127.0.0.1

port 6389

dir "/tpsys/redis-409/conf"

sentinel monitor mymaster 127.0.0.1 6379 1    mymaster:哨兵监控的master名  127.0.0.1 6379:主节点

 

3.复制出sentinel-6399.conf和sentinel-6309.conf

编辑sentinel-6399.conf

daemonize yes

bind 127.0.0.1

port 6399

dir "/tpsys/redis-409/conf"

sentinel monitor mymaster 127.0.0.1 6379 1

(编辑sentinel-6309.conf同上)

以上就是redis的主从和哨兵模式搭建的详细过程,如有疑问请留言。

 

 

 

猜你喜欢

转载自blog.csdn.net/ttaio0/article/details/85261827