Aller au contenu principal
Version : Suivant

Simuler les pannes Redis

Traduction Bêta Non Officielle

Cette page a été traduite par PageTurner AI (bêta). Non approuvée officiellement par le projet. Vous avez trouvé une erreur ? Signaler un problème →

Ce document explique comment utiliser Chaosd pour simuler des pannes Redis. Cette fonctionnalité utilise les interfaces Golang du package go-redis et l'outil en ligne de commande redis-server. Vous pouvez créer des expériences en mode ligne de commande ou en mode service.

Créer des expériences en mode ligne de commande

Avant de créer une expérience, vous pouvez exécuter la commande suivante pour voir les types de pannes Redis pris en charge par Chaosd :

chaosd attack redis -h

Le résultat est le suivant :

Redis attack related commands

Usage:
chaosd attack redis [command]

Available Commands:
cache-expiration expire keys in Redis
cache-limit set maxmemory of Redis
cache-penetration penetrate cache
sentinel-restart restart sentinel
sentinel-stop stop sentinel

Flags:
-h, --help help for redis

Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

Use "chaosd attack redis [command] --help" for more information about a command.

Actuellement, Chaosd prend en charge la simulation de l'expiration du cache, de la pénétration du cache, de la limitation du cache, du redémarrage du sentinelle et de l'arrêt du sentinelle.

Simuler l'expiration du cache en mode ligne de commande

La signification de cette commande est identique à EXPIRE dans Redis. Pour plus de détails, consultez la documentation officielle Redis.

note

Actuellement, Chaosd ne prend pas en charge la récupération des clés ayant exécuté cache-expiration. Veuillez donc les sauvegarder à l'avance si vous souhaitez les récupérer.

Commandes pour l'expiration du cache

chaosd attack redis cache-expiration -h

Le résultat est le suivant :

expire keys in Redis

Usage:
chaosd attack redis cache-expiration [flags]

Flags:
-a, --addr string The address of redis server
--expiration string The expiration of the key. A expiration string should be able to be converted to a time duration, such as "5s" or "30m" (default "0")
-h, --help help for cache-expiration
-k, --key string The key to be set a expiration, default expire all keys
--option string The additional options of expiration, only NX, XX, GT, LT supported
-p, --password string The password of server

Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

Description de la configuration pour l'expiration du cache

Configuration itemAbbreviationTypeDescriptionValue
addrastringThe address and port of Redis server to be injected into the fault, for example 127.0.0.1:6379Default value: ""
expirationNonestringThe specified key will be expired after expiration arrivesDefault value: "0". Make sure that the string is in the format supported by time.Duration
keykstringThe key to be expiredDefault value: "", which means the expiration is set for all keys
optionNonestringAdditional options for expiration. Only versions of Redis after 7.0.0 support this flagDefault value: "". Only NX, XX, GT, and LT are supported
passwordpstringThe password to log in to the serverDefault value: ""

Exemple pour simuler l'expiration du cache

chaosd attack redis cache-expiration -a 127.0.0.1:6379 --option GT --expiration 1m

Simuler la limitation du cache en mode ligne de commande

Commandes pour la limitation du cache

chaosd attack redis cache-limit -h

Le résultat est le suivant :

set maxmemory of Redis

Usage:
chaosd attack redis cache-limit [flags]

Flags:
-a, --addr string The address of redis server
-h, --help help for cache-limit
-p, --password string The password of server
--percent string The percentage of maxmemory
-s, --size string The size of cache (default "0")

Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

Description de la configuration pour la limitation du cache

Configuration itemAbbreviationTypeDescriptionValue
addrastringThe address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379Default value: ""
passwordpstringThe password to log in to the serverDefault value: ""
percentNonestringSpecifies maxmemory as a percentage of the original valueDefault value: ""
sizesstringSpecifies the size of maxmemoryDefault 0, which means no limitation of memory

Exemple pour simuler la limitation du cache

chaosd attack redis cache-limit -a 127.0.0.1:6379 -s 256M

Simuler la pénétration du cache en mode ligne de commande

Cette commande envoie le nombre spécifié de requêtes GET au serveur Redis aussi rapidement que possible en utilisant Redis Pipeline. Comme les clés demandées n'existent pas sur le serveur Redis, ces requêtes provoqueront un phénomène de pénétration du cache.

