一、【接收端配置】
#cat /etc/rsyncd.conf
uid = root
gid = root
max connections = 8
pid file = /var/run/rsyncd.pid
log file=/var/log/rsyncd.log
hosts allow = 192.168.3.0/24
[dkms]
read only=no
write only=no
path=/data/digitalkey/upload/dkms
comment=dkms update
auth users=root #必須設(shè)置,否則無(wú)密碼訪(fǎng)問(wèn)
secrets file=/etc/rsync.password
#chmod 600 /etc/rsync.password 必須為600權(quán)限
-rw------- 1 root root 14 May 15 13:38 /etc/rsync.password
#vi /etc/rsync.password 訪(fǎng)問(wèn)權(quán)限
root:pass1234
以deamon模式運(yùn)行
#rsync --daemon --config=/etc/rsyncd.conf
二、【發(fā)送端(rsync + inotify)】
rsync只需要配置密碼權(quán)限
#cat /etc/rsync.password
pass1234
測(cè)試
#rsync -avu /data/digitalkey/upload/dkms/ root@192.168.3.243::dkms --password-file=/etc/rsync.password
三、【inotify安裝】
1、下載inotify安裝包
wget --no-check-certificate https://jaist.dl.sourceforge.net/project/inotify-tools/inotify-tools/3.13/inotify-tools-3.13.tar.gz
2、解壓安裝包并進(jìn)入解壓文件夾
tar -zxf inotify-tools-3.13.tar.gz
cd inotify-tools-3.13/
3、安裝inotify
./configure
make
make install
4、檢查是否安裝成功
#inotifywait
No files specified to watch!
四、【創(chuàng)建腳本】
#vi inotify_rsync.sh文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-449874.html
#!/bin/bash
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,delete,create,attrib /data/digitalkey/upload/dkms \
| while read files
do
rsync -avu /data/digitalkey/upload/dkms/ root@192.168.3.243::dkms --password-file=/etc/rsync.password > /dev/null 2>&1
echo "rsync was finished !" >> /tmp/rsync.log 2>&1
done
#/yunwei/sh/inotify_rsync.sh & 后臺(tái)運(yùn)行
#echo “/yunwei/sh/inotify_rsync.sh &” >> /etc/rc.local 腳本加入系統(tǒng)自啟動(dòng)文件
#ps -ef|grep rsync 查看進(jìn)程
root 2504 1 0 13:27 ? 00:00:00 rsync --daemon --config=/etc/rsyncd.conf
root 8615 2421 0 14:12 pts/0 00:00:00 /bin/bash /yunwei/sh/inotify_rsync.sh
root 8618 8615 0 14:12 pts/0 00:00:00 /bin/bash /yunwei/sh/inotify_rsync.sh
root 8620 2421 0 14:12 pts/0 00:00:00 grep --color=auto rsync文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-449874.html
到了這里,關(guān)于Linux下rsync+inotify實(shí)現(xiàn)實(shí)時(shí)文件同步的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!