Centos rsync file synchronization configuration step sharing

  • 2020-05-06 12:07:41
  • OfStack

rsync is a data image backup tool under the unix system, which can be seen from the naming of the software -- remote sync

has the following features:
You can mirror and save entire directory trees and file systems.
It is easy to keep the permissions of the original file, the time, the soft and hard links, and so on.
No special privileges are required to install.
Fast: rsync copies everything the first time, but transfers only the modified files the next time. rsync can compress and uncompress data during transmission, so it can use less bandwidth.
Security: files can be transferred using scp, ssh, or through a direct socket connection.
Supports anonymous transmission to facilitate site mirroring.


I. server-side configuration:
# yum -y install xinetd

# vi /etc/xinetd.d/rsync
The following code will be


service rsync 
{ 
disable = yes 
socket_type = stream 
wait = no 
user = root 
server = /usr/bin/rsync 
server_args =  � daemon 
log_on_failure += USERID 
}


disable = yes = disable = no

Then start xinetd
# / etc/init d/xinetd start or service xinetd restart
Note: if a firewall is installed on the server remember to open the port, the default port is 873

# telnet 127.0.0.1 873
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
# iptables -A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 873 -j ACCEPT
# iptables -A INPUT -p tcp -m tcp --dport 873 -j DROP

# vi /etc/ rsyncd.conf

#Global Settings
uid = root # in what capacity does rsync
run gid = root
use chroot = no # chroot
is not used max connections = 20 # maximum number of connections
secrets file = /etc/ .secrets # password file location, authentication file Settings, set username and password
log file = / var log/rsyncd log # rsync specified log file, not send logs to syslog
pid file = / var run/rsyncd pid # specify rsync
pid file lock file = / var run/rsync lock # designated support max connections parameters lock file, the default value is/var run/rsyncd lock
comment = hello world
motd file = /etc/ rsyncd. motd # welcome information file name and location (this file does not have, you can add)

[backup] # here is the module name for authentication, and on the client side you need to specify
path = / titan24 / www/repos #
mirror directory needs to be done auth users = rsync # authorization account. The authenticated user name, if this line is not present, indicates anonymity, with multiple users separating
read only = no # yes hosts allow = 192.168.3.128 # allow access to the server IP
hosts deny = * # blacklist
list = true # allows the column file
#ignore errors # can ignore some extraneous IO errors
#exclude = cache/111/ cache/222/ # ignored directory

# vi /etc/ rsyncd.secrets (set username and password for access)

User name: private,

Give the file the correct permissions
# chown root:root /etc/rsyncd.secrets
chmod 600 /etc/ rsyncd.secrets   # (must be 600)

ii, client end synchronization

The
client appears to have installed rsync by default, and
if not # yum -y install rsync

Perform asynchronous synchronous operations:

/usr/bin/rsync -avz --progress   rsync@192.168.3.191::backup   /www

crontab -e #(files can be synchronized every three minutes on a regular basis)

*/3   * * * * rsync -avz --progress   rsync@192.168.3.191::backup   /www

The following command is complete:

#vi /etc/rsyncd.pas
Add the password
rsyncofpass
Note that the client password file only requires a password, not a username!

Change file permissions :
#chmod 0600 /etc/rsyncd.pas

#rsync -vzrtopgu --progress --delete --password-file=/etc/rsyncd.pas   rsync_user@192.168.0.2::rsync_module_name1 /www/

v in this command line -vzrtopg is verbose,
z is for compression transmission,
r is recursive,
topg is a parameter that keeps the original attributes of the file, such as owner and time.
u synchronizes only the files that have been updated to avoid the files that have not been updated being updated again, but be careful to synchronize the clocks of both machines.
The display of the details of the progress is displayed This means that if the server deletes the file, the client deletes the file to make it exactly the same.
rsync_user@192.168.0.2::rsync_module_name1, rsync_module_name1 is the module name, which is the custom name in /etc/ rsyncd.conf, rsync_user is the user name that can be synchronized in the specified module.
The last /www is the backup to the local directory name.
In this case, you can also set up an encrypted connection with the -e ssh parameter.
The password file can be specified by using the wok with password-file =/password/path/file to be used in the script without having to interactively enter the authentication password.

# / usr local/rsync/bin/rsync - vzrtopg � progress � delete rsync_user@192.168.0.2: : rsync_module_name1 / tmp/
Password:
Or you can make password file
Because the system crontab is required to execute, the method of reading in the password file is adopted here,
That's when it happens.

synchronization command description:

1 show the contents of the directory

Command
-
a) rsync
b) rsync -r
c) rsync jack@192.168.0.1::
d) rsync ssh_user@192.168.0.1:

The command says
--
a) displays the contents of the directory (tier 1)
b) recursively displays the contents of the directory
c) displays the contents of the remote host directory
* note 1: port mode, based on rsync user authentication
* note 2: directories on rsync server must have permissions on xx7.

d) view the contents of the remote host directory
* note 1: remote shell mode,
authentication based on the local user of the system through ssh connection * note 2: only one colon (:) is used, and the username is ssh user of the remote host, and the password is ssh user.
* note 3: use "" to list information about the folder itself. To list folder contents, use "/".

Parameter
--
-r performs recursive operations on directories

synchronization between local directories
Command
-
Note: (/) ***
b) rsync -av, progress,
c) rsync -avu, progress, delete/
d) rsync-av, progress, temp-dir =/tmp/

The command says
--
a) synchronize all files in the src-dir directory to
in the dst-dir directoryb) synchronize all files in the src-dir directory to
in the dst-dir/src-dir directory c) update the contents of src-dir directory with differences to dst-dir directory. If there is an increase/update, add replacement; if there is a decrease, delete
d) is larger than a) with the addition of the hang temp-dir =/tmp, which specifies /tmp as the temporary swap area to avoid the error of not synchronizing the files due to insufficient target directory space.

Parameter description
--
-a is equivalent to the set
of -rlptgoD -u is the same as the copyright.
is not updated if the target file is newer than the source file -v shows the synchronized file
The display shows the percentage progress and transfer rate
when the file is synchronized Remove files
from the target directory that have more than the source directory

synchronization between remote hosts Command
-
a) rsync-avz (progress jack@192.168.0.1::/
b) rsync - avz � progress jack@192.168.0.1: : / � password - file = / home jack/rsync jack
c) rsync - avuz � progress � delete jack@192.168.0.1: : / � password - file = / home jack/rsync jack
d) rsync-avz, progress jack@192.168.0.1::/

The command says
--
a) synchronizes the contents of the local directory to the directory of the remote host 192.168.0.1. jack is the rsync database user (see 3. /etc/ rsync.secrets)
b) synchronizes
non-interactive login files by automatically reading the user's password c) is more than b -u and delete
d) synchronize remote host content to local directory


Related articles: