无法使用Docker中的mongoshell连接到mongodb云。 在Opensuse 42.3 linux平台上工作。 IP_FORWARD已启用,防火墙已被禁用。
./mongodbshell/bin/mongo "mongodb+srv://cluster0-ry2xn.mongodb.net/test" --username
然而,它从户外码头工作得很好。以下是我的码头环境信息。
$ 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
Docker oS基于kali linux -
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的身份验证有关吗?非常感谢任何帮助。
答案 0 :(得分:1)
IP_FORWARD是不够的,您需要在这些不同网络之间使用masquerade(或NAT)。如果网络之间存在一个公共网关,则也可以使用静态路由。
答案 1 :(得分:1)
Kali linux不是mongo支持的发行版。
因此需要验证/ usr / bin / mongo --version是否不会返回输出中提到的openssl。 然后,在这种情况下卸载所有现有的mongodb工具&服务器&客户。
然后重新安装一个为debian 7/8平台构建的mongo客户端,具体取决于使用的Kali linux发行版。 (在我看来是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