服務器信息:
*.*.110.72:rsync客戶端+inotify(下文110.72代替)
*.*.41.66:rsync服務器端(下文41.66)
其中*.*.110.72向*.*.41.66中的兩個目錄進行同步,防火墻、selinux、NetworkManager均已關閉(已向網絡工程師發出請求:開放873端口)
部署rsync:
41.66使用yum安裝rsync、xinted
# yum -y install rsync xinetd
添加配置文件:
# vim /etc/rsyncd.conf
log file = /var/log/rsyncd.log ? 日志文件
pidfile = /var/run/rsyncd.pid ? pid文件
lock file = /var/run/rsync.lock ?lock文件
secrets file = /etc/rsync.pass ?用戶文件
motd file = /etc/rsyncd.Motd
[images]
path = /webapp/rhweb/public/images ?文件被同步的路徑
comment = Qzinfo ? 描述
uid = root ? 運行權限
gid = root ? 運行權限
port=873 ? 端口號
use chroot = no ?增加軟連接的備份
read only = no ? 可寫
list = no ? ?不現實本地資源列表
max connections = 200 ?最大連接數
timeout = 600 ? ?超時時間
auth users = Qzinfo ? 允許的用戶
hosts allow = 172.16.110.72 ?允許的IP?
[qyqz]
path = /webapp/fpcy/fpcy/jsp/einv/common/images/qyqz
comment = qyqz
uid = root
gid = root
port=873
use chroot = no
read only = no
list = no
max connections = 200
timeout = 600
auth users = Qzinfo
hosts allow = 172.16.110.72
[test]
path = /test
comment = test
uid = root
gid = root
port=873
use chroot = no
read only = no
list = no
max connections = 200
timeout = 600
auth users = Qzinfo
hosts allow = 172.16.110.72
配置用戶密碼:
# vim /etc/rsync.pass
用戶名:密碼
為兩個文件夾設置600的權限。
# chmod 600? /etc/rsync.pass
# chmod 600? /etc/rsyncd.conf
將rsync添加到xinetd
# vim /etc/xinetd.d/rsync
disable = yes
啟動服務
# /etc/init.d/xinetd start
110.72部署客戶端
yum安裝rsync
# yum -y install rsync
新建密碼文件:
# vim /etc/rsync.pass
密碼
設置權限
# chmod 600? /etc/rsync.pass
測試:
rsync -vzrtopg? --progress --password-file=/etc/rsync.pass /test Qzinfo@*.*.110.72::test
部署Inotify(110.72)
解壓編譯并安裝
# tar -zxf inotify-tools-3.14.tar.gz
# ./config --prefix=/usr/local/inotify/? && make && make install
向sysctl.conf添加最大文件數并使其生效
# vim /etc/sysctl.conf
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
# ?sysctl -p
編寫監控腳本
# vim inotify_images.sh
#!/bin/bash
host=*.*.41.66 ?目標ip
src=/app/ZZSDZFP_PDF_BJ/WebRoot/WEB-INF/classes/file/qzimg/ ?目標路徑
des=images ?模塊名
user=Qzinfo 用戶名
/usr/local/inotify/bin/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/rsync.pass $src $user@$host::$des
echo "${files} was rsynced" >>/usr/local/inotify/rsync.log 2>&1
done
添加執行權限:
# chmod +x inotify_images.sh
后臺運行
# nohup ./inotify_images.sh
編寫另一個腳本:
vim inotify_qyqz.sh
#!/bin/bash
host=*.*.41.66 ?目標ip
src=/app/ZZSDZFP_PDF_BJ/WebRoot/WEB-INF/classes/file/qzimg/ ?目標路徑
des=qyqz? 模塊名
user=Qzinfo 用戶名
/usr/local/inotify/bin/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/rsync.pass $src $user@$host::$des
echo "${files} was rsynced" >>/usr/local/inotify/rsync.log 2>&1
done
添加權限:
# chmod? +x inotify_qyqz.sh
后臺運行
# nohup ./inotify_qyqz.sh