1. 程式人生 > >配置Rsync和Rsync + inotify

配置Rsync和Rsync + inotify

三方 傳遞 sin b- change 庫函數 dep 修改 語言

第一部分:配置Rsync


一、介紹Rsync工具

rsync是一個遠程數據同步工具,可通過LAN/WAN快速同步多臺主機間的文件。它使用所謂的“Rsync演算法”來使本地和遠程兩個主機之間的文件達到同步,這個算法只傳送兩個文件的不同部分,而不是每次都整份傳送,因此速度相當快。所以通常可以作為備份工具來使用。

Rsync的特性如下:

1)支持拷貝特殊文件如鏈接,設備等

2)可以有排除指定文件或目錄同步的功能,相當於打包命令tar

3)可以保持原來文件或目錄的權限,時間,軟硬鏈接等所有屬性均不改變。

4)可實現增量同步,即只同步發生變化的數據,因此數據傳輸效率更高

5)可以使用rcp,rsh,ssh等方式來配合傳輸文件,也可以通過直接的socker鏈接

6)支持匿名的或認證的進程模式傳輸,方便進行數據備份及鏡像。


二、測試環境

Server:CentOS74-01 192.168.1.160

Client: CentOS74-02 192.168.1.161


[root@CentOS74-01 ~]# cat /etc/redhat-release

CentOS Linux release 7.4.1708 (Core)

[root@CentOS74-02 ~]# cat /etc/redhat-release

CentOS Linux release 7.4.1708 (Core)


三、配置rsync服務端

(1)參數介紹

comment = public archive #模塊描述

path = /var/www/pub #需要同步的路徑

use chroot = yes #默認是yes|true,如果為true,那麽在rsync在傳輸文件以前首先chroot到path參數指定的目錄下。這樣做的原因是實現額外的安全防護,但是缺點是需要root權限,並且不能備份指向外部的符號連接指向的目錄文件。

max connections=10 #最大連接數

lock file = /var/lock/rsyncd #指定支持max connections參數的鎖文件。

the default for read only is yes...

read only = yes #只讀選項

list = yes #客戶請求時可用模塊時是否列出該模塊

uid = nobody #設定該模塊傳輸文件時守護進程應該具有的uid

gid = nogroup #設定該模塊傳輸文件時守護進程應具有的gid,此項與uid配合可以確定文件的訪問權限

exclude = #用來指定多個由空格隔開的多個模式列表,並將其添加到exclude列表中。這等同於在客戶端命令中使用--exclude來指定模式,不過配置文件中指定的exlude模式不會傳遞給客戶端,而僅僅應用於服務器。一個模塊只能指定一個exlude選項,但是可以在模式前面使用"-"和"+"來指定是exclude還是include #這個我的理解是排除目錄中不需同步的文件

exclude from = #可以指定一個包含exclude模式定義的文件名

include = #與exclude相似

include from = #可以指定一個包含include模式定義的文件名

auth users = #該選項指定由空格或逗號分隔的用戶名列表,只有這些用戶才允許連接該模塊。這裏的用戶和系統用戶沒有任何關系。如果"auth users"被設置,那麽客戶端發出對該模塊的連接請求以後會被rsync請求challenged進行驗證身份這裏使用的 challenge/response認證協議。用戶的名和密碼以明文方式存放在"secrets file"選項指定的文件中。默認情況下無需密碼就可以連接模塊(也就是匿名方式)

secrets file = /etc/rsyncd.secrets #該文件每行包含一個username:password對,以明文方式存儲,只有在auth users被定義時,此選項才生效。同時我們需要將此文件權限設置為0600

strict modes = yes #該選項指定是否監測密碼文件的權限,如果該選項值為true那麽密碼文件只能被rsync服務器運行身份的用戶訪問,其他任何用戶不可以訪問該文件。默認值為true

hosts allow = #允許的主機

hosts deny = #拒絕訪問的主機

ignore errors = no #設定rsync服務器在運行delete操作時是否忽略I/O錯誤

ignore nonreadable = yes #設定rysnc服務器忽略那些沒有訪問文件權限的用戶

transfer logging = no #使rsync服務器使用ftp格式的文件來記錄下載和上載操作在自己單獨的日誌中

