lsyncd + rsync real-time synchronization

A, lsyncd About
the same function and lsyncd sersync, belong to real-time synchronization tool, but Lsyncd more powerful, Lysncd actually lua language encapsulates inotify and rsync tool, using the Linux kernel's inotify trigger mechanism, and then to the difference synchronization via rsync to achieve real-time results. Lsyncd most powerful is that simple and efficient transmission of vast amounts of data and lsyncd supports multiple operating modes.
Second, prepare the environment

server CPU name ip address Service Software
Server rsync 172.16.1.41 rysncd
Client nfs 172.16.1.31 lsyncd

Third, the server machine installation and configuration
download rsyncd

[root@rsync ~]# yum install -y rsyncd

Conf configuration file

[root@rsync ~]# cat /etc/rsyncd.conf
uid = rsync
gid = rsync
port = 873
fake super = yes
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
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
#hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = "backup dir by oldboy"
path = /backup

Rsync create virtual users

[root@rsync ~]# useradd rsync -M -s /sbin/nologin 

Create a backup directory

[root@rsync ~]# mkdir backup

Modifies the owner and group permissions

[root@rsync ~]# chown rysnc.rsync /backup

Create a password file

[root@rsync ~]# touch /etc/rsync.password
[root@rsync ~]# echo "rsync_backup:1" >/etc/rsync.password

Modify access to the root

[root@rsync ~]# chmod 600 /etc/rsync.password

Services start / join boot from Kai

[root@rsync ~]# systemctl restart rsyncd
[root@rsync ~]# systemctl enable  rsyncd

Fourth, the client machine and configuration
download service

[root@nfs ~]# yum install -y lsyncd

Profiles

[root@nfs ~]# cat /etc/lsyncd.conf 
settings {
    logfile      ="/var/log/lsyncd.log",
    statusFile   ="/usr/local/lsyncd-2.1.5/var/lsyncd.status",
    inotifyMode  = "CloseWrite",
    maxProcesses = 1,  #延迟1秒
    -- nodaemon =true,
    }

sync {
    default.rsync,
    source    = "/backup", #客户端目录
    target    = "[email protected]::backup", #服务端模块
    -- excludeFrom = "/etc/rsyncd.d/rsync_exclude.lst",
    rsync     = {
        binary    = "/usr/bin/rsync",
        password_file = "/etc/rsync.password", #免交互密码文件
        archive   = true,
        compress  = true,
        verbose   = true
        }
    }

Create a password file

[root@nfs ~]# touch /etc/rsync.password
[root@nfs ~]# echo "1" > /etc/rsync.password

Modify access to the root

[root@nfs ~]# chmod 600 /etc/rsync.password

Create a client-server storage directory

[root@nfs ~]# mkdir /backup

Services start / boot from Kai

[root@nfs ~]# systemctl restart lsyncd
[root@nfs ~]# systemctl enable lsyncd

Fifth, check the status of open service and test the effect of real-time synchronization
server

[root@rsync ~]# systemctl status rsyncd
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-01-27 14:00:48 CST; 18min ago
 Main PID: 7942 (rsync)
   CGroup: /system.slice/rsyncd.service
           └─7942 /usr/bin/rsync --daemon --no-detach

Jan 27 14:00:48 rsync systemd[1]: Stopped fast remote file copy program daemon.
Jan 27 14:00:48 rsync systemd[1]: Started fast remote file copy program daemon.

Client

[root@nfs ~]# systemctl status lsyncd
● lsyncd.service - Live Syncing (Mirror) Daemon
   Loaded: loaded (/usr/lib/systemd/system/lsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-01-27 14:15:49 CST; 4min 53s ago
 Main PID: 8016 (lsyncd)
   CGroup: /system.slice/lsyncd.service
           └─8016 /usr/bin/lsyncd -nodaemon /etc/lsyncd.conf

Jan 27 14:15:49 nfs systemd[1]: Unit lsyncd.service entered failed state.
Jan 27 14:15:49 nfs systemd[1]: lsyncd.service failed.
Jan 27 14:15:49 nfs systemd[1]: Started Live Syncing (Mirror) Daemon.
Jan 27 14:15:49 nfs lsyncd[8016]: 14:15:49 Error: Cannot open status file "/usr/local/lsyncd-2.1.5/...ctory
Jan 27 14:15:49 nfs lsyncd[8016]: sending incremental file list
Jan 27 14:15:49 nfs lsyncd[8016]: deleting backup/
Jan 27 14:15:49 nfs lsyncd[8016]: ./
Jan 27 14:15:49 nfs lsyncd[8016]: sent 331 bytes  received 40 bytes  742.00 bytes/sec
Jan 27 14:15:49 nfs lsyncd[8016]: total size is 1,890,490  speedup is 5,095.66
Jan 27 14:15:59 nfs lsyncd[8016]: 14:15:59 Error: Cannot open status file "/usr/local/lsyncd-2.1.5/...ctory
Hint: Some lines were ellipsized, use -l to show in full.

Testing:
The client creates files

[root@nfs ~]# cd /backup/
[root@nfs backup]# touch 123.txt
[root@nfs backup]# ll
total 0
-rw-r--r-- 1 root root 0 Jan 27 14:22 123.txt

Server test results

[root@rsync ~]# cd /backup
[root@rsync backup]# ll
total 0
-rw-r--r-- 1 rsync rsync 0 Jan 27 14:22 123.txt
Published 11 original articles · won praise 1 · views 256

Guess you like

Origin blog.csdn.net/octtom/article/details/104092311