Centos rsync file Sync configuration step sharing _linux

Source: Internet
Author: User
Tags anonymous chmod readable ssh custom name file permissions iptables rsync

Rsync is a data mirroring Backup tool under Unix-like systems, which can be seen from the name of the software--remote sync

its characteristics are as follows:
Can be mirrored to save the entire directory tree and file system.
It is easy to maintain the original file permissions, time, soft and hard links and so on.
can be installed without special permissions.
Fast: Rsync replicates all content on the first synchronization, but only the modified files are transferred the next time. Rsync can compress and decompress in the process of transmitting data, so it can use less bandwidth.
Security: You can use the SCP, SSH and other means to transfer files, of course, can also be connected through a direct socket.
Support for anonymous transmission, to facilitate the use of Web site mirror image.


First, server-side configuration:
# yum-y Install xinetd

# Vi/etc/xinetd.d/rsync
The following code

Copy Code code as follows:

Service rsync
{
Disable = yes
Socket_type = Stream
wait = no
user = root
Server =/usr/bin/rsync
Server_args =–daemon
Log_on_failure + + USERID
}


Disable = yes change to disable = no

and start xinetd.
#/etc/init.d/xinetd Start or service xinetd restart
Note: If the server is equipped with a firewall, 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 (this file is created if it does not exist)

#Global Settings
uid = root #以什么身份运行rsync
gid = root
Use chroot = no #不使用chroot
Ma x connections = #最大连接数
Secrets file =/etc/rsyncd.secrets #密码文件位置, authentication file settings, setting user name and password
Log file =/var/log/rsync D.log #指定rsync的日志文件 without sending the log to the syslog
pid file =/var/run/rsyncd.pid #指定rsync的pid文件
Lock file =/var/run/rsync.lo CK #指定支持max The lock file for the connections parameter, the default value is/var/run/rsyncd.lock
comment = Hello world
#motd file =/etc/rsyncd.motd #欢迎 Information file name and location (this file is not, you can add it yourself)

[Backup] # Here is the Certified module name, the client side needs to specify
Path =/titan24/www/repos # need to do mirror directory
Auth users = rsync # Authorized account number. The authenticated username, if it is not, is anonymous and is used by more than one user, separating the
Read only = no # Yes to read only value to no meaning readable and writable, data recovery with no
hosts allow = 192.168.3.128 #允许访问的服务器IP
Hosts deny = * #黑名单
List = true # allow column files
#ignore errors # to ignore extraneous IO errors
#exclude = cache/111/cache/222/ #忽略的目录

# Vi/etc/rsyncd.secrets (set access (authenticated) Username password)

rsync:111111 # Username: password

Correct permissions to the file
# chown Root:root/etc/rsyncd.secrets
# chmod 600/etc/rsyncd.secrets # (must be 600)

Second, the client side of the synchronization

The client defaults as if it had been installed in rsync, without the words installed:
# yum-y Install rsync

To perform an asynchronous synchronization operation:

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

# crontab-e # (You can sync files every three minutes at timed time)

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

The following command is complete:

#vi/etc/rsyncd.pas
Add password
Rsyncofpass
Note that the client's password file requires only a password and does not require a username!

To 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/

The V in-VZRTOPG in this command line is verbose,
Z is a compressed transmission,
R is recursive,
TOPG are the parameters that keep the original attributes of the file, such as the owner and the time.
You are only synchronizing the files that have been updated, so that files that are not updated are updated once, but be aware of the synchronization of both machines ' clocks.
–progress means showing detailed progress,
–delete means that if the server side deletes this file, then the client also deletes the file accordingly, maintaining true consistency.
Later in the rsync_user@192.168.0.2::rsync_module_name1, the rsync_module_name1 is the module name, which is the custom name in/etc/rsyncd.conf, rsync_ User is the username specified in the specified module that can be synchronized.
The final/www is the backup to the local directory name.
In this case, you can also use the e-ssh parameter to establish an encrypted connection.
You can use –password-file=/password/path/file to specify a password file, so that it can be used in the script without having to enter the authentication password interactively, it should be noted that this password file permission attribute must be set to only the owner-readable.

#/usr/local/rsync/bin/rsync-vzrtopg–progress–deletersync_user@192.168.0.2::rsync_module_name1/tmp/
Password:
Or you can make password files.
Because of the need for system crontab execution, here is the way to read the password file,
This is the time to succeed.

sync command Description:

1 Displaying directory Contents

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

Command description
———
A) Display directory contents (first level)
b) recursive display of directory content
c) Displaying the contents of the remote host directory
* NOTE 1: Port mode, authentication based on rsync user
* Note the directory on the 2:rsync server must have XX7 permissions.

d) View the contents of the remote host directory
* Note 1:remote shell mode, authentication based on system local user via SSH connection
* NOTE 2: This only uses a colon (:), while the user name is the remote host SSH user, the password is the SSH user's corresponding password.
* Note 3: Use "" To list information about the folder itself. To list the contents of a folder, you should use "/".

Parameter description
———
-R recursive operation of the directory

2 Sync between local directories

Command
——
a) rsync-av–progress/* * * ATTENTION (/) * * *
b) rsync-av–progress
c) Rsync-avu–progress–delete/
D) rsync-av–progress–temp-dir=/tmp/

Command description
———
A) Synchronize all files in the Src-dir directory to the Dst-dir directory
b Synchronize all files in the Src-dir directory to the Dst-dir/src-dir directory
c) The content of the Src-dir directory to the Dst-dir directory for differential updates, there are additions/updates to add replacement, there is a reduction in the deletion
D) More than a –temp-dir=/tmp, that is, specify/tmp as a temporary swap area, so as to avoid errors due to insufficient target directory space caused by the inability to sync files.

Parameter description
———
-A is equivalent to the-rlptgod set
-U is equivalent to –update and is not updated when the target file is newer than the source file
-V Display synchronized files
–progress percentage progress, transfer rate when file synchronization is displayed
–delete Delete files in the destination directory more than the source directory

3 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::/

Command description
———
A to synchronize the contents of the local directory to the remote host 192.168.0.1 directory, Jack is an rsync database user (see 3/etc/rsync.secrets)
(b) Synchronization of non-interactive logon files by automatically reading user passwords
c) more than B-U and –delete
d Synchronize remote host content to local directory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.