Skip to content

Commit 898458b

Browse files
authored
Merge pull request #368 from sspencerwire/edit_365
Edit 365
2 parents be15587 + 6d38761 commit 898458b

File tree

6 files changed

+71
-48
lines changed

6 files changed

+71
-48
lines changed

docs/books/learning_rsync/01_rsync_overview.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ What are the backup methods?
2323

2424
## rsync in brief
2525

26-
On a server, I backed up the first partition to the second partition, which is commonly known as "Local backup." The specific backup tools are `tar` , `dd` , `dump` , `cp `, etc. can be achieved. But in fact, it is still "Don't put the eggs in the same basket." Once the hardware fails and cannot boot and start normally, the data still cannot be retrieved. In order to solve the local backup For this problem, we introduced another kind of backup --- "remote backup".
26+
On a server, I backed up the first partition to the second partition, which is commonly known as "Local backup." The specific backup tools are `tar` , `dd` , `dump` , `cp `, etc. can be achieved. But you shouldn't "put all of your eggs in the same basket." Once the hardware fails and cannot start normally, the data still cannot be retrieved." In order to solve the local backup For this problem, we introduced another kind of backup --- "remote backup".
2727

28-
Some people will say, I use the `tar` or `cp` command on the first server, and then transfer it to the second server via `scp` or `sftp`.
28+
Some people will say, can't I just use the `tar` or `cp` command on the first server and send it to the second server via `scp` or `sftp`?
2929

3030
In a production environment, the amount of data is relatively large. First of all, `tar` or `cp` consumes a lot of time and occupies system performance. Transmission via `scp` or `sftp` also occupies a lot of network bandwidth, which is not allowed in the actual production environment. Secondly, these commands or tools need to be manually entered by the administrator and need to be combined with the crontab of the scheduled task. However, the time set by crontab is not easy to grasp, and the set time is too short. For example, if it is executed once every 1 minute, it may happen that the first script is not executed, and the second script is executed again; the set time has passed For example, if it is executed once every 5 hours, there may be data loss because the data is not backed up in time.
3131

@@ -48,10 +48,13 @@ The original `rsync` was maintained by the Australian programmer <font color=red
4848
**rsync itself is only an incremental backup tool and does not have the function of real-time data synchronization. It needs to be supplemented with another program. In addition to this, synchronization is one-way, and if you want two-way backup, you need to use another tool to achieve it. **
4949

