linux下實現web數據同步的四種方式(性能比較)教程
實現web數據同步的四種方式=======================================1、nfs實現web數據共享2、rsync +inotify實現web數據同步3、rsync+sersync更快更節約資源實現web數據同步4、unison+inotify實現web數據雙向同步=======================================一、nfs實現web數據共享
?nfs能實現數據同步是通過NAS(網絡附加存儲),在服務器上共享一個文件,且服務器需要設置文件系統的權限和配置文件設置的權限,權限兩者之間取交集,然后客戶端把共享的文件掛載到本地,客戶端對文件有讀寫權限,則實現數據的同步。nfs+web:服務器端的配置:1)、安裝相關軟件,httpd提供web服務,nfs-utils提供nfs服務[root@jie1 ~]# yum -y install httpd nfs-utils2)、設置web的相關配置,使得web能夠提供web服務
復制代碼代碼如下:[root@jie1 ~]# vim /etc/httpd/conf/httpd.conf?########################################?ServerName :80?#DocumentRoot "/var/www/html"?? #提供虛擬主機,注釋默認存放網頁文件的路徑???? ServerName ??? 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? (rw,sync,root_squash,anonuid=48,anongid=48)?#nfs是以id號來確定是否能訪問共享的文件的,因為兩個服務器都安裝了httpd軟件,都會有apache用戶,所以apache用戶的id號能訪問共享的文件?#/web/htdocs 共享的目錄?# 指定客戶端能共享此文件,多個客戶端用逗號隔開?#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:????????????????????????????????????