Set up Rsync + Inotify in CentOS6.4 for Real-Time Synchronization

Source: Internet
Author: User
Tags inotify connection reset rsync

Set up Rsync + Inotify in CentOS6.4 for Real-Time Synchronization
Set up Rsync + Inotify in 64-bit CentOS6.4 _ for Real-Time Synchronization

Rsync is a file synchronization service in linux. In simple terms, the server opens port 873, the client connects to this port, and synchronizes the directory configured on the server, it can be understood that after the client compares the server resources, it adds, deletes, and modifies incremental or differential data. The function supports upload (push) or download (obtain) comparison, that is, the remote data is compared with the local data, and then added, deleted, and modified to the remote data.

Centos6.4 is installed by default. You only need to enable the dependency service xinetd.

Environment setup:

1. First disable selinux and iptables

[Vi/etc/sysconfig/selinux]

Change [SELINUX = enforcing] to [SELINUX = disabled]

To modify the selinux configuration, restart the server to make the configuration take effect.

[Service iptables stop]

[Chkconfig iptables off]

2. configuration is divided into two parts:

ServerTerminal:

1. Install rsync (centos6.4 is installed by default)

[Yum install rsync-y]

[Yum install xinetd-y]

2. Start the rsync dependency service

[/Etc/init. d/xinetd start]

[Chkconfig xinetd on]

3. Configure/etc/rsyncd. conf

[Vi/etc/rsyncd. conf]

Uid = root

Gid = root

Use chroot = no

Max connections = 10

Strict modes = yes

Port = 873

Address = 192.168.1.13

[Mail]

Path =/home/domains/

Comment = mirror for extmail

Ignore errors

Read only = no

List = no

Auth users = user

Secrets file =/etc/rsync. pas

Hosts allow = 192.168.1.14

Hosts deny = 0.0.0.0/0

Pid file =/var/run/rsyncd. pid

Lock file =/var/run/rsync. lock

Log file =/var/log/rsyncd. log

Parameter Details

Read only = no # indicates writable

Port = 873 # port

4. Configure/etc/rsync. pas

On the server side, you must add the login name and password. On the client, you only need to enter the password

[Vi/etc/rsync. pas]

User: 123456

Chmod 600/etc/rsync. pas # prevent non-root Account Modification!

6. Start rsync

Rsync -- daemon -- config =/etc/rsyncd. conf

ClientTerminal:

1. Install rsync (centos6.4 is installed by default)

[Yum install rsync-y]

[Yum install xinetd-y]

2. Start the rsync dependency service

[/Etc/init. d/xinetd start]

[Chkconfig xinetd on]

3. the password file must be configured on the client.

[Vi/etc/rsync. pas]

123456 # consistent with the user password on the server !!

Chmod 600/etc/rsync. pas # Same server license

4. Run the following command on the client to synchronize data:

Download (obtain ):

[Rsync-auzv -- progress -- delete -- password-file =/etc/rsync.pasuser@192.168.1.13: mail/home/domains]

Upload (push ):

[Rsync-auzv -- progress -- delete -- password-file =/etc/rsync. pas/home/domains/* user@192.168.1.13: mail]

If you are not using the port number specified in the -- port 873 # configuration file, you must add the -- port parameter.

!!!!! Parameter Details !!!!!

User@192.168.1.13: mail/home/domains.

Auth users = user corresponding to the server configuration file

And server/etc/rsync. pas user name: Password (user: 123456)

IP address of the server corresponding to 192.168.1.13

[Mail] of the server configuration file corresponding to mail

/Home/domains indicates the path in which data is stored in the client directory after the client synchronizes data from the server.

@ And:

----------------

Rewrite encrypted data in the preceding format (full format ):

Download (obtain ):

# Rsync-auzvP -- delete-e "ssh-p22" root@192.168.1.13:/home/domains // home/domains/-- port 873

Upload (push ):

# Rsync-auzvP -- delete-e "ssh-p22"/home/domains/root@192.168.1.13:/home/domains/-- port 873

Note: -- progress can be abbreviated as-P

5. scheduled tasks:

Add a command in crontab to set Automatic execution every minute.

# Crontab-e

----------------------

* ***/Usr/bin/rsync-auzv -- progress -- delete -- password-file =/etc/rsync.pasuser@192.168.1.13: mail/home/domains

---------------------

6. For security, if the system enables the firewall, we recommend that you add an iptables command.

# Iptables-a input-P tcp -- dport: 873-j ACCEPT

7. If you need multiple different directories to support synchronization, add another

[MYSQL]

Path =/usr/local/mysql/data

Comment = mysql mirror

Ignore errors

Read only = yes

List = no

Auth users = root

Secrets file =/etc/rsync. pas

Hosts allow = 172.24.40.50

Hosts deny = 0.0.0.0/0

Pid file =/var/run/rsyncd. pid

Lock file =/var/run/rsync. lock

Log file =/var/log/rsyncd. log

Restart rsync

# Pkill rsync

# Rsync -- daemon -- config =/etc/rsyncd. conf

Then, run the following command on the client to synchronize data:

Rsync-auzv -- progress -- delete -- password-file =/etc/rsync.pasuser@192.168.1.14: MYSQL/usr/local/mysql/data

----------------- Success -----------------------------

Note: configuration process problems:

Question 1:

Problems encountered on the client:

Rsync-auzv -- progress -- password-file =/etc/rsync.pasroot@192.168.133.128: backup/home/

Rsync: cocould not open password file "/etc/rsync. pas": No such file or directory (2)

Password:

@ ERROR: auth failed on module backup

Rsync error: error starting client-server protocol (code 5) at main. c (1506) [runner ER = 3.0.7]

This problem occurs: the file/etc/rsync. pas is not set on the client, but this parameter is added when the rsync command is used --

Password-file =/etc/rsync. pas

Question 2:

Rsync-auzv -- progress -- password-file =/etc/rsync.pasroot@192.168.133.128: backup/home/

@ ERROR: auth failed on module backup

Rsync error: error starting client-server protocol (code 5) at main. c (1506) [runner ER = 3.0.7]

This problem occurs: the file/etc/rsync. pas has been set on the client, and the password 111111 is set in it, which is consistent with that on the server,

The server segment is set incorrectly. The server side should set/etc/rsync. pas, which contains root: 111111. the login name is indispensable here.

Question 3:

Rsync-auzv -- progress -- password-file =/etc/rsync.pasroot@192.168.133.128: backup/home/

@ ERROR: chdir failed

Rsync error: error starting client-server protocol (code 5) at main. c (1506) [runner ER = 3.0.7]

This problem occurs because the/home/backup directory on the server is not set, so the prompt is: chdir failed

Question 4:

Rsync: write failed on "/home/backup2010/wensong": No space left on device (28)

Rsync error: error in file IO (code 11) at handler er. c (302) [handler ER = 3.0.7]

Rsync: connection unexpectedly closed (2721 bytes encoded Ed so far) [generator]

Rsync error: error in rsync protocol data stream (code 12) at io. c (601) [generator = 3.0.7]

Unable to operate because the disk space is insufficient.

You can use df/home/backup2010 to view available and used space.

Question 5: network collection problems

1. Permission issues

A message similar to the following is displayed: rsync: opendir "/kexue" (in dtsChannel) failed: Permission denied (13) check whether the synchronization directory Permission is 755.

2. time out

Rsync: failed to connect to 203.100.192.66: Connection timed out (110)

Rsync error: error in socket IO (code 10) at clientserver. c (124) [handler ER = 3.0.5]

Check the server port netstat-tunlp for remote telnet testing.

3. The service is not started.

Rsync: failed to connect to 10.10.10.170: Connection refused (111)

Rsync error: error in socket IO (code 10) at clientserver. c (124) [handler ER = 3.0.5]

Start the service: rsync -- daemon -- config =/etc/rsyncd. conf

4. Full disk space

Rsync: recv_generator: mkdir "/teacherclubBackup/rsync ...... "Failed: No space left on device (28)

* ** Skipping any contents from this failed directory ***

5. Ctrl + C or a large number of files

Rsync error: canceled ed SIGINT, SIGTERM, or SIGHUP (code 20) at rsync. c (544) [Cycler = 3.0.5]

Rsync error: canceled ed SIGINT, SIGTERM, or SIGHUP (code 20) at rsync. c (544) [generator = 3.0.5]

6. xnetid startup

Rsync: read error: Connection reset by peers (104)

Rsync error: error in rsync protocol data stream (code 12) at io. c (759) [runner ER = 3.0.5]

View rsync logs

Rsync: unable to open configuration file "/etc/rsyncd. conf": No such file or directory

The default location of the configuration file for xnetid search is/etc, and a soft link is created based on the actual situation. For example:

Ln-s/etc/rsyncd. conf/etc/rsyncd. conf

You can also change the path of the specified default configuration file in the/etc/xinetd. d/rsync configuration file.

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.