rsync+lsyncd to realize real-time file synchronization
yum -y install rsyncd (both the synchronized end and the synchronized end need to be installed)
1. Provide lsyncd installation source
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
- 1
- 2
2. Dependency of installing lsyncd from yum
yum -y install lua lua-devel pkgconfig gcc asciidoc
- 1
- 2
3. Error reporting of steps after pre-resolution (100% test recurrence rate)
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
resolvent:
vi /etc/yum.repos.d/epel.repo
- 1
- 2
Edit the ා number before the baseurl under [epel] to remove, and add ා number before mirrorlist.
Correct configuration:
[epel] name=Extra Packages for Enterprise Linux 6 - $basearch baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
4. Install lsyncd, yum
yum install lsyncd
- 1
- 2
5. Create a directory for the log file (most likely an existing directory)
mkdir /var/log/lsyncd
- 1
- 2
Write profile
1.VI edit configuration file
vi /etc/lsyncd.conf
- 1
- 2
2. The simplest way to write configuration files (local synchronization)
# vi etc/lsyncd.conf settings { logfile ="/var/log/lsyncd/lsyncd.log", statusFile ="/var/log/lsyncd/lsyncd.status", inotifyMode = "CloseWrite or Modify", maxProcesses = 8, -- nodaemon = true, } sync { default.rsync, source = "/data/home/wwwroot/default", target = "10.252.108.84:/data/home/wwwroot/default", delay = 0, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, verbose = true, rsh = "/usr/bin/ssh -p 2222 -o StrictHostKeyChecking=no" } } sync { default.rsync, source = "/home/wwwroot/jifen", target = "10.252.108.84:/home/wwwroot/jifen", delay = 0, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, verbose = true, rsh = "/usr/bin/ssh -p 2222 -o StrictHostKeyChecking=no" } } sync { default.rsync, source = "/data/home/wwwroot/default", target = "120.78.173.222:/data/home/wwwroot/default", delay = 0, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, verbose = true, rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no" } } sync { default.rsync, source = "/home/wwwroot/jifen", target = "120.78.173.222:/home/wwwroot/jifen", delay = 0, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, verbose = true, rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no" } } sync { default.rsync, source = "/data/config", target = "120.78.173.222:/data/config", delay = 0, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, verbose = true, rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no" } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
You need to set more synchronization parameters to extend the profile
Syncing more directories can directly copy sync blocks
Be careful not to leave out the comma after each line
Start Lsyncd service
1. Start lsyncd service
/etc/init.d/lsyncd start
- 1
- 2
2. Display service running status
/etc/init.d/lsyncd status
- 1
- 2
3. Set lsyncd service self start
chkconfig lsyncd on
- 1
- 2
Reference resources
Installation and configuration of lsyncd under centos and Ubuntu
https://www.scalescale.com/tips/nginx/lsyncd-live-file-syncronization-linux/
Explanation of the Settings section of the configuration file in the official document
https://github.com/axkibe/lsyncd/wiki/Lsyncd-2.1.x-%E2%80%96-The-Configuration-File
Explanation of sync part in configuration file in official document
https://github.com/axkibe/lsyncd/wiki/Lsyncd%202.1.x%20%E2%80%96%20Layer%204%20Config%20%E2%80%96%20Default%20Behavior
A Chinese article, in the installation and configuration of a lot of help to me
https://linux.cn/article-5849-1.html