Skip to content

Redis Replication

Angeheftet Verschoben Redis
4 1 599
  • Spielen wir mal folgendes Szenario durch, wir haben eine Redis Datenbank und möchten diese Datenbank irgendwo anders nochmal haben. Nennen wir es eine Sicherung. Redis hat dafür eine Master/Slave Möglichkeit eingebaut.

    Ok, wir wissen das es nicht gut ist im Internet Daten im Klartext von einem Server zum nächsten zu schicken. Also brauchen wir etwas verschlüsseltes 😉 Dazu habe ich mich ja ein wenig mit Wireguard beschäftigt Beitrag

    Damit haben wir also eine Möglichkeit von Server1 (Master) zum Server2 (Slave) eine verschlüsselte Verbindung aufzubauen und das ohne großen Aufwand.

    Die Konfiguration von Redis ist recht einfach zu erledigen.

    Server 1 MASTER

    /etc/redis/redis.conf

    Ich gehe hier nur auf die Parameter ein, die für die Replication wichtig sind!

    bind 127.0.0.1 ::1 192.168.10.1
    

    Hier sehen wir drei IP-Adressen.

    • 127.0.0.1 localhost
    • ::1 Das gleiche für IPv6
    • 192.168.10.1

    Die ersten beiden sind Standard, die dritte habe ich erweitert. Dabei handelt sich um meine Wireguard IP-Adresse, die im privaten Netz 192.168.10.x liegt.

    Diese DB hat ein Passwort

    requirepass XXXXXXXXXXXX
    

    Nach den Änderungen den Dienst Redis kurz neustarten.

    service redis restart
    

    Das war's.

    Server 2 SLAVE

    /etc/redis/redis.conf

    Hier ist es nicht nötig eine IP-Adresse anzugeben.

    bind 127.0.0.1 ::1
    

    Der Master muss ja auf der Schnittstelle lauschen, ob da was für ihn ankommt. Der Slave nimmt einfach über die Wireguard Schnittstelle wg0 die Verbindung auf.

    slaveof 192.168.10.1  6379
    

    Hiermit definieren wir, welcher Rechner im Netz der Master ist. In diesem Fall 192.168.10.1, meine Wireguard-Adresse. Der Port ist Standard 6379.

    Damit weiß der Slave wo er den Master erreichen kann. Dazu nimmt er über die Schnittstelle wg0 Verbindung mit dem Rechner auf der IP-Adresse 192.168.10.1 auf. Also nutzt er die verschlüsselte Verbindung von Wireguard.

    Da der Master passwortgeschützt ist, muss der Slave natürlich das PW kennen, ohne bekommt er ja keine Verbindung. Dafür nutzt Redis folgenden Befehl.

    masterauth XXXXXXXXXX
    

    Das alles speichern und den Dienst neustarten.

    service redis restart
    

    In derselben Sekunde wo der Dienst neugestartet wird, ist die DB auch schon da.

    Vorher

    root@rp_64_test:/etc/redis# ls -la /var/lib/redis
    total 12
    drwxr-x---  2 redis redis 4096 Mar 21 16:05 .
    drwxr-xr-x 27 root  root  4096 Mar 21 15:59 ..
    -rw-rw----  1 redis redis   92 Mar 21 16:05 dump.rdb
    

    Nachher

    root@rp_64_test:/etc/redis# ls -la /var/lib/redis
    total 7020
    drwxr-x---  2 redis redis    4096 Mar 21 16:09 .
    drwxr-xr-x 27 root  root     4096 Mar 21 15:59 ..
    -rw-r-----  1 redis redis 7178902 Mar 21 16:09 dump.rdb
    

    Vom Master der Datentransfer über wg0

    Vorher

    root@rp64_nextcloud:~# wg
    interface: wg0
      public key: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
      private key: (hidden)
      listening port: 35866
    
    peer: zj1ajjcBhgFSe+NUHtnTNQ4+emsVgHDPVOeQHVKK4U4=
      endpoint: 192.168.3.14:39717
      allowed ips: 192.168.10.2/32
      latest handshake: 10 seconds ago
      transfer: 19.04 KiB received, 21.66 KiB sent
    

    Nachher

    root@rp64_nextcloud:/etc/redis# wg
    interface: wg0
      public key: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
      private key: (hidden)
      listening port: 35866
    
    peer: zj1ajjcBhgFSe+NUHtnTNQ4+emsVgHDPVOeQHVKK4U4=
      endpoint: 192.168.3.14:39717
      allowed ips: 192.168.10.2/32
      latest handshake: 59 seconds ago
      transfer: 120.10 KiB received, 7.33 MiB sent
    

    Er hat die Datenbank, ca. 6,9 MB groß, zum Slave gesendet.

    Master

    root@rp64_nextcloud:/etc/redis# ls -lha /var/lib/redis
    total 6,9M
    drwxr-x---  2 redis redis 4,0K Mär 21 17:09 .
    drwxr-xr-x 29 root  root  4,0K Mär  2 12:52 ..
    -rw-rw----  1 redis redis 6,9M Mär 21 17:09 dump.rdb
    

    Slave

    root@rp_64_test:/etc/redis# ls -lha /var/lib/redis
    total 6.9M
    drwxr-x---  2 redis redis 4.0K Mar 21 16:09 .
    drwxr-xr-x 27 root  root  4.0K Mar 21 15:59 ..
    -rw-r-----  1 redis redis 6.9M Mar 21 16:09 dump.rdb
    

    Und wg0

    root@rp_64_test:/etc/redis# wg
    interface: wg0
      public key: zj1ajjcBhgFSe+NUHtnTNQ4+emsVgHDPVOeQHVKK4U4=
      private key: (hidden)
      listening port: 39717
    
    peer: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
      endpoint: 192.168.3.208:35866
      allowed ips: 192.168.10.1/32
      latest handshake: 1 minute, 4 seconds ago
      transfer: 7.32 MiB received, 110.20 KiB sent
    

    Fertig! Eine nette Sache, eine Redis Datenbank zu sichern.

    Und zum Schluß, der Slave ist standardmäßig read-only. Der sollte also am Master nichts kaputt machen.

    # Since Redis 2.6 by default slaves are read-only.
    #
    # Note: read only slaves are not designed to be exposed to untrusted clients
    # on the internet. It's just a protection layer against misuse of the instance.
    # Still a read only slave exports by default all the administrative commands
    # such as CONFIG, DEBUG, and so forth. To a limited extent you can improve
    # security of read only slaves using 'rename-command' to shadow all the
    # administrative / dangerous commands.
    slave-read-only yes
    

    Quelle: https://redis.io/topics/replication

  • Wenn man NodeBB-Foren betreibt, sollte die Vorgehensweise so sein.

    • Redis Master starten
    • Redis Slave starten
    • Danach erst die Foren!!

    Wieder was gelernt 🙂

  • In den Logs sieht das so aus.

    Master

    855:M 10 May 2020 07:51:45.458 * DB loaded from disk: 0.563 seconds
    855:M 10 May 2020 07:51:45.458 * Ready to accept connections
    855:M 10 May 2020 07:51:45.713 * Replica 10.0.0.2:6379 asks for synchronization
    855:M 10 May 2020 07:51:45.713 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for 'd6042ec68cc9b4e3ccd8ebd8e28012133c24efb4', my replication IDs are '071743$
    855:M 10 May 2020 07:51:45.713 * Starting BGSAVE for SYNC with target: disk
    855:M 10 May 2020 07:51:45.716 * Background saving started by pid 859
    859:C 10 May 2020 07:51:46.107 * DB saved on disk
    859:C 10 May 2020 07:51:46.111 * RDB: 24 MB of memory used by copy-on-write
    855:M 10 May 2020 07:51:46.162 * Background saving terminated with success
    855:M 10 May 2020 07:51:46.324 * Synchronization with replica 10.0.0.2:6379 succeeded
    855:M 10 May 2020 07:51:50.674 # Connection with replica 10.0.0.2:6379 lost.
    855:M 10 May 2020 07:51:51.254 * Replica 10.0.0.2:6379 asks for synchronization
    855:M 10 May 2020 07:51:51.255 * Partial resynchronization request from 10.0.0.2:6379 accepted. Sending 0 bytes of backlog starting from offset 1.
    855:M 10 May 2020 07:56:47.021 * 10 changes in 300 seconds. Saving...
    855:M 10 May 2020 07:56:47.023 * Background saving started by pid 978
    978:C 10 May 2020 07:56:47.426 * DB saved on disk
    978:C 10 May 2020 07:56:47.428 * RDB: 28 MB of memory used by copy-on-write
    855:M 10 May 2020 07:56:47.529 * Background saving terminated with success
    855:M 10 May 2020 07:56:52.961 # Connection with replica 10.0.0.2:6379 lost.
    855:M 10 May 2020 07:56:53.649 * Replica 10.0.0.2:6379 asks for synchronization
    855:M 10 May 2020 07:56:53.649 * Partial resynchronization request from 10.0.0.2:6379 accepted. Sending 0 bytes of backlog starting from offset 6413.
    855:M 10 May 2020 08:01:48.089 * 10 changes in 300 seconds. Saving...
    855:M 10 May 2020 08:01:48.091 * Background saving started by pid 1044
    1044:C 10 May 2020 08:01:48.502 * DB saved on disk
    1044:C 10 May 2020 08:01:48.505 * RDB: 24 MB of memory used by copy-on-write
    855:M 10 May 2020 08:01:48.594 * Background saving terminated with success
    

    Slave

    1324:S 10 May 2020 07:56:53.651 * DB loaded from disk: 0.638 seconds
    1324:S 10 May 2020 07:56:53.651 * Before turning into a replica, using my master parameters to synthesize a cached master: I may be able to synchronize with the new master with just a partia$
    1324:S 10 May 2020 07:56:53.651 * Ready to accept connections
    1324:S 10 May 2020 07:56:53.651 * Connecting to MASTER 10.0.0.4:6379
    1324:S 10 May 2020 07:56:53.651 * MASTER <-> REPLICA sync started
    1324:S 10 May 2020 07:56:53.652 * Non blocking connect for SYNC fired the event.
    1324:S 10 May 2020 07:56:53.653 * Master replied to PING, replication can continue...
    1324:S 10 May 2020 07:56:53.654 * Trying a partial resynchronization (request 86ba864a2575c203a4eddd80bd6f4b058ebe1fb7:6413).
    1324:S 10 May 2020 07:56:53.655 * Successful partial resynchronization with master.
    1324:S 10 May 2020 07:56:53.655 * MASTER <-> REPLICA sync: Master accepted a Partial Resynchronization.
    1324:S 10 May 2020 08:01:54.077 * 10 changes in 300 seconds. Saving...
    1324:S 10 May 2020 08:01:54.080 * Background saving started by pid 1494
    1494:C 10 May 2020 08:01:54.523 * DB saved on disk
    1494:C 10 May 2020 08:01:54.527 * RDB: 0 MB of memory used by copy-on-write
    1324:S 10 May 2020 08:01:54.582 * Background saving terminated with success
    
  • Um die Verbindung zu testen, kann man folgende Befehle nutzen.

    redis-cli -h 10.1.1.0 -p 6379 -a <PASSWORD>
    

    und

    telnet 10.1.1.0 6379
    
  • AI Bots aussperren

    Linux linux block-ai nginx
    2
    0 Stimmen
    2 Beiträge
    191 Aufrufe
    FrankMF
    Wir können das noch für eine sanfte Methode erweitern, das ist die Datei robots.txt, wo man sich in alten Zeiten mal dran hielt. Einige Bots machen das, andere nicht. Praktisch, das o.g. Projekt bietet diese Datei auch an. Dann werden wir das kurz mal mit einbauen. ai-block.sh #!/bin/bash # Script um AI-Bots zu blocken # https://github.com/ai-robots-txt/ai.robots.txt/tree/main mkdir /root/AI-test cd /root/AI-test ## Daten holen curl -O https://raw.githubusercontent.com/ai-robots-txt/ai.robots.txt/master/nginx-block-ai-bots.conf curl -O https://raw.githubusercontent.com/ai-robots-txt/ai.robots.txt/master/robots.txt ## Daten in nginx einbauen mv nginx-block-ai-bots.conf /etc/nginx/blocklists/ mv robots.txt /var/www/html ## NGINX neustarten systemctl restart nginx.service Damit das in nginx funktioniert. Den Server Block um folgendes erweitern. # Serve robots.txt directly from Nginx location = /robots.txt { root /var/www/html; try_files $uri =404; } Kurzer Test https://<DOMAIN>/robots.txt Ergebnis User-agent: AI2Bot User-agent: Ai2Bot-Dolma User-agent: Amazonbot User-agent: anthropic-ai User-agent: Applebot User-agent: Applebot-Extended User-agent: Brightbot 1.0 User-agent: Bytespider User-agent: CCBot User-agent: ChatGPT-User User-agent: Claude-Web User-agent: ClaudeBot User-agent: cohere-ai User-agent: cohere-training-data-crawler User-agent: Crawlspace User-agent: Diffbot User-agent: DuckAssistBot User-agent: FacebookBot User-agent: FriendlyCrawler User-agent: Google-Extended User-agent: GoogleOther User-agent: GoogleOther-Image User-agent: GoogleOther-Video User-agent: GPTBot User-agent: iaskspider/2.0 User-agent: ICC-Crawler User-agent: ImagesiftBot User-agent: img2dataset User-agent: imgproxy User-agent: ISSCyberRiskCrawler User-agent: Kangaroo Bot User-agent: Meta-ExternalAgent User-agent: Meta-ExternalFetcher User-agent: OAI-SearchBot User-agent: omgili User-agent: omgilibot User-agent: PanguBot User-agent: Perplexity-User User-agent: PerplexityBot User-agent: PetalBot User-agent: Scrapy User-agent: SemrushBot-OCOB User-agent: SemrushBot-SWA User-agent: Sidetrade indexer bot User-agent: Timpibot User-agent: VelenPublicWebCrawler User-agent: Webzio-Extended User-agent: YouBot Disallow: /
  • Restic v0.17.2 released

    Restic restic linux
    1
    0 Stimmen
    1 Beiträge
    163 Aufrufe
    Niemand hat geantwortet
  • MongoDB Compass

    Linux mongodb flatpak linux
    1
    3
    0 Stimmen
    1 Beiträge
    250 Aufrufe
    Niemand hat geantwortet
  • Manjaro Stable jetzt mit Plasma 6

    Linux kde linux wayland plasma6
    1
    0 Stimmen
    1 Beiträge
    303 Aufrufe
    Niemand hat geantwortet
  • KDE Plasma 6 - Beta 2

    Linux kde linux
    2
    0 Stimmen
    2 Beiträge
    271 Aufrufe
    FrankMF
    Leider hat die Realität mich etwas vom Testen neuer Software abgehalten, aber jetzt geht es langsam wieder los. Den Start macht KDE Plasma 6 - Beta 2. Auch wenn ich schon brennend auf die RC1 warte, die lässt aber noch auf sich warten... https://pointieststick.com/category/this-week-in-kde/ Ok, also die Beta 2 auf meinen Stick und ab damit in mein Testsystem. Einmal starten, kurz danach taucht der KDE Neon Desktop auf. [image: 1705002299148-20240110_201838-resized.jpg] [image: 1705002324795-20240110_201852-resized.jpg] Und klick, wird die Installation gestartet. Danach begrüßt uns dieses Fenster. Ich weiß nicht, warum diese Information nicht automatisch ermittelt wird - nervig. [image: 1705002522434-20240110_201924-resized.jpg] Der Rest der Installation lief einwandfrei, ich habe aber keine besondere Installation vorgenommen. Ganze NVMe plattgemacht und alles drauf. Nichts verschlüsselt usw. Eine Installation, die ich so für meinen Haupt-PC nicht machen würde. Eine Kleinigkeit ist mir noch aufgefallen. Der Calamares Installer der benutzt wird, hat bei mir keine Sonderzeichen akzeptiert. Ich hoffe das wird bis zum Release gefixt. Hier noch kurz das Testsystem [image: 1705003417706-screenshot_20240111_210201.png] Ich nutze ausschließlich Wayland, das läuft einfach wesentlich besser. Aber, ich weiß da draußen gibt es viele die das nicht mögen. Das schöne an Linux - ihr habt die freie Wahl. Was war mir negativ aufgefallen? Installer - keine automatische Standortbestimmung Installer - nimmt keine Sonderzeichen für das PW an Login Window - nach Eingabe PW wird die Taste RETURN nicht akzeptiert. Muss ich mit der Maus anklicken. Skalierung auf meinem Monitor nicht optimal - Schrift unscharf Was ist mir positiv aufgefallen? Ich nutze einen 4K Monitor zum Testen. Die Skalierung war automatisch auf 175%. Eine fast perfekte Wahl, wenn da nicht die unscharfe Schrift wäre. Ich habe das auf 150% gestellt, danach war es deutlich besser. Updates kann man sich über das grafische Frontend holen Standby-Modus ging Und einen nervigen FF Bug konnte ich nicht nachstellen. Auf meinem aktuellen System, KDE Plasma 5, flackert der Bildschirm gelegentlich, wenn ich in der Taskleiste durch die geöffneten FF Fenster scrolle. Bei Plasma 6 konnte ich das bis jetzt noch nicht feststellen. Fazit Sieht gut aus, der Release von KDE Plasma 6 wird gut. Ich freu mich drauf. Und diesen komischen Updatevorgang den KDE Neon da benutzt, diesen M$ Style, den könnt ihr direkt wieder in die Mülltonne kloppen. Das möchte ich bei Linux nicht sehen. [image: 1705005840070-screenshot_20240111_214255-resized.png]
  • ZFS - Wichtige Befehle

    Linux zfs linux
    3
    0 Stimmen
    3 Beiträge
    963 Aufrufe
    FrankMF
    Heute mal drüber gestolpert, das es auch so was geben kann. root@pve2:~# zpool status pool: pool_NAS state: ONLINE status: Some supported and requested features are not enabled on the pool. The pool can still be used, but some features are unavailable. action: Enable all features using 'zpool upgrade'. Once this is done, the pool may no longer be accessible by software that does not support the features. See zpool-features(7) for details. scan: scrub repaired 0B in 00:20:50 with 0 errors on Sun Apr 13 00:44:51 2025 config: NAME STATE READ WRITE CKSUM pool_NAS ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 ata-WDC_WDS100T1R0A-68A4W0_230520800733 ONLINE 0 0 0 ata-WDC_WDS100T1R0A-68A4W0_230520801376 ONLINE 0 0 0 errors: No known data errors Was machen? Als erstes mal ein Backup angestoßen. Danach root@pve2:~# zpool get all pool_NAS | grep feature pool_NAS feature@async_destroy enabled local pool_NAS feature@empty_bpobj active local pool_NAS feature@lz4_compress active local pool_NAS feature@multi_vdev_crash_dump enabled local pool_NAS feature@spacemap_histogram active local pool_NAS feature@enabled_txg active local pool_NAS feature@hole_birth active local pool_NAS feature@extensible_dataset active local pool_NAS feature@embedded_data active local pool_NAS feature@bookmarks enabled local pool_NAS feature@filesystem_limits enabled local pool_NAS feature@large_blocks enabled local pool_NAS feature@large_dnode enabled local pool_NAS feature@sha512 enabled local pool_NAS feature@skein enabled local pool_NAS feature@edonr enabled local pool_NAS feature@userobj_accounting active local pool_NAS feature@encryption enabled local pool_NAS feature@project_quota active local pool_NAS feature@device_removal enabled local pool_NAS feature@obsolete_counts enabled local pool_NAS feature@zpool_checkpoint enabled local pool_NAS feature@spacemap_v2 active local pool_NAS feature@allocation_classes enabled local pool_NAS feature@resilver_defer enabled local pool_NAS feature@bookmark_v2 enabled local pool_NAS feature@redaction_bookmarks enabled local pool_NAS feature@redacted_datasets enabled local pool_NAS feature@bookmark_written enabled local pool_NAS feature@log_spacemap active local pool_NAS feature@livelist enabled local pool_NAS feature@device_rebuild enabled local pool_NAS feature@zstd_compress enabled local pool_NAS feature@draid enabled local pool_NAS feature@zilsaxattr disabled local pool_NAS feature@head_errlog disabled local pool_NAS feature@blake3 disabled local pool_NAS feature@block_cloning disabled local pool_NAS feature@vdev_zaps_v2 disabled local Das kommt von neuen Funktionen, die zu ZFS hinzugefügt wurden und bei Erstellung des Pools nicht vorhanden waren. Dann upgraden wir mal root@pve2:~# zpool upgrade pool_NAS This system supports ZFS pool feature flags. Enabled the following features on 'pool_NAS': zilsaxattr head_errlog blake3 block_cloning vdev_zaps_v2 Kontrolle root@pve2:~# zpool status pool: pool_NAS state: ONLINE scan: scrub repaired 0B in 00:20:50 with 0 errors on Sun Apr 13 00:44:51 2025 config: NAME STATE READ WRITE CKSUM pool_NAS ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 ata-WDC_WDS100T1R0A-68A4W0_230520800733 ONLINE 0 0 0 ata-WDC_WDS100T1R0A-68A4W0_230520801376 ONLINE 0 0 0 errors: No known data errors Features kontrollieren root@pve2:~# zpool get all pool_NAS | grep feature pool_NAS feature@async_destroy enabled local pool_NAS feature@empty_bpobj active local pool_NAS feature@lz4_compress active local pool_NAS feature@multi_vdev_crash_dump enabled local pool_NAS feature@spacemap_histogram active local pool_NAS feature@enabled_txg active local pool_NAS feature@hole_birth active local pool_NAS feature@extensible_dataset active local pool_NAS feature@embedded_data active local pool_NAS feature@bookmarks enabled local pool_NAS feature@filesystem_limits enabled local pool_NAS feature@large_blocks enabled local pool_NAS feature@large_dnode enabled local pool_NAS feature@sha512 enabled local pool_NAS feature@skein enabled local pool_NAS feature@edonr enabled local pool_NAS feature@userobj_accounting active local pool_NAS feature@encryption enabled local pool_NAS feature@project_quota active local pool_NAS feature@device_removal enabled local pool_NAS feature@obsolete_counts enabled local pool_NAS feature@zpool_checkpoint enabled local pool_NAS feature@spacemap_v2 active local pool_NAS feature@allocation_classes enabled local pool_NAS feature@resilver_defer enabled local pool_NAS feature@bookmark_v2 enabled local pool_NAS feature@redaction_bookmarks enabled local pool_NAS feature@redacted_datasets enabled local pool_NAS feature@bookmark_written enabled local pool_NAS feature@log_spacemap active local pool_NAS feature@livelist enabled local pool_NAS feature@device_rebuild enabled local pool_NAS feature@zstd_compress enabled local pool_NAS feature@draid enabled local pool_NAS feature@zilsaxattr enabled local pool_NAS feature@head_errlog active local pool_NAS feature@blake3 enabled local pool_NAS feature@block_cloning enabled local pool_NAS feature@vdev_zaps_v2 enabled local So, alle neuen Features aktiviert. Jetzt kann der Pool weiterhin seine Arbeit machen.
  • Mainline 5.13.x

    Images linux rockpro64
    1
    0 Stimmen
    1 Beiträge
    238 Aufrufe
    Niemand hat geantwortet
  • Restic - Ein Backupkonzept - Wiederherstellung

    Verschoben Restic linux restic
    1
    0 Stimmen
    1 Beiträge
    766 Aufrufe
    Niemand hat geantwortet