Linux下安裝Rsync 檔案同步

2021-10-06 06:19:10 字數 2133 閱讀 6534

# centos:

yum -y install rsync xinetd

# ubuntu:

sudo apt-get install rsync xinetd

# 編輯配置檔案

vi /etc/rsyncd.conf

# 找到你的安裝路徑

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

lock file = /var/run/rsync/rsyncd.lock

log file = /var/log/rsync/rsyncd.log

[120]

# 需要同步的路徑

path = /www/wwwroot/www.0357120.gov.cn/

# 備註

comment = 120

# 所用賬號

uid = root

gid = root

read only = false

# 許可權賬號此處和下面的密碼檔案對應賬號

auth users = rsync

secrets file = /etc/rsyncd.passwd

transfer logging = yes

list = yes

ignore errors

vim /etc/rsyncd.passwd
# 密碼內容

rsync:密碼字串

# 編輯檔案

sudo vim /etc/default/rsync

# 找到這一行 取消注釋

rsync_enable=inetd

# 編輯檔案

sudo vim /etc/xinetd.d/rsync

# 寫入內容

service rsync

sudo chmod 600 /etc/rsyncd.passwd
# ubuntu

sudo /etc/init.d/xinetd restart

# centos

service xinetd restart

注意:如果你找不到xinetd配置檔案無法通過xinetd來達到服務重啟或者程序守護,可以通過rsync自身命令:

rsync --daemon --config=/etc/rsyncd.conf
安裝這裡不講了。說下配置:

你的專案目錄下新建:【rsync_exclude.txt】 這個檔案是排除你不想同步的檔案的。比如uploads上傳資料夾,基礎目錄是你專案目錄也就是【rsync_exclude.txt】所在目錄(文章最後附一張本地專案路徑圖)

.ds_store

.gitignore

.git

.idea

rsync.sh

rsync.secret

rsync_exclude.txt

你的專案目錄下新建:【rsync.secret】 這個檔案是儲存你的【rsync】密碼的, 就是你上面【rsyncd.passwd】的密碼

密碼文字
然後這個密碼檔案需要600許可權

sudo chmod 600 ./rsyncd.passwd
最後新建乙個【rsync.sh】檔案,這是核心同步語法:

#!/bin/bash
解釋下:這裡ip的話就是你的伺服器ip,專案名是你上面配置的如截圖:

執行直接: 本地進入專案下執行rsync.sh即可

./rsync.sh

Linux下使用rsync同步檔案

遇到的問題是幾台遊戲伺服器,有一台新的伺服器之前已經copy linux的scp命令 過檔案上去,但在測試的過程中發現還是無法正常不顯示出來,然後用httpwatch去分析請求的資源,發現有乙個請求的位址是404 檔案不存在 然後ssh登入上去,找到指定目錄,發現確實是沒有這個檔案。為了不至於再co...

windows下rsync部署安裝

2012 06 05 12 06 13 分類 系統 標籤 rsync windows 字型大小訂閱 rsync在windows與windows伺服器之間的同步設定 1.準備兩台機器 server 192.168.0.201 client 192.168.0.202 檔案 cwrsync client...

Linux下rsync檔案同步伺服器配置詳解

目錄 1.什麼是rsync 2 rsync 伺服器的理由和用途 3 架設rsync伺服器過程 3.1 rsync的安裝 3.2 rsync伺服器的配置檔案 4 架設rsync伺服器的示例說明 4.1 全域性定義 4.2 模組定義 5 啟動rsync 伺服器及防火牆的設定 5.1 啟動rsync伺服器...