主服务器安装设置运行:
安装rsync
# yum install rsync
# yum install xinetd
设置rsync
# vi /etc/xinetd.d/rsync
修改配置
disable = no
server_args
= --daemon --config=/etc/rsyncd.conf
# vi /etc/rsync.passwd
dzhinternet
# chmod 600 /etc/rsync.passwd
启动rsync
# service xinetd start
安装inotify-tools
从sourceforge.net上下在inotify-tools-3.13.tar.gz。
# tar zxvf inotify-tools-3.13.tar.gz
# cd inotify-tools-3.13
# ./configure --prefix=/usr/local/inotify
# make
# make install
创建复制脚本
此项功能主要是将主服务器端的目录/home/StatServer里的内容,如果修改了(无论是添加、修改、删除文件)能够通过inotify监控到,并通过rsync实时的同步给从服务器的/home/StatServer里,下面是通过shell脚本实现的。
# vi /usr/bin /rsync.sh
#!/bin/bash
host=从服务器ip
src=/home/StatsServer
des=data
user=zxx
/usr/local/inotify/bin/inotifywait -mrq
--timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib
$src | while read files
do
/usr/bin/rsync -vzrtopg --delete --progress
--password-file=/etc/rsync.passwd $src $user@$host::$des
echo "${files} was rsynced"
>>/tmp/rsync.log 2>&1
done
# chmod 764 /usr/bin /rsync.sh
设置开始运行
# echo "/usr/bin /rsync.sh "
>> /etc/rc.local
运行脚本
# sh /usr/bin/rsync.sh &
从服务器安装设置运行:
安装rsync
# yum install rsync
# yum install xinetd
设置rsync
# vi /etc/xinetd.d/rsync
修改配置:
disable = no
server_args
= --daemon --config=/etc/rsyncd.conf
# vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = yes
max connections = 10
strict modes = yes
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/log/rsyncd.lock
#secrets file =
/usr/local/rsync/etc/rsyncd.Pas
#motd file = /usr/local/rsync/etc/rsyncd.Motd
[data]
path = /home
comment = CMCC DATA
ignore errors
read only = no
write only = no
hosts allow = 主服务器ip
hosts deny = *
list = false
uid = root
gid = root
auth users = zxx
secrets file = /etc/rsync.passwd
# vi /etc/rsync.passwd
zxx:dzhinternet
# chmod 600 /etc/rsync.passwd
启动rsync
# service xinetd start
阅读(669) | 评论(0) | 转发(0) |