redis 2.8.7 linux的哨兵环境配置问题,如何让它自动启动,应该订阅什么? [英] redis 2.8.7 sentinel environment configuration questions for linux, how to make it autostart, what they should subscribe to?

查看:90
本文介绍了redis 2.8.7 linux的哨兵环境配置问题,如何让它自动启动,应该订阅什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我们正在尝试使用 redis 2.8.7 作为缓存存储(来自使用 bookleeve 客户端的 .NET Web 应用程序).目前看来这是一项非常有趣和令人兴奋的任务,redis 文档非常好,但由于缺乏实际的实践经验,我确实对如何正确完成预期配置有几个问题.

for now we're trying to play with redis 2.8.7 as cache storage (from the .NET web application using booksleeve client). It seems to be very interesting and exciting task at the moment, redis documentation is very nice, but due to lack of real practical experience I do have couple of questions about how expected configuration should be done properly.

我以下篇文章为主要配置源:

I took next articles as main configuration source:

  1. 安装具有自动启动功能的 redis(使用 init 脚本,以便在重新启动后一切都能正常启动):http://redis.io/topics/quickstart
  2. 将redis部署到azure中:http://haishibai.blogspot.com/2014/01/walkthrough-setting-up-redis-cluster-on.html

最初的想法/假设 - 是让 1 个 redis 主实例和 2 个从属实例与 linux Ubuntu 一起运行.为了提供实例的高可用性 - 我决定使用哨兵.所以我现在的预期配置是这样的:

Initial idea/assumption - is to have 1 redis master and 2 slave instances running with linux Ubuntu. In order to provide high availability of the instances - I've decided to use sentinel. So my expected configuration looks like this at the moment:

  1. MasterInstance:VM1(linux、Ubuntu),端口:6379(重启 linux 时自动启动)
  2. Slave1:VM2(linux、ubuntu),端口:6380(重启 linux 时自动启动):slaveOf MasterID 6379
  3. Slave2:VM3(linux、ubuntu),端口:6379(重启 linux 时自动启动):slaveOf MasterIP 6379

VM 启动后,我可以看到我已经成功连接了 2 个从站并与主站同步:来自主人的跟踪样本:

After VMs started, I can see that I've got 2 slaves successfully connected and syncing with Master: Trace sample from the master:

[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

现在我需要设置哨兵实例...

now I need to setup sentinel instances ...

  1. 我将 sentinel.conf 从初始 redis-stable 包复制到 3 VM runnung redis(1 个主服务器和两个从服务器)
  2. 在每个配置中我做了下一个修改:

  1. I copied sentinel.conf from the initial redis-stable package into 3 VM runnung redis (1 master and both slaves)
  2. Inside each config I've done next modifications:

sentinel monitor mymaster MasterPublicIP 6379 2

sentinel monitor mymaster MasterPublicIP 6379 2

在每个 VM 上使用下一个命令行启动哨兵:

on each VM started sentinel using next command line:

redis-server/etc/redis/sentinel.conf -- sentinel

redis-server /etc/redis/sentinel.conf -- sentinel

在那之后,我得到了哨兵成功启动的响应......在所有虚拟机上......在我启动所有 3 个哨兵实例后,我得到了下一个跟踪样本(sentinel.conf 文件更新了有关从属和其他哨兵实例的信息):

After that I've got the response that sentinel successfully started ... on all VMs... After I started all 3 sentinel instances I've got next trace sample (sentinel.conf files were updated with information about slaves and other sentinel instances):

[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

根据跟踪样本,我有下一个问题.如果有人能澄清它们,那就太好了:

based on the trace sample, I have next questions. It will be great, if someone can clarify them:

  1. 为什么我在这里看到 -dup-sentinel master mymaster 配置...是不是因为我为同一个 master 实例添加了 3 个 sentinel(也许我需要为每个 redis 实例注册 1 个 sentinel - 所以 1 个 sentinel 将是映射到主节点和其他 2 个哨兵 - 映射到 2 个从节点)?
  2. 如何以启动redis服务器的方式启动哨兵(即使VM重新启动也会自动启动)?- 我是否需要执行相同的操作并将它们注册为普通的 redis-server 实例?
  3. 是否可以将哨兵实例与 redis-server 托管在同一 VM 中?

之后,我启动了新的腻子连接并启动了 redis-cli 以使用哨兵 API,但在我的以下命令中收到了下一个响应:

After that I started new putty connection and started redis-cli to work with sentinel APIs, but received next response on my command below:

127.0.0.1:6379> SENTINEL masters

(error) ERR unknown command 'SENTINEL'

我想我在这里做了一些愚蠢的事情... :(我做错了什么以及如何从终端连接测试哨兵 API?

I guess I've done something stupid here... :( What I've done wrong and how to test sentinel APIs from the terminal connection?

在此先感谢您的帮助.

推荐答案

我猜《SENTINEL masters》应该跑在Redis哨兵上

I guess "SENTINEL masters" should be run on the Redis sentinel

redis-cli -p 26379(默认哨兵端口)

redis-cli -p 26379 (which the default sentinel port)

然后发出

127.0.0.1:26379> 哨兵大师

127.0.0.1:26379> SENTINEL masters

你会得到一些东西

1) 名字"2)我的主人"3)IP"4)127.0.0.1"5)端口"6)6379"...

1) "name" 2) "mymaster" 3) "ip" 4) "127.0.0.1" 5) "port" 6) "6379" . . .

即使虚拟机重启也自动启动哨兵

To start sentinels automatically even then VM is restarted

首先在 sentinel.conf 中设置 daemonize yes

first set daemonize yes into sentinel.conf

并在这里修改初始化脚本(https://github.com/antirez/redis/blob/unstable/utils/redis_init_script) 以反映哨兵端口和 .conf 位置.

and modify the init script here (https://github.com/antirez/redis/blob/unstable/utils/redis_init_script) to reflect the sentinel port and .conf location.

$EXEC $CONF --sentinel # 以哨兵模式启动

$EXEC $CONF --sentinel # starting in Sentinel mode

剩下的就像你在 redis 服务器上所做的一样.

and the rest is like you did for redis server.

这篇关于redis 2.8.7 linux的哨兵环境配置问题,如何让它自动启动,应该订阅什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