服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Redis - 基于redis集群设置密码的实例

基于redis集群设置密码的实例

2019-11-14 17:18带鱼兄 Redis

今天小编就为大家分享一篇基于redis集群设置密码的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

注意事项:

1.如果是使用redis-trib.rb工具构建集群,集群构建完成前不要配置密码,集群构建完毕再通过config set + config rewrite命令逐个机器设置密码

2.如果对集群设置密码,那么requirepass和masterauth都需要设置,否则发生主从切换时,就会遇到授权问题,可以模拟并观察日志

3.各个节点的密码都必须一致,否则Redirected就会失败

?
1
2
3
config set masterauth abc
config set requirepass abc
config rewrite

测试版本:

redis3.0.7

测试环境:

centos7

集群规模:

3主3从

集群构建成功前的redis配置:

?
1
2
3
4
5
6
7
8
9
10
11
12
port 8000
cluster-enabled yes
cluster-config-file "nodes-8000.conf"
cluster-node-timeout 15000
dir "/opt/redisdata"
appendonly yes
appendfilename "appendonly-8000.aof"
logfile "/opt/redisdata/8000.log"
daemonize yes
pidfile "/var/run/redis-8000.pid"
dbfilename "dump-8000.rdb"
cluster-require-full-coverage no

集群构建成功后的redis配置:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
port 8004
cluster-enabled yes
cluster-config-file "nodes-8004.conf"
cluster-node-timeout 15000
dir "/opt/redisdata"
appendonly yes
appendfilename "appendonly-8004.aof"
logfile "/opt/redisdata/8004.log"
daemonize yes
pidfile "/var/run/redis-8004.pid"
dbfilename "dump-8004.rdb"
cluster-require-full-coverage no
# Generated by CONFIG REWRITE
requirepass "abc"
masterauth "abc"

测试:

1.8002是主,8005是8002的从,现在要kill掉8002模拟主从切换

基于redis集群设置密码的实例

2.查看8005的日志,8005最终被选举成新的master

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
21227:S 14 Jun 07:28:49.343 # Connection with master lost.
21227:S 14 Jun 07:28:49.343 * Caching the disconnected master state.
21227:S 14 Jun 07:28:49.433 * Connecting to MASTER 127.0.0.1:8002
21227:S 14 Jun 07:28:49.433 * MASTER <-> SLAVE sync started
21227:S 14 Jun 07:28:49.434 # Error condition on socket for SYNC: Connection refused
21227:S 14 Jun 07:28:50.437 * Connecting to MASTER 127.0.0.1:8002
 
21227:S 14 Jun 07:29:06.205 # Start of election delayed for 564 milliseconds (rank #0, offset 337).
21227:S 14 Jun 07:29:06.507 * Connecting to MASTER 127.0.0.1:8002
21227:S 14 Jun 07:29:06.507 * MASTER <-> SLAVE sync started
21227:S 14 Jun 07:29:06.507 # Error condition on socket for SYNC: Connection refused
21227:S 14 Jun 07:29:06.808 # Starting a failover election for epoch 10.
21227:S 14 Jun 07:29:06.810 # Failover election won: I'm the new master.
21227:S 14 Jun 07:29:06.810 # configEpoch set to 10 after successful failover
21227:M 14 Jun 07:29:06.810 * Discarding previously cached master state.

3.再次启动8002,查看8005的日志,8002已经变成8005的slave

?
1
2
3
4
5
6
7
8
21227:M 14 Jun 07:32:53.511 * Slave 127.0.0.1:8002 asks for synchronization
21227:M 14 Jun 07:32:53.511 * Full resync requested by slave 127.0.0.1:8002
21227:M 14 Jun 07:32:53.511 * Starting BGSAVE for SYNC with target: disk
21227:M 14 Jun 07:32:53.511 * Background saving started by pid 21613
21613:C 14 Jun 07:32:53.513 * DB saved on disk
21613:C 14 Jun 07:32:53.513 * RDB: 0 MB of memory used by copy-on-write
21227:M 14 Jun 07:32:53.612 * Background saving terminated with success
21227:M 14 Jun 07:32:53.612 * Synchronization with slave 127.0.0.1:8002 succeeded

4.简单测试了GET SET命令,正常

以上这篇基于redis集群设置密码的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

延伸 · 阅读

精彩推荐
  • RedisLinux Redis 的安装步骤详解

    Linux Redis 的安装步骤详解

    这篇文章主要介绍了 Linux Redis 的安装步骤详解的相关资料,希望大家通过本文能掌握如何安装Redis,需要的朋友可以参考下 ...

    carl-zhao3822019-11-08
  • Redisredis启动,停止,及端口占用处理方法

    redis启动,停止,及端口占用处理方法

    今天小编就为大家分享一篇redis启动,停止,及端口占用处理方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧 ...

    澄海单挑狂5152019-11-14
  • RedisRedis分布式锁升级版RedLock及SpringBoot实现方法

    Redis分布式锁升级版RedLock及SpringBoot实现方法

    这篇文章主要介绍了Redis分布式锁升级版RedLock及SpringBoot实现,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以...

    等不到的口琴7802021-07-25
  • RedisRedis存取序列化与反序列化性能问题详解

    Redis存取序列化与反序列化性能问题详解

    这篇文章主要给大家介绍了关于Redis存取序列化与反序列化性能问题的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参...

    这名字已经存在9742021-02-24
  • Redis聊一聊Redis与MySQL双写一致性如何保证

    聊一聊Redis与MySQL双写一致性如何保证

    一致性就是数据保持一致,在分布式系统中,可以理解为多个节点中数据的值是一致的。本文给大家分享Redis与MySQL双写一致性该如何保证,感兴趣的朋友一...

    mind_programmonkey6432021-08-12
  • RedisRedis数据结构之链表与字典的使用

    Redis数据结构之链表与字典的使用

    这篇文章主要介绍了Redis数据结构之链表与字典的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友...

    白泽来了4052021-08-03
  • Redis在ssm项目中使用redis缓存查询数据的方法

    在ssm项目中使用redis缓存查询数据的方法

    本文主要简单的使用Java代码进行redis缓存,即在查询的时候先在service层从redis缓存中获取数据。如果大家对在ssm项目中使用redis缓存查询数据的相关知识感...

    caychen8962019-11-12
  • Redis就这?Redis持久化策略——AOF

    就这?Redis持久化策略——AOF

    今天为大家介绍Redis的另一种持久化策略——AOF。注意:AOF文件只会记录Redis的写操作命令,因为读命令对数据的恢复没有任何意义...

    头发茂密的刘叔4052021-12-14