linux系統中Rsync + Lsync即時檔案同步配置詳解

來源:互聯網
上載者:User

使用Rsync + Lsync可實現即時檔案同步,本文就介紹如何配置Rsync + Lsync。並測試檔案同步功能。
伺服器資訊:

主:10.86.255.154
從:10.86.255.155

1.從服務設定。

1.1.安裝配置rsync xinet。

# yum -y install rsync xinet
# cp /etc/xinetd.d/rsync /etc/xinetd.d/rsync.bkp0625
# vim /etc/xinetd.d/rsync
 # default: off
 # description: The rsync server is a good addition to an ftp server, as it \
 #       allows crc checksumming etc.
service rsync
{
        disable = no             →修改‘yes’為‘no’
        flags           = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID

1.2.啟動xinetd並設定開機啟動項。

# /etc/init.d/xinetd start
# chkconfig xinetd o

1.3.建立同步檔案的存放目錄。

# mkdir /home/backup

1.4.建立rsyncd.conf設定檔。

# vim /etc/rsyncd.conf
[zabbix.cc-web]        →名字任意
path = /home/backup      →同步檔案存放路徑
hosts allow = 10.86.255.154 →允許串連的主機(指定主伺服器IP)
hosts deny = *
list = true
uid = root
gid = root
read only = false

2.主伺服器設定。

2.1.安裝rsync。

# yum -y install rsync

2.2.建立同步對象中,不需要同步的檔案一覽表。

# vim /etc/rsync_exclude.lst
test
test.txt

2.3.在主伺服器,執行以下命令。

測試將主伺服器/var/www/html/下檔案同步到從伺服器/home/backup

# rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /var/www/html/ 10.86.255.155::zabbix.cc-web
backup]# ls zabbix.cc

3.使用Rsync + Lsync,當檔案或目錄發生變更時,可做到即時同步。

3.1.登入主伺服器,下載安裝Lsync。

# yum install lsyncd -y

3.2.配置lsyncd檔案。

# cp /etc/sysconfig/lsyncd /etc/sysconfig/lsyncd.bkp0625
# vim /etc/sysconfig/lsyncd
# Keep the space there for systemd. Don't nest variables without
# changing the systemd service file to use: /usr/bin/sh -c 'eval XXXX'
#
LSYNCD_OPTIONS="-pidfile /var/run/lsyncd.pid /etc/lsyncd.conf"  →去掉’‘#’
#LSYNCD_OPTIONS=" "
3.3.配置lsyncd.conf,添加以下內容:

# vim /etc/lsyncd.conf

settings{
statusFile = "/tmp/lsyncd.stat",
statusInterval = 1,
}
sync{
default.rsync,
source="/var/www/html/",          →指定需同步的源檔案目錄
target="10.86.255.155::zabbix.cc-web",  →從伺服器IP:(rsyncd.conf設定的名字)
excludeFrom="/etc/rsync_exclude.lst",   →排除檔案清單

}

3.4.啟動lsync。

# /etc/rc.d/init.d/lsyncd start

3.5.在主伺服器,建立新測試檔案。

html]# touch kongqiao

3.6.在從伺服器確認,同步成功。

backup]# ls
kongqiao

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.