Under CentOS6.4 build Rsync + Inotify achieve real-time synchronization

CentOS6.4_64 bit lower to build Rsync + Inotify achieve real-time synchronization

rsync file synchronization services under linux, the server function is simply to open 873 port, the client is connected to this port, and server-side configuration of directory synchronization, can be understood as a client server-side resources than later, to increase the amount or the difference data CRUD operations function supports upload (push) or download (get) than the right, which is a remote data than the local data to remote data and then perform CRUD operations, and local data to remote data and then compared Local data CRUD operations.

centos6.4 default has been installed, simply open it to ensure xinetd dependent services.

Environment to build:

First, the first close selinux and iptables

[Vi / etc / sysconfig / selinux]

The [SELINUX = enforcing] is amended as [SELINUX = disabled]

Selinux modify the configuration you need to restart the server so that it takes effect

[Service iptables stop]

[Chkconfig iptables off]

Second, the configuration is divided into two portions

server-side:

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

[Yum install rsync -y]

[Yum install xinetd -y]

2. Start rsync dependent services

[/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 Description

read only = no # represents write

port = 873 # port

4. Configure /etc/rsync.pas

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

[Vi /etc/rsync.pas]

user: 123456

chmod 600 /etc/rsync.pas # prevent non-root account changes!

6. Start rsync

rsync –daemon –config = / etc / rsyncd.conf

client side:

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

[Yum install rsync -y]

[Yum install xinetd -y]

2. Start rsync dependent services

[/etc/init.d/xinetd Start]

[Chkconfig xinetd on]

3. The client must be configured with a password file

[Vi /etc/rsync.pas]

123456 # and consistent user password server! !

chmod 600 /etc/rsync.pas # same server ↑

4. Then enter the command in the client synchronization:

Download (Get):

[Rsync -auzv –progress –delete –password-file = / etc / rsync.pas user@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 –port 873 # configuration file to specify the port number; add the –port parameters required

! ! ! ! ! Parameter Description! ! ! ! !

user@192.168.1.13 :: mail / home / domains

the corresponding server-side user profile auth users = user

And server-side /etc/rsync.pas within Username: Password (user: 123456)

192.168.1.13 IP address corresponding to the server

mail the corresponding server-side configuration file [mail]

/ Home / domains represent client-side data stored in the directory path after the client-side synchronization server-side data

@ Has played characters with :: Connectivity

—————-

Encrypted with the format above rewrite (full format):

Download (Get):

# 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. The timing of scheduled tasks:

Add a command in crontab, set automatically once per minute.

# Crontab -e

———————-

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

———————

6. For safety, if the system enable the firewall, it is recommended to add a iptables command

# Iptables -A INPUT -P tcp –dport: 873 -j ACCEPT

7. If you need to support several different directories synchronization, and then add a

[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 enter the command synchronization client

rsync -auzv –progress –delete –password-file = / etc / rsync.pas user@192.168.1.14 :: MYSQL / usr / local / mysql / data

—————– Done —————————–

Note: The configuration process issues:

Question 1:

Problems encountered in the client:

rsync -auzv –progress –password-file = / etc / rsync.pas root@192.168.133.128 :: backup / home /

rsync: could 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) [Receiver = 3.0.7]

Encountered this problem: client side is not set /etc/rsync.pas this document, and use rsync command, add this parameter –

password-file = / etc / rsync.pas

Question 2:

rsync -auzv –progress –password-file = / etc / rsync.pas root@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) [Receiver = 3.0.7]

Encountered this problem: client side has been set /etc/rsync.pas this document, which also set a password 111111, and servers the same, but

Server segment is provided with an error, the server should be set /etc/rsync.pas, which content root: 111111, login name here indispensable

Question 3:

rsync -auzv –progress –password-file = / etc / rsync.pas root@192.168.133.128 :: backup / home /

ERROR: Chdir failed

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

We encounter this problem, because the server / home / backup directory where backup is not provided, so prompt: 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 receiver.c (302) [receiver = 3.0.7]

rsync: connection unexpectedly closed (2721 bytes received so far) [generator]

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

Disk space is not enough, so I can not operate.

You can check the free space and used space by df / home / backup2010

Question 5: network collection problems

1, permissions issue

Similar to the following tips: rsync: opendir “/ kexue” (in dtsChannel) failed: Permission denied (13) Note Check whether the synchronization of directory permissions to 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) [receiver = 3.0.5]

Port netstat -tunlp check the server, remote telnet test.

3, the service does not start

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

rsync error: error in socket IO (code 10) at clientserver.c (124) [receiver = 3.0.5]

Start Service: rsync –daemon –config = / etc / rsyncd.conf

4, disk space is full

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: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c (544) [receiver = 3.0.5]

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

6, xnetid start

rsync: read error: Connection reset by peer (104)

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

View rsync log

rsync: unable to open configuration file “/etc/rsyncd.conf”: No such file or directory

profile location xnetid find default under / etc, create a soft link depending on the circumstances. For instance:

ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf

Or change the default configuration file path specified in the configuration file /etc/xinetd.d/rsync