现在我们正在尝试使用 redis 2.8.7 作为缓存存储(来自使用 booksleeve 客户端的 .NET Web 应用程序)。目前这似乎是一项非常有趣和令人兴奋的任务,redis 文档非常好,但由于缺乏真正的实践经验,我确实对如何正确完成预期配置有几个问题。
我将下一篇文章作为主要配置来源:
- 安装具有自动启动功能的 redis(使用初始化脚本,以便在重新启动后一切都将重新正常启动):http ://redis.io/topics/quickstart
- 将redis部署到天蓝色:http ://haishibai.blogspot.com/2014/01/walkthrough-setting-up-redis-cluster-on.html
最初的想法/假设 - 是让 1 个 redis 主实例和 2 个从属实例在 linux Ubuntu 上运行。为了提供实例的高可用性——我决定使用哨兵。所以我预期的配置现在看起来像这样:
- MasterInstance:VM1(linux,Ubuntu),端口:6379(linux重启时自动启动)
- Slave1:VM2(linux,ubuntu),端口:6380(linux重启时自动启动):slaveOf MasterID 6379
- Slave2:VM3(linux,ubuntu),端口:6379(linux重启时自动启动):slaveOf MasterIP 6379
虚拟机启动后,我可以看到我已经成功连接了 2 个从站并与主站同步:来自主站的跟踪示例:
[1120] 25 Mar 14:11:18.629 - 1 clients connected (0 slaves), 793352 bytes in use
[1120] 25 Mar 14:11:18.634 * Slave asks for synchronization
[1120] 25 Mar 14:11:18.634 * Full resync requested by slave.
[1120] 25 Mar 14:11:18.634 * Starting BGSAVE for SYNC
[1120] 25 Mar 14:11:18.634 * Background saving started by pid 1227
[1227] 25 Mar 14:11:18.810 * DB saved on disk
[1227] 25 Mar 14:11:18.810 * RDB: 0 MB of memory used by copy-on-write
[1120] 25 Mar 14:11:18.836 * Background saving terminated with success
[1120] 25 Mar 14:11:18.837 * Synchronization with slave succeeded
[1120] 25 Mar 14:11:23.829 - DB 0: 2 keys (0 volatile) in 4 slots HT.
[1120] 25 Mar 14:11:23.829 - DB 2: 4 keys (0 volatile) in 4 slots HT.
[1120] 25 Mar 14:11:23.829 - 0 clients connected (1 slaves), 1841992 bytes in use
[1120] 25 Mar 14:11:29.011 - DB 0: 2 keys (0 volatile) in 4 slots HT.
[1120] 25 Mar 14:11:29.011 - DB 2: 4 keys (0 volatile) in 4 slots HT.
[1120] 25 Mar 14:11:29.011 - 0 clients connected (1 slaves), 1841992 bytes in use
[1120] 25 Mar 14:11:29.826 - Accepted 168.62.36.189:1024
[1120] 25 Mar 14:11:29.828 * Slave asks for synchronization
[1120] 25 Mar 14:11:29.828 * Full resync requested by slave.
[1120] 25 Mar 14:11:29.828 * Starting BGSAVE for SYNC
[1120] 25 Mar 14:11:29.828 * Background saving started by pid 1321
[1321] 25 Mar 14:11:29.871 * DB saved on disk
[1321] 25 Mar 14:11:29.871 * RDB: 0 MB of memory used by copy-on-write
[1120] 25 Mar 14:11:29.943 * Background saving terminated with success
[1120] 25 Mar 14:11:29.946 * Synchronization with slave succeeded
[1120] 25 Mar 14:11:34.195 - DB 0: 2 keys (0 volatile) in 4 slots HT.
[1120] 25 Mar 14:11:34.195 - DB 2: 4 keys (0 volatile) in 4 slots HT.
[1120] 25 Mar 14:11:34.195 - 0 clients connected (2 slaves), 1862920 bytes in use
现在我需要设置哨兵实例...
- 我将 sentinel.conf 从最初的 redis-stable 包复制到 3 个 VM runnung redis(1 个主设备和两个从设备)
在每个配置中,我都做了下一个修改:
哨兵监控 mymaster MasterPublicIP 6379 2
在每个 VM 上使用下一个命令行启动哨兵:
redis-server /etc/redis/sentinel.conf -- 哨兵
之后,我得到了哨兵成功启动的响应......在所有虚拟机上......在我启动了所有 3 个哨兵实例后,我得到了下一个跟踪样本(sentinel.conf 文件更新了有关从属和其他哨兵实例的信息):
[1743] 25 Mar 16:35:46.450 # Sentinel runid is 05380d689af9cca1e826ce9c85c2d68c65780878
[1743] 25 Mar 16:35:46.450 # +monitor master mymaster MasterIP 6379 quorum 2
[1743] 25 Mar 16:36:11.578 * -dup-sentinel master mymaster MasterIP 6379 #duplicate of 10.119.112.41:26379 or 83666bdd03fd064bcf2ec41ec2134d4e1e239842
[1743] 25 Mar 16:36:11.578 * +sentinel sentinel 10.119.112.41:26379 10.119.112.41 26379 @ mymaster 168.62.41.1 6379
[1743] 25 Mar 16:36:16.468 # +sdown sentinel 10.175.220.134:26379 10.175.220.134 26379 @ mymaster 168.62.41.1 6379
[1743] 25 Mar 16:36:40.876 * -dup-sentinel master mymaster MasterIP 6379 #duplicate of 10.175.220.134:26379 or fe9edeb321e04070c6ac6e28f52c05317a593ffd
[1743] 25 Mar 16:36:40.876 * +sentinel sentinel 10.175.220.134:26379 10.175.220.134 26379 @ mymaster 168.62.41.1 6379
[1743] 25 Mar 16:37:10.962 # +sdown sentinel 10.175.220.134:26379 10.175.220.134 26379 @ mymaster 168.62.41.1 6379
根据跟踪样本,我有下一个问题。如果有人可以澄清它们,那就太好了:
- 为什么我在这里看到 -dup-sentinel master mymaster 配置...是不是因为我为同一个主实例添加了 3 个哨兵(也许我需要为每个 redis 实例注册 1 个哨兵——所以 1 个哨兵将被映射到主人和其他 2 个哨兵——给 2 个奴隶)?
- 如何以启动 redis 服务器的方式启动哨兵(即使 VM 重新启动也会自动启动)?- 我是否需要执行相同的操作并将它们注册为普通的 redis-server 实例?
- 可以将哨兵实例托管在与 redis-server 相同的 VM 中吗?
之后,我启动了新的 putty 连接并启动了 redis-cli 以使用 sentinel API,但在下面的命令中收到了下一个响应:
127.0.0.1:6379> SENTINEL masters
(error) ERR unknown command 'SENTINEL'
我想我在这里做了一些愚蠢的事情...... :(我做错了什么以及如何从终端连接测试哨兵API?
预先感谢您的任何帮助。