服务端
wget http://rsync.samba.org/ftp/rsync/src/rsync-3.0.7.tar.gz
rpm -e –nodeps rpm -qa |grep rsync
tar zxvf rsync-3.0.7.tar.gz
cd rsync-3.0.7
./configure –prefix=/elain/apps/rsync
make && make install
cd ..
ln -s /elain/apps/rsync/bin/rsync /bin/rsync
vi /elain/apps/rsync/rsyncd.conf #如果不存在,直接用VI新建
添加:
#################################
uid = root
gid = root
use chroot = no
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[logs]
path = /logs/
ignore errors
read only = false
list = false
hosts allow = 10.0.0.0/24
hosts deny = 0.0.0.0/32
auth users = log
secrets file = /etc/rsync.password
#######################################
mkdir /logs
chmod -R 700 /logs #新建目录backup及给予权限
echo “log:123” >/elain/apps/rsync/rsync.password #配置帐号及密码
chmod 600 /elain/apps/rsync/rsync.password #配置rsync.passwd文件权限
ln -s /elain/apps/rsync/rsyncd.conf /etc/rsyncd.conf
ln -s /elain/apps/rsync/rsync.password /etc/rsync.password
echo “/bin/rsync –daemon”>>/etc/rc.local #设置为开机自启动
#添加定时任务
##################################
Info : mkdir log dir
Author : dingtm
CTime : 2011.05.25
00 00 * mkdir -p /logs/apps/date +%Y
/date +%m
/date +%d
&& mkdir -p /logs/system/date +%Y
/date +%m
/date +%d
##################################
rsync –daemon # 启动服务
客户端:
vi /root/scripts/rsync_log.sh
########################################
#!/bin/sh
Info : rsync logs to logserver
Author : dingtm
CTime : 2011.05.25
YEAR=date +%Y
MONTH=date +%m
DAY=date +%d
rsync -vuzrtopg –progress –bwlimit=5000 /elain/logs/ –password-file=/etc/rsync.password log@10.1.39.214::logs/apps/$YEAR/$MONTH/$DAY/$HOSTNAME
sleep 300
rsync -vuzrtopg –progress –bwlimit=5000 /var/log/ –password-file=/etc/rsync.password log@10.1.39.214::logs/system/$YEAR/$MONTH/$DAY/$HOSTNAME/
if [ $? -eq 0 ];then
echo “$(date +”%Y-%m-%d %H:%M:%S”) logs rsync success” >> /var/log/rsync.log
else
echo “$(date +”%Y-%m-%d %H:%M:%S”) logs rsync error” >> /var/log/rsync.log
fi
###############################################
chmod 700 /root/scripts/rsync_log.sh
添加定时任务:
####################################
Info : rsync logs to logserver
Author : dingtm
CTime : 2011.05.25
00 /bin/sh /root/scripts/rsync_log.sh
####################################
echo “123” >/etc/rsync.password
chmod 600 /etc/rsync.password
以上日期按逻辑上应改成
DAY=date +%d
改成 DAY=date -d yesterday +%d
PS:以上只是一个思路,有待改进,此为我写的最初版,在生产环境中我已经改进了很多