1. Architecture
Server side: 192.168.202.135
Client: 192.168.202.129
2.rsync server-Side installation configuration
Yum Install rsync-y #安装rsync服务
To provide a configuration file for the Rsync service:
vim /etc/rsyncd.conf #文件默认不存在, add the following uid = root # The user who started the service process gid = root #启动服务进程的用户组port = 873 # Port number to monitor when initiating rsync service with daemon hosts allow = 192.168.202.0/24 #允许哪些客户端能够连接服务max connections = 0 #指定该服务的最大并发连接数, 0 means no limit to timeout= 300 #指定超时时间pid file = /var/run/rsyncd.pid #pid文件路径lock file = /var/run/rsync.lock #锁文件路径log file = /var/log/rsyncd.log #日志文件路径 [backup] #模块声明path =/rsync/test #指定当前模块在rsync服务器上的同步路径, this parameter is the read only = no that must be specified #是否允许客户端上传文件list = no #当客户请求列出可以使用的模块列表时, whether the module should be listed auth users = rsync #指定由空格或逗号分隔的User Name list, only these users are allowed to connect the module secrets file = /etc/rsync.passwd #保存密码和用户名文件, you need to generate
To set the password file:
VIM/ETC/RSYNC.PASSWD #添加以下内容rsync: 123456chmod 600/etc/rsync.passwd #修改密码文件权限为600
Note: when the parameter strict modes in the configuration file is True, the permissions of the rsync authentication password file must be 600, otherwise the client will not be able to connect to the server. each line in the Rsync authentication password file specifies a user name: the password pair, in the format: USERNAME:PASSWD.
Start the Rsync service and set the power-on self-boot:
/usr/bin/rsync--daemon #以守护进程方式启动rsync服务echo "/usr/bin/rsync--daemon" >>/etc/rc.local #添加开机自启动
3.rsync Client Installation and configuration
Install Inotify-tools:
Before installing Inotify-tools, verify that your Linux kernel is 2.6.13, and that the config_inotify option is turned on at compile time, or it can be detected by the following command, if the following output appears, Description Support:
[Email protected] ~]# ls/proc/sys/fs/inotify/max_queued_events max_user_instances max_user_watches
Installation:
wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz Tar xvf inotify-tools-3.14.tar.gz CD inotify-tools-3.14./configure make;make Install
Writing the rsync.sh monitoring script:
#!/bin/bashhost=192.168.202.135src=/data/www/des=backupuser=rsync/usr/local/bin/inotifywait -mrq -- timefmt '%d/%m/%y %h:%m ' --format '%t %w%f ' -e modify,delete, create,attrib ${src} | while read file do rsync -vzrtopg --delete --progress ${src} ${user}@${host}::${des} -- password-file=/etc/www.pwd && echo "${files} was rsynced" >> /tmp/rsync.log 2>&1 echo "---------------------------------------------------------------------------" done
Establish the authentication file (the client authentication file is only used to add the password) and run the rsync.sh script in the background:
Echo ' rsync ' >>/etc/www.pwdchmod 600/etc/ww.pwdnohup sh/root/rsync.sh & Echo "Nohup sh/root/rsync.sh &" >>/etc/rc.local
Resources:
Rsync Server Installation and configuration: http://www.cnblogs.com/mchina/p/2829944.html
Rsync+inotify implementing file Batch update: http://kerry.blog.51cto.com/172631/734087/
Rsync+inotify enables real-time data backup:
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=11840697&id=3890795
CentOS6.5 for Rsync+inotify real-time synchronization