环境: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 /etc/rsyncd/rsyncd.conf (主配置文件)
touch /etc/rsyncd/secrets (验证用户和密码存放地)
touch /etc/rsyncd/rsyncd.motd (服务器描述信息)
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 (设置服务器IP地址)
uid = root (服务器传输文件时用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 (忽略IO错误)
auth users = cs (验证用户,我的用户是cs)
secrets file = /etc/rsyncd/rsyncd.secrets (指向验证用户存放文件)
6.修改rsyncd.secrets 和rsyncd.motd 文件
vi /etc/rsyncd/rsyncd.secrets
cs:123456 (cs就存在的系统用户,但密码最好设为跟系统密码不一样)
vi /etc/rsyncd/rsyncd.motd
++++++++++++++++++++++++++++++++
Welcome
++++++++++++++++++++++++++++++++
7.重启服务
service xinetd restart
客户端同步测试(客户端要安装rsync)
rsync –avzP [email protected]::backup /var/local
意思就是用cs用户登录服务器,将backup指定的目录数据保存到我本地/var/local
测试并不是一帆风顺,遇到些问题,可看参考链接。
客户机完全同步服务器