How to Use rsync for Data Synchronization in Linux
Source: Internet
Author: User
Article Title: How to Use rsync for Data Synchronization in Linux. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic categories first install Rsync, such as on Redhat Fedora Linux or RHEL AS3:
Rpm-ivh rsync-2.5.7-5.3E.i386.rpm
Installation is complete.
The rsync client and server are both in the same execution file, but the parameters added are different.
For example, if server A is 192.168.0.100 and server B is 192.168.0.101, for example, synchronize files in the/www/downloads/new directory on server 101 to the/www/download directory of 192.168.0.100, then, run rsync on 100 as the server and 101 as the client.
First, set up the configuration file of the 192.168.0.100 server.
Vi/etc/rsyncd. conf
The content is as follows:
Uid = nobody
Gid = nobody
Use chroot = yes
Max connections = 4
Pid file =/var/run/rsyncd. pid
Lock file =/var/run/rsync. lock
Log file =/var/log/rsyncd. log
[Downloads]
Path =/www/downloads/
Ignore errors
Read only = false
List = false
Hosts allow = 192.168.0.101/24
Hosts deny = 0.0.0.0/32
Auth users = backup
Secrets file =/etc/rsyncd. pwd
In a configuration file, uid and gid indicate the running identity. chroot indicates that the directory is automatically switched after the connection, and read only = false indicates that other clients are allowed to upload data to the server on the local machine. Host allow and deny are restricted connection addresses. Auth user is the authenticated user name, And secrets file =/etc/rsyncd. pwd indicates that the password is read here when the authenticated user name is used.
Next, edit the password file:
Vi/etc/rsyncd. pwd
Backup: 123456
Set Password File Permission 700: (LOGIN fails if the permission is incorrect)
Chmod 700/etc/rsyncd. pwd
Then start the rsync service:
/Usr/bin/rsync -- daemon
Add rsync to the Automatic startup script and start it automatically after it is started:
Echo "/usr/bin/rsync -- daemon">/etc/rc. d/rc. local
Note that iptables must allow connection to port 873 of rsync.
For example, synchronize files in the/www/downloads/new directory on 101 to the/www/downloads directory of 192.168.0.100.
The execution script is created:
Vi/root/rsync. sh
Rsync-vrtL -- progress \
/Www/downloads/new /*\
Backup@192.168.0.100: downloads \
-- Password-file =/root/rsync. pwd
-V indicates that the output result is displayed, r indicates the persistence attribute, t indicates the persistence time, and L indicates that soft link is treated as a common file.
Create a client password file:
Vi/root/rsync. pwd
123456
Note: The client password script does not contain the user name.
Set Password File Permission 700: (LOGIN fails if the permission is incorrect)
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.