【问题标题】:rsync'ing files between two remote servers, get errors stating rsync command not found on remote serverrsync'ing 两个远程服务器之间的文件,得到错误说明远程服务器上找不到 rsync 命令
【发布时间】:2010-10-18 10:30:07
【问题描述】:

我正在尝试使用

在两台服务器之间同步文件
rsync -avlzp /source user@server:/destination

但是我得到错误说明

bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(635) [sender=3.0.2]

但 rsync 安装在两台服务器上。我究竟做错了什么?我也试过了

rsync -av -e "ssh -l ssh-user" /source server:/destination

结果相同。

我主要是尝试使用 rsync,以便它只复制存在差异的差异......

谢谢

【问题讨论】:

    标签: rsync


    【解决方案1】:

    关于这个问题有很多很好的信息,包括上面的答案。但就我而言,我是源机器和目标机器的管理员,我希望了解发生了什么以及哪些“正确”的配置选项可以解决这个问题。我还没有完全成功,但其他人似乎可能会发现此信息有用。

    正如上面的回答所说,当运行交互式 shell 时,rsync 可能位于远程机器上的路径中,但在通过 ssh 运行 rsync 时不会。正如 Siddesh 在http://siddesh-bg.blogspot.com/2009/02/rsync-command-not-found-error-even.html 中指出的那样,这可以通过从本地 shell 显式指定远程 rsync 的路径来解决:

    rsync -av --rsync-path=/usr/local/bin/rsync -e "ssh -l ssh-user" /source server:/destination
    

    但作为管理员,我想解决问题,而不仅仅是解决问题。 OldSchool 在https://groups.google.com/group/comp.unix.solaris/browse_thread/thread/0a06a4d382d752d8?pli=1

    上发布了一个有用的故障排除方法

    他建议你找出远程机器上正在为你运行的 shell,然后在那里建立了什么 PATH:

    ssh user@host 'echo $SHELL' 
    ssh user@host 'echo $PATH' 
    

    Tom Feiner 在Why does an SSH remote command get fewer environment variables then when run manually? 有一篇很好的帖子,讨论了 SSH 命令执行 shell 的环境建立。

    OldSchool 还指出,“man sshd_config”提供了一些关于 ssh 会话如何获取环境的信息。 sshd_config 设置“PermitUserEnvironment”可以设置为允许用户在服务器端的 ~/.ssh/environment 和 AuthorizedKeysFile 文件中的环境选项由 sshd 处理。默认为否。

    因此,使用默认 sshd_config 设置,路径将由您的默认 shell 构建。如果您的 ssh 命令请求交互式会话 (ssh user@host),那么在远程服务器上,默认 shell 将执行交互式登录,这可能会导致您期望的 PATH。但是,如果您正在为 rsync (rsync -av --rsync-path=/usr/local/bin/rsync -e "ssh -l ssh-user" /source server:/destination) 启动 ssh 会话,那么远程服务器会给出你是一个 SSH 命令执行 shell,它是一个非交互式 shell。在我的例子中,远程非交互式 shell (bash) 没有执行 /etc/profile,因为它只对交互式 shell 或带有 --login 选项的非交互式 shell 执行此操作。我可以这样强制:

    ssh user@host 'echo $PATH;source /etc/profile;echo $PATH' 
    

    我还研究了 Daniel Barrett 和 Richard Silverman 的“SSH The Secure Shell”(O'Reilly 2001),并在 /etc/ssh/sshrc 中设置了一个路径,我希望它可以使 rsync 可用于 SSH 命令执行 shell,但是,/ etc/ssh/sshrc 在调用用户 shell 或命令之前执行,显然它的环境没有传递给该 shell 或命令。

    此时我会对 rsync 命令行选项感到满意,即:

    rsync -av --rsync-path=/usr/local/bin/rsync -e "ssh -l ssh-user" /source server:/destination
    

    因为我担心如果我更改 sshd_config 设置“PermitUserEnvironment”,那么我的服务器上的安全审核可能会失败。在我对我们组织的安全审计有了更多经验之后,我可能会重新审视这个问题。

    【讨论】:

      【解决方案2】:

      当运行交互式 shell 时,rsync 可能在远程机器上的路径中,但在通过 ssh(使用非交互式 shell)运行 rsync 时不会。例如,.bashrc 通常只为交互式 shell 运行,因此如果在此处定义了路径,则在远程端运行 rsync --server 时将不会对其进行解析。试试 /etc/profile。详情请见bash(1)

      您可以使用--rsync-path 指定远程机器上rsync 二进制文件的路径。

      【讨论】:

      • 谢谢。使用 --rsync-path 让这对我有用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      相关资源
      最近更新 更多