Simulation von Redis-Fehlern
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.
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 item | Abbreviation | Type | Description | Value |
|---|---|---|---|---|
addr | a | string | The address and port of Redis server to be injected into the fault, for example 127.0.0.1:6379 | Default value: "" |
expiration | None | string | The specified key will be expired after expiration arrives | Default value: "0". Make sure that the string is in the format supported by time.Duration |
key | k | string | The key to be expired | Default value: "", which means the expiration is set for all keys |
option | None | string | Additional options for expiration. Only versions of Redis after 7.0.0 support this flag | Default value: "". Only NX, XX, GT, and LT are supported |
password | p | string | The password to log in to the server | Default 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 item | Abbreviation | Type | Description | Value |
|---|---|---|---|---|
addr | a | string | The address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379 | Default value: "" |
password | p | string | The password to log in to the server | Default value: "" |
percent | None | string | Specifies maxmemory as a percentage of the original value | Default value: "" |
size | s | string | Specifies the size of maxmemory | Default 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 item | Abbreviation | Type | Description | Value |
|---|---|---|---|---|
addr | a | string | The address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379 | Default value: "" |
password | p | string | The password to log in to the server | Default value: "" |
request-num | None | int | Specifies the number of requests to be sent to the Redis server | Default 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 item | Abbreviation | Type | Description | Value |
|---|---|---|---|---|
addr | a | string | The address and port of Sentinel to be injected into the fault, such as 127.0.0.1:26379 | Default value: "" |
conf | c | string | Specifies the path of Sentinel config file, this file will be used to revover the Sentinel | Default value: "" |
flush-config | None | bool | Forces Sentinel to rewrite its configuration on disk, including the current Sentinel state | Default value: true |
password | p | string | The password to log in to the server | Default value: "" |
redis-path | None | string | Specifies the path of redis-server command-line tool | Default 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 item | Abbreviation | Type | Description | Value |
|---|---|---|---|---|
addr | a | string | The address and port of Sentinel to be injected into the fault, such as 127.0.0.1:26379 | Default value: "" |
conf | c | string | Specifies the path of Sentinel configuration file, which is used to recover the Sentinel | Default value: "" |
flush-config | None | bool | Forces Sentinel to rewrite its configuration on disk, including the current Sentinel state | Default value: true |
password | p | string | The password to log in to the server | Default value: "" |
redis-path | None | string | Specifies the path of redis-server command-line tool | Default 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:
-
Starten Sie Chaosd im Dienstmodus:
chaosd server --port 31767 -
Senden Sie eine
POST-HTTP-Anfrage an den Pfad/api/attack/redisdes Chaosd-Services:curl -X POST 127.0.0.1:31767/api/attack/redis -H "Content-Type:application/json" -d '{fault-configuration}'Konfigurieren Sie
fault-configurationentsprechend dem Fehlertyp. Die entsprechenden Parameter entnehmen Sie den folgenden Abschnitten mit Parametern und Beispielen.
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
| Parameter | Description | Type | Value |
|---|---|---|---|
action | Action of the experiment | string | set to "corrupt" |
addr | The address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379 | string | Default value: "" |
expiration | The specified key will be expired after expiration arrives | string | Default value: "0". Make sure that the string is in the format supported by time.Duration |
key | The key to be expired | string | Default value: "", which means the expiration is set for all keys |
option | Additional options for expiration. Only versions of Redis after 7.0.0 support this flag | string | Default value: "". Only NX, XX, GT, and LT are supported |
password | The password to log in to the server | Default 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
| Parameter | Description | Type | Value |
|---|---|---|---|
action | Action of the experiment | string | set to "cacheLimit" |
addr | The address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379 | string | Default value: "" |
password | The password to log in to the server | string | Default value: "" |
percent | Specifies maxmemory as a percentage of the original value | string | Default value: "" |
size | Specifies the size of maxmemory | string | Default 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
| Parameter | Description | Type | Value |
|---|---|---|---|
action | Action of the experiment | string | set to "penetration" |
addr | The address and port of Redis server to be injected into the fault, such as 127.0.0.1:6379 | string | Default value: "" |
password | The password to log in to the server | string | Default value: "" |
request-num | Specifies the number of requests to be sent to the Redis server | int | Default 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
| Parameter | Description | Type | Value |
|---|---|---|---|
action | Action of the experiment | string | set to "restart" |
addr | The address and port of Sentinel to be injected into the fault, such as 127.0.0.1:26379 | string | Default value: "" |
conf | Specifies the path of Sentinel configuration file, which is used to recover the Sentinel | string | Default value: "" |
flush-config | Forces Sentinel to rewrite its configuration on disk, including the current Sentinel state | bool | Default value: true |
password | The password to log in to the server | string | Default value: "" |
redis-path | Specifies the path of redis-server command-line tool | string | Default 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
| Parameter | Description | Type | Value |
|---|---|---|---|
action | Action of the experiment | string | set to "stop" |
addr | The address and port of Sentinel to be injected into the fault, such as 127.0.0.1:26379 | string | Default value: "" |
conf | Specifies the path of Sentinel configuration file, which is used to recover the Sentinel | string | Default value: "" |
flush-config | Forces Sentinel to rewrite its configuration on disk, including the current Sentinel state | bool | Default value: true |
password | The password to log in to the server | string | Default value: "" |
redis-path | Specifies the path of redis-server command-line tool | string | Default 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"}'