配置 Rsync 服务器,模拟真实环境服务器数据同步。
A 是源服务器,B、C 为客户端服务器,因需求,B、C 服务器需
要从 A 某个同步某个目录到本地。
正式安装,官网下载 rsync 稳定版本,然后进行安装编译。
cd /usr/src ;wget
http://rsync.samba.org/ftp/rsync/src/rsync-3.0.7.tar.gz
tar xzf rsync-3.0.7.tar.gz && cd rsync-3.0.7 && ./configure --
prefix=/usr/local/rsync &&make &&make install
安装完毕,配置 rsync 配置文件,默认/etc/不存在 rsyncd.conf 配
置文件,需要手动创建,配置内容为如下:cat rsyncd.conf
###[global] 全局配置
uid = nobody
gid = nobodyuse chroot = no
max connections = 30
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
[www]
read only = yes
path = /usr/local/webapps
comment = www
auth users =test
secrets file = /etc/rsync.pas
hosts allow = 192.168.0.11,192.168.0.12
[web]
read only = yes
path = /data/www/web
comment = webauth users =test
secrets file = /etc/rsync.pas
hosts allow = 192.168.1.11,192.168.0.0/24Rsync 配置参数说明:
[www] #要同步的模块名
path = /usr/local/webapps #要同步的目录
comment = www #这个名名称无所谓,最后模块名一直)
read only = no # no 客户端可上传文件,yes 只读
write only = no # no 客户端可下载文件,yes 不能下载
list = yes #是否提供资源列表
auth users =test #登陆系统使用的用户名,没有默认为匿名。
hosts allow = 192.168.0.10,192.168.0.20 #本模块允许通过的 IP
地址
hosts deny = 192.168.1.4 #禁止主机 IP
secrets file=/etc/rsync.pas #密码文件存放的位置
启动服务器端 RSYNC 主进程, /usr/local/rsync/bin/rsync
--daemon ,监听端口 TCP 873
设置 rsync 服务器端同步密钥:
vi /etc/rsync.pas
username:userpasswd (表示用户名:密码)test:test999
保存完毕,chmod 600 /etc/rsync.pas 设置权限为宿主用户读写。
最后在客户端配置同步密钥和命令,如下设置即可同步。
vi /etc/rsync.pas 输入服务器端配置的密码:
test999
保存即可开始同步:执行如下语句
Rsync -aP --delete test@192.168.0.100::www /usr/local/webapps
--password-file=/etc/rsync.pas
Rsync -aP --delete test@192.168.0.100::web /data/www/web
--password-file=/etc/rsync.pas
注*/usr/local/webapps 为客户端的目录,@前 test 是认证的用户名;
IP 后面 www 为 rsync 服务器端的模块名称。
Rsync 常用参数解析: