rsync 服务端和客户端 简单配置

 

环境:Centos 6.9安全

两台服务器,A(192.168.223.129) 和 B(192.168.223.130)。A 做为服务端,B做为客户端从A服务器同步目录。把A的/usr/src 目录下的内容同步到B的/rsync/ 目录。服务器

首先配置下epel 源:tcp

rpm -ivh https://mirrors.ustc.edu.cn/epel/epel-release-latest-6.noarch.rpm测试

全都先安装下rsync:ui

yum install rsyncspa

而后,A 先建立/etc/rsyncd.conf 配置文件(默认没有),内容以下:3d

uid = nobody
gid = nobody
#hosts allow = *
hosts allow = 192.168.223.130
use chroot = no
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log

[tools]
path = /usr/src
list = no
comment = Rsync share test
auth users = haha #同步的帐户
secrets file = /etc/rsync_users
exclude = blank.png ; spinner.gif ; WEB-INF #同步时排除哪些文件和目录
read only = false
timeout = 300

echo "haha:1234567" >/etc/rsync_users #配置同步须要的用户和密码code

chmod 600 /etc/rsync_users  #必需要修改权限,否则会报错blog

开启服务端:进程

rsync --daemon --config=/etc/rsyncd.conf

会已守护进程的方式后台运行。

能够把这句写到/etc/rc.local 中,开机启动。

rsync 监听端口是873,说明服务端已经配置好了。

接下来是B服务器客户端:

客户端不用配置配置文件,直接能够从服务端同步目录,命令以下:

/usr/bin/rsync -avzP --delete --password-file=/etc/rsync.pass haha@192.168.223.129::tools /rsync/

 

注意:客户端要生成/etc/rsync.pass 这个密码文件(路径随意),内容是同步帐号的密码,即:echo "1234567" >/etc/rsync.pass, 而且权限要是600,否则会报错。

 

如图,从A 服务器同步过来两个文件夹和一个文件。

 

问题:

一、通常防火墙都是默认开启的,能够用 iptables -I INPUT -p tcp --dport 873 -j ACCEPT 命令开放本机873端口,而且经过命令 /etc/init.d/iptables save 保存防火墙配置。也能够暂时经过 /etc/init.d/iptables stop 关闭防火墙,或永久关闭 chkconfig iptables off(重启后也不会开启,除非/etc/init.d/iptables start 开启)

二、确保客户端的/etc/rsync.pass 和服务端的 /etc/rsync_users 文件权限都是600.

三、肯定/etc/rsync_users 中配置的帐户和/etc/rsyncd.conf 中配置的auth users= 的值 还有客户端同步命令中的帐户名相同。

四、经测试,/etc/rsync_users 中配置的帐户和密码都是虚拟的,不用真实在服务器上建立帐号和密码,但为了安全,还请设置复杂一点。

相关文章
相关标签/搜索