Rsync+inotify的文件同步部署之部署

服務(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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容