环境:CentOS 5.2 (两台)
rsync服务器IP:192.168.1.114
客户端IP:192.168.1.115
1、安装rsync,并通过xinetd管理rsync
yum install rsync xinetd
2、修改/etc/xinetd.d/rsync文件,使其随xinetd启动而启动
vim /etc/xinetd.d/rsync
将disable = yes 修改为 disable = no
3、防火墙设置(rsync默认端口 837)
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
Service iptables restart
4.创建rsync需要的文件
mkdir /etc/rsyncd
touch
touch
touch
ln /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf
chmod 600 /etc/rsyncd.secrets
chown root:root /etc/rsyncd.secrets
5.修改主配置文件
vi /etc/rsyncd/rsyncd.conf
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
port = 873
address = 192.168.1.114
uid = root
gid = root
use chroot = yes
read only = yes
#limit access to private LANs
hosts allow=192.168.1.0/255.255.255.0
hosts deny=*
max connections = 5
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
[backup]
path = /home
list=yes
ignore errors
auth users = cs
secrets file = /etc/rsyncd/rsyncd.secrets
6.修改rsyncd.secrets 和rsyncd.motd 文件
vi /etc/rsyncd/rsyncd.secrets
cs:123456
vi /etc/rsyncd/rsyncd.motd
++++++++++++++++++++++++++++++++
Welcome
++++++++++++++++++++++++++++++++
7.重启服务
service xinetd restart
客户端同步测试(客户端要安装rsync)
rsync –avzP cs@192.168.1.114::backup
意思就是用cs用户登录服务器,将backup指定的目录数据保存到我本地/var/local
测试并不是一帆风顺,遇到些问题,可看参考链接。
客户机完全同步服务器
- touch rsync.password
(创建一个存放密码的文件) - chmod 600 rsync.password
- echo "123456"> rsync.password
(写入密码) - rsync -avzP
--delete --password-file=rsync.password cs@192.168.1.114::backup /var/local