Rsync+Inotify

Rsync+Inotify

Rsync這個一般使用系統自帶的服務,服務端需要啟動客戶端無需啟動,服務端設置開機自動啟動

systemctl start rsyncd? ??

systemctl status rsyncd

systemctl restart rsyncd

systemctl enable rsyncd

Inotify單獨下載安裝,在客戶端安裝

服務端配置文件: /etc/rsync.pass? 填入賬號密碼格式root:password

/etc/rsyncd.conf

Vim /etc/rsyncd.conf

uid = nobody

?gid = nobody

?use chroot = yes

?max connections = 4

?pid file = /var/run/rsyncd.pid

lockfile = /var/run/rsyncd.lock

log file = /var/log/rsyncd.log

# exclude = lost+found/

# #? transfer logging = yes

# #?? timeout = 900

# #??? ignore nonreadable = yes

# #??? # dont compress?? = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# #

[BIM]

path = /app/services/tomcat-idp/webapps/idp/themes/default/loginimage

write only = yes

read only = no

hosts allow = *

list = yes

uid = root

gid = root

auth users = root

secrets file = /etc/rsync.pass

服務器端登陸有ip限制,如果ip變了,請更改hosts allow

客戶端配置文件/etc/rsync.pass? 填入賬號密碼格式root:password

客戶端同步腳本

#!/bin/bash
src=/app/home/loginUploads/des1=*
dest2=**
deshost=***
deshost2=***
user=root
user2=root
port=873
moudle=BIM
echo "1"
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e modify,delete,create,attrib $src | while read file DATE TIME DIR;
echo "3"
do
echo "1"
rsync -vzrtopg --port $port --progress --delete --password-file=/etc/rsync.pass $src  $user@$deshost::$moudle
rsync -vzrtopg --port $port --progress --delete --password-file=/etc/rsync.pass $src  $user2@$deshost2::$moudle
echo "${files} was rsynced" >> /var/log/rsync.log 2>&1
done

設置客戶端開機自啟動

nohup sh /app/inotify.sh &填入 /etc/rc.local

chmod 777 /etc/rc.local

Inotify說明

inotifyinotify-tools包提供。在安裝inotify-tools之前,請確保內核版本高于2.6.13,且在/proc/sys/fs/inotify目錄下有以下三項,這表示系統支持inotify監控

inotify-tools源碼包地址:https://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

tar xf inotify-tools-3.14.tar.gz

./configure --prefix=/usr/local/inotify-tools-3.14

make && make install

ln -s /usr/local/inotify-tools-3.14 /usr/local/inotify

其中inotifywait命令用于等待文件發生變化,所以可以可以實現監控(watch)的功能,該命令是inotify的核心命令。inotifywatch用于收集文件系統的統計數據,例如發生了多少次inotify事件,某文件被訪問了多少次等等,一般用不上。

以下是inotify相關的內核參數。

(1)./proc/sys/fs/inotify/max_queued_events:調用inotify_init時分配到inotify instance中可排隊的event數的最大值,超出值時的事件被丟棄,但會觸發隊列溢出Q_OVERFLOW事件。

(2)./proc/sys/fs/inotify/max_user_instances:每一個real user可創建的inotify instances數量的上限。

(3)./proc/sys/fs/inotify/max_user_watches:每個inotify實例相關聯的watches的上限,即每個inotify實例可監控的最大目錄、文件數量。如果監控的文件數目巨大,需要根據情況適當增加此值

echo 30000000 > /proc/sys/fs/inotify/max_user_watches

inotifywait命令的選項:

