Replication

CentOS 7 上的 MongoDB 複製集配置問題

  • March 7, 2019

我的 mongodb 實例不會獨立執行,我無法找到原因。它可能很簡單。請指出我正確的方向。

Linux myserver 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

mongo -version
MongoDB shell version v4.0.6

執行命令:

> > mongo –host 10.0.0.7/admin –port 27017 -u user -p mypassword > > >

返回:

MongoDB shell version v3.4.13
connecting to: mongodb://admin:27017/?replicaSet=10.0.0.7
2019-03-06T00:54:32.412-0500 I NETWORK  [thread1] Starting new replica set monitor for 10.0.0.7/admin:27017
2019-03-06T00:54:32.414-0500 I NETWORK  [thread1] getaddrinfo("admin") failed: Name or service not known
2019-03-06T00:54:32.414-0500 W NETWORK  [thread1] No primary detected for set 10.0.0.7
2019-03-06T00:54:32.414-0500 I NETWORK  [thread1] All nodes for set 10.0.0.7 are down. This has happened for 1 checks in a row.
2019-03-06T00:54:32.914-0500 I NETWORK  [thread1] getaddrinfo("admin") failed: Name or service not known

所以我登錄到主機上的 mongo shell 並執行:

use admin show users

{
       "_id" : "admin.myname",
       "user" : "myname",
       "db" : "admin",
       "roles" : [
               {
                       "role" : "readWriteAnyDatabase",
                       "db" : "admin"
               },
               {
                       "role" : "root",
                       "db" : "admin"
               },
               {
                       "role" : "userAdminAnyDatabase",
                       "db" : "admin"
               }
       ],
       "mechanisms" : [
               "SCRAM-SHA-1",
               "SCRAM-SHA-256"
       ] }

rs.status()

{
       "ok" : 0,
       "errmsg" : "not running with --replSet",
       "code" : 76,
       "codeName" : "NoReplicationEnabled"
}

配置文件

# mongod.conf

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

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

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

# how the process runs
processManagement:
 fork: true  # fork and run in background
 pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
 timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
 port: 27017
#  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
 bindIpAll: true

security:
 authorization: "enabled"

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

mongo –host 10.0.0.7/admin –port 27017 -u user -p mypassword

上面的命令10.0.0.7replica setnameadminhostname. 這就是您收到錯誤的原因。

使用以下任何命令連接到 MongoDB 數據庫

mongo 10.0.0.7/admin --port 27017 -u user -p mypassword

mongo admin --host 10.0.0.7 --port 27017 -u user -p mypassword

引用自:https://dba.stackexchange.com/questions/231427