log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes. #設定日誌格式

timeout = 600 #超時設置(秒)

refuse options = checksum dry-run #定義一些不允許客戶對該模塊使用的命令選項列表

dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz #告訴rysnc那些文件在傳輸前不用壓縮,默認已設定壓縮包不再進行壓縮


(2)rsync服務端配置

創建用戶rsync:

[root@CentOS74-01 ~]# useradd rsync
[root@CentOS74-01 ~]# passwd rsync
Changing password for user rsync.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@CentOS74-01 ~]# 
[root@CentOS74-01 ~]# cat /etc/passwd | grep rsync
rsync:x:1000:1000::/home/rsync:/bin/bash

修改配置文件/etc/rsyncd.conf:

[root@CentOS74-01 ~]# cat /etc/rsyncd.conf 
uid = rsync
gid = rsync
use chroot = no
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
hosts allow = 192.168.1.161

[apache]
path = /data/apache/
read only = yes
auth users = tom  (跟系統用戶沒有關系)
secrets file = /etc/rsyncd.secrets

[tomcat]
path = /data/tomcat/
read only = yes

設置rsyncd服務開機啟動:

[root@CentOS74-01 ~]# systemctl enable rsyncd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

啟動rsyncd服務:

[root@CentOS74-01 ~]# systemctl start rsyncd.service

查看 rsyncd 的端口:

[root@CentOS74-01 ~]# netstat -nltp | grep 873
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      1690/rsync

創建密碼文件並賦權限:

[root@CentOS74-01 ~]# vim /etc/rsyncd.secrets 
tom:tom
[root@CentOS74-01 ~]# chmod 600 /etc/rsyncd.secrets
[root@CentOS74-01 ~]# chown root.root /etc/rsyncd.*   (因為rsyncd服務是由root啟動的,所以配置文件和密碼文件的權限要設置為root.root)
[root@CentOS74-01 ~]# ll /etc/rsyncd.*
-rw-r--r-- 1 root root 818 Jul  7 14:55 /etc/rsyncd.conf
-rw------- 1 root root   8 Jul  7 14:38 /etc/rsyncd.secrets

創建測試用的文件:

[root@CentOS74-01 ~]# ll /data/apache/
total 8
-rw-r--r-- 1 root root 7 Jul  7 14:40 apache_1.log
-rw-r--r-- 1 root root 8 Jul  7 14:41 apache_2.log
[root@CentOS74-01 ~]# ll /data/tomcat/
total 8
-rw-r--r-- 1 root root  7 Jul  7 14:41 tomcat_1.log
-rw-r--r-- 1 root root 13 Jul  7 14:41 tomcat_2.log

(3)rsync客戶端配置:

[root@CentOS74-02 ~]# cat /etc/rsyncd.secrets
tom
[root@CentOS74-02 ~]# chown root.root /etc/rsyncd.secrets    
[root@CentOS74-02 ~]# chmod 600 /etc/rsyncd.secrets 
[root@CentOS74-02 ~]#

(4)測試

遇到錯誤一:

[root@CentOS74-02 ~]# rsync -avz --password-file=/etc/rsyncd.secrets [email protected]::web /data/web/
rsync: failed to connect to 192.168.1.160 (192.168.1.160): No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(122) [Receiver=3.0.9]

查看服務器 CentOS74-01 上的防火墻,發現是running的狀態:

[root@CentOS74-01 ~]# firewall-cmd --state
running

關閉防火墻:

[root@CentOS74-01 ~]# systemctl stop firewalld.service
[root@CentOS74-01 ~]# firewall-cmd --state            
not running

關閉防火墻開機啟動:

