服務端
---------------------------------
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
配置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
year=`date +%y`
month=`date +%m`
day=`date +%d`
rsync -vuzrtopg --progress --bwlimit=5000 /elain/logs/ --password-file=/etc/rsync.password [email protected]::logs/apps/$year/$month/$day/$hostname
sleep 300
rsync -vuzrtopg --progress --bwlimit=5000 /var/log/ --password-file=/etc/rsync.password [email protected]::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
添加定時任務:
####################################
00 * * * * /bin/sh /root/scripts/rsync_log.sh
echo "123" >/etc/rsync.password
chmod 600 /etc/rsync.password
ps:以上隻是一個思路,有待改進,此為我寫的最初版,在生産環境中我已經改進了很多
本文位址為:http://www.elain.org/?p=237,更多技術請通路:elain'blog ---http://www.elain.org/