通过 SSH 隧道建立许多并发 Cassandra 数据库连接

通过 SSH 隧道建立许多并发 Cassandra 数据库连接

我有一个使用 PyCassa Cassandra 客户端打开与 Cassandra 服务器的多个并发连接的应用程序。当我在数据库服务器上本地运行客户端应用程序时,它可以正常工作。但是,当我通过 ssh 隧道将 Cassandra 端口转发到数据库服务器并通过此隧道将客户端应用程序连接到服务器时,一些连接会通过,但通常会收到如下错误:

'2012210105:49:49'|WARNING |_append_historyStorage|75  |Exception when appending to CassandraTimeSeries
Traceback (most recent call last):
  File "atr/cassandratimeseries.py", line 140, in append
    cf = self._getColumnFamily(duration, 'main')
  File "atr/cassandratimeseries.py", line 63, in _getColumnFamily
    return ColumnFamily(ConnectionPool(self._keyspace, pool_timeout=100, timeout=15, max_overflow=5), self._columnFamilyName(duration, table_type), **self._column_family_op_options)
  File "/usr/local/lib/python2.7/dist-packages/pycassa/pool.py", line 356, in __init__
    self.fill()
  File "/usr/local/lib/python2.7/dist-packages/pycassa/pool.py", line 415, in fill
    conn = self._create_connection()
  File "/usr/local/lib/python2.7/dist-packages/pycassa/pool.py", line 403, in _create_connection
    (exc.__class__.__name__, exc))
AllServersUnavailable: An attempt was made to connect to each of the servers twice, but none of the attempts succeeded. The last failure was TTransportException: TSocket read 0 bytes

在我通过 ssh 连接到服务器的终端上打印了一行类似这样的消息:

channel 1034: open failed: administratively prohibited: open failed
channel 1035: open failed: administratively prohibited: open failed
channel 1036: open failed: administratively prohibited: open failed
channel 1037: open failed: administratively prohibited: open failed
channel 1038: open failed: administratively prohibited: open failed
channel 1039: open failed: administratively prohibited: open failed
channel 1040: open failed: administratively prohibited: open failed

有趣的是,如果我尝试 ssh 到服务器,我会得到:

channel 1023: chan_read_failed for istate 1
channel 1023: chan_write_failed for ostate 3
Shared connection to xx.xxx.xxx.xxx closed.

如果我删除 /tmp 中的主套接字文件,那么我可以再次 ssh 到它。

有什么想法可能出了什么问题吗?我已经通过 /etc/security/limits.conf 为客户端和服务器增加了 nofile 限制(到一万),然后重新启动。“打开失败:管理上禁止”表明存在一些管理限制。它是什么,我该如何提高它(我应该如何自己解决这个问题?)

除了连接到本地端口之外,还有其他方式使 ssh 隧道受到更多限制吗?

谢谢

答案1

有趣的是,我以前从未遇到过这种情况。我会尝试你已经做过的事情,因此对于后续步骤,我在 ssh 源中追踪了“管理禁止”消息,它只在一种情况下出现,并且它在 sshd.c 中出现,然后我按照 channels.c 和 session.c 中的逻辑进行操作

这似乎是 SSH 中唯一可以取消限制允许的通道数量的代码,在 sshd.c 或 channels.c 中我没有看到任何硬性限制

/* setup the channel layer */
if (!no_port_forwarding_flag && options.allow_tcp_forwarding)
    channel_permit_all_opens();

您能否检查服务器上的 sshd_config 并确保设置了以下选项:

AllowTcpForwarding yes

我对我自己的答案不太满意的地方是,在某个地方似乎存在 1024 的限制,我希望在代码中追踪到这个限制。1024 通常是 limits.conf 中打开文件数量的默认限制 - 在启动 sshd 的 shell 中,是否还有其他任何地方设置了 ulimit?

相关内容