[root@CentOS74-01 ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

遇到錯誤二:

[root@CentOS74-02 ~]# rsync -avz --password-file=/etc/rsyncd.secrets [email protected]::apache /data/apache/
receiving incremental file list
rsync: mkdir "/data/apache" failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(587) [Receiver=3.0.9]
[root@CentOS74-02 ~]#

需要現在客戶端上面創建文件夾/data/apache/:

[root@CentOS74-02 ~]# mkdir -pv /data/apache/
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/apache/’

[root@CentOS74-02 ~]# rsync -avz --password-file=/etc/rsyncd.secrets [email protected]::apache /data/apache/
receiving incremental file list
./
apache_1.log
apache_2.log

sent 96 bytes  received 229 bytes  30.95 bytes/sec
total size is 15  speedup is 0.05
[root@CentOS74-02 ~]#

在服務器 CentOS74-01 上面新創建apache_3.log,並把權限設置為640:

[root@CentOS74-01 apache]# chmod 640 apache_3.log 
[root@CentOS74-01 apache]# ll
total 12
-rw-r--r-- 1 root root 7 Jul  7 14:40 apache_1.log
-rw-r--r-- 1 root root 8 Jul  7 14:41 apache_2.log
-rw-r----- 1 root root 6 Jul  7 15:25 apache_3.log
[root@CentOS74-01 apache]#

然後再在客戶端 CentOS74-02 上運行以下命令:

[root@CentOS74-02 ~]# rsync -avz --password-file=/etc/rsyncd.secrets [email protected]::apache /data/apache/
receiving incremental file list
./
rsync: send_files failed to open "apache_3.log" (in apache): Permission denied (13)

sent 77 bytes  received 260 bytes  674.00 bytes/sec
total size is 21  speedup is 0.06
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1518) [generator=3.0.9]
[root@CentOS74-02 ~]#

原因:因為在服務器 CentOS74-01 上面,/etc/rsyncd.conf 裏面的uid = rsync gid = rsync,而 rsync 對apache_3.log並沒有讀權限,所以報 Permission denied (13)。

(5)使用無密碼方式拷貝

由於/etc/rsyncd.conf中的[tomcat]模塊並沒有配置需要認證選項,所以可以使用無密碼方式同步文件:

目前/data/tomcat的屬主屬組是root.root:

[root@CentOS74-02 ~]# ll /data
total 0
drwxr-xr-x 2 root root 46 Jul  7 15:25 apache
drwxr-xr-x 2 root root  6 Jul  7 16:04 tomcat

修改屬主屬組為tomcat.tomcat:

[root@CentOS74-02 ~]# chown tomcat.tomcat /data/tomcat/
[root@CentOS74-02 ~]# ll /data/
total 0
drwxr-xr-x 2 root   root   46 Jul  7 15:25 apache
drwxr-xr-x 2 tomcat tomcat  6 Jul  7 16:04 tomcat

su到tomcat用戶,使用tomcat用戶身份用rsync同步文件:

[root@CentOS74-02 ~]# su tomcat
[tomcat@CentOS74-02 root]$ cd /data/tomcat/
[tomcat@CentOS74-02 tomcat]$ rsync -avz 192.168.1.160::tomcat /data/tomcat/
receiving incremental file list
./
tomcat_1.log
tomcat_2.log

sent 69 bytes  received 196 bytes  25.24 bytes/sec
total size is 20  speedup is 0.08
[tomcat@CentOS74-02 tomcat]$ ll
total 8
-rw-r--r-- 1 tomcat tomcat  7 Jul  7 14:41 tomcat_1.log
-rw-r--r-- 1 tomcat tomcat 13 Jul  7 14:41 tomcat_2.log

刪除tomcat日誌文件,使用root用戶同步文件:

[tomcat@CentOS74-02 tomcat]$ rm -fr tomcat_*
[tomcat@CentOS74-02 tomcat]$ exit
exit

在客戶端上面使用root從服務器端拷貝文件到/data/tomcat/下面,會把該目錄的屬主屬組修改為root.root:

[root@CentOS74-02 ~]# rsync -avz 192.168.1.160::tomcat /data/tomcat/
receiving incremental file list
./
tomcat_1.log
tomcat_2.log

sent 69 bytes  received 196 bytes  25.24 bytes/sec
total size is 20  speedup is 0.08
[root@CentOS74-02 ~]# ll /data/
total 0
drwxr-xr-x 2 root root 46 Jul  7 15:25 apache
drwxr-xr-x 2 root root 46 Jul  7 14:41 tomcat
[root@CentOS74-02 ~]# ll /data/tomcat/
total 8
-rw-r--r-- 1 root root  7 Jul  7 14:41 tomcat_1.log
-rw-r--r-- 1 root root 13 Jul  7 14:41 tomcat_2.log
[root@CentOS74-02 ~]#

四、rsync的不足

與傳統的cp、tar備份方式相比,rsync具有安全性高、備份迅速、支持增量備份等優點,通過rsync可以解決對實時性要求不高的數據備份需求,例如定期的備份文件

服務器數據到遠端服務器,對本地磁盤定期做數據鏡像等。

隨著應用系統規模的不斷擴大,對數據的安全性和可靠性也提出的更好的要求,rsync在高端業務系統中也逐漸暴露出了很多不足,首先,rsync同步數據時,需要掃描

所有文件後進行比對,進行差量傳輸。如果文件數量達到了百萬甚至千萬量級,掃描所有文件將是非常耗時的。而且正在發生變化的往往是其中很少的一部分,這是非常

低效的方式。其次,rsync不能實時的去監測、同步數據,雖然它可以通過crontab方式進行觸發同步,但是兩次觸發動作一定會有時間差,這樣就導致了服務端和客戶端

數據可能出現不一致,無法在應用故障時完全的恢復數據。基於以上原因,rsync+inotify組合出現了!



第二部分:配置Rsync + inotify


一、inotify簡介

inotify實際上是Linux系統的一個內核特性(在Linux2.6.13中開始引入),它是一種高精度的異步文件系統事件監控機制,它監控文件系統操作,比如增刪改、移動等細微事件,而且相當靈敏。

可以通過以下命令判斷當前內核是否支持,出現以下三個文件代表已支持該特性。

[root@CentOS74-01 ~]# ll /proc/sys/fs/inotify/
total 0
-rw-r--r-- 1 root root 0 Jul  7 17:02 max_queued_events
-rw-r--r-- 1 root root 0 Jul  7 17:02 max_user_instances
-rw-r--r-- 1 root root 0 Jul  7 17:02 max_user_watches

參數含義:

max_queued_events

設置inotify實例事件(event)隊列可容納的事件數量。

max_user_instances

設置每個用戶可以運行的inotifywait或inotifywatch命令的進程數。

max_user_watches

設置inotifywait或inotifywatch命令可以監視的文件數量(單進程)。


如果監控的文件數目巨大,需要根據情況,適當增加這些參數的大小,可以達到優化性能的目的:

[root@CentOS74-01 ~]# echo 50000000 > /proc/sys/fs/inotify/max_queued_events
[root@CentOS74-01 ~]# echo 50000000 > /proc/sys/fs/inotify/max_user_watches
[root@CentOS74-01 ~]# echo 65535 > /proc/sys/fs/inotify/max_user_instances

將上面的命令行加入/etc/rc.d/rc.local文件裏,實現每次重啟系統都自動生效。


二、安裝inotify-tools工具包

前面說的inotify是內核特性,而inotify-tools則是一套使用C語言開發的第三方接口庫函數,它提供了兩個個已經編譯好的二進制命令,可以對內核特性進行調用,更加方便得監控文件系統。

使用源碼包安裝:

[root@CentOS74-01 src]# ls
inotify-tools-3.13.tar.gz
root@CentOS74-01 src]# tar -zxf inotify-tools-3.13.tar.gz 
[root@CentOS74-01 src]# ls
inotify-tools-3.13  inotify-tools-3.13.tar.gz
[root@CentOS74-01 src]# cd inotify-tools-3.13
[root@CentOS74-01 inotify-tools-3.13]# ls
aclocal.m4  ChangeLog     config.h.in  configure     COPYING  INSTALL     libinotifytools  Makefile.am  man      NEWS    src
AUTHORS     config.guess  config.sub   configure.ac  depcomp  install-sh  ltmain.sh        Makefile.in  missing  README
[root@CentOS74-01 inotify-tools-3.13]# ./configure --prefix=/usr/local/inotify
[root@CentOS74-01 inotify-tools-3.13]# make && make install

安裝成功後在bin目錄下會生成inotifywait和inotifywatch兩個命令:

[root@CentOS74-01 bin]# pwd
/usr/local/inotify/bin
[root@CentOS74-01 bin]# ls
inotifywait  inotifywatch

命令作用

inotifywait 用來等待文件上的一個特定事件,可以監控整個目錄樹的變化。

inotifywatch 它是用來收集被監控的文件系統統計數據。


