【问题标题】:From Rails to Mongodb connection over ssl not working通过 ssl 从 Rails 到 Mongodb 连接不起作用
【发布时间】:2020-10-01 23:01:53
【问题描述】:

我能够通过 ssl(工作)从 mongo shell 连接 mongodb: mongo --ssl --sslCAFile ca.crt --sslPEMKeyFile client.pem mongodb://xxxx:xxxx@xxxxx:27017/test_db?authSource=admin

从 rails 我无法连接我的 mongoid 配置文件如下:

development:
  clients:
    default:
      #database: mastt_development
      uri: mongodb://xxxx:xxxx@xxxxx:27017/test_db?authSource=admin
#      hosts:
#        - localhost:27017
  options:
    max_pool_size: 3
    wait_queue_timeout: 300
    ssl: true
    ssl_cert: /home/ubuntu/client.pem
    ssl_verify: true
    ssl_ca_cert: /home/ubuntu/ca.crt
 options:
    raise_not_found_error: false

rails c
2.6.2 :001 > User.count
Traceback (most recent call last):
        1: from (irb):1
Mongo::Error::NoServerAvailable (No primary server is available in cluster: #<Cluster topology=Unknown[prod-mongo-v2:27017] servers=[#<Server address=prod-mongo-v2:27017 UNKNOWN>]> with timeout=30, LT=0.015)
2.6.2 :002 > exit

MongDB 服务器日志:

2020-06-12T06:22:05.955+0000 I  NETWORK  [conn680] end connection xx.xx.xx.xx:55240 (0 connections now open)
2020-06-12T06:22:16.549+0000 I  NETWORK  [listener] connection accepted from xx.xx.xx.xx:55241 #681 (1 connection now open)
2020-06-12T06:22:16.559+0000 I  NETWORK  [conn681] Error receiving request from client: SSLHandshakeFailed: The server is configured to only allow SSL connections. Ending connection from 157.45.197.173:55241 (connection id: 681)

请帮忙解决这个问题

【问题讨论】:

    标签: ruby-on-rails mongodb mongoid


    【解决方案1】:

    您将这些选项设置为 Mongoid 选项,但它们需要设置为驱动程序选项。示例见here

    简而言之,将第一个 options 移动到与配置中的 uri 相同的级别。

    您似乎在顶层也有两次options

    【讨论】:

    • 非常感谢。第一个选项移动工作正常。第二个选项在正确的位置
    猜你喜欢
    • 2023-01-04
    • 2014-08-14
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    • 2013-02-10
    相关资源
    最近更新 更多