xinetd+lsyncd+rsync雙向同步

服務(wù)器name->ip
  drbd1: 192.168.171.136
  drbd2: 192.168.171.135
  1. apt-get安裝三個(gè)軟件 xinetdlsyncd、rsync,配置好ssh免密鑰登錄
  2. root@drbd2# vi /etc/rsyncd.conf
[diskb]                           --> 名字標(biāo)識(shí),用于rsync命令冒號(hào)后面
path = /mnt/diskb                 --> 目錄的路徑
list = true                       --> 列出服務(wù)器上提供同步數(shù)據(jù)的目錄,默認(rèn)是yes,為了安全建議no
uid = root                        --> 運(yùn)行命令的用戶,默認(rèn)是nobody,如果系統(tǒng)不存在這個(gè)用戶,會(huì)出錯(cuò)
gid = root                        --> 運(yùn)行命令的用戶組,默認(rèn)是nobody,如果系統(tǒng)不存在這個(gè)用戶,會(huì)出錯(cuò)
read only = false                 --> 只讀選項(xiàng),意思是不讓客戶端上傳文件到服務(wù)器
hosts allow = 192.168.171.136     --> 允許這個(gè)ip訪問,通常與hosts deny配合使用
hosts deny = *                    --> 禁止除允許列表中的所有地址的訪問
  1. root@drbd2# vi /etc/xinetd.d/rsync
service rsync
{
   disable         = no
   socket_type     = stream
   wait            = no
   user            = root
   server          = /usr/bin/rsync
   server_args     = --daemon
   log_on_failure  += USERID
}
  1. root@drbd2# service xinetd restart 重啟xinetd服務(wù)之后,在drbd1上用命令測試一下
  2. root@drbd1# rsync -avz --delete /mnt/diskb/ 192.168.171.135::diskb #測試命令,如果能夠同步成功,就往下走,否則檢查一下配置,直到成功
命令解析:
a:--archive 歸檔模式,表示以遞歸方式傳輸文件,并保持所有文件屬性
v:--verbose 詳細(xì)模式輸出
z:--compress 對(duì)備份的文件在傳輸時(shí)進(jìn)行壓縮處理
---其他的參數(shù)---
u:--update 僅僅進(jìn)行更新,也就是跳過所有已經(jīng)存在于DST,并且文件時(shí)間晚于要備份的文件。(不覆蓋更新的文件)
q:--quiet 精簡輸出模式
--delete 刪除那些DST中SRC沒有的文件

更多參數(shù)配置

  1. root@drbd1# vi /etc/lsyncd.conf
settings {
    logfile      ="/tmp/lsyncd.log",        --> 日志文件路徑
    statusFile   ="/tmp/lsyncd.status",     --> 狀態(tài)文件路徑
    inotifyMode  = "CloseWrite",            --> 在文件結(jié)束寫之后同步,也可以寫Modify
    maxProcesses = 7,                       --> 同時(shí)進(jìn)程最大個(gè)數(shù)
}
  
sync {
    default.rsync,                            --> 同步模式,有rsync、rsyncssh、direct三種
    source    = "/mnt/diskb",                 --> 監(jiān)聽的目錄
    target    = "192.168.171.135::diskb",     --> 也可以寫為服務(wù)端地址以及rsync的名字標(biāo)識(shí)
    delete    = "running",       --> 為了保持target與souce完全同步,Lsyncd默認(rèn)會(huì)delete = true來允許同步刪除
    delay     = 5,               --> 累計(jì)事件,等待rsync同步延時(shí)時(shí)間,即5秒內(nèi),對(duì)同一文件的修改只同步一次
    rsync     = {                             --> rsync參數(shù)
        binary    = "/usr/bin/rsync",     
        archive   = true,     
        compress  = true,                     --> 開啟壓縮
        verbose   = true
    }
}

更多參數(shù)配置

  1. root@drbd1# lsyncd -log all /etc/lsyncd.conf 啟動(dòng)進(jìn)程
  2. root@drbd1# vi /etc/rc.localexit 0之前,加入lsyncd -log all /etc/lsyncd.conf,完成開機(jī)自動(dòng)執(zhí)行
  3. 至此配置好了一半:即drbd1的目錄/mnt/diskb中的任意修改都會(huì)同步到drbd2/mnt/diskb中,如果要實(shí)現(xiàn)另一半操作,交換主從,再配置一遍即可
  4. 單個(gè)文件的同步的配置:/etc/rsyncd.conf片段:
sync {
    default.rsync,
    source    = "/tmp",
    target    = "drbd2::html",
    delete    = "running",
    delay     = 5,
    rsync     = {
        binary    = "/usr/bin/rsync",
        archive   = true,
        compress  = true,
        verbose   = true,
        _extra = {"--include-from=/etc/lsyncd.include", "--exclude=*"}
    }
}
--> _extra 參數(shù)是執(zhí)行rsync命令時(shí),不修改直接帶上的參數(shù)。
--> 2.1.*版本之前有rsyncOps={"--include-from=/etc/lsyncd.include","--exclude=*"}的寫法,現(xiàn)在被_extra替代
  1. 包含文件/etc/lsyncd.include
single.file
test.file

其他要包含的文件,每個(gè)占一行

最后編輯于
?著作權(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),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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