服务端:192.168.131.141
监控端:192.168.131.142
[[email protected] ~]# yum install -y rsync
服务端:
[[email protected] ~]# 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
创建用户
[[email protected] ~]# useradd -s /sbin/nologin -M rsync
创建备份目录
[[email protected] ~]# mkdir /backup
授权目录rsync 用户
[[email protected] ~]# chown -R rsync /backup/
输入用户与密码:
[[email protected] ~]# echo "rsync_backup:pwd123" >/etc/rsync.password
授权:
[[email protected] ~]# chmod 600 /etc/rsync.password
启动服务
[[email protected] ~]# rsync --daemon
查看服务端口
[[email protected] ~]# 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
加入开机启动:
[[email protected] ~]# echo "rsync --daemon" >>/etc/rc.local
客户端:
[[email protected] ~]# yum install -y rsync
创建密码:
[[email protected] ~]# echo "pwd123" > /etc/rsync.password
授权:
[[email protected] ~]# chmod 600 /etc/rsync.password
备份:
推:把本地目录文件推到备份目录里面(工作中最多)
[[email protected] ~]# rsync -avz /var/ [email protected]::backup --password-file=/etc/rsync.password
拉:把备份目录拉到 本地文件夹中
[[email protected] ~]# rsync -avz [email protected]::backup /media/ --password-file=/etc/rsync.password
具体 按时备份请编写任务脚本计划,
IP:192.168.131.142 inotify 时时同步配置
[[email protected] ~]# tar xf inotify-tools-3.14.tar.gz
[[email protected] ~]# cd inotify-tools-3.14
[[email protected] inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify/
[[email protected] inotify-tools-3.14]# make && make install
[[email protected] ~]# mkdir -p /server/scripts/
创建脚本:请复制,参数请做修改
[[email protected] 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 [email protected]::backup/ --password-file=/etc/rsync.password
done
#############进入 / 目录将 tmp/ 里面的内容与rsync 备份目录做时时同步
授权:[[email protected] scripts]# chmod a+x inotify.sh
调试:[[email protected] scripts]# sh -x inotify.sh
永久开启:[[email protected] scripts]# /bin/sh /server/scripts/inotify.sh &
加入开机启动:[[email protected] scripts]# echo "/bin/sh inotify.sh&" >> /etc/rc.local
实验测试: 完成
~
~
~