inotify+rsync安装配置

释放双眼,带上耳机,听听看~!

1.两台机器192.168.1.2,
192.168.1.3,想把
192.168.1.2的数据同步到
192.168.1.3中

2.测试开始,可以先关闭防火墙和内核
linux的selinux的防火墙,避免防火墙影响

关闭防火墙,例如centos7,其他系统版本自己查询如何关闭


1
2
3
1    $ systemctl stop firewalld.service #停止firewall  
2    $ systemctl disable firewalld.service #禁止firewall开机启动  
3

1
2
1 关闭linux的selinux防火墙
2

永久性关闭:生效需要重启



1
2
3
1    $ vi /etc/selinux/config  
2    SELINUX=disabled  
3

1
2
1 临时性关闭:生效无需重启
2


1
2
1$ setenforce 0  
2

3.安装rsync(两台服务器)

前往rsync官网下载最新版本 http://rsync.samba.org/ftp/rsync/src  找到最新的rsync-*.*.*.tar.gz


1
2
3
4
5
1    $ tar zxvf rsync-*.*.*.tar.gz  
2    $ cd rsync-*.*.*  
3    $ ./configure --prefix=/usr/local/rsync  
4    $ make && make install  
5

4.配置rsyncd.conf (
192.168.1.3)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
1    $ vi /etc/rsync.conf  
2    #pid文件的存放位置  
3    pid file = /var/run/rsync.pid  
4    #日志文件位置,启动rsync后自动产生这个文件,无需提前创建  
5    log file = /var/log/rsync.log  
6    #支持max connections参数的锁文件  
7    lock file=/var/run/rsync.lock  
8    #用户认证配置文件,里面保存用户名称和密码  
9    secrets file = /etc/rsync.pw  
10    #rsync启动时欢迎信息页面文件位置  
11    motd file = /etc/rsyncd.motd  
12    transfer logging = yes  
13    log format = %t %a %m %f %b  
14    syslog facility = local3  
15    #自定义名称  
16    [data]  
17    #设置需要同步的目录  
18    path = /data/test/  
19    #模块名称与[data]自定义名称相同  
20    comment = data  
21    exclude = blank.png ; spinner.gif ; downsimple.png ; rails.png ; WEB-INF/  
22    #默认端口  
23    port = 873  
24    #设置rsync运行权限为root  
25    uid = root  
26    #设置rsync运行权限为root  
27    gid = root  
28    #设置超时时间  
29    timeout = 600  
30    #最大连接数  
31    max connections = 200  
32    #默认为true,修改为no,增加对目录文件软连接的备份  
33    use chroot = no  
34    #设置rsync服务端文件为读写权限  
35    read only = no  
36    #不显示rsync服务端资源列表  
37    list = no  
38    #允许进行数据同步的客户端IP地址  
39    hosts allow = 192.168.1.3  
40

1
2
1 可以设置多个目录(
2

192.168.1.3)



1
2
3
4
5
6
7
8
9
1    #增加test1目录  
2    [test1]  
3    path = /data/test1  
4    list = yes  
5    ignore errors  
6    comment = ucweb-file system  
7    secrets file = /etc/rsync.pw  
8    exclude = blank.png ; spinner.gif ; downsimple.png ; rails.png ; WEB-INF/  
9

1
2
1 建立密码认证文件(
2

192.168.1.3)



1
2
3
1    $ vi /etc/rsync.pw  
2    root:123456  
3

配置rsyncd.motd文件,开始传送的时候会显示(
192.168.1.3)



1
2
3
4
5
6
7
1    $ vi /etc/rsyncd.motd  
2    ###############################  
3    #                             #  
4    #        start rsync          #  
5    #                             #  
6    ###############################  
7

1
2
1 5.启动rsync
2


1
2
3
1$ /usr/local/rsync/bin/rsync --daemon --config=/etc/rsyncd.conf  <span><span></span></span>
2<span><span></span></span>
3

开机启动rsync


1
2
1    $ echo '/usr/local/rsync/bin/rsync --daemon --config=/etc/rsyncd.conf'>>/etc/rc.d/rc.local
2

6.建立密码认证文件(192.168.1.2)



1
2
3
1    $ vi /etc/rsync.pw  
2    123456  
3

7.测试开始



1
2
1$ /usr/local/rsync/bin/rsync -avH --port=873 --progress --delete /data/test/ root@192.168.1.3::data --password-file=/etc/rsync.pw  
2

1
2
1   查看192.168.1.2上是否有同步  
2

8.安装inotify-tools(192.168.1.2)



1
2
3
4
5
6
1    $ wget https://codeload.github.com/rvoicilas/inotify-tools/zip/master  
2    $ tar zxvf inotify-tools-*.*.tar.gz  
3    $ cd inotify-tools-*.*  
4    $ ./configure --prefix=/usr/local/inotify  
5    $ make && make install  
6

1
2
1 9.查看是否安装成功
2


1
2
1    $ ll /yunwei8/apps/inotify/bin/inotifywa*  
2

10.新建一个inotify.sh文件同步


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1    #!/bin/sh  
2      
3    # get the current path  
4    CURPATH=`pwd`  
5      
6    /usr/local/inotify/bin/inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \  
7    -e close_write /data | while read date time dir file; do  
8      
9           FILECHANGE=${dir}${file}  
10           # convert absolute path to relative  
11           FILECHANGEREL=`echo "$FILECHANGE" | sed 's_'$CURPATH'/__'`  
12      
13           rsync -avH --port=873 --progress --delete /data/test/ root@192.168.1.3::data --password-file=/etc/rsync.pw  
14            echo "At ${time} on ${date}, file $FILECHANGE was backed up via rsync"  
15    done  
16

时刻监听文件

给TA打赏
共{{data.count}}人
人已打赏
安全技术安全运维

Windows服务器如何发现被黑

2018-5-20 12:24:31

安全技术

node.js – JWT有效负载应该有多少信息?

2021-12-21 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索