【问题标题】:Mongo::Error::NoServerAvailable: No primary server is available in clusterMongo::Error::NoServerAvailable:集群中没有可用的主服务器
【发布时间】:2020-02-07 18:49:22
【问题描述】:

部署到生产环境(通过 gitlab)时出现以下错误:

Mongo::Error::NoServerAvailable: No primary server is available in cluster: 
#<Cluster topology=
   ReplicaSetNoPrimary[url1:27017,url2:27017,url3:27017,url4:27017,url5:27017,name=mobile01] 
   servers=[
     #<Server address=url1:27017 UNKNOWN>,
     #<Server address=url2:27017 UNKNOWN>,
     #<Server address=url3:27017 UNKNOWN>,
     #<Server address=url4:27017 UNKNOWN>,
     #<Server address=url5:27017 UNKNOWN>]> with timeout=30, LT=0.015

我一直试图在 Rails 控制台中本地重现错误,这是我的配置:

ap Mongoid.client(:default).instance_values
{
  "srv_records" => nil,
    "options" => {
        "database" => "mydb",
        "auth_source" => "admin",
        "retry_reads" => true,
        "retry_writes" => true,
        "user" => "rp_projects",
        "password" => "xxxxxxxxxxxxxxxxx",
        "ssl" => true,
        "replica_set" => "mobile01",
        "connect" => :replica_set,
        "platform" => "mongoid-7.0.5"
   },
   "database" => #<Mongo::Database:0x70156564542240 name=mydb>,
   "cluster" => #<Mongo::Cluster:0x70156564540720 servers=[] 
                   topology=
                   ReplicaSetNoPrimary[url1:27017,url2:27017,url3:27017,url4:27017,url5:27017,
                   name=mobile01]>
}

服务器在 docker 镜像中运行。我在配置中遗漏了什么吗?我应该在这里寻找什么?

【问题讨论】:

    标签: ruby-on-rails docker mongoid


    【解决方案1】:
    1. 验证您是否能够使用 MongoDB shell(mongo 二进制文件)连接到节点。您很可能没有连接。

    2. 将日志级别设置为调试 (https://docs.mongodb.com/mongoid/master/tutorials/mongoid-configuration/#logging),它将告诉您驱动程序在尝试连接到部署时正在做什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 2017-06-15
      • 2017-03-13
      • 1970-01-01
      • 2020-04-01
      • 2019-11-08
      • 1970-01-01
      相关资源
      最近更新 更多