Rsync保持两服务器数据一致

上次数据通过NFS拷贝过去后,只是实验一下,还没有真正迁移,现在两边数据又有不一样的;这次准备用rhel本身的rsync服务保持数据同步
服务端配置
1,发现原系统已安装rsync,就直接利用
#rpm -qa | grep rsync
rsync-2.5.7-5.3E
#ls /etc/xinetd.d/rsync
/etc/xinetd.d/rsync
2,主要是更改rsyncd.conf和 rsync这两个文件
#mkdir /etc/rsyncd
#cd /etc/rsyncd
#ls
rsyncd.conf #主配置文件
rsyncd.motd #banner消息
rsyncd.secrets #里面的内容用户名:密码
3,#cat rsyncd.conf
pid file = /var/run/rsyncd.pid
port = 873
address = 服务器IP
uid = root
gid = root
use chroot = yes
read only = yes
max connections = 5
motd file = /etc/rsyncd/rsyncd.motd
log file = /var/log/rsync.log
[home]
path = /home
list = yes
ignore errors
auth users = root
hosts allow = 客户端IP
secrets file = /etc/rsyncd/rsyncd.secrets
strict modes = yes
[home2]
path = /home2
list = yes
ignore errors
auth users = root
hosts allow = 客户端IP
secrets file = /etc/rsyncd/rsyncd.secrets
strict modes = yes
[home3]
path = /home3
list = yes
ignore errors
auth users = root
hosts allow = 客户端IP
secrets file = /etc/rsyncd/rsyncd.secrets
strict modes = yes
[cvs]
path = /cvs
list = yes
ignore errors
auth users = root
hosts allow = 客户端IP
secrets file = /etc/rsyncd/rsyncd.secrets
strict modes = yes
#
4,#cat /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no #开
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon --config=/etc/rsyncd/rsyncd.conf #主配置文件的位置
log_on_failure += USERID
}
# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
# netstat -tulpn | grep :873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 26323/xinetd
客户端配置
1,# rpm -qa | grep rsync
rsync-3.0.6-4.el5_7.1
2,#直接用命令复制
rsync -avz --progress --delete root@服务端IP::home /home --password-file=/etc/rsyncd.secrets
rsync -avz --progress --delete root@服务端IP::home2 /home2 --password-file=/etc/rsyncd.secrets
rsync -avz --progress --delete root@服务端IP::home3 /home3 --password-file=/etc/rsyncd.secrets
rsync -avz --progress --delete root@服务端IP::cvs /cvs --password-file=/etc/rsyncd.secrets
客户端的rsyncd.secrets文件里只要写上密码即可
其中-a 代表rlptgoD,其实就是保证目录及文件的权限,修改时间,属主,组等一致
--progress 查看进程
--delete 客户端内容和服务的一致,当服务端有删除时,客户端也要删除
另外由于strict modes 开了,rsyncd.secrets文件权限要设置成600