Linux Rsync同步服务器的安装配置
博客已经搬家,请访问如下地址:http://www.czhphp.com
什么是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
 
  以上两个错误是大家经常会遇到的,我今天就遇到了这个权限的问题,但是奇怪的是我的文件权限的问题,也只是提示
auth failed on module ***
定时执行:
vi backup.sh
#!/bin/bash
   /usr/bin/rsync -vzrtopg --delete --progress root@10.3.0.39::Backup  /home/wwwroot/zyadsc 
     
crontab -e
*/1 * * * * /home/wwwroot/zyadsc/backup.sh > /dev/null 2>&1
每分钟备份
以上为从主机同步数据到备份机,同理从备份机到主机
/usr/bin/rsync -vzrtopg --delete --progress /home/wwwroot/zyadsc root@10.3.0.39::Backup
请确保备份服务器同步用户root,对模块Backup所在目录有读、写、执行的权限。
rsync参数说明:
 -h, --help           this message
 -V, --version        output version information
 -n, --numeric        don't resolve service names
 -r, --resolve       resolve host names
 -a, --all            display all sockets
 -l, --listening      display listening sockets
 -o, --options       show timer information
 -e, --extended      show detailed socket information
 -m, --memory        show socket memory usage
 -p, --processes      show process using socket
 -i, --info           show internal TCP information
 -s, --summary        show socket usage summary
 
 -4, --ipv4          display only IP version 4 sockets
 -6, --ipv6          display only IP version 6 sockets
 -0, --packet display PACKET sockets
 -t, --tcp            display only TCP sockets
 -u, --udp            display only UDP sockets
 -d, --dccp           display only DCCP sockets
 -w, --raw            display only RAW sockets
 -x, --unix           display only Unix domain sockets
 -f, --family=FAMILY display sockets of type FAMILY  
    
                    
                
                
            
        
浙公网安备 33010602011771号