安装rsync算法
yum install rsync xinetd -yshell
2.配置rsyncd.confvim
vim /etc/rsyncd/rsyncd.confbash
uid = root pid = root port = 873 use chroot = no log file = /var/log/rsyncd.log log format = %t %a %f %b max connections = 200 timeout = 300 pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock read only = false list = false ignore errors [image] comment = test_img path = /data/ hosts allow = 192.168.0.12 auth users = test secrets file = /etc/rsyncd/test.pass
3.修改xinetd配置
服务器
vi /etc/xinetd.d/rsyncssh
service rsync { disable = no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon --config=/etc/rsyncd/rsyncd.conf log_on_failure += USERID }
4.启动xintedsocket
/etc/init.d/xinetd startide
测试推送:测试
/usr/bin/rsync -vzrtopg --progress /data/ user@host:/db/ 服务器之间作好SSH信任,本次没用--password-file
5.安装inotify
优化
wget tar -xzvf inotify-tools-3.14.tar.gz && cd inotify-tools-3.14 && ./configure --prefix=/usr/local/inotify && make && make install
inotify优化
# 添加环境变量 export PATH=/usr/local/inotify/bin/:$PATH # 能够在内核处先优化好 echo 50000000 >/proc/sys/fs/inotify/max_user_watches echo 327679 >/proc/sys/fs/inotify/max_queued_events
6.inotify监控测试:添加删除文件
[root@test]# /usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move /data 21/04/21 17:04 /data/a.jpgCREATE 21/04/21 17:04 /data/a.jpgMODIFY 21/04/21 17:04 /data/a.jpgATTRIB 21/04/21 17:04 /data/a.jpgCLOSE_WRITE,CLOSE 21/04/21 17:04 /data/a.jpgDELETE
7.inotify+rsync测试
#!/bin/bash src="/data/" dst="/db/" host="192.168.0.12" /usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move $src | while read file do /usr/bin/rsync -vzrtopg --progress $src $user@$host:$dst done
[root@test bin]$ ./rsync_inotify.sh sending incremental file list ./ 20200330/ 20200330/20200330_ActivityLevel.bytes 6 100% 0.00kB/s 0:00:00 (xfer#1, to-check=1/4) 20200330/a.jpg 4 100% 3.91kB/s 0:00:00 (xfer#2, to-check=0/4) sent 201 bytes received 57 bytes 172.00 bytes/sec total size is 10 speedup is 0.04 sending incremental file list sent 105 bytes received 13 bytes 78.67 bytes/sec total size is 10 speedup is 0.08 sending incremental file list sent 105 bytes received 13 bytes 236.00 bytes/sec total size is 10 speedup is 0.08 sending incremental file list 20200330/
8.inotify参数
inotifywait 语法: inotifywait [-hcmrq] [-e ] [-t ] [--format ] [--timefmt ] [ ... ] 参数: -h,–help 输出帮助信息 @ 排除不须要监视的文件,能够是相对路径,也能够是绝对路径。 –fromfile 从文件读取须要监视的文件或排除的文件,一个文件一行,排除的文件以@开头。 -m, –monitor 接收到一个事情而不退出,无限期地执行。默认的行为是接收到一个事情后当即退出。 -d, –daemon 跟–monitor同样,除了是在后台运行,须要指定–outfile把事情输出到一个文件。也意味着使用了–syslog。 -o, –outfile 输出事情到一个文件而不是标准输出。 -s, –syslog 输出错误信息到系统日志 -r, –recursive 监视一个目录下的全部子目录。 -q, –quiet 指定一次,不会输出详细信息,指定二次,除了致命错误,不会输出任何信息。 –exclude 正则匹配须要排除的文件,大小写敏感。 –excludei 正则匹配须要排除的文件,忽略大小写。 -t , –timeout 设置超时时间,若是为0,则无限期地执行下去。 -e , –event 指定监视的事件。 -c, –csv 输出csv格式。 –timefmt 指定时间格式,用于–format选项中的%T格式。 –format 指定输出格式。 %w 表示发生事件的目录 %f 表示发生事件的文件 %e 表示发生的事件 %Xe 事件以“X”分隔 %T 使用由–timefmt定义的时间格式 inotifywatch 语法: inotifywatch [-hvzrqf] [-e ] [-t ] [-a ] [-d ] [ ... ] 参数: -h, –help 输出帮助信息 -v, –verbose 输出详细信息 @ 排除不须要监视的文件,能够是相对路径,也能够是绝对路径。 –fromfile 从文件读取须要监视的文件或排除的文件,一个文件一行,排除的文件以@开头。 -z, –zero 输出表格的行和列,即便元素为空 –exclude 正则匹配须要排除的文件,大小写敏感。 –excludei 正则匹配须要排除的文件,忽略大小写。 -r, –recursive 监视一个目录下的全部子目录。 -t , –timeout 设置超时时间 -e , –event 只监听指定的事件。 -a , –ascending 以指定事件升序排列。 -d , –descending 以指定事件降序排列。 可监听事件 access 文件读取 modify 文件更改。 attrib 文件属性更改,如权限,时间戳等。 close_write 以可写模式打开的文件被关闭,不表明此文件必定已经写入数据。 close_nowrite 以只读模式打开的文件被关闭。 close 文件被关闭,无论它是如何打开的。 open 文件打开。 moved_to 一个文件或目录移动到监听的目录,即便是在同一目录内移动,此事件也触发。 moved_from 一个文件或目录移出监听的目录,即便是在同一目录内移动,此事件也触发。 move 包括moved_to和 moved_from move_self 文件或目录被移除,以后再也不监听此文件或目录。 create 文件或目录建立 delete 文件或目录删除 delete_self 文件或目录移除,以后再也不监听此文件或目录 unmount 文件系统取消挂载,以后再也不监听此文件系统。
9.rsync参数
-v, --verbose 详细模式输出 -q, --quiet 精简输出模式 -c, --checksum 打开校验开关,强制对文件传输进行校验 -a, --archive 归档模式,表示以递归方式传输文件,并保持全部文件属性,等于-rlptgoD -r, --recursive 对子目录以递归模式处理 -R, --relative 使用相对路径信息 -b, --backup 建立备份,也就是对于目的已经存在有一样的文件名时,将老的文件从新命名为~filename。可使用--suffix选项来指定不一样的备份文件前缀。 --backup-dir 将备份文件(如~filename)存放在在目录下。 -suffix=SUFFIX 定义备份文件前缀 -u, --update 仅仅进行更新,也就是跳过全部已经存在于DST,而且文件时间晚于要备份的文件。(不覆盖更新的文件) -l, --links 保留软链结 -L, --copy-links 想对待常规文件同样处理软链结 --copy-unsafe-links 仅仅拷贝指向SRC路径目录树之外的链结 --safe-links 忽略指向SRC路径目录树之外的链结 -H, --hard-links 保留硬链结 -p, --perms 保持文件权限 -o, --owner 保持文件属主信息 -g, --group 保持文件属组信息 -D, --devices 保持设备文件信息 -t, --times 保持文件时间信息 -S, --sparse 对稀疏文件进行特殊处理以节省DST的空间 -n, --dry-run现实哪些文件将被传输 -W, --whole-file 拷贝文件,不进行增量检测 -x, --one-file-system 不要跨越文件系统边界 -B, --block-size=SIZE 检验算法使用的块尺寸,默认是700字节 -e, --rsh=COMMAND 指定使用rsh、ssh方式进行数据同步 --rsync-path=PATH 指定远程服务器上的rsync命令所在路径信息 -C, --cvs-exclude 使用和CVS同样的方法自动忽略文件,用来排除那些不但愿传输的文件 --existing 仅仅更新那些已经存在于DST的文件,而不备份那些新建立的文件 --delete 删除那些DST中SRC没有的文件 --delete-excluded 一样删除接收端那些被该选项指定排除的文件 --delete-after 传输结束之后再删除 --ignore-errors 及时出现IO错误也进行删除 --max-delete=NUM 最多删除NUM个文件 --partial 保留那些因故没有彻底传输的文件,以是加快随后的再次传输 --force 强制删除目录,即便不为空 --numeric-ids 不将数字的用户和组ID匹配为用户名和组名 --timeout=TIME IP超时时间,单位为秒 -I, --ignore-times 不跳过那些有一样的时间和长度的文件 --size-only 当决定是否要备份文件时,仅仅察看文件大小而不考虑文件时间 --modify-window=NUM 决定文件是否时间相同时使用的时间戳窗口,默认为0 -T --temp-dir=DIR 在DIR中建立临时文件 --compare-dest=DIR 一样比较DIR中的文件来决定是否须要备份 -P 等同于 --partial --progress 显示备份过程 -z, --compress 对备份的文件在传输时进行压缩处理 --exclude=PATTERN 指定排除不须要传输的文件模式 --include=PATTERN 指定不排除而须要传输的文件模式 --exclude-from=FILE 排除FILE中指定模式的文件 --include-from=FILE 不排除FILE指定模式匹配的文件 --version 打印版本信息 --address 绑定到特定的地址 --config=FILE 指定其余的配置文件,不使用默认的rsyncd.conf文件 --port=PORT 指定其余的rsync服务端口 --blocking-io 对远程shell使用阻塞IO -stats 给出某些文件的传输状态 --progress 在传输时现实传输过程 --log-format=formAT 指定日志文件格式 --password-file=FILE 从FILE中获得密码 --bwlimit=KBPS 限制I/O带宽,KBytes per second -h, --help 显示帮助信息