配置rsync服务端及2台机器配置文件同步(Linux 实测通过)

(后面列一下我们用的sersync,使用sersync 大概628G 大小不一的图片文件及文件夹,15个同步工作组线程,同步了13个小时,io 大概13到15  MB/s,大概1G一分钟。刚开始10个同步工作组线程,速度很慢,增加了5个同步工作组线程,速度快了一倍,所以如果是20个工作组线程7个小时应该能同步完) 

原文链接  http://wenku.baidu.com/link?url=33U36GbrgvXv9__m2E5PKPDHKGvdtt2RL7V6t5bPvpETurxyt2iJ1X4I1fuE-rh59ls00ojGDnSFy_cBWYc-P5W1l2eYCHy5TNlUF6xqhk3  (居然在百度找到一个靠谱的文章,很意外)


环境 Centos6.5 系统机器2台:服务器192.168.191.140,客户机:192.168.191.128 
1. 先关闭2台机器的防火墙: /etc/init.d/iptables stop 

2台机器安装rsync软件包:   

有两种 安装方式 第一种 yum 安装 yum install rsync -y 安装好直接启动

第二种  从原始网站下载源码安装:http://rsync.samba.org/ftp/rsync/ 

[root@localhost bin]#./configure 
[root@localhost bin]#make  
[root@localhost bin]#make install  
2.  服务器端操作  
rsync安装时没有提供一个配置文件模板,需要自己手动创建,名称为rsyncd.conf。
配置文件文件分为两部分,全局参数和模块参数。  
A.服务器端机器新建文件:vi /etc/rsyncd.conf 
添加以下内容 
#[global]全局配置 
uid = root 
gid = root  
max connections = 15 
transfer logging = true 
log format = %h %o %f %l %b 
log file = /var/log/rsyncd.log 
pid file = /var/run/rsyncd.pid 
lock file = /var/run/rsyncd.lock slp 
refresh = 300   
#客户端连接模块配置 
[rsynczgp] 
path = /rsyncdir 
comment = zgprsync 
read only = no 
auth users = root  
secrets file = /etc/rsync.ser.pass 
# rsynczgp 是客户机链接的模块名称,你可以配置多个模块链接到不同客户端 
#path 要把文件同步到服务端哪个目录上 #/etc/rsync.ser.pass  
客户机链接的账号密码
B.创建服务端文件夹:mkdir /rsyncdir  
C.新建文件vi /etc/rsync.ser.pass添加以下内容, 
是客户机链接的账号密码格式:用户名:密码  
例如:root:zgp66dashun 
D.修改 权限  chmod 600 /etc/rsync.ser.pass  
(不修改客户端会报错:@ERROR: auth failed on module rsynczgp  rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]) 
E.启动服务器端程序 rsync --daemon  
F.查看服务器端是否启动成功 
lsof -i:873 
如下:  
[root@localhost etc]# lsof -i:873  
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME  
rsync   25364 root    3u  IPv4  55277      0t0  TCP *:rsync (LISTEN) 
rsync   25364 root    5u  IPv6  55278      0t0  TCP *:rsync (LISTEN) 
至此,服务端配置完成。  
##########################分隔符##########################  
3.  以下是客户机上操作配置  
A、新建上传下载目录 : mkdir /rsyncud  
B、在目录下/ rsyncud   创建任意文件:touch 123456.txt  
C、创建客户端密码保存文件vi /etc/rsync.client.pass添加内容格式:  passwd  (服务端为root:passwd,客户端仅需要passwd)文件内容要和服务器端的配置密码一致,本例为:zgp66dashun  
D、更改密码文件/etc/rsync.client.pass权限为600 chmod 600 /etc/rsync.client.pass (不更改报错:  password file must not be other-accessible continuing without password file)       
E、同步客户端/rsyncud/下文件到 服务器端(IP:192.168.191.140)  
rsync -avz --delete /rsyncud/ [email protected]::rsynczgp --password-file=/etc/rsync.client.pass 
如下:  
[root@localhost rsyncud]# rsync -avz --delete /rsyncud/ [email protected]::rsynczgp --password-file=/etc/rsync.client.pass  
sending incremental file list 
./ 
123456.txt   
sent 13590 bytes  received 30 bytes  27240.00 bytes/sec 
total size is 68636  speedup is 5.04  
F、从服务器端/rsyncdir目录同步文件到客户端的/rsyncud/目录下: 
 rsync -avz --delete [email protected]::rsynczgp /rsyncud --password-file=/etc/rsync.client.pass   
receiving incremental file list 
./ 
123456.txt   


sent 80 bytes  received 13658 bytes  27476.00 bytes/sec 
total size is 68636  speedup is 5.00 
[root@localhost rsyncud]# ls /rsyncud/ 123456.txt   
##########################分隔符##########################  
4.  修改rsync配置后服务器端需要重启: 




Killall rsync
rsync –daemon   
lsof –i:873 5.  
客户端写脚本运行持续更新
vi /root/rsync.job
输入  rsync -avz --delete /rsyncud/ [email protected]::rsynczgp --password-file=/etc/ rsync.client.pass     
将脚本加入crontab  crontab –e  * * * * * /bin/sh /root/rsync.job

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章