现在我们尝试使用redis 2.8.7作为缓存存储(来自使用booksleeve客户端的.NET Web应用程序)。 目前这似乎是一个非常有趣和令人兴奋的任务,redis文档非常好,但是由于缺乏实际的实践经验,我确实有一些关于如何正确完成预期配置的问题。
我将下一篇文章作为主要配置来源:
最初的想法/假设 - 是使用Linux Ubuntu运行1个redis master和2个slave实例。为了提供实例的高可用性 - 我决定使用哨兵。所以我的预期配置目前看起来像这样:
虚拟机启动后,我可以看到我已成功连接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实例......
在每个配置中我做了下一次修改:
sentinel monitor mymaster MasterPublicIP 6379 2
使用下一个命令行启动了哨兵:
redis-server /etc/redis/sentinel.conf - sentinel
之后我得到了哨兵在所有虚拟机上成功启动的响应...... 在我启动了所有3个sentinel实例后,我得到了下一个跟踪示例(sentinel.conf文件已更新有关slave和其他sentinel实例的信息):
[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
基于跟踪样本,我有下一个问题。如果有人能澄清它们会很棒:
之后我启动了新的putty连接并启动了redis-cli以使用sentinel API,但在下面的命令中收到了下一个响应:
127.0.0.1:6379> SENTINEL masters
(error) ERR unknown command 'SENTINEL'
我想我在这里做了些蠢事...... :( 我做错了什么以及如何从终端连接测试Sentinel API?
提前感谢您的帮助。
答案 0 :(得分:13)
我猜" SENTINEL大师"应该在Redis哨兵上运行
redis-cli -p 26379(默认的哨兵端口)
然后发出
127.0.0.1:26379> SENTINEL大师
你会得到一些东西
1)" name" 2)" mymaster" 3)" ip" 4)" 127.0.0.1" 5)" port" 6)" 6379" 。 。
即使然后重启VM,也要自动启动标记
首先将daemonize yes设置为sentinel.conf
并在此处修改init脚本(https://github.com/antirez/redis/blob/unstable/utils/redis_init_script)以反映sentinel端口和.conf位置。
$ EXEC $ CONF --sentinel#在Sentinel模式下启动
其余的就像你为redis服务器所做的那样。
答案 1 :(得分:1)
首先,您不要在主服务器上运行Sentinel。 Sentinel旨在检测主机何时出现故障。如果在与主服务器相同的系统上运行Sentinel,则在丢失系统时将丢失Sentinel。出于同样的原因,您不应将奴隶用作附加测试点。
您希望从客户端运行的位置运行Sentinel,以确保您正在测试网络中断。
接下来,您提到您已将奴隶信息添加到您的哨兵配置中。您没有在sentinel中配置从站 - 它通过主站发现它们。我怀疑你为每个奴隶添加了额外的哨兵监视器命令 - 这确实会导致重复的监视尝试。
第三,正如@yofpro所提到的,要运行sentinel命令,你需要连接到sentinel-not Redis master或slave。