lsyncd自動同步配置


因生產環境需要,需要將2.60上的數據目錄,備份到2.61上;計划利用lsyncd的實時同步功能來實現備份。

源:172.16.2.60  Ubuntu系統

備份:172.16.2.61  Ubuntu系統

主要的幾個步驟是:

1.配置2.602.61上,實現無密碼登錄。

2.源機上安裝lsyncd服務

3.源機上開啟rsync服務

4.備份機上開啟rsync服務

注意事項:ubuntu系統的root用戶默認沒有開啟,需要先開啟root用戶的ssh登錄權限。

具體如下:

1.配置源與備份主機之間的無密碼登錄

 root@ubuntu-yangben01:~# ssh-keygen -t rsa

 root@ubuntu-yangben01:~# ssh-copy-id root@172.16.2.61

2.源機上安裝lsyncd服務

 root@ubuntu-yangben01:~# apt install lsyncd

安裝成功后,你可以在:/usr/share/doc/lsyncd/examples,看到Lsyncd配置使用示例,你可以參考這些示例自己再編寫配置

手動創建日志文件和狀態文件的目錄:

root@ubuntu-yangben01:~# mkdir -p /var/log/lsyncd

root@ubuntu-yangben01:~# touch /var/log/lsyncd/lsyncd.log

root@ubuntu-yangben01:~# touch /var/log/lsyncd/lsyncd.status

配置文件詳情:

root@ubuntu-yangben01:~# cat /etc/lsyncd/lsyncd.conf.lua 

----

-- User configuration file for lsyncd.

--

-- Simple example for default rsync, but executing moves through on the target.

--

--sync{default.rsyncssh, source="src", host="localhost", targetdir="dst/"}

settings {

    logfile ="/var/log/lsyncd/lsyncd.log",

    statusFile ="/var/log/lsyncd/lsyncd.status",

    inotifyMode = "CloseWrite",

    maxProcesses = 8,

    }

-- rsync模式 + ssh shell

-- 第一個同步目錄

sync {

    default.rsync,

    source    = "/data",

    target    = "root@172.16.2.61:/data",

    maxDelays = 5,

    delay = 30,

    rsync     = {

        binary = "/usr/bin/rsync",

        archive = true,

        compress = true,

        bwlimit   = 2000

        }

    }

--第二個同步目錄

sync {

    default.rsync,

    source    = "/yangben",

    target    = "root@172.16.2.61:/yangben",

    maxDelays = 5,

    delay = 30,

    rsync     = {

        binary = "/usr/bin/rsync",

        archive = true,

        compress = true,

        bwlimit   = 2000

        }

}

配置文件編輯完后,啟動lsyncd,查看狀態,並設置開機自啟。

root@ubuntu-yangben01:~# systemctl start lsyncd

root@ubuntu-yangben01:~# systemctl status lsyncd

root@ubuntu-yangben01:~# systemctl enable lsyncd

3.ubuntu默認安裝了rsync,但是默認是沒有啟動的,需要手動啟用。

  編輯vim /etc/default/rsync,RSYNC_ENABLE=false改為true,保存;

  然后重啟lsyncd服務,systemctl restart lsyncd

  (這個地方卡了我很久,服務起來了,但就是不產生日志,后面排查了好久,才發現是rsync沒有啟用。當然,這一步也可以放到前面操作,就省去重啟lsyncd服務這一步。)

4.備份機上開啟rsync服務

5.驗證同步效果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM