Centos 7.0 enables real-time synchronization via rsync and INotify

Source: Internet
Author: User
Tags inotify centos rsync

I've written it before. Timed backups via rsync: Windows2008 and Centos7.0 via rsync for Updates (backup), and now the need for real-time synchronous backups via rsync and INotify. The first step: Getting Ready for work 1. INotify Introduction

Inotify is a Linux feature that monitors file system operations such as read, write, and create. The Inotify is responsive, very simple to use, and much more efficient than the busy polling of cron tasks. Learn how to integrate INotify into your application and discover a set of command-line tools that you can use to further automate system governance. (from Baidu Encyclopedia)

2. Rsync Introduction

Rsync is a data mirroring Backup tool--remote Sync under Unix-like systems. A fast incremental backup tool remote sync that supports local replication or synchronizes with other SSH and rsync hosts. (from Baidu Encyclopedia)

3. Rsync and INotify Real-time synchronization schematic diagram 4. Environment Deployment

(1) database server (inotify-master) ip:192.168.221.131

(2) Backup server (Inotify-slave) ip:192.168.221.136

Step Two: Deploy the backup server Inotify-slave

Here is the deployment of the Inotify-slave environment, configuring the Rsync daemon mode of Operation 1. Check if rsync is installed

1 Rpm-qa|grep rsync

2. Add rsync users and module catalogs and change their user groups

1 Useradd rsync-s/sbin/nologin-m #添加rsync用户
1 grep rsync/etc/passwd
1 Mkdir/jhonse/back #创建rsync Daemon Module directory for working mode
1 Chown Rsync.rsync/jhonse/back #更改模块目录的用户组

3. Configure the Rsync configuration file/etc/rsyncd.conf

01 #/etc/rsyncd:configuration file for rsync daemon mode
02
03 # See rsyncd.conf Mans page for more options.
04
05 # Configuration Example:
06
07 # uid = nobody
08 # gid = Nobody
09 # Use chroot = yes
10 # Max connections = 4
11 # pid File =/var/run/rsyncd.pid
12 # exclude = lost+found/
13 # Transfer logging = yes
14 # timeout = 900
15 # Ignore nonreadable = yes
16 # dont compress = *.gz *.tgz *.zip *.z *. Z *.rpm *.deb *.bz2
17
18 # [FTP]
19 # path =/home/ftp
20 # comment = FTP export area
21st
22 #工作中指定用户 (requires a specified user)
23 UID = rsync
24 GID = rsync
25
26 #相当于黑洞. Error targeting
27 Use chroot = no
28 #有多少个客户端同时传文件
29 Max connections = 200
30
31 #超时时间
32 Timeout = 300
33 #进程号文件
34 PID file =/var/run/rsyncd.pid
35 #日志文件
36 Lock file =/var/run/rsync.lock
37 #日志文件
38 Log file =/var/log/rsyncd.log
39
40 #模块开始
41 #这个模块对应的是推送目录
42 #模块名称随便起
43 [Backup]
44 #需要同步的目录
45 Path =/jhonse/back/
46 #表示出现错误忽略错误
47 Ignore errors
48 #表示网络权限可写 (Local control is truly writable)
49 Read Only = False
50 #这里设置IP或让不让同步
51 List = False
52 #指定允许的网段
53 Hosts allow = 192.168.221.0/255
54 #拒绝链接的地址, the following represents a link that is not rejected.
55 Hosts Deny = 0.0.0.0/32
56 #不要动的东西 (default)
57 #虚拟用户
58 Auth users = Rsync_backup
59 #虚拟用户的密码文件
60 Secrets file =/etc/rsync.password

4. Configure the virtual user's password file

Create a Rsync.password file in the/etc directory and add a virtual account and password

Format: Account: Password

1 Rsync_backup:jhonse

5. Rsync.password The password file to increase security

1 chmod 600/etc/rsync.password

6. Start the Rsync service

1 Rsync--daemon
1 Ps-ef |grep rsync
1 NETSTAT-LNUTP |grep rsync

Step Three: Deploy the database server (inotify-master)

Description: INotify was installed and executed by the Rsync client 1. See if the current system supports inotify

1 ll/proc/sys/fs/inotify/

If max_queued_events, Max_user_instances, max_user_watches are shown, support inotify

1 /proc/sys/fs/inotify/max_queued_evnets
2 Represents the maximum value assigned to the number of events that can be queued in inotify instance when calling Inotify_init, an event that exceeds this value is discarded, but the In_q_overflow event is triggered.
3 /proc/sys/fs/inotify/max_user_instances
4 Represents the maximum number of inotify instatnces that each real user ID can create.
5 /proc/sys/fs/inotify/max_user_watches
6 Represents the maximum number of directories that can be monitored per inotify instatnces. If you monitor a large number of files, you need to increase the size of this value appropriately, depending on the situation.
7 Example: Echo 30000000 >/proc/sys/fs/inotify/max_user_watches
2. Download the inotify source package and compile the installation
1 wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz #下载inotify源码包
2 ll inotify-tools-3.14.tar.gz
3 TAR-ZXF inotify-tools-3.14.tar.gz
4 CD inotify-tools-3.14
5 ./configure--prefix=/usr/local/inotify-tools-3.14 #配置inotify, and specify the installation path to/usr/local/inotify-3.14
6 Make && make install

3. INotify's inotifywait command common parameters detailed

01 cd/usr/local/inotify-tools-3.14/
02 ./bin/inotifywait--help
03 -r|--recursive Watch directories recursively. #递归查询目录
04 -q|--quiet print (only print events). #打印监控事件的信息
05 -m|--monitor Keep listening for events forever.        Without this option, inotifywait would exit after one event is received. #始终保持事件监听状态
06 --excludei <pattern> like--exclude but case insensitive. #排除文件或目录时, case insensitive.
07 --TIMEFMT <fmt> strftime-compatible format string for use with%T in--format string. #指定时间输出的格式
08 --format <fmt> Print using a specified printf-like format string; Read the man page for more details.
09 #打印使用指定的输出类似格式字符串
10 -e|--event <event1> [-e|--event <event2> ...] Listen
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.