Zum Hauptinhalt springen
Version: 2.6.7

Simulation von Redis-Fehlern

Inoffizielle Beta-Übersetzung

Diese Seite wurde von PageTurner AI übersetzt (Beta). Nicht offiziell vom Projekt unterstützt. Fehler gefunden? Problem melden →

Dieses Dokument erklärt, wie Sie mit Chaosd Redis-Fehler simulieren können. Diese Funktion nutzt Golang-Interfaces aus dem go-redis-Paket und das Kommandozeilen-Tool redis-server. Sie können Experimente entweder im Kommandozeilenmodus oder Service-Modus erstellen.

Experimente im Kommandozeilenmodus erstellen

Vor dem Erstellen eines Experiments können Sie folgenden Befehl ausführen, um die unterstützten Redis-Fehlertypen anzuzeigen:

chaosd attack redis -h

Das Ergebnis sieht wie folgt aus:

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.

Chaosd unterstützt derzeit die Simulation von Cache-Verfall, Cache-Penetration, Cache-Limit, Sentinel-Neustart und Sentinel-Stopp.

Cache-Verfall im Kommandozeilenmodus simulieren

Die Bedeutung dieses Befehls entspricht EXPIRE in Redis. Weitere Details finden Sie in der offiziellen Redis-Dokumentation.

Hinweis

Aktuell unterstützt Chaosd nicht die Wiederherstellung von Schlüsseln, die cache-expiration ausgeführt haben. Bitte sichern Sie diese daher im Voraus, falls eine Wiederherstellung benötigt wird.

Befehle für Cache-Verfall

chaosd attack redis cache-expiration -h

Das Ergebnis sieht wie folgt aus:

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

Konfigurationsbeschreibung für Cache-Verfall

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: ""

Beispiel für Cache-Verfall-Simulation

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

Cache-Limit im Kommandozeilenmodus simulieren

Befehle für Cache-Limit

chaosd attack redis cache-limit -h

Das Ergebnis sieht wie folgt aus:

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

Konfigurationsbeschreibung für Cache-Limit

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

Beispiel für Cache-Limit-Simulation

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

Cache-Penetration im Kommandozeilenmodus simulieren

Dieser Befehl sendet mit Redis Pipeline die angegebene Anzahl von GET-Anfragen so schnell wie möglich an den Redis-Server. Da die angefragten Schlüssel nicht existieren, verursachen diese Anfragen einen Cache-Penetration-Effekt.

Befehle für Cache-Penetration

chaosd attack redis cache-penetration -h

Das Ergebnis sieht wie folgt aus:

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

Konfigurationsbeschreibung für Cache-Penetration

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

Beispiel für Cache-Penetration-Simulation

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

Sentinel-Neustart im Kommandozeilenmodus simulieren

Befehle für Sentinel-Neustart

chaosd attack redis sentinel-restart -h

Das Ergebnis sieht wie folgt aus:

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

Konfigurationsbeschreibung für Sentinel-Neustart

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: ""

Beispiel für Sentinel-Neustart-Simulation

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

Sentinel-Stopp im Kommandozeilenmodus simulieren

Befehle für Sentinel-Stopp

chaosd attack redis sentinel-stop -h

Das Ergebnis sieht wie folgt aus:

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

Konfigurationsbeschreibung für Sentinel-Stopp

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: ""

Beispiel für Sentinel-Neustart-Simulation

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

Redis-Fehler-Experimente im Service-Modus erstellen

Gehen Sie wie folgt vor, um Experimente im Dienstmodus zu erstellen:

  1. Starten Sie Chaosd im Dienstmodus:

    chaosd server --port 31767
  2. Senden Sie eine POST-HTTP-Anfrage an den Pfad /api/attack/redis des Chaosd-Services:

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

    Konfigurieren Sie fault-configuration entsprechend dem Fehlertyp. Die entsprechenden Parameter entnehmen Sie den folgenden Abschnitten mit Parametern und Beispielen.

Hinweis

Notieren Sie sich beim Starten eines Experiments die UID des Experiments. Um das Experiment zu beenden, senden Sie eine DELETE-HTTP-Anfrage an den Pfad /api/attack/{uid} des Chaosd-Dienstes.

Cache-Verfall im Service-Modus simulieren

Parameter für Cache-Verfall-Simulation

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: ""

Beispiel für Cache-Verfall-Simulation im Service-Modus

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"}'

Cache-Limit über den Dienstmodus simulieren

Parameter für die Simulation des Cache-Limits

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

Beispiel für die Simulation des Cache-Limits über den Dienstmodus

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%"}'

Cache-Penetration über den Dienstmodus simulieren

Parameter für die Simulation der Cache-Penetration

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

Beispiel für die Simulation der Cache-Penetration über den Dienstmodus

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"}'

Sentinel-Neustart über den Dienstmodus simulieren

Parameter für die Simulation des Sentinel-Neustarts

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: ""

Beispiel für die Simulation des Sentinel-Neustarts über den Dienstmodus

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"}'

Sentinel-Stopp über den Dienstmodus simulieren

Parameter für die Simulation des Sentinel-Stopps

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: ""

Beispiel für die Simulation des Sentinel-Stopps über den Dienstmodus

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"}'