Rsync is a remote synchronization function of the software, it can synchronize the file at the same time, you can keep the original file permissions, time, hard and soft links and other additional information, through the ssh way to transfer files, this article will introduce how to use rsync synchronization asterCC Record the folder monitor, test the rsync server IP address to 192.168.1.90.

First, the server configuration

Install

  • AsterCC system based on CentOS6, file synchronization environment needs rsync and xinetd support, xinetd is used for rsync client for the synchronization request to rsyncd, the installation method is as follows:

yum install -y rsync xinetd

Configuration

  • Rsync mainly has the following three configuration files rsyncd.conf (main configuration file), rsyncd.secrets (password file), rsyncd.motd (rysnc server information), these files do not exist by default need to create them, the operation is as follows:

mkdir rsyncd # Create a folder for storing configuration files in a centralized management.

touch /etc/rsyncd.conf  # Create rsyncd.conf This is the rsync server's configuration file.

touch /etc/rsyncd/rsyncd.secrets  #Create rsyncd.secrets This is the user password file.

chmod 600 /etc/rsyncd/rsyncd.secrets  # Will rsyncd.secrets the password file file attributes set to root and the authority to set to 600 or else can not be successful backup.

touch /etc/rsyncd/rsyncd.motd # Define rsync server information.

  • Rsyncd.conf is the main configuration file for the rsync server. This article we provide a configuration file example, as follows:

#port = 873   # Specify the operating port default is 873 can also specify their own, do not set, use the '#' comment out.
uid = root   # Server-side transmission of documents to which users to implement the default is nobody, but nobody may encounter permission problems Some documents from the server pull down This article users use root.
gid = root # Ibid to set the server-side transmission of documents to which group to implement.

use chroot = no  # Whether to use chroot, the advantage is likely to protect the system from being exploited by the vulnerability. The disadvantage is that superuser privileges are required, and the symbolic link file will be excluded.
read only = yes  # Read only mode does not allow the client to upload files to the server, the other there is a write only option.

hosts allow=192.168.1.0/24 # Allow the host, you can specify a single IP can also specify the entire network segment can improve security, multiple address formats to use spaces separated.
#hosts deny=* # Specify not allowed to connect rsync server machine, you can use the scope of the definition of hosts allow to define the default is no hosts deny definition can be used '#' comment out.

max connections = 5 # The maximum number of connections to the client.
pid file = /var/run/rsyncd.pid   # Tell the process to write to the /var/run/rsyncd.pid file.
secrets file = /etc/rsyncd/rsyncd.secrets   # Specify the password file path.
log file = /var/log/rsyncd.log  # Open the rsync server log.

lock file = /tmp/rsync.lock   # Specifies the lock file that supports the max connections parameter.        
#motd file = /etc/rsyncd/rsyncd.motd   # Specify the definition of the server information file path, when the user login will see this information, non must be used '#' comment out.      
transfer logging = yes   # So that the rsync server record the download and upload operations in their own separate log.

log format = %t %a %m %f %b   # This option allows you to customize the log file by using transfer logging. The format is a string containing the format identifier,% t current time,% a remote IP address,% m module name,% f file name,% B The actual number of bytes transmitted, the detailed settings can be self study.
syslog facility = local3   # Specifies that rsync sends a log message to syslog. The common message levels are: uth, authpriv, cron, daemon, ftp, kern, lpr, mail, news, local0, local1, local2, local3, local4, local5, local6, Local7 and other default value is daemon. 
timeout = 300   # This option allows you to override the customer specified IP timeout. With this option, you can ensure that the rsync server does not wait for a crashing client forever. The timeout unit is in seconds 0 indicates no timeout definition This is also the default value.

[monitor]   # Module it provides us with a link name, in this module is linked to the /var/spool/asterisk/monitor directory to use [name] form.
path = /var/spool/asterisk/monitor   # Specify the location of the file directory which is required to be specified.
list=no   # This means that the directory on the rsync server that provides the synchronization data is listed on the server. The default is yes. If you do not want to list it, set it to no.
ignore errors   # Ignore IO errors.
auth users = test   # Certified users.
comment = Get monitor   # Annotation information can be defined by yourself.
#exclude = data/ cache/   # Exclude the meaning of the monitor directory under the data and cache excluded, there are spaces between the directory, there is no comment can be used ’#‘.

  • Set /etc/xinetd.d/rsync, refer to the following figure:

Disable set to no, flags set to IPv4, server set to rsync path can be used whereis rsync view, and then execute “service xinetd restart” to make the above settings take effect.

Note that rsync default port is 873 or configured to other ports, you need to set the iptables firewall to allow the port to pass.

  • Set the rsyncd.secrets server password file.

Set the password file format is very simple, rsyncd.secrets content format: user name: password format, the following example:

test:astercc

  • Set the rsyncd.motd server advertisement file, which defines the server to send the user login information. It is not necessary can be used '#' comment out.

Start the rsync daemon

/usr/bin/rsync --daemon

Second, the client configuration

The client creates a password verification file

  • Client to create a password authentication file rsyncd.secrets, the advantage of this setting is to specify the password no longer manually enter the password verification, easy to set up in the crontab synchronization.

echo "astercc" > /root/rsyncd.secrets
chmod 600 /root/rsyncd.secrets

The client synchronizes the remote file

  • The test obtains the file information that the remote server can synchronize.

rsync -avzP test@192.168.1.90::monitor /var/spool/asterisk/monitor --password-file=/root/rsyncd.secrets

  • Synchronize the remote server to share the file information, this case is synchronized asterCC recording folder /var/spool/asterisk/monitor。

rsync -avzP test@192.168.1.90::monitor /var/spool/asterisk/monitor --password-file=/root/rsyncd.secrets

You can set the above command to crontab for timing file synchronization.

-a To archive mode operation, copy the directory, symbolic link is equivalent to  "-rlptgoD"
-z Compression when transmitting.
-P Transmission progress.
-v Print the progress of information, and-P a little relationship, try their own. You can see the document.
--delete Is that if the server to delete the file, then the client also delete the file accordingly, to maintain a true consistency, this case only for recording file backup so do not need this option.
--password-file=/password/path/file To specify the password file, so that you can use in the script without the need to enter the interactive authentication password, and here need to pay attention to is the password file permissions is 600.

en/how-to/how_to_use_rsync_to_synchronize_files_on_a_remote_server.txt · Last modified: 2017/12/12 11:05 (external edit)
Recent changes RSS feed Debian Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki