Lsync 同步软件的运用

公司使用智齿的机器崩了,要做数据迁移。

由三台老机器迁移到三台新kvm机器

我们需要把其中一台34.38的的东西实时同步两份,一份到30.18的glusterfs,一份到34.41的/data

同时也要注意30.18的GFS中已经有两个虚机文件,32.6和34.38的qcow2

所以lsync务必要小心,不能删除已有文件

172.18.34.38上面的lsyncd.conf如下,同步到两个目的地: 注意下面的参数:

  1. maxProcesses = 2 # 本机用于rsync的进程数

  2. delete = ‘running’ # 只删除lsync启动之后删除的文件,目的文件夹中原有的文件保存

  3. exclude = “upload” # 第二个同步中排除的目录,注意这里是匹配全路径中的部分字串,upload 可以匹配到 /data/new/chatmsg/upload/allajl.jpg,就upload目录下文件大,所以把它排除。**这里的规则是和rsync中exclude的写法不同的!!!**只取路径中的upload字串就可以排除。

 1----
 2-- User configuration file for lsyncd.
 3--
 4-- Simple example for default rsync, but executing moves through on the target.
 5--
 6-- For more examples, see /usr/share/doc/lsyncd*/examples/
 7-- 
 8-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}
 9
10settings {
11    logfile = "/var/log/lsyncd/lsyncd.log",
12    statusFile = "/var/log/lsyncd/lsyncd-status.log",
13    statusInterval = 5,
14    maxProcesses = 2
15}
16
17sync {
18    default.rsync,
19    source = "/data/new",
20    target = "172.18.30.18::new",
21    delete = 'running',
22    delay = 5,
23    rsync     = {
24        binary = "/usr/bin/rsync",
25        archive = true,
26        compress = false,
27        verbose   = true
28    }
29}
30
31sync {
32    default.rsync,
33    source = "/data",
34    target = "172.18.34.41::new",
35    delete = 'running',
36    exclude = "upload",
37    delay = 5,
38    rsync     = {
39        binary = "/usr/bin/rsync",
40        archive = true,
41        compress = false,
42        verbose   = true
43    }
44}

对端rsyncd的配置如下:

 1# cat /etc/rsyncd.conf 
 2# /etc/rsyncd: configuration file for rsync daemon mode
 3
 4# See rsyncd.conf man page for more options.
 5
 6# configuration example:
 7
 8# uid = nobody
 9# gid = nobody
10# use chroot = yes
11# max connections = 4
12# pid file = /var/run/rsyncd.pid
13# exclude = lost+found/
14# transfer logging = yes
15# timeout = 900
16# ignore nonreadable = yes
17# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
18
19# [ftp]
20#        path = /home/ftp
21#        comment = ftp export area
22uid = root
23gid = root
24use chroot = no
25max connections = 200
26timeout = 300
27pid file = /var/run/rsyncd.pid
28lock file = /var/run/rsync.lock
29log file = /var/log/rsyncd.log
30
31[new]
32path = /root
33ignore errors
34read only = false
35list = false
36hosts allow = 172.18.34.38
37hosts deny = 0.0.0.0/32

这是个极端强力的工具,墙裂推荐!。


Linux加密压缩tar包
开发投诉FTP慢问题的解决
comments powered by Disqus