1. 程式人生 > 實用技巧 >rsync+sersync實現檔案實時同步

rsync+sersync實現檔案實時同步

rsync配置

伺服器端:
cat /etc/rsyncd.conf :

uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
auth users = rsync_backup
secrets file = /etc/rsync.password
#
[backup]
comment = "backup"
path = /backup
ignore errors
hosts allow = 10.0.0.0/24
list = false
read only = false
fake super = yes
[root@k8s-master1 10.0.0.65]# chmod 644 /etc/rsync.password
[root@k8s-master1 10.0.0.65]# cat /etc/rsync.password
rsync_backup:123456

客戶端:

echo 123456 >/root/client.pass
chmod 644 /root/client.pass

rsync測試:

rsync -avz /backup/ [email protected]::backup/$(hostname -i) --password-file=/root/client.pass

檢查:

[root@k8s-master1 backup]# ls /backup/10.0.0.65/
access_log   error.log

sersync 配置傳送日誌到伺服器

  1. 建立密碼檔案
    echo 123456 >/root/client.pass

  2. 修改配置

    <sersync>
        <localpath watch="/var/log/nginx">
            <remote ip="10.0.0.63" name="backup/$(hostname -i)"/>
        </localpath>
        <rsync>
            <!-- <commonParams params="-artuz"/> -->
            <commonParams params="-artuz"/>
            <auth start="true" users="rsync_backup" passwordfile="/root/client.pass"/>
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            <timeout start="false" time="100"/><!-- timeout=100 -->
            <ssh start="false"/>
        </rsync>
  1. 啟動sersync
/usr/local/sersync/bin/sersync -dro /usr/local/sersync/conf/confxml.xml
  1. 測試日誌同步