服務(wù)器信息:
*.*.110.72:rsync客戶端+inotify(下文110.72代替)
*.*.41.66:rsync服務(wù)器端(下文41.66)
其中*.*.110.72向*.*.41.66中的兩個(gè)目錄進(jìn)行同步,防火墻、selinux、NetworkManager均已關(guān)閉(已向網(wǎng)絡(luò)工程師發(fā)出請(qǐng)求:開(kāi)放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 ? 運(yùn)行權(quán)限
gid = root ? 運(yùn)行權(quán)限
port=873 ? 端口號(hào)
use chroot = no ?增加軟連接的備份
read only = no ? 可寫
list = no ? ?不現(xiàn)實(shí)本地資源列表
max connections = 200 ?最大連接數(shù)
timeout = 600 ? ?超時(shí)時(shí)間
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
用戶名:密碼
為兩個(gè)文件夾設(shè)置600的權(quán)限。
# chmod 600? /etc/rsync.pass
# chmod 600? /etc/rsyncd.conf
將rsync添加到xinetd
# vim /etc/xinetd.d/rsync
disable = yes
啟動(dòng)服務(wù)
# /etc/init.d/xinetd start
110.72部署客戶端
yum安裝rsync
# yum -y install rsync
新建密碼文件:
# vim /etc/rsync.pass
密碼
設(shè)置權(quán)限
# chmod 600? /etc/rsync.pass
測(cè)試:
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添加最大文件數(shù)并使其生效
# vim /etc/sysctl.conf
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
# ?sysctl -p
編寫監(jiān)控腳本
# vim inotify_images.sh
#!/bin/bash
host=*.*.41.66 ?目標(biāo)ip
src=/app/ZZSDZFP_PDF_BJ/WebRoot/WEB-INF/classes/file/qzimg/ ?目標(biāo)路徑
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
添加執(zhí)行權(quán)限:
# chmod +x inotify_images.sh
后臺(tái)運(yùn)行
# nohup ./inotify_images.sh
編寫另一個(gè)腳本:
vim inotify_qyqz.sh
#!/bin/bash
host=*.*.41.66 ?目標(biāo)ip
src=/app/ZZSDZFP_PDF_BJ/WebRoot/WEB-INF/classes/file/qzimg/ ?目標(biāo)路徑
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
添加權(quán)限:
# chmod? +x inotify_qyqz.sh
后臺(tái)運(yùn)行
# nohup ./inotify_qyqz.sh