|
| 1 | +--- |
| 2 | +title: rsync-Demo 01 |
| 3 | +author: tianci li |
| 4 | +contributors: Steven Spencer, Ganna Zhyrnova |
| 5 | +update: 2021-11-04 |
| 6 | +--- |
| 7 | + |
| 8 | +# Vorwort |
| 9 | + |
| 10 | +`rsync` muss vor der Datensynchronisierung eine Benutzerauthentifizierung durchführen. **Es gibt zwei Protokollmethoden für die Authentifizierung: SSH-Protokoll und rsync-Protokoll (der Standardport des rsync-Protokolls ist 873)** |
| 11 | + |
| 12 | +* Login-Methode mit SSH-Protokollüberprüfung: Benutzen Sie das SSH-Protokoll als Basis für die Authentifizierung der Benutzeridentität (d.h. verwenden Sie den Systembenutzer und das Passwort zur Verifizierung) und führen Sie dann die Datensynchronisierung durch. |
| 13 | +* Login-Methode für rsync-Protokollüberprüfung: Benutzen Sie das `rsync`-Protokoll für die Authentifizierung (Benutzer, die keine GNU/Linux-Systembenutzer sind, ähnlich wie vsftpd-virtuelle Benutzer), und führen Sie dann die Datensynchronisierung durch. |
| 14 | + |
| 15 | +Vor der spezifischen Demonstration der rsync-Synchronisierung müssen Sie den Befehl `rsync` verwenden. In Rocky Linux 8 ist das rsync-rpm-Paket standardmäßig installiert und die Version 3.1.3-12 ist wie folgt: |
| 16 | + |
| 17 | +```bash |
| 18 | +[root@Rocky ~]# rpm -qa|grep rsync |
| 19 | +rsync-3.1.3-12.el8.x86_64 |
| 20 | +``` |
| 21 | + |
| 22 | +```txt |
| 23 | +Basic format: rsync [options] original location target location |
| 24 | +Commonly used options: |
| 25 | +-a: archive mode, recursive and preserves the attributes of the file object, which is equivalent to -rlptgoD (without -H, -A, -X) |
| 26 | +-v: Display detailed information about the synchronization process |
| 27 | +-z: compress when transferring files |
| 28 | +-H: Keep hard link files |
| 29 | +-A: retain ACL permissions |
| 30 | +-X: retain chattr permissions |
| 31 | +-r: Recursive mode, including all files in the directory and subdirectories |
| 32 | +-l: still reserved for symbolic link files |
| 33 | +-p: Permission to retain file attributes |
| 34 | +-t: time to retain file attributes |
| 35 | +-g: retain the group belonging to the file attribute (only for super users) |
| 36 | +-o: retain the owner of the file attributes (only for super users) |
| 37 | +-D: Keep device files and other special files |
| 38 | +``` |
| 39 | + |
| 40 | +Persönliche Verwendung durch den Autor: `rsync -avz Originalstandort Zielstandort` |
| 41 | + |
| 42 | +## Umgebungsbeschreibung |
| 43 | + |
| 44 | +| Item | Beschreibung | |
| 45 | +| ---------------------- | ---------------- | |
| 46 | +| Rocky Linux 8 (Server) | 192.168.100.4/24 | |
| 47 | +| Fedora 34 (Client) | 192.168.100.5/24 | |
| 48 | + |
| 49 | +Sie können Fedora 34 zum Hochladen und Herunterladen verwenden |
| 50 | + |
| 51 | +```mermaid |
| 52 | +graph LR; |
| 53 | +RockyLinux8-->|pull/download|Fedora34; |
| 54 | +Fedora34-->|push/upload|RockyLinux8; |
| 55 | +``` |
| 56 | + |
| 57 | +Sie können Rocky Linux 8 auch zum Hochladen und Herunterladen verwenden |
| 58 | + |
| 59 | +```mermaid |
| 60 | +graph LR; |
| 61 | +RockyLinux8-->|push/upload|Fedora34; |
| 62 | +Fedora34-->|pull/download|RockyLinux8; |
| 63 | +``` |
| 64 | + |
| 65 | +## Demonstration basierend auf SSH-Protokoll |
| 66 | + |
| 67 | +!!! tip "Hinweis" |
| 68 | + |
| 69 | + Hier verwenden sowohl Rocky Linux 8 als auch Fedora 34 den root-Benutzer, um sich einzuloggen. In diesem Beispiel ist Fedora 34 der Client und Rocky Linux 8 der Server. |
| 70 | + |
| 71 | +### pull/download |
| 72 | + |
| 73 | +Da es auf dem SSH-Protokoll basiert, erstellen wir zuerst einen Benutzer auf dem Server: |
| 74 | + |
| 75 | +```bash |
| 76 | +[root@Rocky ~]# useradd testrsync |
| 77 | +[root@Rocky ~]# passwd testrsync |
| 78 | +``` |
| 79 | + |
| 80 | +Auf der Client-Seite wird es heruntergeladen, und die Datei auf dem Server ist /rsync/aabbcc |
| 81 | + |
| 82 | +```bash |
| 83 | +[root@fedora ~] # rsync -avz [email protected]:/rsync/aabbcc /root |
| 84 | + |
| 85 | +receiving incremental file list |
| 86 | +aabbcc |
| 87 | +sent 43 bytes received 85 bytes 51.20 bytes/sec |
| 88 | +total size is 0 speedup is 0.00 |
| 89 | +[root@fedora ~]# cd |
| 90 | +[root@fedora ~]# ls |
| 91 | +aabbcc |
| 92 | +``` |
| 93 | +
|
| 94 | +Die Übertragung war erfolgreich. |
| 95 | +
|
| 96 | +!!! tip "Tip" |
| 97 | +
|
| 98 | + Wenn der SSH-Port des Servers nicht der Standard ist, 22, können Sie den Port wie folgt angeben: `rsync -avz -e 'ssh -p [port]'. |
| 99 | +
|
| 100 | +### push/upload |
| 101 | +
|
| 102 | +```bash |
| 103 | +[root@fedora ~]# touch fedora |
| 104 | +[root@fedora ~]# rsync -avz /root/* [email protected]:/rsync/ |
| 105 | + |
| 106 | +sending incremental file list |
| 107 | +anaconda-ks.cfg |
| 108 | +fedora |
| 109 | +rsync: mkstemp " /rsync/.anaconda-ks.cfg.KWf7JF " failed: Permission denied (13) |
| 110 | +rsync: mkstemp " /rsync/.fedora.fL3zPC " failed: Permission denied (13) |
| 111 | +sent 760 bytes received 211 bytes 277.43 bytes/sec |
| 112 | +total size is 883 speedup is 0.91 |
| 113 | +rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1330) [sender = 3.2.3] |
| 114 | +``` |
| 115 | + |
| 116 | +**Eingabeaufforderung verweigert, wie Sie damit umzugehen sollten?** |
| 117 | + |
| 118 | +Überprüfen Sie zuerst die Berechtigungen des /rsync/ Verzeichnisses. Offensichtlich gibt es keine "w"-Berechtigung. Wir können `setfacl` verwenden, um die Berechtigung zu erteilen: |
| 119 | + |
| 120 | +```bash |
| 121 | +[root@Rocky ~ ] # ls -ld /rsync/ |
| 122 | +drwxr-xr-x 2 root root 4096 November 2 15:05 /rsync/ |
| 123 | +``` |
| 124 | + |
| 125 | +```bash |
| 126 | +[root@Rocky ~ ] # setfacl -mu:testrsync:rwx /rsync/ |
| 127 | +[root@Rocky ~ ] # getfacl /rsync/ |
| 128 | +getfacl: Removing leading ' / ' from absolute path names |
| 129 | +# file: rsync/ |
| 130 | +# owner: root |
| 131 | +# group: root |
| 132 | +user::rwx |
| 133 | +user:testrsync:rwx |
| 134 | +group::rx |
| 135 | +mask::rwx |
| 136 | +other::rx |
| 137 | +``` |
| 138 | + |
| 139 | +Versuchen Sie es noch einmal! |
| 140 | + |
| 141 | +```bash |
| 142 | +[root@fedora ~ ] # rsync -avz /root/* [email protected]:/rsync/ |
| 143 | + |
| 144 | +sending incremental file list |
| 145 | +anaconda-ks.cfg |
| 146 | +fedora |
| 147 | +sent 760 bytes received 54 bytes 180.89 bytes/sec |
| 148 | +total size is 883 speedup is 1.08 |
| 149 | +``` |
0 commit comments