Centos7 安装配置rsync

rsync下载 https://download.samba.org/pub/rsync/

服务器端(源服务器)

1、安装rsync

[root@192 /]# tar -zxf  rsync-3.1.3.tar.gz

[root@192 /]# cd rsync-3.1.3

[root@192 /]# yum -y install rsync
2、查看配置文件位置:
[root@192 /]# rpm -qc rsync
/etc/rsyncd.conf
/etc/sysconfig/rsyncd
3、配置rsync
[root@192 etc]# vi /etc/rsyncd.conf

[root@192 log]# cat /etc/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 = root         #设置运行rsync进程的用户
 gid = root
 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  #传输时候不压缩的文件
log file = /var/log/rsync.log #日志文件
[www] #模块名
      read only = no
      path = /var/www #服务器端同步文件路径
      comment = WWW pages #描述
      auth users = baker  #用户名,不是Linux用户,只是服务器端和客户端进行通信的用户,随便设置
      secrets file = /etc/rsyncd.pass #密码存储文件



4、设置密码
[root@192 etc]# echo "baker:liuhaitao" > /etc/rsyncd.pass
5、修改密码文件的权限(只能是600)
[root@192 etc]# chmod 600  /etc/rsyncd.pass
6、重启rsync服务
[root@192 etc]# systemctl restart rsyncd.service
7、查看是否已经监听873端口
[root@192 etc]# netstat -lntp


---------------------------------------------------------------------------------


客户端(备份服务器)
1、安装
[root@192 ~]# yum install rsync
2、设置密码(和服务器端不同,客户端直接填写密码就可以了)
[root@192 ~]# vi /etc/rsyncd.pass
liuhaitao
3、设置密码文件权限
chmod 600 /etc/rsyncd.pass
4、创建备份文件存放路径
[root@192 home]# mkdir /home/www




将服务器www模块下要本分的文件同步到本地/home/www目录下
[root@192 www]# rsync -auv --password-file=/etc/rsyncd.pass [email protected]::www /home/www


遇到错误:
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [Receiver=3.0.9]


(服务器端和客户端)需要安装
yum install -y openssh-clients


遇到错误:
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(764) [Receiver=3.0.9]


问题是因为服务器端,873端口被占用,直接killall rsync 后启动正常


遇到问题
rsync: opendir "/." (in www) failed: Permission denied (13
解决
关闭SELinux
setenforce 0 


[root@192 www]# rsync -auv --password-file=/etc/rsyncd.pass [email protected]::www /home/www
成功备份


---------------------------------------------------------------------------------------------------












问题:linux下Rsync 服务器启动错误-->failed to create pid file /var/run/rsyncd.pid: File exists


解决方案:rm -rf /var/run/rsyncd.pid;再重新启动Rsync服务(rsync --daemon)








参考资料
http://blog.csdn.net/q290994/article/details/78079991?foxhandler=RssReadRenderProcessHandler
http://blog.csdn.net/peisl/article/details/6931088
http://blog.csdn.net/q290994/article/details/78079991?foxhandler=RssReadRenderProcessHandler
https://www.linuxidc.com/Linux/2016-04/130609.htm
https://www.linuxidc.com/Linux/2017-06/144757.htm
http://www.jb51.net/article/41417.htm
http://blog.csdn.net/baiwz/article/details/32339049
http://blog.csdn.net/u013378306/article/details/52064730


https://rsync.samba.org/documentation.html


你可能感兴趣的:(Linux)