One - One Code All

Blog Content

Redis 哨兵模式 设置密码

Nosql   2014-10-25 17:02:22

1、下载

http://download.redis.io/releases/redis-4.0.11.tar.gz


2、解压

tar zxvf redis-4.0.11.tar.gz -C /opt/module/


3、安装

cd redis-4.0.11

make

make install


4、修改配置文件

4.1 拷贝redis.conf  为master.conf、slave.conf两个文件

  两个文件都在redis的安装目录中


4.2 master.conf修改

  找到port port 6379(可以不修改)

  找到:bind 127.0.0.1(修改成:bind 0.0.0.0,记得修改成自己ip,远程才能访问。) 

  找到:protected-mode no(设置成:protected-mode no;保护模式关闭,如果你不关闭保护模式,启动哨兵的时候,无法正常运行。还有个解决办法就是你设置密码,但是一般都不设置redis的密码。麻烦,我每次连接还得输入密码。在部署中,可以设置密码。) 

  找到:daemonize no(设置成:daemonize yes,标示后台启动。)


  daemonize yes //redis后台运行

  pidfile /var/run/redis_6379.pid //pidfile文件对应

  appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志 

  requirepass 123456  设置密码


4.3 slave.conf修改

  重复4.2的内容

    找到:bind 127.0.0.1(修改成:bind 0.0.0.0,记得修改成自己ip,远程才能访问。) 

   找到:# slaveof (把注释去掉,最后我这里是修改成:slaveof 172.17.36.17 6379,这样表明自己是从服务器。) 

   找到:masterauth 123456  #链接到master的密码,前面设置了 requirepass 123456


4.4 sentinel.conf

  port 26379 //端口

  bind 本机ip

  sentinel auth-pass mymaster 123456              //链接master的密码

  protected-mode no(设置成:protected-mode no;保护模式关闭,如果你不关闭保护模式,启动哨兵的时候,无法正常运行)

  sentinel monitor mymaster 172.17.36.17 6379 2 # 其中mymaster是监控的这一套master-slave的名字,2是2个sentinel认为master有问题就故障转移 172.17.36.17  masterIP

  sentinel down-after-milliseconds mymaster 30000 # sentinel失去master3万毫秒就认为master有问题了

  sentinel parallel-syncs mymaster 1 # 每个时间点只有1个slave对新master进行复制,不并发

  sentinel failover-timeout mymaster 180000 # 故障转移时间


5、启动master、slave、sentinel服务

  cd /opt/module/redis-4.0.11

  redis-server master.conf

  redis-server slave.conf

  nohup redis-server sentinel.conf --sentinel &     

 

6、客户端连接测试

redis-cli -h 172.17.36.17 -p 26379 -a 123456 info Sentinel

redis-cli -h 172.17.36.17 -p 26379 -a 123456 SENTINEL get-master-addr-by-name mymaster

 



上一篇:redis带密码的客户端连接方法
下一篇:Redis内存满了的几种解决方法

The minute you think of giving up, think of the reason why you held on so long.