实验需求:在服务器(192.168.100.1)端搭建rsync服务,将/usr/src目录同步到客户端/rsync目录

一.服务器配置

1.开启服务

#vim /etc/xinetd.d/rsync

……

   disable = no                   //把disable = yes改成no    

……

或者执行以下命令也能开启服务

# chkconfig rsync on

#service xinetd start


2.建立rsync账号文件

# vim /etc/rsync_users

 ruser:123456

# chmod 600 /etc/rsync_users           //修改权限


3.创建rsync主配置文件

# vim /etc/rsyncd.conf              //默认不存在

uid = nobody

gid = nobody

use chroot = yes

pid file = /var/run/rsyncd.pid

log file = /var/log/rsyncd.log


[tools]

path = /usr/src

comment = Rsync share test

auth users = ruser

secrets file = /etc/rsync_user

read only = yes


4.重启xinetd服务

# service xinetd restart


二.客户端配置

1.创建测试目录

# mkdir /rsync


2.同步rsync共享目录

# rsync ruser@192.168.100.1::tools    //浏览共享

# vim /root/rsync_pass                   //设定密码文件

  123456                                //只需写登录用户密码,要与服务器端设置密码一致

# chmod 600 /root/rsync_pass             //不修改权限会报错

# rsync -az --password-file=/root/rsync_pass ruser@192.168.100.1::tools /rsync  //同步



3.将rsync放入crontab计划任务,每天同步一次

#crontab -e
0 5 * * * /usr/bin/rsync -a --password-file=/root/rsync_pass ruser@192.168.100.1::tools /rsync