Skip to content

Redis Replication

Angeheftet Verschoben Redis
4 1 586
  • 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
    
  • Restic v0.17.0 released

    Restic restic linux
    1
    0 Stimmen
    1 Beiträge
    154 Aufrufe
    Niemand hat geantwortet
  • Semaphore - Installation & Anwendung

    Verschoben Ansible semaphore ansible linux
    4
    9
    0 Stimmen
    4 Beiträge
    2k Aufrufe
    FrankMF
    Ich parke das mal hier, damit ich das nicht noch mal vergesse. Hat mich eben mal wieder eine Stunde gekostet /etc/ansible/ansible.cfg [defaults] host_key_checking = False Edit -> https://linux-nerds.org/topic/1493/ansible-host_key_checking
  • Samba Installation - Server & Client

    Linux samba linux
    1
    0 Stimmen
    1 Beiträge
    155 Aufrufe
    Niemand hat geantwortet
  • Redis - Zweite Instanz

    Redis redis linux
    1
    0 Stimmen
    1 Beiträge
    297 Aufrufe
    Niemand hat geantwortet
  • 10G

    Linux 10g linux
    2
    0 Stimmen
    2 Beiträge
    208 Aufrufe
    FrankMF
    Bedingt durch ein paar Probleme mit der Forensoftware, habe ich einen kleinen Datenverlust erlitten. Dazu gehören auch hier einige Beiträge. Dann versuche ich das mal zu rekonstruieren. Oben hatten wir das SFP+ Modul ja getestet. Als nächsten Schritt habe ich die ASUS XG-C100F 10G SFP+ Netzwerkkarte in meinen Hauptrechner verbaut. [image: 1635752117002-20211028_162455_ergebnis.jpg] Die Verbindung zum Zyxel Switch erfolgt mit einem DAC-Kabel. Im Video zum Zyxel Switch wurde schön erklärt, das die DAC Verbindung stromsparender als RJ45 Adapter sind. Somit fiel die Wahl auf die DAC Verbindungen. Hier nochmal das Video. https://www.youtube.com/watch?v=59I-RlliRms So sieht so ein DAC Verbindungskabel aus. Die SFP+ Adapter sind direkt daran montiert. [image: 1635752308951-20211028_170118_ergebnis.jpg] ethtool root@frank-MS-7C37:/home/frank# ethtool enp35s0 Settings for enp35s0: Supported ports: [ FIBRE ] Supported link modes: 100baseT/Full 1000baseT/Full 10000baseT/Full 2500baseT/Full 5000baseT/Full Supported pause frame use: Symmetric Receive-only Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 100baseT/Full 1000baseT/Full 10000baseT/Full 2500baseT/Full 5000baseT/Full Advertised pause frame use: Symmetric Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 10000Mb/s Duplex: Full Port: FIBRE PHYAD: 0 Transceiver: internal Auto-negotiation: on Supports Wake-on: pg Wake-on: g Current message level: 0x00000005 (5) drv link Link detected: yes iperf3 ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Accepted connection from 192.168.3.207, port 44570 [ 5] local 192.168.3.213 port 5201 connected to 192.168.3.207 port 44572 [ ID] Interval Transfer Bitrate Retr Cwnd [ 5] 0.00-1.00 sec 1.10 GBytes 9.43 Gbits/sec 46 1.59 MBytes [ 5] 1.00-2.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.60 MBytes [ 5] 2.00-3.00 sec 1.10 GBytes 9.42 Gbits/sec 3 1.60 MBytes [ 5] 3.00-4.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.60 MBytes [ 5] 4.00-5.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.61 MBytes [ 5] 5.00-6.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.63 MBytes [ 5] 6.00-7.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.63 MBytes [ 5] 7.00-8.00 sec 1.09 GBytes 9.41 Gbits/sec 0 1.68 MBytes [ 5] 8.00-9.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.68 MBytes [ 5] 9.00-10.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.68 MBytes [ 5] 10.00-10.02 sec 22.5 MBytes 9.45 Gbits/sec 0 1.68 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.02 sec 11.0 GBytes 9.42 Gbits/sec 49 sender
  • ZFS - Wichtige Befehle

    Linux zfs linux
    3
    0 Stimmen
    3 Beiträge
    887 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.
  • NanoPi R2S - OpenWRT VLAN

    Verschoben NanoPi R2S nanopir2s openwrt linux
    11
    8
    0 Stimmen
    11 Beiträge
    2k Aufrufe
    FrankMF
    @thrakath1980 Ok, du meinst die FriendlyArm Variante von OpenWRT. Ich denke, da sollte man besser alles neu machen. Leider ist das bei OpenWRT nicht so einfach zu updaten/upgraden wie z.B. bei einem Linux Kernel. Ich habe es mal runtergeladen, wenn ich mal Zeit habe, schau ich mal rein.
  • NanoPi R2S - OpenWRT

    Verschoben NanoPi R2S nanopir2s openwrt linux
    6
    6
    0 Stimmen
    6 Beiträge
    746 Aufrufe
    FrankMF
    @thrakath1980 Ich wollte noch auf ein Thema zurück kommen. Das Original OpenWRT auf dem R2S ist ja ein Snapshot. Den kann man ohne Probleme aktualisieren. Unten ist dann ein Haken mit "Keep settings...." Gerade probiert, ging einwandfrei. Netzwerkeinstellungen und Firewall Settings blieben erhalten.