-m:表示始終監控,否則應該是監控到了一次就退出監控了
-r:遞歸監控,監控目錄中的任何文件,包括子目錄。遞歸監控可能會超出max_user_watches的值,需要適當調整該值
@<file>:如果是對目錄進行遞歸監控,則該選項用于排除遞歸目錄中不被監控的文件。file是相對路徑還是絕對路徑由監控目錄是相對還是絕對來決定
-q--quiet的意思,靜默監控,這樣就不會輸出一些無關的信息
-e:指定監控的事件。一般監控的就deletecreateattribmodifyclose_write
--exclude <pattern> :通過模式匹配來指定不被監控的文件,區分大小寫
--excludei <pattern>:通過模式匹配來指定不被監控的文件,不區分大小寫
--timefmt:監控到事件觸發后,輸出的時間格式,可指定可不指定該選項,一般設置為[--timefmt '%Y/%m/%d %H:%M:%S']
--format:用戶自定義的輸出格式,如[--format '%w%f %e%T']
? %w:產生事件的監控路徑,不一定就是發生事件的具體文件,例如遞歸監控一個目錄,該目錄下的某文件產生事件,將輸出該目錄而非其內具體的文件
? %f:如果監控的是一個目錄,則輸出產生事件的具體文件名。其他所有情況都輸出空字符串
? %e:產生的事件名稱
? %T:以"--timefmt"定義的時間格式輸出當前時間,要求同時定義"--timefmt"

inotifywait -e可監控的事件:

access:文件被訪問
modify:文件被寫入
attrib:元數據被修改。包括權限、時間戳、擴展屬性等等
close_write:打開的文件被關閉,是為了寫文件而打開文件,之后被關閉的事件
close_nowriteread only模式下文件被關閉,即只能是為了讀取而打開文件,讀取結束后關閉文件的事件
close:是close_writeclose_nowrite的結合,無論是何種方式打開文件,只要關閉都屬于該事件
open:文件被打開
moved_to:向監控目錄下移入了文件或目錄,也可以是監控目錄內部的移動
moved_from:將監控目錄下文件或目錄移動到其他地方,也可以是在監控目錄內部的移動
move:是moved_tomoved_from的結合
moved_self:被監控的文件或目錄發生了移動,移動結束后將不再監控此文件或目錄
create:在被監控的目錄中創建了文件或目錄
delete:刪除了被監控目錄中的某文件或目錄
delete_self:被監控的文件或目錄被刪除,刪除之后不再監控此文件或目錄
umount:掛載在被監控目錄上的文件系統被umountumount后不再監控此目錄
isdir :監控目錄相關操作

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/535289.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/535289.shtml
英文地址,請注明出處:http://en.pswp.cn/news/535289.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

logstash密碼設置步驟

生成密鑰存儲倉庫 cd /app/logstash-6.8.4/bin/ ./logstash-keystore create 輸入y 添加Logstash中可引用的變量 ./logstash-keystore add es_user 輸入elastic ./logstash-keystore add es_pwd 輸入bamBoo123 ./logstash-keystore add kafka_pwd 輸入bamBoo123 ./logstash…

清理cacahe腳本

#! /bin/bash # 需要釋放內存的&#xff0c;內存使用百分比&#xff0c;可以傳參&#xff0c;默認是85% max_rate$1 if [ ! "$max_rate" ] ; thenmax_rate85 fi echo "max_rate: $max_rate"totalfree -m | awk NR2 | awk {print $2} usedfree -m | awk NR2…

Prometheus node_exporter 指標說明及告警規則表達

Prometheus node_exporter 指標說明及告警規則表達_獨步秋風的博客-CSDN博客_node exporter 指標

UnicodeEncodeError: 'gbk' codec can't encode character '\xeb' in position 20: illegal multibyte sequ

源代碼&#xff1a;with open (os.path.join(self.root,filename),mode‘w’,newline’’) as f: writercsv.writer(f) for img in images: nameimg.split(os.sep)[-2] labelself.name2lable[name] writer.writerow([img,label]) 解決方法 在open&#xff08;&#xff09;里面…

列表生成式(List)

列表生成式即List Comprehensions&#xff0c;是Python內置的非常簡單卻強大的可以用來創建list的生成式。 list(range(1,6)) [1,2,3,4,5]print([x*x for x in range(10)]) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]print([x*x for x in range(10) if x%20]) [0, 4, 16, 36, 64]

