rsync "connection refused" 错误

rsync "connection refused" error

我对 rsync 很着迷,它给我一个 "connection refused" 错误。这是我的问题: 我有两台服务器,用于存储数据,安装了 rsync,因为我需要两台服务器保持同步。这样,在一个服务器上的修改将在另一台服务器上引起相同的修改,反之亦然。第一个节点 (sn1) 工作,而第二个 (sn2) 不工作。在细节上。 - sn1 有 192.168.13.131 作为 ip 地址 - sn2 的 IP 地址为 192.168.13.132

如果我从 sn1 或 sn2 给出 rsync rsync://192.168.13.131,它工作正常;而如果我从 sn1 或 sn2 给出 rsync rsync://182.168.13.132,我会得到这个错误:

rsync: failed to connect to 192.168.13.132 (192.168.13.132): Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(125) [Receiver=3.1.2]

这里有一些关于 sn2 的信息。 /etc/rsyncd.conf

uid = swift
gid = swift
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
address = 192.168.130.132

[account]
max connections = 20
path = /srv/node/
read only = False
lock file = /var/lock/account.lock

[container]
max connections = 20
path = /srv/node/
read only = False
lock file = /var/lock/container.lock

[object]
max connections = 20
path = /srv/node/
read only = False
lock file = /var/lock/object.lock

/etc/default/rsync

# defaults file for rsync daemon mode
#
# This file is only used for init.d based systems!
# If this system uses systemd, you can specify options etc. for rsync
# in daemon mode by copying /lib/systemd/system/rsync.service to
# /etc/systemd/system/rsync.service and modifying the copy; add required
# options to the ExecStart line.

# start rsync in daemon mode from init.d script?
#  only allowed values are "true", "false", and "inetd"
#  Use "inetd" if you want to start the rsyncd from inetd,
#  all this does is prevent the init.d script from printing a message
#  about not starting rsyncd (you still need to modify inetd's config yourself).
RSYNC_ENABLE=true

# which file should be used as the configuration file for rsync.
# This file is used instead of the default /etc/rsyncd.conf
# Warning: This option has no effect if the daemon is accessed
#          using a remote shell. When using a different file for
#          rsync you might want to symlink /etc/rsyncd.conf to
#          that file.
# RSYNC_CONFIG_FILE=

# what extra options to give rsync --daemon?
#  that excludes the --daemon; that's always done in the init.d script
#  Possibilities are:
#   --address=123.45.67.89              (bind to a specific IP address)
#   --port=8730                         (bind to specified port; default 873)
RSYNC_OPTS=''

# run rsyncd at a nice level?
#  the rsync daemon can impact performance due to much I/O and CPU usage,
#  so you may want to run it at a nicer priority than the default priority.
#  Allowed values are 0 - 19 inclusive; 10 is a reasonable value.
RSYNC_NICE=''

# run rsyncd with ionice?
#  "ionice" does for IO load what "nice" does for CPU load.
#  As rsync is often used for backups which aren't all that time-critical,
#  reducing the rsync IO priority will benefit the rest of the system.
#  See the manpage for ionice for allowed options.
#  -c3 is recommended, this will run rsync IO at "idle" priority. Uncomment
#  the next line to activate this.
# RSYNC_IONICE='-c3'

# Don't forget to create an appropriate config file,
# else the daemon will not start.

现在一些日志。 /var/log/rsyncd.log

2018/05/04 15:10:16 [889] rsyncd version 3.1.2 starting, listening on port 873
2018/05/04 15:10:16 [889] bind() failed: Cannot assign requested address (address-family 2)
2018/05/04 15:10:16 [889] unable to bind any inbound sockets on port 873
2018/05/04 15:10:16 [889] rsync error: error in socket IO (code 10) at socket.c(555) [Receiver=3.1.2]

ps aux | grep rsync 命令在 sn2 上的输出:

sn2       1555  0.0  0.1  13136  1060 pts/0    S+   15:46   0:00 grep --color=auto rsync

ps aux | grep rsync 命令在 sn1 上的输出:

sn1      12875  0.0  0.1  13136  1012 pts/0    S+   15:48   0:00 grep --color=auto rsync
root     21281  0.0  0.2  12960  2800 ?        Ss   13:31   0:00 /usr/bin/rsync --daemon --no-detach

