inotify实时同步并发测试
echo -en "`date +%H:%M`\t" >>/tmp/tmp.log && tree |wc -l >>/tmp/tmp.log
cat /tmp/tmp.log
cp /tmp/tmp.log /tmp/new/inotify_10_`uname -n`.log
>/tmp/tmp.log
inotify实时同步测试:
在inotify监控平台192.168.1.147机器上执行脚本inotify_w.sh,同时对147和149机器在目录/backup下批量执行如下命令:
echo -en "`date +%H:%M`\t" >>/tmp/tmp.log && tree |wc -l >>/tmp/tmp.log
抽集多个数据
192.168.1.147机器上的数据:
[root@client-rsync backup]# cat /tmp/tmp.log
09:30 12230
09:30 12746
09:30 12908
09:30 13945
09:31 14665
09:31 15065
09:31 15384
09:31 15743
09:32 17463
09:32 17703
09:32 18103
09:32 18630
09:33 20342
09:33 20577
09:33 20577
192.168.1.149机器上的数据:
[root@server-rsync backup]# cat /tmp/tmp.log
09:30 12201
09:30 12737
09:30 12906
09:30 13945
09:31 14665
09:31 15065
09:31 15384
09:31 15715
09:32 17463
09:32 17703
09:32 18103
09:32 18583
09:33 20295
09:33 20577
09:33 20577
分别在这两台机器上执行操作:cp /tmp/tmp.log /tmp/new/inotify_80_`uname -n`.log 备份数据之后清空/tmp/tmp.log文件,执行命令: >/tmp/tmp.log
远程拷贝147机器上的数据到149机器:
[root@client-rsync tmp]# scp /tmp/new/* root@192.168.1.149:/tmp/new/
通过paste命令把149机器目录/tmp/new下的两文件合并到一起:
[root@server-rsync new]# ll
total 8
-rw-r--r--. 1 root root 180 Mar 12 09:49 inotify_80_client-rsync.log
-rw-r--r--. 1 root root 180 Mar 12 09:48 inotify_80_server-rsync.log
[root@server-rsync new]# paste inotify_80_client-rsync.log inotify_80_server-rsync.log >inotify_80.txt
[root@server-rsync new]# cat inotify_10.txt
09:30 12230 09:30 12201
09:30 12746 09:30 12737
09:30 12908 09:30 12906
09:30 13945 09:30 13945
09:31 14665 09:31 14665
09:31 15065 09:31 15065
09:31 15384 09:31 15384
09:31 15743 09:31 15715
09:32 17463 09:32 17463
09:32 17703 09:32 17703
09:32 18103 09:32 18103
09:32 18630 09:32 18583
09:33 20342 09:33 20295
09:33 20577 09:33 20577
09:33 20577 09:33 20577
[root@server-rsync new]# awk '{if($1==$3) print $1" "$2" "$4" "(($2-$4));}' inotify_80.txt
09:30 12230 12201 29
09:30 12746 12737 9
09:30 12908 12906 2
09:30 13945 13945 0
09:31 14665 14665 0
09:31 15065 15065 0
09:31 15384 15384 0
09:31 15743 15715 28
09:32 17463 17463 0
09:32 17703 17703 0
09:32 18103 18103 0
09:32 18630 18583 47
09:33 20342 20295 47
09:33 20577 20577 0
09:33 20577 20577 0
-----------------------------------------------------------------------------------------------------------------------------------
依次增加inotify监控脚本中count的数值:
count=100
(1)
[root@client-rsync ~]# cat /tmp/tmp.log
15:18 8485
15:18 8594
15:18 9592
15:18 9892
15:19 11675
15:19 12012
15:19 12688
15:19 13435
15:20 15605
15:20 15806
15:20 16186
15:20 16384
15:20 16635
15:20 16635
(2)
[root@server-rsync backup]# cat /tmp/tmp.log
15:18 8442
15:18 8594
15:18 9592
15:18 9892
15:19 11633
15:19 11992
15:19 12681
15:19 13388
15:20 15586
15:20 15787
15:20 16177
15:20 16380
15:20 16635
15:20 16635
(3)
[root@server-rsync new]# paste inotify_100_client-rsync.log inotify_100_server-rsync.log >inotify_100.txt
(4)
[root@server-rsync new]# awk '{if($1==$3) print $1" "$2" "$4" "(($2-$4));}' inotify_100.txt
15:18 8485 8442 43
15:18 8594 8594 0
15:18 9592 9592 0
15:18 9892 9892 0
15:19 11675 11633 42
15:19 12012 11992 20
15:19 12688 12681 7
15:19 13435 13388 47
15:20 15605 15586 19
15:20 15806 15787 19
15:20 16186 16177 9
15:20 16384 16380 4
15:20 16635 16635 0
15:20 16635 16635 0
-----------------------
count=200
(1)
[root@client-rsync backup]# cat /tmp/tmp.log
15:36 19631
15:37 20350
15:37 20508
15:37 20708
15:37 21787
15:37 24101
15:38 25961
15:38 26448
15:39 28993
15:39 29256
15:39 29661
15:39 29661
(2)
[root@server-rsync backup]# vim /tmp/tmp.log
15:36 19558
15:37 20317
15:37 20508
15:37 20708
15:37 21727
15:37 24026
15:38 25904
15:38 26375
15:39 28939
15:39 29171
15:39 29661
15:39 29661
(3)
root@server-rsync new]# paste inotify_200_client-rsync.log inotify_200_server-rsync.log >inotify_200.txt
[root@server-rsync new]# cat inotify_200.txt
15:36 19631 15:36 19558
15:37 20350 15:37 20317
15:37 20508 15:37 20508
15:37 20708 15:37 20708
15:37 21787 15:37 21727
15:37 24101 15:37 24026
15:38 25961 15:38 25904
15:38 26448 15:38 26375
15:39 28993 15:39 28939
15:39 29256 15:39 29171
15:39 29661 15:39 29661
15:39 29661 15:39 29661
(4)
[root@server-rsync new]# awk '{if($1==$3) print $1" "$2" "$4" "(($2-$4));}' inotify_200.txt
15:36 19631 19558 73
15:37 20350 20317 33
15:37 20508 20508 0
15:37 20708 20708 0
15:37 21787 21727 60
15:37 24101 24026 75
15:38 25961 25904 57
15:38 26448 26375 73
15:39 28993 28939 54
15:39 29256 29171 85
15:39 29661 29661 0
15:39 29661 29661 0
总结:每秒并发200数据,inotify同步数据几乎无延迟(小于1秒)!(sersync和inotify都是基于单向的实时同步;而union是双向同步,csync多向同步。)
[root@client-rsync shell]# chmod +x inotify.sh ---->nohup命令执行脚本前要先给脚本执行权限,否则执行不了!
[root@client-rsync shell]# nohup /shell/inotify.sh &
[1] 12766
[root@client-rsync shell]# ps -ef |grep ino
root 12766 4602 0 16:46 pts/2 00:00:00 /bin/bash /shell/inotify.sh
root 12767 12766 0 16:46 pts/2 00:00:00 /usr/local/inotify-tools-3.14//bin/inotifywait -mrq --timefmt %d/%m/%y %H:%M --format %T %w%f -e close_write,delete,create,attrib /backup
root 12768 12766 0 16:46 pts/2 00:00:00 /bin/bash /shell/inotify.sh
root 12770 4602 0 16:46 pts/2 00:00:00 grep ino
补充:
1)inotify.sh脚本内容
#!/bin/bash
host01=192.168.1.149
src=/backup
dst=backup
user=rsync_backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify-tools-3.14/
#judge
if [ ! -e "$src" ] \
|| [ ! -e "${rsync_passfile}" ] \
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \
|| [ ! -e "/usr/bin/rsync" ];
then
echo "Check File and Folder"
exit 9
fi
${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \
| while read file
do
cd $src && rsync -aruz -R --delete ./ --timeout=100 $user@$host01::$dst --password-file=${rsync_passfile} >/dev/null 2>&1
done
exit 0
2)inotify_w.sh脚本内容:
#!/bin/sh
count=100
while true
do
for ((i=1;i<=$count;i++))
do
/bin/cp 10k.jpg /backup/10k_`echo $(date)$RANDOM|md5sum |cut -c 1-8`.$ijpg
done
sleep 1
for ((i=1;i<=$count;i++))
do
/bin/cp 30k.jpg /backup/30k_`echo $(date)$RANDOM|md5sum |cut -c 1-8`.$ijpg
done
sleep 1
for ((i=1;i<=$count;i++))
do
/bin/cp 50k.jpg /backup/50k_`echo $(date)$RANDOM|md5sum |cut -c 1-8`.$ijpg
done
sleep 1
done