同步大文件,10G这样的大文件有时也会出问题,终端,未完整同步完时,会变成一个隐藏文件,可以通过断点续传等参数实现传输 。一次性远程拷贝可以用scp
Rsync备份实战 配置rsync服务端步骤 1,配置服务器,查看当前rsync安装包和版本号 rsync --version rsync-3.0.6-12.el6.x86_64 2,vim /etc/rsyncd.conf 添加配置文件rsync配置文件官网:https://rsync.samba.org/ftp/rsync/rsyncd.conf.html
#配置文件详解,更多参数查看man rsyncd.conf #Rsync server #created by hejian 19:50 2019-3-17 ##rsyncd.conf start## uid = rsync //客户端具备的权限(不存在,需要创建) gid = rsync use chroot = no //安全相关 max connections = 2000 //客户端连接数 timeout = 600 //超时 pid file = /var/run/rsyncd.pid #进程ID文件 lock file = /var/run/rsync.lock #锁文件 log file = /var/log/rsyncd.log #日志文件 ignore errors #忽略错误 read only = false #可读写 list = false #不可以远程列表 hosts allow = 192.168.105.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup //虚拟用户 secrets file = /etc/rsync.password //存放用户账号密码的文件 ##################################### [backup] //模块调用 #comment = backup by hejian 19:50 2019-3-17 path = /backup //共享目录 [hejian] path = /hejian 3,创建rsync用户及共享目录/backup,并给目录赋予权限 useradd rsync -s /sbin/nologin -M id rsync mkdir /backup chown -R rsync.rsync /backup/ 4,创建密码文件 echo "rsync_backup:123" > /etc/rsync.password chmod 600 /etc/rsync.password 5,启动rsync服务并查看 rsync --daemon lsof -i :873 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsync 1647 root 3u IPv4 12479 0t0 TCP *:rsync (LISTEN) rsync 1647 root 5u IPv6 12480 0t0 TCP *:rsync (LISTEN) netstat -tunlp|grep rsync tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 1647/rsync tcp 0 0 :::873 :::* LISTEN 1647/rsync ss -tunlp|grep rsync tcp LISTEN 0 5 :::873 :::* users:(("rsync",1647,5)) tcp LISTEN 0 5 *:873 *:* users:(("rsync",1647,3)) ps -ef|grep rsync root 1647 1 0 20:11 ? 00:00:00 rsync --daemon root 1660 1505 0 20:12 pts/0 00:00:00 grep --color=auto rsync 6,加入开机自启动 echo "rsync --daemon" >>/etc/rc.local cat /etc/rc.local rsync客户端配置步骤 1,创建密码文件,并修改权限 echo "123" > /etc/rsync.password (与服务端密码保持一致,免密登陆) chmod 600 /etc/rsync.password(与服务端密码权限保持一致) ll /etc/rsync.password 2,发送文件rsync(push或pull都是从客户端来操作) (push)rsync -avz /backup/ rsync_backup@10.0.0.41::backup/ --password-file=http://www.likecs.com/etc/rsync.password (pull)rsync -avz rsync://rsync_backup@10.0.0.41:873/backup/ /backup/ --password-file=http://www.likecs.com/etc/rsync.password echo $? = 0 就代表程序运行是正确的 排除推送 rsync -avz --exclude=a /root/test/ rsync_backup@10.0.0.41::backup/ --password-file=http://www.likecs.com/etc/rsync.password 排错 #Rsync server #created by hejian 19:50 2019-3-17 ##rsyncd.conf start## uid = rsync gid = rsync use chroot = no max connections = 2000 timeout = 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.0.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup secrets file = /etc/rsync.password ##################################### [backup] comment = backup by hejian 19:50 2019-3-17 path = /backup虚拟机快照
rsync实战测试准备环境,修改IP,修改主机名,修改主题参数颜色,备份主要配置文件等
客户端报错
报错一: [root@lamp01:/tmp]# rsync -avz /tmp/ raync_backup@192.168.105.136::backup --password-file=rsync.password rsync: failed to connect to 192.168.105.136: No route to host (113) rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]排错:服务端防火墙开启了
报错二: [root@lamp01:/tmp]# rsync -avz /tmp/ raync_backup@192.168.105.136::backup --password-file=rsync.password rsync: could not open password file "rsync.password": No such file or directory (2) Password: @ERROR: auth failed on module backup rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]第一个错误是路径写错了--password-file=http://www.likecs.com/etc/rsync.password
第二个错误是服务端密码文件和客户端写反了,服务端写账号和密码,客户端只写密码;还有服务端的passwod文件都是root,backup文件用户是rsync;还有一个问题是拼错了一个单词导致一直验证失败