Explication détaillée de Redis - Introduction à Sentinel

无忌哥哥
Libérer: 2023-04-03 06:40:02
original
3254 Les gens l'ont consulté

Répertoire

  • Configurer la réplication maître-esclave Redis

    • Utilisez la commande ping pour vérifier si elle est démarrée

    • Afficher les informations de lien sur le nœud maître

  • Commencer à déployer le nœud sentinelle

  • Déployer sentinelle

  • Déployer sentinelle

  • Démarrer Sentinel

    • Démontrer le basculement

    • Afficher les informations sur le nœud actuellement surveillé par Sentinel

    • Interrompre le nœud principal de Redis

    • Vérifiez si le nœud principal de Redis a changé

C'est la fin de l'introduction à Sentinel, pas assez Les corrections sont les bienvenues.

Configurer la réplication maître-esclave Redis

Un nœud maître (port 6379), deux nœuds esclaves (port 6380, 6381), non pour configuration, veuillez consulter mon article précédent sur la réplication maître-esclave Redis.

Utilisez la commande ping pour vérifier s'il est démarré

redis-cli -h 127.0.0.1 -p 6379 ping
Explication détaillée de Redis - Introduction à Sentinel comme suit, retournez PONG pour indiquer que les trois services Redis ont été démarrés Démarrage terminé

Un nœud maître :
Explication détaillée de Redis - Introduction à Sentinel

Deux nœuds esclaves : Explication détaillée de Redis - Introduction à Sentinel

查看6379的连接信息
命令:info replication
可以发现6379的角色是master,有两个从节点,也就是端口为6380,6381的从节点(redis)
Copier après la connexion

Explication détaillée de Redis - Introduction à Sentinel Le nœud maître affiche les informations du lien

同样在6380 从节点中,该节点的角色是slave(从节点),与主节点的连接状态为up(master_link_status),通过这个命令可以方便的查看各个节点的连接状态等信息。
Copier après la connexion

Explication détaillée de Redis - Introduction à Sentinel

除了用info replication命令外,如下命令也可以快速查看链接信息
redis-cli -h 127.0.0.1 -p 6381 info replication
看个人喜好用哪个命令。
Copier après la connexion

Explication détaillée de Redis - Introduction à Sentinel

Commencer à déployer le nœud sentinelle

peut être déployé via des nœuds sentinelles pour rendre la réinitialisation maître-esclave Redis plus hautement disponible. Alors, à quoi sert sentinelle, au sens littéral ? On peut voir que sentinel signifie "sentinel". Il est utilisé pour surveiller les nœuds redis surveillés par Sentinel et a la fonction de basculement. Lorsque le nœud redis surveillé par sentinel est interrompu de manière inattendue, sentinel sélectionnera automatiquement un redis avec le rôle de nœud esclave en tant que nœud maître pour maintenir le suivant et garantir la bonne relation de réplication maître-esclave, et le nœud esclave d'origine est toujours un esclave. nœud, mais leur nœud maître devient le service Redis du nœud maître nouvellement mis à niveau. Commençons par construire une sentinelle étape par étape.
进入安装redis的目录下的配置目录,我的本地是/etc/redis
Copier après la connexion

Explication détaillée de Redis - Introduction à SentinelDéployer Sentinelle

我这边就直接使用原本的sentinel.conf配置,来作为第一个sentinel节点。我们可以进入sentinel.conf配置看下里面到底有啥配置信息:
sentinel monitor mymaster 127.0.0.1 6379 2 //监控的主节点IP和端口,其中mymaster是该节点的别名,2表示判断主节点失败至少需要两个节点同意
sentinel down-after-milliseconds mymaster 30000  //通过ping命令,各个sentinel节点向redis节点是否可达,超过30000毫秒,就判定不可达
sentinel failover-timeout mymaster 180000 //故障转移超时时间为180000毫秒
如果还有其它的配置,可以自己在探索下
Copier après la connexion

启动命令:
sudo redis-sentinel sentinel.conf --sentinel
Copier après la connexion

Explication détaillée de Redis - Introduction à SentinelDémarrer Sentinelle

查看sentinel启动情况
redis-cli -h 127.0.0.1 -p 26379 INFO Sentinel
可以看出与查看redis启动的情况命令类似,截图中可以看到此时sentinel监控redis节点是端口为6379的服务,6379有两个从节点,状态为OK,别名是mymaster
Copier après la connexion

Explication détaillée de Redis - Introduction à Sentinel

继续再配置两个sentinel节点,
sudo cp sentinel.conf  sentinel2.conf 
sudo cp sentinel.conf  sentinel3.conf 
修改两个配置的端口为26380, 26381,其它配置可以不用修改
修改完后,分别启动
sudo redis-sentinel sentinel2.conf --sentinel
sudo redis-sentinel sentinel3.conf --sentinel
Copier après la connexion

Explication détaillée de Redis - Introduction à Sentinel

启动后再次查看sentinel.conf的配置,可以发现配置中多了两个从节点的信息,截图如下:
Copier après la connexion

Explication détaillée de Redis - Introduction à Sentinel

Explication détaillée de Redis - Introduction à Sentinel

查看26379端口的Sentinel节点监控的主节点信息
Copier après la connexion
Démontrer le défaut Transfert

Explication détaillée de Redis - Introduction à SentinelAfficher les informations du nœud actuellement surveillé par sentinel

查看目前redis的进程ps -ef | grep redis
Copier après la connexion

Explication détaillée de Redis - Introduction à Sentinel

之前我们sentinel监控的主节点是6379这个端口,这时候我们kill这个端口的进程,或者使用shutdown命令:
redis-cli -h 127.0.0.1 -p 6379 shutdown
过了30秒之后查看26379端口的Sentinel节点监控的主节点信息,发现主节点信息变成了6380端口的redis(之前的从节点)
Copier après la connexion

Explication détaillée de Redis - Introduction à SentinelInterrompre le nœud principal de redis

验证6380端口的redis变成主节点,此时我们在6380 的redis上设置一个key值,在6381端口的redis上验证是否能获取到该key值
Copier après la connexion

Explication détaillée de Redis - Introduction à SentinelVérifiez si le nœud maître redis a changé

此时发现,6380变成了主节点,6381从节点没有变化,还是从节点。
下面我再次启动6379端口的redis
Copier après la connexion

Explication détaillée de Redis - Introduction à Sentinel

发现原先的主节点6379已经变成了从节点,而它的主节点变成了6380。此时我们再回过头看下26379的监控节点变化,还是6380端口。
Copier après la connexion

Explication détaillée de Redis - Introduction à Sentinel
Explication détaillée de Redis - Introduction à Sentinel

C'est la fin de l'introduction à Sentinel. Toutes les lacunes sont les bienvenues pour être corrigées.

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!