Commandes pour la pénétration du cache

chaosd attack redis cache-penetration -h

Le résultat est le suivant :

penetrate cache

Usage:
chaosd attack redis cache-penetration [flags]

Flags:
-a, --addr string The address of redis server
-h, --help help for cache-penetration
-p, --password string The password of server
--request-num int The number of requests

Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

Description de la configuration pour la pénétration du cache

Configuration itemAbbreviationTypeDescriptionValue
addrastringThe address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379Default value: ""
passwordpstringThe password to log in to the serverDefault value: ""
request-numNoneintSpecifies the number of requests to be sent to the Redis serverDefault value: 0

Exemple pour simuler la pénétration du cache

chaosd attack redis cache-penetration -a 127.0.0.1:6379 --request-num 100000

Simuler le redémarrage du sentinelle en mode ligne de commande

Commandes pour le redémarrage du sentinelle

chaosd attack redis sentinel-restart -h

Le résultat est le suivant :

restart sentinel

Usage:
chaosd attack redis sentinel-restart [flags]

Flags:
-a, --addr string The address of redis server
-c, --conf string The config of Redis server
--flush-config Force Sentinel to rewrite its configuration on disk (default true)
-h, --help help for sentinel-restart
-p, --password string The password of server
--redis-path string The path of the redis-server command

Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

Description de la configuration pour le redémarrage du sentinelle

Configuration itemAbbreviationTypeDescriptionValue
addrastringThe address and port of Sentinel to be injected into the fault, such as 127.0.0.1:26379Default value: ""
confcstringSpecifies the path of Sentinel config file, this file will be used to revover the SentinelDefault value: ""
flush-configNoneboolForces Sentinel to rewrite its configuration on disk, including the current Sentinel stateDefault value: true
passwordpstringThe password to log in to the serverDefault value: ""
redis-pathNonestringSpecifies the path of redis-server command-line toolDefault value: ""

Exemple pour simuler le redémarrage du sentinelle

chaosd attack redis sentinel-restart -a 127.0.0.1:26379 --conf /home/redis-test/sentinel-26379.conf

Simuler l'arrêt du sentinelle en mode ligne de commande

Commandes pour l'arrêt du sentinelle

chaosd attack redis sentinel-stop -h

Le résultat est le suivant :

stop sentinel

Usage:
chaosd attack redis sentinel-stop [flags]

Flags:
-a, --addr string The address of redis server
-c, --conf string The config path of Redis server
--flush-config Force Sentinel to rewrite its configuration on disk (default true)
-h, --help help for sentinel-stop
-p, --password string The password of server
--redis-path string The path of the redis-server command

Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

Description de la configuration pour l'arrêt du sentinelle

Configuration itemAbbreviationTypeDescriptionValue
addrastringThe address and port of Sentinel to be injected into the fault, such as 127.0.0.1:26379Default value: ""
confcstringSpecifies the path of Sentinel configuration file, which is used to recover the SentinelDefault value: ""
flush-configNoneboolForces Sentinel to rewrite its configuration on disk, including the current Sentinel stateDefault value: true
passwordpstringThe password to log in to the serverDefault value: ""
redis-pathNonestringSpecifies the path of redis-server command-line toolDefault value: ""

Exemple pour simuler le redémarrage du sentinelle

chaosd attack redis sentinel-stop -a 127.0.0.1:26379 --conf /home/redis-test/sentinel-26379.conf

Créer des expériences de panne Redis en mode service

Pour créer des expériences en mode service, procédez comme suit :

  1. Lancez Chaosd en mode service :

    chaosd server --port 31767
  2. Envoyez une requête HTTP POST au chemin /api/attack/redis du service Chaosd.

    curl -X POST 127.0.0.1:31767/api/attack/redis -H "Content-Type:application/json" -d '{fault-configuration}'

    Dans la commande ci-dessus, vous devez configurer fault-configuration selon les types de panne. Pour les paramètres correspondants, reportez-vous aux paramètres et exemples de chaque type de panne dans les sections suivantes.

note

