rsyc是什么?(百度百科介绍)
rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote
Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。
如何安装
1.服务器端(接收文件)
rsyncd.conf参数文件配置
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
# [ftp]
# path = /home/ftp
# comment = ftp export area
uid = www
gid = www
use chroot = no
max connections = 200
timeout = 300
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 = 88.88.88.0/24
auth users = rsync_backup
secrets file = /etc/rsync.pass
fake super = yes
[data]
comment = "myrsync directory"
path = /data
useradd www -M -s /sbin/nologin
mkdir /data
chown -R www.www /data
echo 'rsync_backup:123456' >>/etc/rsync.pass
chmod 600 /etc/rsync.pass
rsync --daemon
netstat -lntp|grep rsync
echo '/usr/bin/rsync --daemon' >>/etc/rc.local
systemctl stop firewalld
chmod 600 /etc/rsync.pass
ll /data/
2.客户端(发送文件)
echo '123456' >>/etc/rsync.pass
chmod 600 /etc/rsync.pass
mkdir /data
systemctl stop firewalld
chmod 777 -R /data/
touch /data/2.txt
rsync -avz --delete /data/ rsync_backup@88.88.88.236::data --password-file=/etc/rsync.pass
3.客户端目录实时同步到服务器端(通过定时任务实现)
vi /usr/bin/rsync.sh
#!/bin/bash
for i in $(seq 1 60)
do
rsync -avz --delete /data/ rsync_backup@88.88.88.236::data --password-file=/etc/rsync.pass
sleep 1
done
chmod +x /usr/bin/rsync.sh
crontab -e
* * * * * sh /usr/bin/rsync.sh >>/var/log/$(date +%y%m%d).txt
service crond restart
报错
- No route to host
关闭服务器端防火墙 - auth failed on module data
可能是参数文件/etc/rsyncd.conf内文件注释问题,去掉注释