5050
### Basic Principles and Features
51+
5152
How does `rsync` achieve efficient one-way data synchronization backup?
52-
The core of `rsync` is its **Checksum algorithm** . If you are interested, you can go to [ Rsync Working Principle ](https://rsync.samba.org/how-rsync-works.html) and [ rsync Algorithm ](https ://rsync.samba.org/tech_report/) I understand that this part is beyond the scope of the author's ability, so I won't give too much explanation.
53+
54+
The core of `rsync` is its **Checksum algorithm**. If you are interested, you can go to [How Rsync works](https://rsync.samba.org/how-rsync-works.html) and [The rsync algorithm](https://rsync.samba.org/tech_report/) for more information, This section is beyond the author's competence and will not be covered too much.
5355

5456
The characteristics of `rsync` are:
57+
5558
* The entire directory can be updated recursively;
5659
* Can selectively retain file synchronization attributes, such as hard link, soft link, owner, group, corresponding permissions, modification time, etc., and can retain some of the attributes;
5760
* Support two protocols for transmission, one is ssh protocol, the other is rsync protocol

docs/books/learning_rsync/02_rsync_demo01.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ update: 2021-11-04
1515
Before the specific demonstration of rsync synchronization, you need to use the `rsync` command. In Rocky Linux 8, the rsync rpm package is installed by default, and the version is 3.1.3-12, as follows:
1616

1717
```bash
18-
[root@Rocky ~ ] # rpm -qa|grep rsync
18+
[root@Rocky ~]# rpm -qa|grep rsync
1919
rsync-3.1.3-12.el8.x86_64
2020
```
2121

@@ -72,14 +72,14 @@ Fedora34-->|pull/download|RockyLinux8;
7272
Since it is based on the SSH protocol, we first create a user in the server:
7373

7474
```bash
75-
[root@Rocky ~ ] # useradd testrsync
76-
[root@Rocky ~ ] # passwd testrsync
75+
[root@Rocky ~]# useradd testrsync
76+
[root@Rocky ~]# passwd testrsync
7777
```
7878

7979
On the client side, we pull/download it, and the file on the server is /rsync/aabbcc
8080

8181
```bash
82-
[root@fedora ~ ] # rsync -avz [email protected]:/rsync/aabbcc /root
82+
[root@fedora ~]# rsync -avz [email protected]:/rsync/aabbcc /root
8383
[email protected] ' s password:
8484
receiving incremental file list
8585
aabbcc
@@ -92,7 +92,7 @@ aabbcc
9292
The transfer was successful.
9393
9494
!!! tip "Attention"
95-
If the server's SSH port is not the default 22, you can specify the port in a similar way-`rsync -avz -e ' ssh -p [port] ' `.
95+
If the server's SSH port is not the default 22, you can specify the port in a similar way---`rsync -avz -e 'ssh -p [port]' `.
9696

9797
### push/upload
9898

@@ -110,7 +110,8 @@ total size is 883 speedup is 0.91
110110
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1330) [sender = 3.2.3]
111111
```
112112

113-
**Prompt permission denied, how to deal with it? **
113+
**Prompt permission denied, how to deal with it?**
114+
114115
First check the permissions of the /rsync/ directory. Obviously, there is no permission. We can use `setfacl` to give permission:
115116

116117
```bash

docs/books/learning_rsync/03_rsync_demo02.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ contributors: Steven Spencer
55
update: 2021-11-04
66
---
77

8-
# Based on the presentation rsync protocol
8+
# Demonstration based on rsync protocol
99
In vsftpd, there are virtual users (impersonated users customized by the administrator) because it is not safe to use anonymous users and local users. We know that a server based on the SSH protocol must ensure that there is a system of users. When there are many synchronization requirements, it may be necessary to create many users. This obviously does not meet the GNU/Linux operation and maintenance standards (the more users, the more insecure), in rsync, for security reasons, there is an rsync protocol authentication login method.
1010

11-
**How ​​to do it? **
11+
**How ​​to do it?**
12+
1213
Just write the corresponding parameters and values ​​in the configuration file. In Rocky Linux 8, you need to manually create the file <font color=red>/etc/rsyncd.conf</font>.
1314

1415
```bash
15-
[root@Rocky ~ ] # touch /etc/rsyncd.conf
16-
[root@Rocky ~ ] # vim /etc/rsyncd.conf
16+
[root@Rocky ~]# touch /etc/rsyncd.conf
17+
[root@Rocky ~]# vim /etc/rsyncd.conf
1718
```
1819

1920
Some parameters and values ​​of this file are as follows, [ here ](04_rsync_configure.md) has more parameter descriptions:
@@ -28,7 +29,7 @@ Some parameters and values ​​of this file are as follows, [ here ](04_rsync_
2829
| comment = rsync | Remarks or description information |
2930
| path = /rsync/ | The system path location where it is located |
3031
| read only = yes| yes means read only, no means read and write |
31-
| dont compress = *.gz *.gz2 *.zip | Which file types do not compress it |
32+
| dont compress = \*.gz \*.gz2 \*.zip | Which file types do not compress it |
3233
| auth users = li| Enable virtual users and define what a virtual user is called. Need to create it yourself|
3334
| secrets file = /etc/rsyncd_users.db | Used to specify the location of the virtual user's password file, which must end in .db. The content format of the file is "Username: Password", one per line |
3435

@@ -38,7 +39,7 @@ Some parameters and values ​​of this file are as follows, [ here ](04_rsync_
3839
Write some file content to <font color=red>/etc/rsyncd.conf</font>, and write the user name and password to /etc/rsyncd_users.db, the permission is 600
3940

4041
```bash
41-
[root@Rocky ~ ] # cat /etc/rsyncd.conf
42+
[root@Rocky ~]# cat /etc/rsyncd.conf
4243
address = 192.168.100.4
4344
port = 873
4445
pid file = /var/run/rsyncd.pid
@@ -47,44 +48,43 @@ log file = /var/log/rsyncd.log
4748
comment = rsync
4849
path = /rsync/
4950
read only = yes
50-
dont compress = * .gz * .bz2 * .zip
51+
dont compress = *.gz *.bz2 *.zip
5152
auth users = li
5253
secrets file = /etc/rsyncd_users.db
53-
[root@Rocky ~ ] # ll /etc/rsyncd_users.db
54+
[root@Rocky ~]# ll /etc/rsyncd_users.db
5455
-rw------- 1 root root 9 November 2 16:16 /etc/rsyncd_users.db
55-
[root@Rocky ~ ] # cat /etc/rsyncd_users.db
56+
[root@Rocky ~]# cat /etc/rsyncd_users.db
5657
li:13579
5758
```
5859

5960
You may need to `dnf -y install rsync-daemon` before you can start the service: `systemctl start rsyncd.service`
6061

6162
```bash
62-
[root@Rocky ~ ] # systemctl start rsyncd.service
63-
[root@Rocky ~ ] # netstat -tulnp
64-
Active Internet connections (only servers)
65-
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
66-
tcp 0 0 0.0.0.0:22 0.0.0.0: * LISTEN 691/sshd
67-
tcp 0 0 192.168.100.4:873 0.0.0.0: * LISTEN 4607/rsync
68-
tcp6 0 0 :::22 ::: * LISTEN 691/sshd
69-
udp 0 0 127.0.0.1:323 0.0.0.0: * 671/chronyd
70-
udp6 0 0 ::1:323 ::: * 671/chronyd
63+
[root@Rocky ~]# systemctl start rsyncd.service
64+
[root@Rocky ~]# netstat -tulnp
65+
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
66+
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 691/sshd
67+
tcp 0 0 192.168.100.4:873 0.0.0.0:* LISTEN 4607/rsync
68+
tcp6 0 0 :::22 :::* LISTEN 691/sshd
69+
udp 0 0 127.0.0.1:323 0.0.0.0:* 671/chronyd
70+
udp6 0 0 ::1:323 :::* 671/chronyd
7171
```
7272

73-
## pull/download
73+
## pull/download
7474

7575
Create a file in the server for verification: `[root@Rocky]# touch /rsync/rsynctest.txt`
7676

7777
The client does the following:
7878

7979
```bash
80-
[root@fedora ~ ] # rsync -avz [email protected]::share /root
80+
[root@fedora ~]# rsync -avz [email protected]::share /root
8181
Password:
8282
receiving incremental file list
8383
./
8484
rsynctest.txt
8585
sent 52 bytes received 195 bytes 7.16 bytes/sec
8686
total size is 883 speedup is 3.57
87-
[root@fedora ~ ] # ls
87+
[root@fedora ~]# ls
8888
aabbcc anaconda-ks.cfg fedora rsynctest.txt
8989
```
9090

@@ -93,8 +93,8 @@ success! In addition to the above writing based on the rsync protocol, you can a
9393
## push/upload
9494

9595
```bash
96-
[root@fedora ~ ] # touch /root/fedora.txt
97-
[root@fedora ~ ] # rsync -avz /root/* [email protected]::share
96+
[root@fedora ~]# touch /root/fedora.txt
97+
[root@fedora ~]# rsync -avz /root/* [email protected]::share
9898
Password:
9999
sending incremental file list
100100
rsync: [sender] read error: Connection reset by peer (104)
@@ -106,7 +106,7 @@ You are prompted that the reading error is related to the "read only = yes" of t
106106
Try again, prompting you permission denied:
107107

108108
```bash
109-
[root@fedora ~ ] # rsync -avz /root/* [email protected]::share
109+
[root@fedora ~]# rsync -avz /root/* [email protected]::share
110110
Password:
111111
sending incremental file list
112112
fedora.txt
@@ -119,7 +119,7 @@ rsync error: some files/attrs were not transferred (see previous errors) (code 2
119119
Our virtual user here is <font color=red>li</font>, which is mapped to the system user <font color=red>nobody</font> by default. Of course, you can change it to other system users. In other words, nobody does not have write permission to the /rsync/ directory. Of course, we can use `[root@Rocky ~]# setfacl -mu:nobody:rwx /rsync/` , try again, and succeed.
120120

121121
```bash
122-
[root@fedora ~ ] # rsync -avz /root/* [email protected]::share
122+
[root@fedora ~]# rsync -avz /root/* [email protected]::share
123123
Password:
124124
sending incremental file list
125125
fedora.txt

docs/books/learning_rsync/05_rsync_authentication-free_login.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ From [rsync Brief Description](01_rsync_overview.md) we know that rsync is an in
1111

1212
With inotify-tools, this program tool can realize one-way real-time synchronization. Since it is real-time data synchronization, the prerequisite is to log in without password authentication.
1313

14-
**Regardless of whether it is rsync protocol or SSH protocol, both can achieve password-free authentication login. **
14+
**Regardless of whether it is rsync protocol or SSH protocol, both can achieve password-free authentication login.**
1515

1616
## SSH protocol password-free authentication login
1717

@@ -40,42 +40,59 @@ The key's randomart image is:
4040
| .o.o. |
4141
+----[SHA256]-----+
4242
```
43+
4344
Then, use the `scp` command to upload the public key file to the server. For example, I upload this public key to the user **testrsync**
45+
4446
```bash
4547
[root@fedora ~]# scp -P 22 /root/.ssh/id_rsa.pub [email protected]:/home/testrsync/
4648
```
49+
4750
```bash
4851
[root@Rocky ~]# cat /home/testrsync/id_rsa.pub >> /home/testrsync/.ssh/authorized_keys
4952
```
53+
5054
Try to log in without secret authentication, success!
55+
5156
```bash
5257
[root@fedora ~]# ssh -p 22 [email protected]
5358
Last login: Tue Nov 2 21:42:44 2021 from 192.168.100.5
5459
[testrsync@Rocky ~]$
5560
```
61+
5662
!!! tip "Attention!"
5763
The server configuration file **/etc/ssh/sshd_config** should be opened <font color=red>PubkeyAuthentication yes</font>
64+
5865
## rsync protocol password-free authentication login
66+
5967
On the client side, the rsync service prepares an environment variable for the system-**RSYNC_PASSWORD**, which is empty by default, as shown below:
68+
6069
```bash
6170
[root@fedora ~]# echo "$RSYNC_PASSWORD"
71+
6272
[root@fedora ~]#
6373
```
74+
6475
If you want to achieve password-free authentication login, you only need to assign a value to this variable. The value assigned is the password previously set for the virtual user <font color=red>li</font>. At the same time, declare this variable as a global variable.
76+
6577
```bash
6678
[root@Rocky ~]# cat /etc/rsyncd_users.db
6779
li:13579
6880
```
81+
6982
```bash
7083
[root@fedora ~]# export RSYNC_PASSWORD=13579
7184
```
85+
7286
Try it, success! No new files appear here, so the list of transferred files is not displayed.
87+
7388
```bash
7489
[root@fedora ~]# rsync -avz [email protected]::share /root/
7590
receiving incremental file list
7691
./
92+
7793
sent 30 bytes received 193 bytes 148.67 bytes/sec
7894
total size is 883 speedup is 3.96
7995
```
96+
8097
!!! tip "tip!"
8198
You can write this variable into **/etc/profile** to make it take effect permanently. The content is: `export RSYNC_PASSWORD=13579`

docs/books/learning_rsync/06_rsync_inotify.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ Append the environment variable PATH, write it to the configuration file and let
2828
[root@Rocky ~]# vim /etc/profile
2929
...
3030
PATH=$PATH:/usr/local/inotify-tools/bin/
31-
[root@Rocky ~]#. /etc/profile
31+
[root@Rocky ~]# . /etc/profile
3232
```
3333

34-
**Why not use the inotify-tools RPM package of the EPEL repository? And the way to use source code to compile and install? **
34+
**Why not use the inotify-tools RPM package of the EPEL repository? And the way to use source code to compile and install?**
3535

36-
The author personally believes that remote data transmission is related to efficiency issues, especially in the production environment, when the number of files to be synchronized is large and the single file is particularly large, this is particularly important. In addition, the new version will have some bug fixes and function expansions, and perhaps the transmission efficiency of the new version will be higher, so I recommend installing inotify-tools by source code. Of course, this is the author's personal suggestion, not every user must follow.
36+
The author personally believes that remote data transmission is a matter of efficiency, especially in a production environment, where there are a large number of files to be synchronized and a single file is particularly large. In addition, the new version will have some bug fixes and function expansions, and perhaps the transmission efficiency of the new version will be higher, so I recommend installing inotify-tools by source code. Of course, this is the author's personal suggestion, not every user must follow.
3737

3838
## Kernel parameter adjustment
3939

@@ -46,6 +46,7 @@ You can adjust the kernel parameters according to the needs of the production en
4646
128
4747
28014
4848
```
49+
4950
* max_queued_events-maximum monitor queue size, default 16384
5051
* max_user_instances-the maximum number of monitoring instances, the default is 128
5152
* max_user_watches-the maximum number of files monitored per instance, the default is 8192
@@ -101,6 +102,7 @@ Type the command in the first terminal pts/0, and the window is locked after pre
101102

102103
```bash
103104
[root@Rocky ~]# inotifywait -mrq -e create,delete /rsync/
105+
104106
```
105107

106108
In the second terminal pts/1, go to the /rsync/ directory and create a file.
@@ -141,7 +143,7 @@ $a | while read directory event file
141143

142144
!!! tip "emphasize again!"
143145
When using the SSH protocol for data synchronization transmission, if the SSH service port of the target machine is not 22, you can use a method similar to this——
144-
`b="/usr/bin/rsync -avz -e'ssh -p [port-number]' /rsync/* [email protected]:/home/testfedora/"`
146+
`b="/usr/bin/rsync -avz -e 'ssh -p [port-number]' /rsync/* [email protected]:/home/testfedora/"`
145147

146148
!!! tip "Attention!"
147149
If you want to start this script at boot

docs/books/learning_rsync/07_rsync_unison_use.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ As we mentioned earlier, one-way synchronization uses rsync + inotify-tools. In
1111

1212
## Environmental preparation
1313

14-
* Both Rocky Linix 8 and Fedora 34 require source code compilation and installation **inotify-tools**, which is not specifically expanded here.
14+
* Both Rocky Linux 8 and Fedora 34 require source code compilation and installation **inotify-tools**, which is not specifically expanded here.
1515
* Both machines must be password-free login authentication, here we use the SSH protocol for
1616
* [ocaml](https://github.com/ocaml/ocaml/) uses v4.12.0, [unison](https://github.com/bcpierce00/unison/) uses v2.51.4.
1717

@@ -49,7 +49,7 @@ Ocaml is a programming language, and the bottom layer of unison depends on it.
4949
[root@Rocky ~]# ls /usr/local/ocaml/
5050
bin lib man
5151
[root@Rocky ~]# echo PATH=$PATH:/usr/local/ocaml/bin >> /etc/profile
52-
[root@Rocky ~]#. /etc/profile
52+
[root@Rocky ~]# . /etc/profile
5353
```
5454

5555
```bash
@@ -87,7 +87,7 @@ bin lib man
8787
...
8888
[root@fedora /usr/local/src/unison-2.51.4]# ls src/unison
8989
src/unison
90-
[root@fedora /usr/local/src/unison-2.51.4] cp -p src/unison /usr/local/bin
90+
[root@fedora /usr/local/src/unison-2.51.4]# cp -p src/unison /usr/local/bin
9191
```
9292

9393

@@ -98,9 +98,9 @@ src/unison
9898
### Configure Rcoky Linux 8
9999

100100
```bash
101-
[root@Rocky ~] mkdir /dir1
102-
[root@Rocky ~] setfacl -m u:testrsync:rwx /dir1/
103-
[root@Rocky ~] vim /root/unison1.sh
101+
[root@Rocky ~]# mkdir /dir1
102+
[root@Rocky ~]# setfacl -m u:testrsync:rwx /dir1/
103+
[root@Rocky ~]# vim /root/unison1.sh
104104
#!/bin/bash
105105
a="/usr/local/inotify-tools/bin/inotifywait -mrq -e create,delete,modify,move /dir1/"
106106
b="/usr/local/bin/unison -batch /dir1/ ssh://[email protected]//dir2"
@@ -116,9 +116,9 @@ done
116116
### Configure Fedora 34
117117

118118
```bash
119-
[root@fedora ~] mkdir /dir2
120-
[root@fedora ~] setfacl -m u:testrsync:rwx /dir2/
121-
[root@fedora ~] vim /root/unison2.sh
119+
[root@fedora ~]# mkdir /dir2
120+
[root@fedora ~]# setfacl -m u:testrsync:rwx /dir2/
121+
[root@fedora ~]# vim /root/unison2.sh
122122
#!/bin/bash
123123
a="/usr/local/inotify-tools/bin/inotifywait -mrq -e create,delete,modify,move /dir2/"
124124
b="/usr/local/bin/unison -batch /dir2/ ssh://[email protected]//dir1"

0 commit comments

Comments
 (0)