753 views
Liunx-服务安装

Rsync配置安装

服务端:192.168.77.74 客户端:192.168.77.73

一、安装(如果系统有自带rsync命令,客户端可以不用装)

[code]

cd /usr/local/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

[/code]

二、配置(服务端)

安装完毕,配置rsync配置文件,如果/etc/rsyncd.conf不存在,则自己创建一个rsyncd.conf配置文件,配置内容为如下

cat /etc/rsyncd.conf

[code]

#########[global] 全局配置

uid = nobody

gid = nobody

use 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 = /www    #同步路径

secrets file = /etc/rsync.pas #密码存放路径

hosts allow = 192.168.77.0/24 #允许的IP

[/code]

三、设置rsync服务器端同步密钥

vim /etc/rsync.pas (服务端)

#username:userpasswd (表示用户名:密码)

[code]ying:123456[/code]

chmod 600 /etc/rsync.pas设置权限为宿主用户读写

vi /etc/rsync.pas 输入服务器端配置的密码:(客户端)

123456

四、启动(服务端)

启动服务器端Rsync主进程,/usr/local/rsync/bin/rsync –daemon ,默认监听端口TCP 873

五、使用(客户端)

这条命令一般再crontab里面写上,定时同步即可

[code]Rsync -aP –delete ying@192.168.77.74::www /usr/local/webapps –password-file=/etc/rsync.pas[/code]

注*/usr/local/webapps为客户端的目录,@前test是认证的用户名;IP后面www为rsync服务器端的模块名称。

六、Rsync 常用参数解析

[code]

-a, –archive    归档模式,表示以递归方式传输文件,并保持所有文件属性。

–exclude=PATTERN    指定排除一个不需要传输的文件匹配模式

–exclude-from=FILE    从 FILE 中读取排除规则

–include=PATTERN    指定需要传输的文件匹配模式

–delete    删除那些接收端还有而发送端已经不存在的文件

-P    等价于 ––partial ––progress

-v, –verbose    详细输出模式

-q, –quiet    精简输出模式

–rsyncpath=PROGRAM    指定远程服务器上的 rsync 命令所在路径

–password-file=FILE    从 FILE 中读取口令,以避免在终端上输入口令,

通常在 cron 中连接 rsync 服务器时使用

[/code]

Leave a Reply

影子专属博客 赣ICP备17013143号