inotifywait有豐富的參數,提供各種各樣的文件監控需求。

參數:

inotifywait參數 含義說明

-r,--recursive 遞歸查詢目錄

-q,--quiet 打印很少的信息,僅僅打印監控事件的信息

-m,--monitor 始終保持事件監聽狀態

--exclude 排除文件或目錄時,不區分大小寫。

--timefmt 指定時間輸出的格式

--format 打印使用指定的輸出類似格式字符串

-e,--event 通過此參數可以指定需要監控的事件,如下一個列表所示


可以監控的文件系統事件:

Events 含義

access 文件被訪問

modify 文件內容被修改

attrib 文件屬性被修改

close_write 可寫文件被關閉

close_nowrite 不可寫文件被關閉

open 文件被打開

moved_fron 文件被移走

move_to 文件被移入

create 創建新文件

delete 文件被刪除

delete_self 自刪除,一個可執行文件在執行時刪除自身

move_self 自移動,一個可執行文件在執行時移動自身

umount 文件系統被卸載

close 文件被關閉(write或nowrite)

move 文件被移動(from或to)


三、rsync服務端配置

配置文件/etc/rsyncd.conf如下:

[root@CentOS74-02 ~]# cat /etc/rsyncd.conf 
uid = rsync
gid = rsync
use chroot = no
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
hosts allow = 192.168.1.160

[apache]
path = /data/apache/
read only = yes
auth users = bob
secrets file = /etc/rsyncd.secrets
[root@CentOS74-02 ~]# cat /etc/rsyncd.secrets
bob:bob123
[root@CentOS74-02 ~]# chmod 600 /etc/rsyncd.secrets
[root@CentOS74-02 ~]# chown root.root /etc/rsyncd.secrets
[root@CentOS74-02 ~]# ll /etc/rsyncd.*
-rw-r--r-- 1 root root 721 Jul  7 18:49 /etc/rsyncd.conf
-rw------- 1 root root  11 Jul  7 18:49 /etc/rsyncd.secrets
[root@CentOS74-02 ~]# firewall-cmd --state
running
[root@CentOS74-02 ~]# systemctl stop firewalld.service
[root@CentOS74-02 ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@CentOS74-02 ~]# systemctl start rsyncd.service
[root@CentOS74-02 ~]# netstat -nltp | grep 873
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      1987/rsync          
[root@CentOS74-02 ~]#

四、rsync客戶端配置

在rsync客戶端上面進行如下配置:

[root@CentOS74-01 bin]# cat /etc/rsyncd.secrets 
bob123
[root@CentOS74-01 bin]# ll /etc/rsyncd.secrets 
-rw------- 1 root root 7 Jul  7 18:55 /etc/rsyncd.secrets

五、測試

報錯一:

[root@CentOS74-01 apache]# rsync -avz --password-file=/etc/rsyncd.secrets /data/apache/  [email protected]::apache             
sending incremental file list
ERROR: module is read only
rsync error: syntax or usage error (code 1) at main.c(879) [Receiver=3.0.9]
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(764) [sender=3.0.9]

原因如下:

在rsync服務端的/etc/rsyncd.conf裏面,read only = yes,修改為read only = no,再測試:


報錯二:

[root@CentOS74-01 apache]# rsync -avz --password-file=/etc/rsyncd.secrets /data/apache/  [email protected]::apache
sending incremental file list
apache_3.log
rsync: mkstemp ".apache_3.log.LyMzT6" (in apache) failed: Permission denied (13)

sent 122 bytes  received 27 bytes  27.09 bytes/sec
total size is 21  speedup is 0.14
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]

原因如下:

rsync服務端的/data/apache目錄屬主屬組是root.root,others組沒有寫的權限,運行如下命令:

[root@CentOS74-02 apache]# chmod -R o+w /data

報錯三:

[root@CentOS74-01 apache]# rsync -avz --password-file=/etc/rsyncd.secrets /data/apache/  [email protected]::apache
sending incremental file list
./
rsync: failed to set times on "." (in apache): Operation not permitted (1)

sent 80 bytes  received 11 bytes  8.67 bytes/sec
total size is 21  speedup is 0.23
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]

