标签:rsync
server端
——————————————
chkconfig iptables off
chkconfig ip6tables off
vim /etc/selinux/config
SELINUX=disabled
yum install -y xinetd rsync
chkconfig xinetd on
chkconfig rsync on
vim /etc/xinetd.d/rsync
disable = no
server_args = --daemon --config=/etc/rsyncd.conf
useradd -M -s /sbin/nologin rsync
vim /etc/rsyncd.conf
################################
uid = rsync
gid = rsync
user chroot = no
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.pid
log file = /var/run/rsyncd.log
################################
[backup]
path = /backup/
ignore errors
read only = no
list = no
hosts allow = 192.168.200.0/255.255.255.0
auth users = apple
secrets file = /etc/rsyncd.password
###################################
vim /etc/rsyncd.password
apple:apple123
chmod 600 /etc/rsyncd.password
client端
——————————————————
chkconfig iptables off
chkconfig ip6tables off
vim /etc/selinux/config
SELINUX=disabled
yum install -y rsync
vim /etc/rsyncd.password
apple123
chmod 600 /etc/rsyncd.password
客户端使用的命令
1.rsync -avz /local1 /local2
2.rsync -avz -e ‘ssh -p 22‘ /local root@192.168.200.88:/redir
3.rsync -avz /local apple@192.168.200.88::backup --password-file=/etc/rsyncd.password
inotify的配置
###################################
tar -xf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14.tar.gz
./configure --prefix=/usr/local/inotify-tools-3.14
make && make install
ln -s /usr/local/inotify-tools-3.14 /usr/local/inotify-tools
./inotifywait -mrq --timefmt ‘%F_%H:%M:%S‘ --format ‘%T %w %f %e‘ -e create /tmp
[option]
-m|--monitor 表示一直保持事件监听状态。
-r|--recursive 表示递归查询目录。
-q|--quiet 表示打印出监控事件
-e 可以指定要监控的事件。
--timefmt使用的是date时间参数
--format
%T由timefmt定义的事件格式
%w表示发生事件的目录
%f表示发生事件的文件
%e表示发生的事件
access 读取文件
modify 修改文件或目录
attrib 修改文件或目录的属性
close_write 文件或目录内容修改后保存关闭
close_nowrite 文件或目录内容打开不修改保存关闭
close file or directory closed, regardless of read/write mode
open file or directory opened
moved_to file or directory moved to watched directory
moved_from file or directory moved from watched directory
move file or directory moved to or from watched directory
create file or directory created within watched directory
delete file or directory deleted within watched directory
delete_self file or directory was deleted
unmount file system containing file or directory unmounted
将rsync结合inotify使用
vim /sh/inotify.sh
#!/bin/bash
/usr/local/inotify-tools/bin/inotifywait -mrq --timefmt ‘%F_%H:%M:%S‘ --format ‘%T %w %f %e‘ -e create,delete,move,close_write /data \
|while read file
do
cd /data &&
rsync -az --delete ./ apple@192.168.200.77::backup --password-file=/etc/rsyncd.password && echo "$file" >>/tmp/rsync.log 2>&1
done
chmod 700 /sh/inotify.sh
echo "/bin/sh /sh/inotify.sh >/dev/null &" >>/etc/rc.local
inotify的优化
cd /proc/sys/fs/inotify
修改
max_queued_events="200000000"
#inotify队列最大长度,如果值太小,会出现"** Event Queue Overflow **"错误,导致监控文件不准确
max_user_watches="2000000000"
#inotifywait命令可以监视文件目录的数量
可以用:find /home/test -type d | wc -l 统计,必须保证max_user_watches值大于统计结果
max_user_instances="65535"
#每个用户创建inotify实例最大值
inotify优缺点
inotify的优点:
1)实时数据同步
inotify缺点:
1)并发如果大于200个文件,同步就会延时
2)监控到的事件后,调用rsync同步是单进程的,sersync是多进程同步
serysnc 功能多:可以对失败的文件重传,真正的守护进程socket,默认多线程同步。
3)如果被监控的目录文件很多,inotify效率会慢,因为每次同步都要检查每一个文件
配置sersync
echo "/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml &" >>/etc/rc.local
标签:rsync
原文地址:http://hdl993101.blog.51cto.com/1242673/1975687