RSYNC

来自Alex's wiki
Admin讨论 | 贡献2016年11月24日 (四) 07:28的版本

跳转至: 导航搜索

rsync+inotify实现实时同步案例
Linux下Rsync+Inotify-tools实现数据实时同步


一个自动化安装脚本

#!/bin/bash
# by ChengleiQIAO
 
 
touch /etc/rsyncd.conf
touch /etc/rsyncd.motd
 
cat << EOF > /etc/rsyncd.conf
// http://sookk8.blog.51cto.com/455855/328076/
uid = root
gid = root
use chroot = no
max connections = 4
strict modes =yes
port = 873
 
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
 
auth users = rsync
secrets file = /etc/rsync.passwd
 
 
[htdocs] //module, set by client
path = /alidata/server/httpd/htdocs
comment = apache wwwroot
ignore errors
read only = no
list = no
auth users = rsync
secrets file = /etc/rsyncd.secrets
hosts allow = 10.172.233.222,10.10.10.10
hosts deny = 0.0.0.0/0
exclude = .svn/
 
EOF
 
 
cat << EOF > /etc/rsyncd.secrets
rsync:Bornedu543
EOF
chmod 600 /etc/rsyncd.secrets
chown root.root /etc/rsyncd.secrets
 
cat << EOF > /etc/rsyncd-client.secrets
Bornedu543
EOF
chmod 600 /etc/rsyncd-client.secrets
chown root.root /etc/rsyncd-client.secrets
 
 
cat << EOF > /etc/rsyncd.motd
++++++++++++++++++++++++++++++++++++++++++++++
Welcome to use the 52jiaoshi rsync services!
           by Chenglei QIAO
++++++++++++++++++++++++++++++++++++++++++++++
EOF
 
#iptables -A INPUT -p tcp --dport 873 -j ACCEPT
lsof -i:873
#start up
sed -i "s/disable[[:space:]]*=[[:space:]]*yes/disable = no/g" /etc/xinetd.d/rsync
 
if [ -f /var/run/rsyncd.pid ] ;then
	rm -f /var/run/rsyncd.pid
fi 
 
#killall rsync
rsync --daemon
 
chkconfig rsync on  
 
grep -q "rsync --daemon" /etc/rc.local  && xxx=1 || echo "rsync --daemon" >>/etc/rc.local
 
#/etc/rc.d/init.d/xinetd reload
#rsync -av /alidata/server/httpd/htdocs/test rsync@10.172.220.56::htdocs --password-file=/etc/rsyncd-client.secrets