Using rsync + Lsync to achieve real-time file synchronization, this article describes how to configure Rsync + Lsync. and test the file synchronization function.
Server information:
Main: 10.86.255.154
From: 10.86.255.155
1. From the service set up.
1.1. Installation configuration 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 a FTP server, as it \
# allows CRC Checksumming etc.
Service rsync
{
Disable = no→ Modify ' yes ' to ' no '
Flags = IPV6
Socket_type = Stream
wait = no
user = root
Server =/usr/bin/rsync
Server_args =--daemon
Log_on_failure + + USERID
1.2. Start the xinetd and set the Power-on startup entry.
#/etc/init.d/xinetd Start
# chkconfig xinetd o
1.3. Create a directory where synchronization files are stored.
# Mkdir/home/backup
1.4. Create the rsyncd.conf configuration file.
# vim/etc/rsyncd.conf
[zabbix.cc-web]→ name arbitrary
Path =/home/backup→ Sync File Store path
Hosts allow = 10.86.255.154→ Allow connected hosts (specify Primary server IP)
Hosts deny = *
List = True
UID = root
GID = root
Read Only = False
2. master server settings.
2.1. Install rsync.
# yum-y Install rsync
2.2. Create a synchronization object with a list of files that do not need to be synchronized.
# Vim/etc/rsync_exclude.lst
Test
Test.txt
2.3. On the primary server, execute the following command.
The test synchronizes the files/var/www/html/the primary server to the/home/backup from the server
# Rsync-avz--delete--exclude-from=/etc/rsync_exclude.lst/var/www/html/10.86.255.155::zabbix.cc-web
backup]# ls zabbix.cc
3. Use Rsync + Lsync, when the file or directory changes, you can do real-time synchronization.
3.1. Login to the main server, download and install Lsync.
# yum Install Lsyncd-y
3.2. Configure the Lsyncd file.
# cp/etc/sysconfig/lsyncd/etc/sysconfig/lsyncd.bkp0625
# VIM/ETC/SYSCONFIG/LSYNCD
# Keep the 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" → Remove ' # '
#LSYNCD_OPTIONS = ""
3.3. Configure lsyncd.conf and add the following:
# vim/etc/lsyncd.conf
settings{
Statusfile = "/tmp/lsyncd.stat",
Statusinterval = 1,
}
sync{
Default.rsync,
Source= "/var/www/html/", → Specify the source file directory to sync
Target= "10.86.255.155::zabbix.cc-web", → from server IP: (rsyncd.conf set name)
Excludefrom= "/etc/rsync_exclude.lst", → Exclude file list
}
3.4. Start Lsync.
#/ETC/RC.D/INIT.D/LSYNCD Start
3.5. On the primary server, create a new test file.
html]# Touch Kongqiao
3.6. In the confirmation from the server, synchronization succeeded.
backup]# ls
Kongqiao