linux下实现web数据同步的四种方式(性能比较)

2019-10-14 21:56:16于海丽

[root@jie3 inotify]# ldconfig -v | grep inotify
/usr/local/inotify/lib:
    libinotifytools.so.0 -> libinotifytools.so.0.4.1
[root@jie3 inotify]# ln -sv /usr/local/inotify/include/ /usr/include/inotify                      #链接头文件到系统能识别的路径下
`/usr/include/inotify' -> `/usr/local/inotify/include/'
[root@jie3 inotify]#

2)、web的相关配置,使得web能够提供服务


[root@jie3 /]# vim /etc/httpd/conf/httpd.conf
########################################
ServerName 172.16.22.3:80
#DocumentRoot "/var/www/html"
<VirtualHost *:80>
   ServerName www.jie.com
   DocumentRoot  /website
</VirtualHost>
#######################################
[root@jie3 /]# mkdir /website
[root@jie3 /]# httpd -t
Syntax OK
[root@jie3 /]# service httpd start
Starting httpd:                                            [  OK  ]
[root@jie3 ~]# cd /website/
[root@jie3 website]#  ls
[root@jie3 website]#
[root@jie3 ~]#

3)、配置能连接rsync的密码文件和传输数据的脚本


[root@jie3 ~]# vim /etc/rsyncd.pwd
#############################################
pwd123  #密码与rsync服务器的密码相同
###############################################
[root@jie3 ~]# chmod 600 /etc/rsyncd.pwd
[root@jie3 ~]# vim  rsync.sh
#####################################################################
#!/bin/bash
host=172.16.22.1
src=/website
des=htdocs
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  --progress --password-file=/etc/rsyncd.secrets $src backuper@$host::$des
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
####################################################################

验证实现同步:


##1、先开启监控的脚本(inotify主机上)
[root@jie3 ~]# bash -x rsync.sh &
#不放在后台可以查看同步的详细过程,生成环境中,建议把此脚本放到后台执行,此脚本会监控客户端数据是否方式变化,如果变化脚本就运行,数据不变化,脚本就会等待着用户的输入
##2、在开一个终端,在此目录创建文件(inotify主机上)
[root@jie3 ~]# cd /website/
[root@jie3 website]# touch index.html test.php testdb.php  inotify.php
[root@jie3 website]# ls
index.html  testdb.php  test.php inotify.php
[root@jie3 website]#
##3、看服务器端,数据是否已经同步过去