什么是rsync:
- rsync 是一个unix系统下的文件同步和传输工具。
- rsync是用"rsync" 算法提供一个客户端和远程文件服务器的文件同步的快速方法。
rsync特性:
- 能更新整个目录和树和文件系统;
- 游戏选择性的保存符号链接,硬链接,文件属性,权限,文件时间和设置等;
- 对于安装来说,没有任何特殊权限要求;
- 对于多文件,内部流水线减少文件等待延时;
- 能用rsh,ssh或者直接端口作为传输端口;
- 支持匿名rsync文件同步,是理想的镜像工具;
rsync安装:
- yum install rsync
- rpm -ivh rsync
- tar -zxvf rsync
- cd rsync-2.6.8-3.1
- ./configure
- make && make install
rsync 配置:
vi /etc/rsyncd.conf
uid = nobody
gid = nobody
hosts allow = *
#hosts deny = 0.0.0.0/32
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[Backup]
path = /home/wwwroot/zyadsc
comment = rsync files
ignore errors
read only = yes
list=yes
auth users = root
secrets file = /etc/rsyncd.scrt
chmod 600 /etc/rsyncd.conf #为了安全
vi /etc/rsyncd.scrt
root:123456
rsync 启动:
/usr/local/bin/rsync --daemon --config=/etc/rsync.conf
开机启动:
vi rsync_start.sh 加入
/usr/local/bin/rsync --daemon --config=/etc/rsync.conf
最好加入pid是否存在的判断,如果存在则删掉重启;
cat rsync_start.sh >> /etc/rc.local
rsync 停止:
ps -aux |grep rsync
kill -9 18572
备份机器设置:
同理需要安装rsync
执行以下命令:
/usr/bin/rsync -vzrtopg --delete --progress root@10.3.0.39::Backup /home/wwwroot/zyadsc
#把root@10.3.0.39的主机 /home/wwwroot/zyadsc 目录下的文件Backup到本机的/home/wwwroot/zyadsc 目录下
--delete:把备份机器上的文件,该文件在主服务器上却没有的文件删除;
--progress :显示备份进度;
同步过程中的错误:
用户密码错误
检查服务器A存储密码文件和服务器B密码文件。
- 服务器A密码文件 /etc/rsyncd.secrets 格式为: username:password
- 服务器B密码文件 password.rsync 格式为:password
文件权限错误
检查服务器A存储密码文件和服务器B密码文件。
- 服务器A密码文件 /etc/rsyncd.secrets 权限为600: chmod 600 /etc/rsyncd.secrets
- 服务器B密码文件 password.rsync 权限为600:chmod 600 password.rsync