首页 > 代码库 > 搭建rsync+inotify
搭建rsync+inotify
服务端:192.168.131.141
监控端:192.168.131.142
[root@khd ~]# yum install -y rsync
服务端:
[root@khd ~]# vim /etc/rsyncd.conf 手动创建
#请复制,修改内容参数
uid = rsync
gid = rsync
use chroot = no
max connections = 2000
strict modes = on
timout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.131.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
comment = lianglab file
list = on
#########################################
[backup]
comment = lianglab file
path = /backup
创建用户
[root@khd ~]# useradd -s /sbin/nologin -M rsync
创建备份目录
[root@khd ~]# mkdir /backup
授权目录rsync 用户
[root@khd ~]# chown -R rsync /backup/
输入用户与密码:
[root@khd ~]# echo "rsync_backup:pwd123" >/etc/rsync.password
授权:
[root@khd ~]# chmod 600 /etc/rsync.password
启动服务
[root@khd ~]# rsync --daemon
查看服务端口
[root@khd ~]# netstat -lntup | grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 2287/rsync
tcp 0 0 :::873 :::* LISTEN 2287/rsync
加入开机启动:
[root@khd ~]# echo "rsync --daemon" >>/etc/rc.local
客户端:
[root@web ~]# yum install -y rsync
创建密码:
[root@web ~]# echo "pwd123" > /etc/rsync.password
授权:
[root@web ~]# chmod 600 /etc/rsync.password
备份:
推:把本地目录文件推到备份目录里面(工作中最多)
[root@web ~]# rsync -avz /var/ rsync_backup@192.168.131.141::backup --password-file=/etc/rsync.password
拉:把备份目录拉到 本地文件夹中
[root@web ~]# rsync -avz rsync_backup@192.168.131.141::backup /media/ --password-file=/etc/rsync.password
具体 按时备份请编写任务脚本计划,
IP:192.168.131.142 inotify 时时同步配置
[root@nfs ~]# tar xf inotify-tools-3.14.tar.gz
[root@nfs ~]# cd inotify-tools-3.14
[root@nfs inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify/
[root@nfs inotify-tools-3.14]# make && make install
[root@nfs ~]# mkdir -p /server/scripts/
创建脚本:请复制,参数请做修改
[root@nfs scripts]# vim inotify.sh
#!bin/sh
inotify=/usr/local/inotify/bin/inotifywait
$inotify -mrq --format ‘%w%f‘ -e create,close_write,delete /tmp \
|while read file
do
cd / &&
rsync -az tmp/ --delete rsync_backup@192.168.131.141::backup/ --password-file=/etc/rsync.password
done
#############进入 / 目录将 tmp/ 里面的内容与rsync 备份目录做时时同步
授权:[root@nfs scripts]# chmod a+x inotify.sh
调试:[root@nfs scripts]# sh -x inotify.sh
永久开启:[root@nfs scripts]# /bin/sh /server/scripts/inotify.sh &
加入开机启动:[root@nfs scripts]# echo "/bin/sh inotify.sh&" >> /etc/rc.local
实验测试: 完成
~
~
~
搭建rsync+inotify