【问题标题】:Failed to connect to local azure cosmosdb emulator无法连接到本地 azure cosmosdb 模拟器
【发布时间】:2019-11-27 09:50:50
【问题描述】:

我在我的 Win10 电脑上安装了Azure CosmosDB Emulator,并且我可以看到启动页面:

但是当我尝试通过 Robo3T 或命令行连接到数据库时,它不起作用。我使用以下命令:

mongo mongodb://localhost:foofoojf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true

我遇到了以下问题:

2019-07-18T14:33:27.265+0200 W NETWORK [thread1] 5000ms 毫秒后无法连接到 127.0.0.1:10255,放弃。 2019-07-18T14:33:27.266+0200 E QUERY [thread1] 错误:无法连接到服务器 localhost:10255,连接尝试失败: 连接@src/mongo/shell/mongo.js:237:13 @(连接):1:6 异常:连接失败

它在本地,所以我认为没有端口问题。是否可能与本地证书或我的公司防火墙有关?

【问题讨论】:

    标签: azure azure-cosmosdb azure-cosmosdb-mongoapi


    【解决方案1】:

    在我的例子中,要与用于 MongoDb 的 Azure CosmosDb API 交互,我们需要在 %localappdata%\CosmosDbEmulator 下创建一个专用的新文件夹并启用 MongoDb 端点 v3.6(请参阅下面 第 1 步中的 PowerShell 命令)。

    注意: 出于任何原因,如果 CosmosDb 模拟器重置为默认文件夹路径 %localappdata%\CosmosDbEmulator(或)无法在 Robo 3T 中连接 然后总是在 Step 1 中再次执行下面的 PowerShell 脚本。

    注意: 从 Robo 3T v1.4 开始,我们没有连接 SSL 标签 设置对话框。相反,我们有一个选项卡 TLS。

    1. Download and install Azure CosmosDb Emulator from https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator?tabs=powershell%2Cssl-netstd21
    2. Download and install Robo 3T (1.4.2 or latest) from https://robomongo.org/download
    3. To show Azure CosmosDb emulator related database(s) in Robo 3T client app
    
    Step 1
    - Launch Azure CosmosDb Emulator 
      (Optional: Just to check CosmosDbEmulator is started successfully)
    - Open Powershell as administrator and execute below commands
    
      # PowerShell Script
      # Change directory to default location where CosmosDb emulator is installed.
      cd\
      cd '.\Program Files\Azure Cosmos DB Emulator\'
                 
      # [Optional] If any cosmosDb emulator instance is running then shutdown
      .\Microsoft.Azure.Cosmos.Emulator.exe /shutdown
            
      # To interact Azure CosmosDb API for MongoDb, create a new folder "<MongoDb>" under 
      # %localappdata%\CosmosDbEmulator and enable MongoDb endpoint v3.6
      .\Microsoft.Azure.Cosmos.Emulator.exe /DataPath="$env:localappdata\CosmosDBEmulator\MongoDb" /EnableMongoDbEndpoint=3.6
    
    Step 2      
    - Now CosmosDb emulator will be successfully started,
      and launches the URL https://localhost:8081/_explorer/index.html in the browser
    - Note down MongoDb connection string details from browser which will be required 
      while creating new Robo 3T connection. The default MongoDb connection string format is 
      mongodb://username:password@host:port/[database]?ssl=true
        - Username: localhost
        - Password (Primary Key): C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
        - Port: 10255
        - Database: admin
        
    Step 3
    - Launch Robo 3T
    - Click on Create new connection 
    - In "Connection" tab
        - Provide Name of the connection as "<CosmosDbEmulator>"
        - Add port number as 10255
            
    - In "Authentication" tab provide details noted down in previous Step 2
        - Check "Perform authentication"
        - Add Database as "admin"
        - Add Username as "https://localhost:8081"
        - Add Password as "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
            
    - In "TLS" tab provide
        - Check "Use TLS protocol"
        - From Authentication Method dropdown select "Self-signed Certificate"
            
    - Click on "Test" button. 
        - It should successfully connects to localhost:10255 via TLS tunnel
        - It should successfully authorise to database "admin"
        
    - Click on "Save" button    
    - Click on "Connect" button. 
        - It will show the admin database and its related collections.
    

    【讨论】:

      【解决方案2】:

      我用ROBO3T工具连接了mongo模拟器,请看我的配置。

      首先,从这个link获取模拟器连接字符串。

      mongodb://localhost:C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==@localhost:10255/admin?ssl=true

      然后创建连接配置:

      连接:

      身份验证

      SSL:

      点击测试按钮:

      用户界面:

      【讨论】:

      • Cannot connect to the MongoDB at localhost:10255. Error: SSL tunnel failure: Network is unreachable or SSL connection rejected by server. Reason: couldn't connect to server localhost:10255, connection attempt failed: SocketException: Error connecting to localhost:10255 (127.0.0.1:10255) :: caused by :: no connection could be made because the target machine actively refused it
      • 你是对的,但为了做到这一点,你需要在 cmd 行中使用以下参数启动 CosmosDb Emulator:CosmosDB.Emulator.exe /EnableMongoDbEndpoint Bounty for you
      • 谢谢,这帮助很大。我使用的是 Robo 3T v1.3 不喜欢的 /EnableMongoDbEndpoint=3.6。将其更改为简单的 /EnableMongoDbEndpoint(降级到 3.2)对我有用。
      猜你喜欢
      • 2021-09-11
      • 2018-05-07
      • 1970-01-01
      • 2020-11-28
      • 2022-12-15
      • 2016-01-11
      • 2019-06-29
      • 2018-12-05
      • 2021-05-07
      相关资源
      最近更新 更多