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

实现web数据同步的四种方式

=======================================

1、nfs实现web数据共享

2、rsync +inotify实现web数据同步

3、rsync+sersync更快更节约资源实现web数据同步

4、unison+inotify实现web数据双向同步

=======================================

一、nfs实现web数据共享

7d69f87010c48e5ea48f1ce2f47a901d.gif

nfs能实现数据同步是通过NAS(网络附加存储),在服务器上共享一个文件,且服务器需要设置文件系统的权限和配置文件设置的权限,权限两者之间取交集,然后客户端把共享的文件挂载到本地,客户端对文件有读写权限,则实现数据的同步。

nfs+web:服务器端的配置:

1)、安装相关软件,httpd提供web服务,nfs-utils提供nfs服务

[root@jie1 ~]# yum -y install httpd nfs-utils

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

代码如下:

[root@jie1 ~]# vim /etc/httpd/conf/httpd.conf

########################################

ServerName 172.16.22.1:80

#DocumentRoot "/var/www/html"   #提供虚拟主机,注释默认存放网页文件的路径

ServerName www.jie.com

DocumentRoot  /web/htdocs

#######################################

[root@jie1 ~]# mkdir -pv /web/htdocs   #创建存放网页的目录

[root@jie1 ~]# cd /web/htdocs/

[root@jie1 htdocs]# touch index.html test.html test.php

[root@jie1 htdocs]# ls

index.html  test.html  test.php

[root@jie1 htdocs]# echo "This is Jie1 Web+nfs Server" >index.html

[root@jie1 htdocs]# httpd -t         #检查web的配置文件是否有语法错误

Syntax OK

[root@jie1 htdocs]# service httpd start  #开启web服务

Starting httpd:                                            [  OK  ]

3)、设置nfs的相关配置,共享网页文件

代码如下:

[root@jie1 htdocs]# id apache #安装httpd软件后,系统会创建apache用户,查看apache的id号

uid=48(apache) gid=48(apache) groups=48(apache)

[root@jie1 htdocs]# vim /etc/exports

######################################

/web/htdocs  172.16.22.3(rw,sync,root_squash,anonuid=48,anongid=48)

#nfs是以id号来确定是否能访问共享的文件的,因为两个服务器都安装了httpd软件,都会有apache用户,所以apache用户的id号能访问共享的文件

#/web/htdocs 共享的目录

#172.16.22.3 指定客户端能共享此文件,多个客户端用逗号隔开

#rw,读写权限

#sync,同步方式

#root_squash,压缩root用户的权限

#anonuid=48,指定此用户的id能访问共享文件

#anongid=48指定此组的id能访问共享文件

######################################

[root@jie1 htdocs]# service nfs start  #开启nfs服务

Starting NFS services:                                     [  OK  ]

Starting NFS quotas:                                       [  OK  ]

Starting NFS mountd:                                       [  OK  ]

Stopping RPC idmapd:                                       [  OK  ]

Starting RPC idmapd:                                       [  OK  ]

Starting NFS daemon:                                       [  OK  ]

[root@jie1 htdocs]#

web:客户端的配置

1)、安装httpd的软件

代码如下:

[root@jie3 /]# yum -y install httpd

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

代码如下:

[root@jie3 /]# vim /etc/httpd/conf/httpd.conf

########################################

ServerName 172.16.22.3:80

#DocumentRoot "/var/www/html"

ServerName www.jie.com

DocumentRoot  /website   #存放网页文件的路径

#######################################

[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]#

实现同步:

1)服务器端设置apache用户对共享的文件有读写权限

代码如下:

[root@jie1 htdocs]#setfacl -R -m u:apache:rwx /web/ #设置apache用户对此中所有文件有读写可执行权限

2)客户端挂载服务器的共享文件,查看客户端是否已经同步服务器端的文件

代码如下:

[root@jie3 website]#cd /root

[root@jie3 ~]# mount -t nfs 172.16.22.1:/web/htdocs /website/ #通过nfs挂载服务器端的文件

[root@jie3 /]#echo "172.16.22.1:/web/htdocs  /website       nfs    defaults,_netdev 0 0" >>/etc/fstab  #实现开机挂载

[root@jie3 ~]# cd /website/

[root@jie3 website]# ls  #查看文件已经同步过来

index.html  test.html  test.php

[root@jie3 website]#

3)客户端在共享的文件中新增文件,查看服务器端是否同步文件

代码如下:

[root@jie3 ~]# cd /website/

[root@jie3 website]# ls

index.html  test.html  test.php

[root@jie3 website]# touch website.html  #在客户端创建此文件

[root@jie3 website]# ls

index.html  test.html  test.php  website.html

[root@jie1 htdocs]# ls  #服务器端,可以查看来着客户端上传的文件

index.html  test.html  test.php  website.html

「点点赞赏,手留余香」

赞赏

还没有人赞赏,快来当第一个赞赏的人吧!

参与评论

提交

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值