版本控制
版本 |
作者 |
日期 |
修改記錄 |
備注 |
V1.0 |
Mr.Wu |
2019-10-15 |
初始創建 |
|
|
|
|
|
|
一、部署規划
Ip地址 |
主機名 |
角色 |
軟件版本(系統自帶) |
10.1.1.26 |
web-server |
生產服務器 |
rsync-3.1.2-4.el7.x86_64 |
10.1.1.27 |
rsync |
備份服務器 |
rsync-3.1.2-4.el7.x86_64 |
二、環境說明
1. 系統版本
CentOS Linux release 7.6.1810 (Core) x86_64
2. 系統初始化
2.1 關閉防火牆及selinx
在所有虛擬機上進行以下操作:
2.2 關閉 NetworkManager 服務
在所有虛擬機上進行以下操作:
三、配置 web-server 服務器
1. 配置文件添加同步模塊
在 web-server 服務器上進行:
[root@web-server ~]
......
[logs]
path = /var/log
comment = all files under this dir
[root@web-server ~]
41

2. 啟動 rsyncd 后台服務
[root@web-server ~]
[root@web-server ~]

四、配置備份服務器
1. 指定同步的路徑 /backup
[root@rsync /]
2. 查看 web 服務端需同步的模塊
[root@rsync /]

五、定時任務實現模塊同步(在備份機上進行)
1. 編寫同步腳本
[root@rsync /]
rsync -av root@10.1.1.26::logs /backup
[root@rsync /]
2. 編寫定時同步任務測試
以每分鍾執行一次進行測試
[root@rsync /]
* * * * * sh /root/rsync.sh &>/dev/null
[root@rsync bakup]
2019年 10月 15日 星期二 20:38:26 CST
[root@rsync bakup]
0
[root@rsync bakup]
2019年 10月 15日 星期二 20:39:01 CST
[root@rsync bakup]
41
六、 rsync+inotify實現文件實時同步(在web服務器部署inotify,在備份服務器配置rsync守護進程)
1. web 服務器部署
1.1 下載安裝 inotify 軟件
[root@web-server ~]
[root@web-server ~]
[root@web-server ~]
[root@web-server inotify]
1.2 檢查 inotify 帶來的兩個命令
[root@web-server inotify]
-rwxr-xr-x 1 root root 60720 10月 15 21:18 /usr/local/bin/inotifywait
-rwxr-xr-x 1 root root 55080 10月 15 21:18 /usr/local/bin/inotifywatch
相關參數:
-m 保持監控狀態
-r 遞歸監控
-q 只打印事件
-e 指定事件
事件:
move 移動
delete 刪除
create 創建
modify 修改
attrib 屬性信息
1.3 編寫同步腳本
[root@web-server inotify]
/usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib,move /var/log/ |while read events
do
rsync -a --delete /var/log/ 10.1.1.27:/backup/
echo "`date +%F\ %T`出現事件$events" >> /var/rsync.log 2>&1
done
1.4 配置web 服務器至備份服務器的免密登錄
[root@web-server inotify]
[root@web-server inotify]
2. 備份服務器起后台進程
[root@rsync log]
[root@rsync log]
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync 93582 root 4u IPv4 236984 0t0 TCP *:rsync (LISTEN)
rsync 93582 root 5u IPv6 236985 0t0 TCP *:rsync (LISTEN)
3. web 服務器起監控並添加文件測試
[root@web-server inotify]
[root@web-server log]
[root@web-server log]
[root@web-server log]
2019-10-15 22:28:11出現事件/var/log/ CREATE,ISDIR 111
2019-10-15 22:28:12出現事件/var/log/ CREATE,ISDIR 112
2019-10-15 22:28:12出現事件/var/log/ CREATE,ISDIR 113
2019-10-15 22:28:19出現事件/var/log/ CREATE file
2019-10-15 22:28:20出現事件/var/log/ ATTRIB file
2019-10-15 22:28:20出現事件/var/log/ CREATE 5
2019-10-15 22:28:20出現事件/var/log/ ATTRIB 5
2019-10-15 22:28:20出現事件/var/log/ CREATE 6
2019-10-15 22:28:20出現事件/var/log/ ATTRIB 6
2019-10-15 22:28:20出現事件/var/log/ CREATE 7
2019-10-15 22:28:21出現事件/var/log/ ATTRIB 7
2019-10-15 22:28:21出現事件/var/log/ CREATE 8
2019-10-15 22:28:21出現事件/var/log/ ATTRIB 8
4. 備份服務器查看
[root@rsync backup]
drwxr-xr-x 2 root root 6 10月 15 22:28 111
drwxr-xr-x 2 root root 6 10月 15 22:28 112
drwxr-xr-x 2 root root 6 10月 15 22:28 113
-rw-r--r-- 1 root root 0 10月 15 22:28 5
-rw-r--r-- 1 root root 0 10月 15 22:28 6
-rw-r--r-- 1 root root 0 10月 15 22:28 7
-rw-r--r-- 1 root root 0 10月 15 22:28 8
-rw-r--r-- 1 root root 0 10月 15 22:28 file