Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

In this deployment process, a server server and a client server (backup server and NFS storage server) are required.

1. Server deployment steps :(backup server)

🔅1. Check whether the software service is installed

[root@backup ~] RPM -qa rsync (Check whether it is installed) rsync-3.0.6-12.el6.x86_64Copy the code

🔅2. If rsync is not installed, install it

[root@backup ~] # Install rsync
[root@backup ~]yum install -y rsync
Copy the code

🔅3. Compile the configuration file of the rsync backup service

This configuration file is prepared based on the contents of the man rsyncd.conf file

[root@backup ~]vim /etc/rsyncd.conf 
This file is the configuration file of the rsync software
Copy the code

Uid = rsync

gid = rsync use chroot = no max connections = 200 timeout = 300 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log [backup] ignore errors read omly = false list = false hosts allow = 172.16.1.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup secrets file = /etc/rsync.password comment = "backup dir  by oldboy" path =/backupCopy the code

The following information is used to parse the content of the configuration file

uid = rsync

Gid = rsync # User group use chroot =no # security-related Max connections =200 # Maximum number of connections timeout =300 # Elapsed time PID file = Log file = /var/log/rsyncd.log file = /var/log/rsyncd.log file = /var/log/rsyncd. pid [backup] # module name path = /backup # module location (path) Ignore errors # ignore error program read only = false # Read-only list = false # Listable Hosts allow =172.16.1.0/24 # Whitelist of rsync server access hosts deny =0.0.0.0/32 # Blacklist of rsync server access auth Users = Secrets file =/etc/rsync.password # Key file for user authentication that does not exist

🔅4. Create a backup directory management user

(Virtual user)

[root@backup ~] useradd -M -s /sbin/nologin rsync
[root@backup ~] id rsync  # check whether a user is created
uid=500(rsync) gid=500(rsync) groups=500(rsync)
Copy the code

🔅5. Create a backup data directory

[root@backup ~] mkdir /backup -p 
[root@backup ~] chown -R rsync.rsync /backup  Rsync = '/backup'
[root@backup ~] ll /backup   # Change the effect as follows
total 8
-rw-r--r-- 1 rsync rsync 158 Aug 11  2021 hosts
Copy the code

🔅 6. Create an authentication user password file

(Password authentication is required for each remote file transfer.)

[root@backup ~] echo "rsync_backup:123456" >>/etc/rsync.password  
# enter rsync_backup and password 123456 into /etc/rsync.password
[root@backup ~] chmod 600 /etc/rsync.password
# change /etc/rsync.password file permissions to root user readable and writable, other user groups can not modify
#r== read permission ==4 w== write permission ==2 x== execute permission ==1
Copy the code

🔅7. Start the rsync backup service daemon

[root@backup ~] rsync --daemon   Start the process command
[root@backup ~] ps -ef|grep rsync  # check whether to start the command
root       2865      1  0 12:17 ?        00:00:00 rsync --daemon
root       2867   2562  0 12:17 pts/2    00:00:00 grep rsync
Copy the code

🔅8. Check the port number of the rsync backup service

(Rsync port number: port 873)

[root@backup ~] netstat -lntup|grep rsync  # check the port numberTCP 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 2865/rsync TCP 0 0: :873 ::*The first message in the output is ipv4 information, you can see the port number 873 and the status information
The second message in the output is the ipv6 message, also see the port number is 873
Copy the code

Ii. Client deployment process :(NFS server)

🔅1. Check whether the rsync service is successfully installed

[root@nfs ~] RPM -qa rsyncCopy the code

🔅2. If rsync is not installed, install it

[root@nfs ~] # Install rsync
[root@nfs ~] yum install -y rsync
Copy the code

🔅3. Create a password file for authorization

[root@nfs ~] echo "123456" >>/etc/rsync.password
# Input the password of the remote transmission file to the password file, which is convenient for future backup and machine without interactive action (no manual input password authentication)
[root@nfs ~] chmod 600 /etc/rsync.password
# change /etc/rsync.password file permissions to root user readable and writable, other user groups can not modify
#r== read permission ==4 w== write permission ==2 x== execute permission ==1
Copy the code

🔅4. Test data backup transmission

[root@nfs ~] rsync-avz /etc/hosts [email protected]::backup --password-file=/etc/rsync.passwordExecute data remote backup transfer command. 172.16.1.41 is the IP address of the backup server
[root@backup ~] ll /backup     Verify the data transfer on the backup server
total 4
-rw-r--r-- 1 rsync rsync 158 Aug 11  2021 hosts
The /etc/hosts directory on the NFS server has been remotely transferred to the /backup directory on the backup server via the rsync service
Copy the code
Rsync [OPTION...]  SRC... [USER@]HOST::DESTRsync Remote backup command format
#rsync -- Data backup commandOPTION... ] -- Command parameters SRC... -- Specifies the data to be backed up on the local server. [user@] -- Specifies the authentication USER for transmitting data. HOST:: -- Specifies the IP address or HOST name of the backup serverCopy the code