wget https://download.samba.org/pub/rsync/src/rsync-3.1.2.tar.gz
tar -zxvf rsync-3.1.2.tar.gz
2、安装
cd rsync-3.1.2
./configure --prefix=/usr/local/rsync && make && make install && mkdir -p /etc/rsyncd
3.配置文件:
uid = 0
gid = 0
max connections = 4
read only = true
#hosts allow = 202.207.177.180
hosts allow = 127.0.0.1,192.168.66.17
transfer logging = true
log format = %h %o %f %l %b
log file = /var/log/rsyncd.log
slp refresh = 300
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
[web]
path = /www/web/api_master
comment = Mirror to Hk server
read only = false
list = false
auth users = rsync_user
secrets file = /etc/rsyncd/rsync.server.password
[api_web]
path = /www/web/api_web
comment = Mirror to Hk server
read only = false
list = false
auth users = rsync_user
secrets file = /etc/rsyncd/rsync.server.password
4.密码验证文件:
cat /etc/rsyncd/rsync.server.password
rsync_user:rsync_good
chmod 600 /etc/rsyncd/rsync.server.password
5.服务重启文件:
vim /etc/init.d/rsyncd
#!/bin/bash
#rsyncd This shell script takes care of starting and stopping standalone rsync.
#chkconfig: - 99 50
#description:rsync is a file transport daemon
#processname:rsync
#config:/etc/rsyncd.conf
#Source function library
. /etc/rc.d/init.d/functions
RETVAL=0
prog="rsync"
rsync="/usr/local/rsync/bin/rsync"
pid="/var/run/rsyncd.pid"
lock="/var/run/rsync.lock"
CFILE="/etc/rsyncd/rsyncd.conf"
start() {
#Start daemons.
[ -x $rsync ] || \
{ echo "FATAL:No such programme"; exit 4; }
[ -f $CFILE ] || \
{ echo "FATAL:config file does not exist"; exit 6; }
echo -n $"Starting $prog daemon..."
$rsync --daemon --config=$CFILE
RETVAL=$?
echo -n "OK!!!"
echo
return $RETVAL
}
stop() {
#Stop daemons
echo -n $"Stopping $prog:..."
kill -9 `cat /var/run/rsyncd.pid`
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $pid && rm -f $lock
echo -n "OK!!!"
echo
return $RETVAL
}
status(){
if [ -f $pid ];then
echo "Rsync is running,pid(`cat $pid`)"
else
echo "Rsync is not running"
fi
}
#call the function we defined
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
*)
echo $"Usage:$0 {start|stop|restart|reload|status}"
exit 2
esac
exit $RETVAL
在客户端拉取服务器上面的数据:
rsync -avz rsync_user@192.168.1.10::web/abc.com /Web_File_Backup/dd/abc_web_db/web_file/ --password-file=/etc/rsyncd/rsync.client.password
rsync -avz rsync_user@127.0.0.1::web /www/web/api_web --password-file=/etc/rsyncd/rsync.client.password --exclude=Upload --exclude=cli.php --exclude=index.php --exclude=Application/Runtime --exclude=Application/Common/Conf --exclude=Application/Home/Conf --exclude=Application/Erp/Conf --exclude=Application/Cli/Conf --delete
将客户端数据推到服务端:
/usr/bin/rsync -avz /www/web/ rsync_user@192.168.6.10::pda --password-file=/etc/rsyncd/rsync.client.password --delete >/tmp/rsync_pda_to_bak_srv_6610.log