这是我看到的两个节点之间的主要区别。

命令 sudo systemctl status rsync 在 sn1 上的输出:

rsync.service - fast remote file copy program daemon
   Loaded: loaded (/lib/systemd/system/rsync.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-05-04 13:31:10 UTC; 2h 19min ago
 Main PID: 21281 (rsync)
    Tasks: 1 (limit: 1113)
   CGroup: /system.slice/rsync.service
           └─21281 /usr/bin/rsync --daemon --no-detach

May 04 13:31:10 sn1 systemd[1]: Started fast remote file copy program daemon.

sn2 中相同命令的输出:

rsync.service - fast remote file copy program daemon
   Loaded: loaded (/lib/systemd/system/rsync.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2018-05-04 15:10:16 UTC; 41min ago
  Process: 889 ExecStart=/usr/bin/rsync --daemon --no-detach (code=exited, status=10)
 Main PID: 889 (code=exited, status=10)

May 04 15:10:15 sn2 systemd[1]: Started fast remote file copy program daemon.
May 04 15:10:16 sn2 systemd[1]: rsync.service: Main process exited, code=exited, status=10/n/a
May 04 15:10:16 sn2 systemd[1]: rsync.service: Failed with result 'exit-code'.

命令 sudo netstat -lptu | grep rsync 在 sn1 上的输出:

tcp        0      0 sn1:rsync               0.0.0.0:*               LISTEN      21281/rsync

而在 sn2 中 returns 什么都没有...

最终 sn2 /etc/hosts 包含

127.0.0.1       localhost.localdomain   localhost
::1             localhost6.localdomain6 localhost6


#ADDED BY ME
#10.0.2.15       sn2
192.168.13.130  proxy-server
192.168.13.131  sn1
192.168.13.132  sn2
#192.168.13.133  sn3
#192.168.13.134  sn4

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

还有 sn1:

127.0.0.1       localhost.localdomain   localhost
::1             localhost6.localdomain6 localhost6


#ADDED BY ME
#10.0.2.15       sn1
192.168.13.130  proxy-server
192.168.13.131  sn1
192.168.13.132  sn2
#192.168.13.133  sn3
#192.168.13.134  sn4

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

我 运行 ubuntu 18.04 在每个服务器节点上,在虚拟机上。 你能帮我弄清楚发生了什么吗?不幸的是,我必须使用 rsync,因为我正在使用 OpenStack Swift,所以不允许更改 :)

好的,我已经完成了。很简单,只要获得超级用户权限,然后启用并启动 rsync 进程:

sudo su

输入密码,然后输入数字

systemctl enable rsync
systemctl start rsync

如果您没有基于 systemctl 的终端,请使用 "service"。

service rsync restart

您可以通过访问 /var/log/rsyncd.log 检查 rsync 现在是否正常工作。 bind() 错误现已消失。

使用默认配置,我总是做 rsync -rtP /home/me/source/ x.x.x.x:/home/someoneelse/source(其中 x.x.x.x 是一个实际的 IP 地址)。我不知道何时或是否需要将 rsync:// 指定为协议。就我而言,在启用 sshd 之前我遇到了你的错误。我还安装了 rsync-daemon 但实际上我不知道是否需要它。这是完整的解决方案(我只在远程计算机上这样做——我相信本地计算机,然后我可以 运行 上面的命令成功,只有 openssh 和 rsync 包):

sudo dnf -y install rsync-daemon openssh
sudo systemctl enable rsyncd
sudo systemctl start rsyncd
sudo systemctl enable sshd
sudo systemctl start sshd

明确地说,我有 Fedora 27,sudo systemctl status firewalld 说防火墙是 运行ning,而且我不必手动创建我知道的防火墙规则(没有实例我的 bash 历史记录中的防火墙或 iptables)。在成功 运行s 的命令(在此答案的顶部)中,我使用了一些选项但它们不是必需的:r:递归,t:将时间戳复制到目标文件, P: 显示进度。正斜杠 (/) 仅位于源路径的末尾,因此 rsync 不会在目标中创建名为 /home/someoneelse/source/source 的目录。