簡體   English   中英

Docker無法連接到mongodb雲

[英]Docker Unable to connect to mongodb cloud

無法使用來自Docker的mongoshell連接到mongodb雲。 在Opensuse 42.3 linux平台上工作。 IP_FORWARD已啟用,防火牆已禁用。

./mongodbshell/bin/mongo  "mongodb+srv://cluster0-ry2xn.mongodb.net/test" --username

但是,它在外部docker上運行良好。 下面給出的是我的docker環境信息。

$ sudo docker info

Containers: 17
 Running: 1
 Paused: 0
 Stopped: 16
Images: 21
Server Version: 17.04.0-ce
Storage Driver: overlay
 Backing Filesystem: xfs
 Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: active
 NodeID: kh7m6ppbeg3ktkk3tueqoiyen
 Is Manager: true
 ClusterID: izl7e06qo269ccagfa0eknz16
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
 Node Address: 192.168.2.14
 Manager Addresses:
  192.168.2.14:2377
Runtimes: oci runc
Default Runtime: runc
Init Binary: 
containerd version:  (expected: 422e31ce907fd9c3833a38d7b8fdd023e5a76e73)
runc version: N/A (expected: 9c2d8d184e5da67c95d601382adf14862e4f2228)
init version: N/A (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
 apparmor
Kernel Version: 4.4.104-39-default
Operating System: openSUSE Leap 42.3
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.45GiB
Name: linux-xleg.suse
ID: SFKG:TIYZ:65WL:TKCG:ZOSW:7ZJI:CW6E:2HJJ:UV7A:ZVXM:V2IN:JZU4
Docker Root Dir: /home/maggi/docker-data
Debug Mode (client): false
Debug Mode (server): false
Username: magnusmel
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support
WARNING: No kernel memory limit support

基於Kali Linux的Docker OS-

cat /etc/os-release 
PRETTY_NAME="Kali GNU/Linux Rolling"
NAME="Kali GNU/Linux"
ID=kali
VERSION="2016.2"
VERSION_ID="2016.2"
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.kali.org/"
SUPPORT_URL="http://forums.kali.org/"
BUG_REPORT_URL="http://bugs.kali.org/"

MongodB客戶信息如下

/opt/mongodbshell/bin/mongo --version
MongoDB shell version v3.6.2
git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
allocator: tcmalloc
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

錯誤輸出:

> connecting to: mongodb+srv://cluster0-ry2xn.mongodb.net/test
> 2018-01-30T18:54:38.451+0000 I NETWORK  [thread1] Starting new replica
> set monitor for
> Cluster0-shard-0/cluster0-shard-00-00-ry2xn.mongodb.net.:27017,cluster0-shard-00-02-ry2xn.mongodb.net.:27017,cluster0-shard-00-01-ry2xn.mongodb.net.:27017
> 2018-01-30T18:54:39.679+0000 W NETWORK  [thread1] Unable to reach
> primary for set Cluster0-shard-0 2018-01-30T18:54:39.679+0000 I
> NETWORK  [thread1] Cannot reach any nodes for set Cluster0-shard-0.
> Please check network connectivity and the status of the set. This has
> happened for 1 checks in a row. 2018-01-30T18:54:41.879+0000 W NETWORK
> [thread1] Unable to reach primary for set Cluster0-shard-0
> 2018-01-30T18:54:41.879+0000 I NETWORK  [thread1] Cannot reach any
> nodes for set Cluster0-shard-0. Please check network connectivity and
> the status of the set. This has happened for 2 checks in a row.

這與不設置基於SSL / TLS的身份驗證有關嗎? 任何幫助將不勝感激。

IP_FORWARD是不夠的,您需要在這些不同的網絡之間偽裝 (或NAT)。 如果網絡之間存在一個公用網關,則也可以使用靜態路由。

mongo不支持Kali linux發行版。

因此,需要驗證/ usr / bin / mongo --version是否不與輸出中提到的openssl一起返回。 然后,在這種情況下,請卸載所有現有的mongodb工具,服務器和客戶端。

然后根據所使用的Kali linux發行版,使用為debian 7/8平台構建的mongo客戶端重新安裝。 (在我的情況下是debian版本8)

這就解決了在docker上使用ssl運行mongo客戶端的問題:

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.6 main" |  tee /etc/apt/sources.list.d/mongodb-org-3.6.list

apt-get update

對於包含服務器的完整mongodb安裝,請按照以下說明運行:

apt-get install -y mongodb-org=3.6.2 mongodb-org-server=3.6.2 mongodb-org-shell=3.6.2 mongodb-org-mongos=3.6.2 mongodb-org-tools=3.6.2

僅安裝特定於版本的mongo客戶端和工具:

   apt-get install -y mongodb-org-shell=3.6.2 mongodb-org-tools=3.6.2

僅安裝默認的mongo客戶端和工具:

   apt-get install -y mongodb-org-shell mongodb-org-tools

我在docker上的mongo輸出-kali linux映像現在顯示已配置的ssl:

MongoDB shell version v3.6.2
git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: debian81
    distarch: x86_64
    target_arch: x86_64

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM