lsyncd real-time synchronization to build guide

lsyncd real-time synchronization to build guide

 

Server need to be synchronized:

1, the installation lsyncd

#yum install -y lsyncd


2, the configuration file lsyncd.conf

settings {
logfile ="/var/log/lsyncd.log",
statusFile ="/var/run/lsyncd.status",
inotifyMode = "CloseWrite",
maxProcesses = 2,
nodaemon =false
}

-. III remote directory synchronization, rsync daemon mode the rsyncd +
Sync {
default.rsync,
Source = "/ opt / app_test", --- need to be synchronized directory
target = "[email protected] :: PensionService", - - a synchronization target server
Delete = "running",
the exclude = {. "*", ".tmp", "log"},
Delay = 0,
the init = to false,
the rsync = {
binary = "/ usr / bin / the rsync",
= to true Archive,
the compress = to true,
verbose = to true,
password_file = "/etc/rsyncd.passwd",
_extra = { "--bwlimit = 200 is"}
}
}


- V. remote directory synchronization, rsync mode + rsyncssh, the same effect as above
Sync {
default.rsyncssh,
Source = "/ opt / app_test3",
Host = "10.28.11.156",
TARGETDIR = "/ opt / app_test3",
the excludeFrom = "/etc/rsync_exclude.lst",
- maxDelays =. 5,
Delay = 0,
- the init = to false,
the rsync = {
binary = "/ usr / bin / the rsync",
Archive = to true,
the compress = to true,
verbose = to true,
_extra = { "--bwlimit = 2000"},
},
SSH = {
Port = 22080
}
}

start lsyncd services:

#service lsyncd start


Objectives synchronization server:

Rsync need to configure the service:

#yum install -y xinetd

Modify: /etc/xinetd.d/rsync

service rsync
{
disable = no ##---yes 改 no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}


rsync configuration file: /etc/rsyncd.conf

uid=root
gid=root
use chroot=no
pid file=/var/run/rsync.pid
max connections=10
lock file=/var/run/rsync.lock
log file=/var/log/rsync.log
motd file=/etc/rsyncd.motd
secrets file=/etc/rsyncd.secrets
hosts allow=10.28.11.156 127.0.0.1 10.28.11.117
auth users=tomcat

[PensionService]
path=/opt/app_test
comment=app_test file
read only=false
list=false

Note: tomcat user needs write access to the / opt / app_test directory

/etc/rsyncd.secrets
tomcat:4zbSsBORKZPPo

#chmod 600 /etc/rsyncd.secrets

Start rsync

#service xinetd start


Note: When using the last mode to synchronize files, two servers need to set up password-free login.

 


lsyncd.conf configuration options Description

settings

Inside is a global setting - represents the beginning of the comment, here are a few popular options Description:

logfile custom log file
stausFile defined state file
nodaemon = true indicates guard mode is not enabled, the default
statusInterval the state lsyncd above statusFile writing interval of 10 seconds by default
event monitoring inotify inotifyMode specified, the default is CloseWrite, Modify, or may also be CloseWrite or Modify
the maximum number of maxProcesses synchronization process. At the same time, if there are 20 files need to be synchronized, and maxProcesses = 8, the maximum can see there are eight rysnc process
maxDelays to the cumulative number of the monitored event activation time synchronization, even though the latter has yet to delay the delay time

sync

Which is the definition of synchronization parameters, you can continue to use maxDelays to rewrite the global variable settings. General The first parameter specifies what mode lsyncd run: rsync, rsyncssh, direct three modes:

default.rsync: between local directory synchronization, use rsync, ssh also be achieved using a form of remote rsync effect, or connect remote rsyncd daemon process;
default.direct: between local directory synchronization, use cp, rm, etc. commands to complete the differential file backups ;
default.rsyncssh: synchronized to the remote host directory, rsync the ssh mode, use the key to authenticate the
source of the source directory synchronization, use an absolute path.
. target destination address corresponding to the definition of several different writing modes:
/ tmp / dest: synchronizing the local directory, can be used for direct mode and rsync
172.29.88.223:/tmp/dest: synchronized to the remote directory server, and may be used rsync mode rsyncssh , splicing command is similar to / usr / bin / rsync --include- from = -ltsd --delete - --exclude = * SOURCE TARGET, the rest is the rsync content, such as specifying username, password-free synchronization
172.29. 88.223 :: module: synchronized to the remote server directory for rsync mode

Examples of the three modes will be given later.
init This is an optimization option when init = false, only changes to files synchronized events that occur after the process started, even if there are differences in the original directory will not be synchronized. The default is to true
Delay cumulative events, waiting for rsync synchronization delay time, default 15 seconds (to a maximum total of 1000 events can not be combined). That is, changes that occur in the lower 15s monitored directory, will accumulate to a rsync synchronization, to avoid too frequent synchronization. (Merger may mean, in the 15s modify the same file twice, and finally sync the latest file)
excludeFrom exclude option to exclude specified after the list of files, such as excludeFrom = "/etc/lsyncd.exclude", if it is a simple exclude, you can use exclude = LIST.

Here's exclusion rules written with native rsync a bit different, more simple:
any part of the monitoring path in a text to match, will be excluded, such as / bin / foo / bar foo can match rule
if the rule slash / at the beginning, then from scratch to match all
end if the rule ends with /, will have to match the monitor path
? matches any character, but does not include the /
* matches zero or more characters, excluding /
** matches zero or more characters, can be /
the delete order to maintain the target with souce fully synchronized, lsyncd default will delete = true to allow synchronization delete. In addition it is false, there are startup, running values, refer Lsyncd 2.1.x ‖ ‖ Layer 4 Config Default Behavior.

rsync

(Reminder, delete and exclude rsync options could have been, in the above configuration is in sync, I think the reason for this is to reduce the cost of rsync)

bwlimit speed limit, unit kb / s, and rsync the same (so important option is not even marked in the document)
the compress compression and transmission defaults to true. Between bandwidth and cpu load balance, the local directory synchronization can consider it to false
PERMS default file permissions are retained.

Rsync other options
there are other modes rsyncssh unique configuration items, such as host, targetdir, rsync_path, password_file, see below example. rsyncOps =. { "- avz" , "- delete"} such wording * version 2.1 is no longer supported.
lsyncd.conf may have a plurality of sync, each Source, each target, the respective mode, independently of each other.

2.3 Starting lsyncd
use the command to load the configuration file, start the daemon automatically synchronize directory operations.

lsyncd -log Exec /usr/local/lsyncd-2.1.5/etc/lsyncd.conf

Guess you like

Origin www.cnblogs.com/wdrain/p/11528462.html