Introduction to the use of rsync configuration

rsync is a tool that can implement incremental backups. With task planning, rsync can achieve timing or interval synchronization, and with inotify or sersync, trigger-type real-time synchronization can be achieved.

rsync is divided into two parts: the server and the client. What we need to configure is the server. The client only needs to configure a password file.

1. Server configuration

The configuration file of rsync is /etc/rsyncd.conf, but since the general system does not have this file, we need to create this file first.

vim /etc/rsyncd.conf

Then fill in the following:

port = 873 #Specify the listening port, the default is 873, you can specify
uid = rsync #The uid to which the daemon belongs, the default is nobody, you may encounter file or directory permission problems, you can be lazy and use root, generally set to rsync
gid = rsync #The gid of the daemon
use chroot = no #Generally set to no
read only = no #Read only option, only let the client read files from the server
write only = yes #Write only option, only let the client write to the server Enter

# to allow access to the IP, you can specify a single IP, you can also specify the entire network segment, which can improve security. The format is between ip and ip, between ip and network segment, and between network segment and network segment with spaces;
hosts allow = 172.16.1.2
max connections = 5 #Maximum number of client connections
log file = /var/ log/rsync.log #rsync server log;
transfer logging = yes #Record the log of the transfer file
log format = %t %a %m %f %b #Log format
syslog facility = local3 #Log level
timeout = 300 #Timeout time

#Module definition
# mainly defines which directory of the server is to be synchronized.
# Each module must be in the form of [name]. This name is what the rsync client sees.
#But the data that the server actually synchronizes is specified by path. Multiple modules can be created in sequence.
#Each module should specify the authentication user and password file, but exclusion is not necessary.
[ logs ] #Module name, the following configurations belong to this module
path = /date #The location of the file directory
list = no #Whether it is listed when checking which directories are provided on the server, no is safer

ignore errors #Ignore I/O errors

#User name and password are stored in clear text in the file specified by the "secrets file" option. By default the module can be connected without a password (i.e. anonymously)

auth users = xxw

secrets file = /etc/rsyncd.secrets #password file



/etc/rsync.conf configuration ends

Then create the password file /etc/rsyncd.secrets, and write the virtual account and password, separated by:, and set the permission to 600.

touch /etc/rsyncd.secrets

echo "xxw:123456">/etc/rsyncd.secrets

chmod 600 /etc/rsyncd.secrets

Create a shared folder /date, set the user and user group to rsync, and the permission to 755 (usually the default is 755)

mkdir /date

chown rsync.rsync /date


Start rsync.

rsync --daemon #If it doesn't work, execute /usr/bin/rsync --daemon with the full path. If the process already exists, you can pkill rsync first, and then start it.

Finally check if the process is started.

lsof -i:873 #or netstat -ntulp | grep ":873"

At this point, the rsync server configuration is complete.



2. Client Configuration

Create a password file /etc/rsyncd.pass, modify it to 600 permissions, and write the password of the server virtual user. (only password, no account required)

echo "123456">/etc/rsyncd.pass

chmod 600 /etc/rsyncd.pass

至此,rsync 客户端配置完成。


全部配置完成后,可以测试了。

rsync -avzp /etc/hosts [email protected]::logs  --password-file=/etc/rsyncd.pass

结果反馈为:

sending incremental file list
hosts

sent 120 bytes  received 27 bytes  294.00 bytes/sec
total size is 158  speedup is 1.07


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325935303&siteId=291194637