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

 

环境:Centos 6.9

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

首先配置下epel 源:

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

全都先安装下rsync:

yum install rsync

然后,A 先创建/etc/rsyncd.conf 配置文件(默认没有),内容如下:

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 #配置同步需要的用户和密码

chmod 600 /etc/rsync_users  #必须要修改权限,不然会报错

开启服务端:

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 服务器同步过来两个文件夹和一个文件。

 

问题:

1、一般防火墙都是默认开启的,可以用 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 开启)

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

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

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

 

posted @ 2017-05-08 21:15  我是地瓜  阅读(1284)  评论(0编辑  收藏  举报
AmazingCounters.com