Lors de l'exécution d'une expérience, notez l'UID de l'expérience. Pour arrêter l'expérience associée à cet UID, envoyez une requête HTTP DELETE au chemin /api/attack/{uid} du service Chaosd.

Simuler l'expiration du cache en mode service

Paramètres pour simuler l'expiration du cache

ParameterDescriptionTypeValue
actionAction of the experimentstringset to "corrupt"
addrThe address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379stringDefault value: ""
expirationThe specified key will be expired after expiration arrivesstringDefault value: "0". Make sure that the string is in the format supported by time.Duration
keyThe key to be expiredstringDefault value: "", which means the expiration is set for all keys
optionAdditional options for expiration. Only versions of Redis after 7.0.0 support this flagstringDefault value: "". Only NX, XX, GT, and LT are supported
passwordThe password to log in to the serverDefault value: ""

Exemple pour simuler l'expiration du cache en mode service

curl -X POST 127.0.0.1:31767/api/attack/redis -H "Content-Type:application/json" -d '{"action":"expiration", "expiration":"1m","addr":"127.0.0.1:6379"}'

Simuler la limite de cache en mode service

Paramètres pour simuler la limite de cache

ParameterDescriptionTypeValue
actionAction of the experimentstringset to "cacheLimit"
addrThe address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379stringDefault value: ""
passwordThe password to log in to the serverstringDefault value: ""
percentSpecifies maxmemory as a percentage of the original valuestringDefault value: ""
sizeSpecifies the size of maxmemorystringDefault 0, which means no limitation of memory

Exemple pour simuler la limite de cache en mode service

curl -X POST 127.0.0.1:31767/api/attack/redis -H "Content-Type:application/json" -d '{"action":"cacheLimit", ""addr":"127.0.0.1:6379", "percent":"50%"}'

Simuler la pénétration de cache en mode service

Paramètres pour simuler la pénétration de cache

ParameterDescriptionTypeValue
actionAction of the experimentstringset to "penetration"
addrThe address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379stringDefault value: ""
passwordThe password to log in to the serverstringDefault value: ""
request-numSpecifies the number of requests to be sent to the Redis serverintDefault value: 0

Exemple pour simuler la pénétration de cache en mode service

curl -X POST 127.0.0.1:31767/api/attack/redis -H "Content-Type:application/json" -d '{"action":"penetration", ""addr":"127.0.0.1:6379", "request-num":"10000"}'

Simuler le redémarrage de Sentinel en mode service

Paramètres pour simuler le redémarrage de Sentinel

ParameterDescriptionTypeValue
actionAction of the experimentstringset to "restart"
addrThe address and port of Sentinel to be injected into the fault, such as 127.0.0.1:26379stringDefault value: ""
confSpecifies the path of Sentinel configuration file, which is used to recover the SentinelstringDefault value: ""
flush-configForces Sentinel to rewrite its configuration on disk, including the current Sentinel stateboolDefault value: true
passwordThe password to log in to the serverstringDefault value: ""
redis-pathSpecifies the path of redis-server command-line toolstringDefault value: ""

Exemple pour simuler le redémarrage de Sentinel en mode service

curl -X POST 127.0.0.1:31767/api/attack/redis -H "Content-Type:application/json" -d '{"action":"restart", ""addr":"127.0.0.1:26379", "conf":"/home/redis-test/sentinel-26379.conf"}'

Simuler l'arrêt de Sentinel en mode service

Paramètres pour simuler l'arrêt de Sentinel

ParameterDescriptionTypeValue
actionAction of the experimentstringset to "stop"
addrThe address and port of Sentinel to be injected into the fault, such as 127.0.0.1:26379stringDefault value: ""
confSpecifies the path of Sentinel configuration file, which is used to recover the SentinelstringDefault value: ""
flush-configForces Sentinel to rewrite its configuration on disk, including the current Sentinel stateboolDefault value: true
passwordThe password to log in to the serverstringDefault value: ""
redis-pathSpecifies the path of redis-server command-line toolstringDefault value: ""

Exemple pour simuler l'arrêt de Sentinel en mode service

curl -X POST 127.0.0.1:31767/api/attack/redis -H "Content-Type:application/json" -d '{"action":"stop", ""addr":"127.0.0.1:26379", "conf":"/home/redis-test/sentinel-26379.conf"}'