
一、服务端操作
1、安装rsync
yum install rsync
2、配置rsyncd
vim /etc/rsyncd.conf uid = root #指定运行该服务的权限 gid = root log file = /var/log/rsyncd.log #指定日志文件 [mag_sync] #定义同步项目名 可以定义多个同步项目 path = /usr/local/apps/www/magazine/file #指定源路径 read only = no #是否只读 auth users = mag_sync #该同步项目的认证用户名 secrets file = /etc/rsync.pas #该同步项目的密码文件 log file=/var/log/rsync.log pid file=/var/run/rsyncd.pid uid=heat gid=heat [wenjian] path=/duizhang use chroot=no max connections=50 read only=no list=true ignore errors timeout = 600 hosts allow=192.168.1.0/24 secrets file = /etc/rsync.pas
3、新增密码文件配置
vim /etc/rsync.pas heat:123456 heat为用户名 123456为密码
4、设置密码文件权限
chmod +600 /etc/rsync.pas
5、控制
启动rsyncd service rsyncd start 重启 service rsyncd restart
6、加入自启动
systemctl enable rsyncd
二、客户端操作
1、安装rsync
yum install rsync
2、配置密码文件
vim /etc/rsync.pas 123456
3、设置密码文件权限
chmod +600 /etc/rsync.pas
4、新建同步文件夹
mkdir /duizhang
5、设置定时任务
crontab -e 输入如下内容: */2 * * * * rsync -av wenjian@192.168.1.25::wenjian /duizhang/ --password-file=/etc/rsync.pas
*/2 * * * * 表示每2分钟进行一次后面的命令
rsync -av wenjian@192.168.1.25::wenjian /duizhang/ –password-file=/etc/rsync.pas
表示到用wenjian账户登录到192.168.1.25,通过密码进行同步