---------------------------------------------------------
Rsync Summary
1, Client Configuration
Configuration file:/etc/rsync_client/rsyncd.conf
Uid=root
Gid=root
Use chroot = no
Max connections = 5
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsync.lock
Log file =/var/log/rsyncd.log
Timeout = 300
Log format =%t%a%m%f%b
Password file: Permission must be 600
/etc/rsync_client/rsyncd.pass
Password123
2 files exist, and as a client, the Rsync service does not need to be started.
2, service-side configuration
Configuration file:/etc/rsync_serv/rsyncd.conf
Uid=root
Gid=root
Use chroot = no
Max connections = 5
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsync.lock
Log file =/var/log/rsyncd.log
Timeout = 300
Log format =%t%a%m%f%b
[Nginx] #模块
Path=/usr/local/nginx#路径
Ignore errors
Read Only = no#需要写入权限
List = no
Auth users = user123#连接认证使用的帐号
Secrets file =/etc/rsync_serv/rsyncd.pass#连接认证使用的密码文件, permission must be 600
Hosts allow = 192.168.1.103#允许连接的客户端
Hosts deny = 0.0.0.0/0#拒绝连接的IP
Password file:/etc/rsync_serv/rsyncd.pass
user123:password123#密码信息需与客户端配置的密码一致
As a service side, you need to start the service:
Rsync--daemon--config=/etc/rsync_serv/rsyncd.conf
3. Synchronize the next Web file on the Nginx directory, executing on the client
Rsync-va--progress--password-file=/etc/rsync_client/rsyncd.pass html/* [email protected]::nginx/html/
If the directory is synchronized, you need to add/
Rsync-va--progress--password-file=/etc/rsync_client/rsyncd.pass conf/[email protected]::nginx/conf
---------------------------------------------------------
Real-time synchronization scripts
#!/bin/sh
#
desthost=192.168.1.108
srcdir=/usr/local/nginx/conf/
#--format '%T%w%f%e ' variables defined are the variables referenced after the while
#%T Time Format
#%w Path
#%f File
#%e Events
INOTIFYWAIT-MR--timefmt '%y-%m-%d_%h:%m:%s '--format '%T%w%f%e '-E close_write,modify,delete,create,attrib $SRCDIR | While read DATE DIR FILE EVENTS
# While the variables declared later correspond to the above formatted variables
Do
#echo "Date: $DATE" >>/var/log/rsync-action.log
#echo "Time: $TIME" >>/var/log/rsync-action.log
#echo "dir: $DIR" >>/var/log/rsync-action.log
#echo "File: $FILE" >>/var/log/rsync-action.log
#echo "--------" >>/var/log/rsync-action.log
File2=${dir}${file}
Event= ' echo ${events} | awk ' {print '} ' #可以在此针对不同的事件做不同的处理
Rsync-vaq--password-file=/etc/rsync_client/rsyncd.pass $SRCDIR [email protected]::nginx/conf
echo "at ${date} in ${desthost}, File $FILE 2 was ${event} via 103 rsync." >>/var/log/rsync-action.log
#将变更信息邮件通知到管理员或者查询后台
#可关联邮件系统或者日志系统进行分析
# ...
Done
---------------------------------------------------------
PS: Need to install Inotify-tools tool separately
This article is from a "sense of direction" blog, be sure to keep this source http://itech.blog.51cto.com/192113/1790417
Note: rsync+inotify Real-time synchronous expansion thinking