uint8 轉換為 float

znp.arange(3,dtypenp.uintj8) >>> z.astype(float) array([ 0., 1., 2.]) >>> np.int8(z) array([0, 1, 2], dtypeint8)

AttributeError: 'NoneType' object has no attribute 'astype'

img cv2.imread(path)#path為圖片地址 print(type(img))>>> <class numpy.ndarray> <class numpy.ndarray> <class numpy.ndarray> <class NoneType>錯誤問題為沒有正確讀到圖片&#xff0c;返回一個Nonetype類型&#xff0c;

pycharm 自動補全括號 引號

過程&#xff1a; File->settings->Editior->General->Smart Keys 勾選Insert paired barckets(),[],{},<>

RuntimeError: freeze_support()

train_dataloaderDataLoader(train_dataset,batch_sizebatch_size,shuffleTrue,num_workers4) 把nu_worker4 去掉 train_dataloaderDataLoader(train_dataset,batch_sizebatch_size,shuffleTrue)

IndexError: list index out of range image_name=self.images_name[index]

這里是引用 def __len__(self):return len(self.images_name) 注意這個地方

NameError: name 'long' is not defined

是因為高版本Python3.x中沒有long類型&#xff0c;只有int類型。 Python2.x中既有long 類型又有int 類型。 所以只需要把long()改為int 就行

Latex 修改公式的的大小

第一種方法&#xff1a;用比較笨的方法&#xff0c;一個一個公式用\begin{small} \begin{equation} \ldots \end{equation} \end{small} 第二種方法&#xff1a;定義新的變量環境 在開始\newenvironment{sequation}{\begin{equation}\small}{\end{equation}}演示代碼&#xff1…

latex表格名的引用問題

##方法 \begin{table} \label{*****} \end{table} 在文章中加入Tab.~\ref{****} 如果沒有顯示出來的話 在文章的開頭加上\usepackage{table}

Anaconda如何重新在開始菜單顯示

步驟&#xff1a; &#xff08;1&#xff09; win R &#xff0c;然后輸入Cmd 進入電腦命令端 &#xff08;2&#xff09;cd 進入anaconda 安裝的路徑&#xff0c;然后 輸入 、、、 python .\Lib_nsis.py mkmenus 、、、 然后就OK了

python 讀取 Excel 文件的方法 csv.reader

with open(./hotel_bookings.csv,newline) as f:readercsv.reader(f)for row in reader:print(row)row 為list 類型

python matplotlib 繪制曲線圖,柱狀圖

matplotlib.pyplot.bar(x, y, width0.8, bottomNone, \*, aligncenter, dataNone, \*\*kwargs) x:x軸的數據值&#xff0c;或者標簽 y:每個標簽的值 width: 每個柱形圖中每個柱子的寬度 bottom&#xff1a;y軸的基準值&#xff08;一般為0&#xff09; align: 柱形圖中每個柱子…

python for while enumerate

for 循環語句 list[2,3,4,5,6] for i in range(len(list)):print(i)print(list[i]) 其中 len() 表示計算數組的長度&#xff0c;range()表示生成一個指定長度的序列&#xff08;0&#xff0c;1&#xff0c;2&#xff0c;3&#xff0c;。。。。&#xff09; list[2,3,4,5,6]fo…

python plt.plot bar 設置繪圖尺寸大小

plt.rcParams(figure.figsize)(12,8) 修改前 修改后

Pandas 中 把Dataframe 格式轉化為 array 數組

’DataFrame’ object has no attribute numpy’ 使用values() 函數 data.values() array([[342. , 27. , 1. , ..., 0. , 0. , 0. ],[737. , 27. , 1. , ..., 0. , 0. , 0. ],[ 7. , 27. , 1. , ..., 0. , 0. , 75. ],...,[ 3…