-rw-r--r-- 1 rsync rsync 6 Jul  7 15:25 apache_3.log
[root@CentOS74-02 apache]# ll
total 12
-rw-r--r-- 1 root  root  7 Jul  7 14:40 apache_1.log
-rw-r--r-- 1 root  root  8 Jul  7 14:41 apache_2.log
-rw-r--r-- 1 rsync rsync 6 Jul  7 15:25 apache_3.log

原因如下:

由於rsync服務端/etc/rsyncd.conf裏面指定的uid和gid是用戶rsync,而服務器上面的/data/apache/的屬主和屬組是root.root,所以報錯,運行

下面的命令修改屬主和屬組為 rsync.rsync

[root@CentOS74-02 ~]# chown -R rsync.rsync /data/apache/
[root@CentOS74-02 ~]# ll /data/apache/
total 8
-rw-r--r-- 1 rsync rsync 7 Jul  7 14:40 apache_1.log
-rw-r--r-- 1 rsync rsync 8 Jul  7 14:41 apache_2.log

再次運行下面的命令,沒有報錯了:

[root@CentOS74-01 apache]# rsync -avz --password-file=/etc/rsyncd.secrets /data/apache/  [email protected]::apache
sending incremental file list
./
apache_3.log

sent 125 bytes  received 30 bytes  310.00 bytes/sec
total size is 21  speedup is 0.14
[root@CentOS74-01 apache]#

六、編寫實時同步腳本

具體腳本內容如下:

[root@CentOS74-01 ~]# cat inotify_rsync.sh 
#!/bin/bash
inotify=/usr/local/inotify/bin/inotifywait
$inotify -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e delete,create,modify,close_write /data/apache | while read file
  do
    rsync -avz --password-file=/etc/rsyncd.secrets /data/apache/  [email protected]::apache
  done

可以使用 nohup將腳本掛到系統後臺運行:

[root@CentOS74-01 ~]# nohup sh /root/inotify_rsync.sh &
[1] 7808
[root@CentOS74-01 ~]# nohup: ignoring input and appending output to ‘nohup.out’

[root@CentOS74-01 ~]# cat nohup.out 
[root@CentOS74-01 ~]#

在rsync客戶端創建測試文件:

[root@CentOS74-01 apache]# touch apache_{4..10}.log
[root@CentOS74-01 apache]# ll
total 12
-rw-r--r-- 1 root root 0 Jul  7 19:32 apache_10.log
-rw-r--r-- 1 root root 7 Jul  7 14:40 apache_1.log
-rw-r--r-- 1 root root 8 Jul  7 14:41 apache_2.log
-rw-r--r-- 1 root root 6 Jul  7 15:25 apache_3.log
-rw-r--r-- 1 root root 0 Jul  7 19:32 apache_4.log
-rw-r--r-- 1 root root 0 Jul  7 19:32 apache_5.log
-rw-r--r-- 1 root root 0 Jul  7 19:32 apache_6.log
-rw-r--r-- 1 root root 0 Jul  7 19:32 apache_7.log
-rw-r--r-- 1 root root 0 Jul  7 19:32 apache_8.log
-rw-r--r-- 1 root root 0 Jul  7 19:32 apache_9.log
[root@CentOS74-01 apache]#

在rsync服務端查看結果:

[root@CentOS74-02 apache]#  ll
total 12
-rw-r--r-- 1 rsync rsync 0 Jul  7  2018 apache_10.log
-rw-r--r-- 1 rsync rsync 7 Jul  7 14:40 apache_1.log
-rw-r--r-- 1 rsync rsync 8 Jul  7 14:41 apache_2.log
-rw-r--r-- 1 rsync rsync 6 Jul  7 15:25 apache_3.log
-rw-r--r-- 1 rsync rsync 0 Jul  7  2018 apache_4.log
-rw-r--r-- 1 rsync rsync 0 Jul  7  2018 apache_5.log
-rw-r--r-- 1 rsync rsync 0 Jul  7  2018 apache_6.log
-rw-r--r-- 1 rsync rsync 0 Jul  7  2018 apache_7.log
-rw-r--r-- 1 rsync rsync 0 Jul  7  2018 apache_8.log
-rw-r--r-- 1 rsync rsync 0 Jul  7  2018 apache_9.log


配置Rsync和Rsync + inotify