保证一个机器的文件内容与主服务器内目录的文件内容自动同步
- 安装(xinetd 与rsync)
- chkconfig rsync on 与 service xinetd restart
- 配置文件 rsyncd.conf
配置文件 rsyncd.conf 默认在 /etc 目录下。为了将所有与 rsync 服务相关的文件放在单独的目录下,可以执行如下命令:
mkdir /etc/rsyncd
touch /etc/rsyncd/rsyncd.conf
ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf
4.编辑vi /etc/rsyncd/rsyncd.conf
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
# GLOBAL OPTIONS
uid = root
gid = root
use chroot = no
read only = yes
#limit access to private LANs
hosts allow=172.16.0.0/255.255.0.0 192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
hosts deny=*
max connections = 5
pid file = /var/run/rsyncd.pid
secrets file = /etc/rsyncd/rsyncd.secrets
#lock file = /var/run/rsync.lock
motd file = /etc/rsyncd/rsyncd.motd
#This will give you a separate log file
log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
# MODULE OPTIONS
[davidhome]
path = /alidata/www/client
list=yes
ignore errors
auth users = david
comment = David home
exclude = important/
编辑hosts allow保证可以同步
编辑MODULE OPTIONS 确认同步目录正确
5.修改rsyncd.secrets文件
里面添加用户名密码
6.客户端使用方式
sudo rsync -avzP –delete david@ip::davidhome /var/www/client
还可以增加参数
–password-file=/tmp/rsync.password
# touch /tmp/rsync.password
# chmod 600 /tmp/rsync.password
# echo "asdf"> /tmp/rsync.password
# rsync -avzP --delete --password-file=/tmp/rsync.password david@172.16.1.135::davidhome /tmp/david/
可能会考虑rsync.password文件的所有者
7.设定定时任务
crontab -e
30 * * * * (sudo rsync -avzP –delete –password-file=/tmp/rsync.password david@120.26.113.130::davidhome /var/www/client)
半个小时执行一次