rsync 服务端启动与基础配置
rsync 守护进程存在两种主要的服务端启动模式
1.daemon 2.xinetd inetd
服务成功启动后,将监听并绑定在 TCP 协议的 873 端口上
查看 xinetd 下的 rsync 配置文件:cat /etc/xinetd.d/rsync
# 默认关闭状态
# 描述信息:rsync 服务器是 FTP 服务器的良好补充,因为它 \
# 支持 CRC 校验和等功能。
service rsync
{disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}配置注意事项:务必正确设置文件的读写权限及属主归属
查看主配置文件内容:cat /etc/rsyncd.conf
motd file = /var/log/rsync/welcome.msg
pid file = /var/log/rsync/rsyncd.pid
lock file = /var/log/rsync/rsync.lock
log file = /var/log/rsync/rsyncd.log
[rsyncwww]
comment = rsync www
path = /var/www/
use chroot = no
max connections = 4
read only = false
list = true
uid = nobody
gid = nobody
auth users = wwwuser
secrets file = /etc/rsyncd.secrets
hosts allow = 1.1.1.1,2.2.2.2
hosts deny = 0.0.0.0/0
ignore errors = yes
transfer logging = yes
log format = "%a %f %l"
#log format = "%o %h [%a] %m (%u) %f %l"
[rsyncroot]
comment = rsync root
path = /
use chroot = no
max connections = 4
read only = true
#read only = false
list = true
uid = root
gid = root
auth users = rootuser
secrets file = /etc/rsyncd.secrets
hosts allow = 1.1.1.1,2.2.2.2
hosts deny = 0.0.0.0/0
ignore errors = yes
transfer logging = yes
log format = "%a %f %l"
rsyncd.secrets 文件每行一个用户,格式为 用户名:密码
基本用法说明
rsync -auvPz --progress dir1 dir2
rsync -ztruvoglpD --progress dir1 dir2
rsync -ztruvoglpD --progress dir1/ dir2
rsync -ztruvoglpD --progress dir1/file1 dir2
若需排除某些目录或文件,可添加 --exclude 参数进行设置
远程连接使用方法
rsync 1.1.1.1:: 仅列出可用模块列表
rsync user@1.1.1.1::
rsync user@1.1.1.1::module
rsync user@1.1.1.1::module/path
若未配置独立的 rsync 服务器,可通过 SSH 协议方式使用
rsync -e ssh -auvPz 1.1.1.1:/etc ./
同步时需注意源路径末尾斜杠 / 的影响
若不包含 /,则会将整个目录名(如 mirror)也包含在内
若包含 /,则仅同步该目录内部的内容到目标位置
rsync -ztruvoglp --progress user@1.1.1.1::module/path ./
为方便脚本调用,可使用 --password-file 参数,同样需注意属主权限
也可设置环境变量 RSYNC_PASSWORD 来访问需要用户认证的 rsync 服务