Real-time synchronization lsyncd

Real-time synchronization lsyncd

1 lsyncd

About 1.1 lsyncd

Lsyncd using a file system event interface (inotify or fsevents) to monitor changes to the local files and directories. Lsyncd organize these events for a few seconds, then generate one or more processes to synchronize changes to the remote file system.
The default synchronization method is rsync Lsyncd is a lightweight real-time mirroring solution. Lsyncd relatively easy to install, does not require a new file system or block. Lysncd does not interfere with the local file system performance can be achieved by fine-grained custom profile. Configure custom actions can even be written from scratch, using the code written in Lua from a shell script to.

1.2 Environmental ready

rsync服务端:默认就有rsync无需安装
lsyncd客户端:安装lsyncd软件


Here, the backup server to server, storage server for the client

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

1.3 rsync configuration file

backup configuration file

[root@backup ~]#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
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = "backup dir by oldboy"
path = /backup

1.4 to create a virtual user rsync

id rsync        #查看以下是否有rsync这个用户
useradd rsync -M -s /sbin/nologin       #创建rsync虚拟用户

1.5 Create a password file and modify access to 600

echo "rsync_backup:123456" >/etc/rsync.password
chmod 600 /etc/rsync.password           #只能root用户才能查看密码

1.6 Create a backup directory / directory to modify the owner and group information

mkdir /backup
chown rsync.rsync /backup

1.7 start the service program / service program to restart

systemctl start rsyncd
systemctl restart rsyncd
systemctl enable  rsyncd

1.8 lsyncd profile

lsyncd profile

root@nfs ~]#cat /etc/lsyncd.conf 
settings {
 logfile = "/var/log/lsyncd/lsyncd.log",
 statusFile = "/var/log/lsyncd/lsyncd.status",
 inotifyMode = "CloseWrite",
 maxProcesses = 8,
}
sync {
 default.rsync,
 source = "/data",
 target = "[email protected]::backup",
 delete= true,
 exclude = { ".*" },
 delay = 1,
rsync = {
 binary = "/usr/bin/rsync",
 archive = true,
 compress = true,
 verbose = true,
 password_file = "/etc/rsync.password",
 _extra = {"--bwlimit=200"}
}
}

1.9 storage server to create a backup directory

mkdir /data

1.10 create a password file, and modify permissions

echo "123456" >/etc/rsync.password  #创建密码文件
chmod 600 /etc/rsync.password

1.11 free interactive file transfer password

rsync -avz /etc/passwd [email protected]::backup --password-file=/etc/rsync.password

Figure execute the above command is present, it proves successful deployment services
image.png

1.12 storage server for testing

[root@nfs data]#touch test.txt
[root@nfs data]#ls
test.txt
++++++++++++++++++++++++++++++
[root@backup backup]#ls
test.txt

Guess you like

Origin www.cnblogs.com/basa/p/11297415.html
Recommended