无法复制数据库|无法连接到服务器本地主机:27017,连接尝试失败

时间:2018-06-29 05:22:46

标签: mongodb

我无法复制数据库。它返回以下错误:

>db.copyDatabase('testing_demo', 'testing');
  

{“ ok”:0,“ errmsg”:“无法连接到服务器localhost:27017,   连接尝试失败”,“代码”:6,“ codeName”:   “ HostUnreachable”}

我不知道为什么说 localhost ,我正在连接到IP地址为 172.31.21.200

的mongodb服务器
mongo --host 172.31.21.200

如果我尝试连接到本地主机,则会出现以下错误:

> mongo --host localhost
MongoDB shell version v3.4.15
connecting to: mongodb://localhost:27017/
2018-06-29T07:42:07.670+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-06-29T07:42:07.670+0000 E QUERY    [thread1] Error: couldn't connect to server localhost:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:240:13
@(connect):1:6
exception: connect failed

mongod.conf文件

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
 port: 27017
 bindIp: 172.31.21.200


#processManagement:

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

db.serverCmdLineOpts()的输出

> db.serverCmdLineOpts();

{
    "argv" : [
        "/usr/bin/mongod",
        "--config",
        "/etc/mongod.conf"
    ],
    "parsed" : {
        "config" : "/etc/mongod.conf",
        "net" : {
            "bindIp" : "172.31.21.200",
            "port" : 27017
        },
        "storage" : {
            "dbPath" : "/var/lib/mongodb",
            "journal" : {
                "enabled" : true
            }
        },
        "systemLog" : {
            "destination" : "file",
            "logAppend" : true,
            "path" : "/var/log/mongodb/mongod.log"
        }
    },
    "ok" : 1
}

lsof的输出

> sudo lsof -iTCP -sTCP:LISTEN | grep mongo

mongod  26384  mongodb    7u  IPv4 306170      0t0  TCP localhost:27017 (LISTEN)

mongo --version的输出

MongoDB shell version v3.4.15
git version: 52e5b5fbaa3a2a5b1a217f5e647b5061817475f9
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

0 个答案:

没有答案