码迷,mamicode.com
首页 > 其他好文 > 详细

rsync+inotify

时间:2018-01-22 20:30:45      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:max   密码   chown   机制   systemctl   isa   too   events   inotify   

rsync

目标服务器端设置

* 默认873端口,本次修改为8888
* rsync  数据镜像备份工具
* xinetd 网络守护进程服务

#安装软件

yum install rsync xinetd -y

rpm -qa|grep rsync  
rsync-3.0.9-18.el7.x86_64

#设置 xindetd 配置文件 开机启动

cat >>  /etc/xinetd.d/rsync  <<EOF
service rsync
{
        disable = no
        flags           = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        port            = 8888
}
EOF
vim /etc/services
254 rsync           8888/tcp                         # rsync
255 rsync           8888/udp                         # rsync

#设置用户

groupadd rsync
useradd -g rsync rsync
mkdir /home/rsync/backup/
chown -R rsync.rsync /home/rsync/backup/

#设置rsyncd配置文件

cat >>  /etc/rsyncd.conf  <<EOF
port = 8888
uid = rsync
gid = rsync
use chroot = no
max connections = 40
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /home/rsync/backup/rsyncd.log

ignore errors
read only = false
list = false
hosts allow = 192.168.10.0/24
hosts deny = 0.0.0.0/32
auth users = rsync
secrets file =/etc/rsyncd.passwd

[backup]
path = /home/rsync/backup/
EOF

#设置账户密码

echo  rsync:hequan            >    /etc/rsyncd.passwd 

#设置权限

chmod 600 /etc/rsyncd.passwd
chmod 600 /etc/rsyncd.conf

#启动

systemctl start xinetd.service
systemctl start rsyncd

源客户端:

yum install xinetd -y

cat >>  /etc/xinetd.d/rsync  <<EOF
service rsync
{
        disable = no
        flags           = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        port            = 8888
}
EOF

vim /etc/services

254 rsync           8888/tcp                         # rsync
255 rsync           8888/udp                         # rsync

cat >> /etc/rsyncd.conf  <<EOF
[www]
path = /data
port = 8888
comment = file rsync
read only = no
kust = no
auth users = root
secrets file = /etc/rsyncd.passwd
hosts allow = 192.168.10.133
list = no
EOF

echo  hequan >  /etc/rsyncd.passwd

chmod 600 /etc/rsyncd.passwd

systemctl start xinetd.service
systemctl start rsyncd

测试: 从客户端 备份 到 服务器
rsync -avH --port=8888 --progress /data rsync@192.168.10.133::backup --password-file=/etc/rsyncd.passwd


inotify

  • 是一种强大的、细粒度的、异步的文件系统事件监控机制

#查看服务器的内核是否支持inotify ,如果有就是支持

ll /proc/sys/fs/inotify     
total 0
-rw-r--r-- 1 root root 0 Jan 22 17:39 max_queued_events
-rw-r--r-- 1 root root 0 Jan 22 17:39 max_user_instances
-rw-r--r-- 1 root root 0 Jan 22 17:39 max_user_watches
yum install make  gcc gcc-c++  -y

cd /usr/local/src/
wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

tar xf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure --prefix=/usr/local/inotify
make && make install

echo "PATH=/usr/local/inotify/bin:$PATH" >> /etc/profile.d/inotify.sh
source /etc/profile.d/inotify.sh
echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf
ln -s /usr/local/inotify/include  /usr/include/inotify
sysctl -a | grep max_queued_events
sysctl -a | grep max_user_watches
sysctl -a | grep max_user_instances

echo  ‘fs.inotify.max_queued_events=99999999  
fs.inotify.max_user_watches=99999999  
fs.inotify.max_user_instances=65535   
‘   >>  /etc/sysctl.conf 

/sbin/sysctl -p
cat >>  /usr/local/inotify/rsync.sh  << EOF
#!/bin/sh
srcdir=/data/nginx
dstdir=backup
rsyncuser=rsync
rsyncpassdir=/etc/rsyncd.passwd
dstip="192.168.10.133"
rsync -avH --port=8888 --progress --delete   $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir

/usr/local/inotify/bin/inotifywait  -mrq --timefmt ‘%d/%m/%y %H:%M‘ --format ‘%T %w%f%e‘ -e close_write,modify,delete,create,attrib,move $srcdir |  while read file
do
    for ip in $dstip
        do
            rsync -avH --port=8888 --progress --delete   $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
            echo "  ${file} was rsynced" >> /tmp/rsync.log   2>&1
        done
done
EOF

chmod   +x /usr/local/inotify/rsync.sh

测试:

/usr/local/inotify/rsync.sh`

正式应用:

nohup  /usr/local/inotify/rsync.sh    > /dev/null 2>&1  &   

rsync+inotify

标签:max   密码   chown   机制   systemctl   isa   too   events   inotify   

原文地址:http://blog.51cto.com/hequan/2063841

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!