在配置文件mongodb中添加ip

在配置文件mongodb中添加ip,mongodb,configuration,Mongodb,Configuration,我已经在windows server 2012上安装了mongodb 3.6,并修改了添加新ip的配置文件 systemLog: destination: file path: c:\data\log\mongod.log storage: dbPath: c:\data\db security: authorization: enabled net: port: 27017 bindIp: 127.0.0.1,192.168.1.11 系统日志

我已经在windows server 2012上安装了mongodb 3.6,并修改了添加新ip的配置文件

systemLog: destination: file path: c:\data\log\mongod.log storage: dbPath: c:\data\db security: authorization: enabled net: port: 27017 bindIp: 127.0.0.1,192.168.1.11 系统日志: 目的地:文件 路径:c:\data\log\mongod.log 存储: dbPath:c:\data\db 安全: 授权:已启用 净: 港口:27017 bindIp:127.0.0.1192.168.1.11 当我尝试启动服务时,这会向我发送下一条消息

The MongoDB service is starting. The MongoDB service could not be started. Service specific error: 48. You can get more help with the NET HELPMSG 3547 command. MongoDB服务正在启动。 无法启动MongoDB服务。 服务特定错误:48。 您可以使用NET HELPMSG 3547命令获得更多帮助。 我检查日志文件并发现此消息

2018-01-24T09:18:23.511-0500 I CONTROL [initandlisten] options: { config: "C:\data\mongod.cfg", net: { bindIp: "127.0.0.1,192.168.1.11", port: 27017 }, security: { authorization: "enabled" }, service: true, storage: { dbPath: "c:\data\db" }, systemLog: { destination: "file", path: "c:\data\log\mongod.log" } } 2018-01-24T09:18:23.512-0500 E STORAGE [initandlisten] Failed to set up listener: SocketException: The requested address is not valid in this context. 2018-01-24T09:18:23.512-0500 I CONTROL [serviceStopWorker] now exiting 2018-01-24T09:18:23.511-0500 I CONTROL[initandlisten]选项:{config:“C:\data\mongod.cfg”,net:{bindIp:“127.0.0.1192.168.1.11”,端口:27017},安全性:{authorization:“enabled”},服务:true,存储:{dbPath:“C:\data\db”},系统日志:{destination:“file”,路径:“C:\data\log\mongod.log”} 2018-01-24T09:18:23.512-0500 E存储[initandlisten]无法设置侦听器:SocketException:请求的地址在此上下文中无效。 2018-01-24T09:18:23.512-0500 I控制[serviceStopWorker]正在退出 现在我修改配置文件,在IP之间添加一个空间

systemLog: destination: file path: c:\data\log\mongod.log storage: dbPath: c:\data\db security: authorization: enabled net: port: 27017 bindIp: 127.0.0.1, 192.168.1.11 系统日志: 目的地:文件 路径:c:\data\log\mongod.log 存储: dbPath:c:\data\db 安全: 授权:已启用 净: 港口:27017 bindIp:127.0.0.1192.168.1.11 然后我开始服务

The MongoDB service is starting .. The MongoDB service started successfully. MongoDB服务正在启动。。 MongoDB服务已成功启动。 我再次检查日志文件,发现以下内容

2018-01-24T09:24:53.807-0500 I CONTROL [initandlisten] options: { config: "C:\data\mongod.cfg", net: { bindIp: "127.0.0.1, 192.168.1.11", port: 27017 }, security: { authorization: "enabled" }, service: true, storage: { dbPath: "c:\data\db" }, systemLog: { destination: "file", path: "c:\data\log\mongod.log" } } 2018-01-24T09:24:53.808-0500 I NETWORK [initandlisten] getaddrinfo(" 192.168.1.11") failed: Unknown host. 2018-01-24T09:24:53.808-0500 W NETWORK [initandlisten] Found no addresses for 192.168.1.11 2018-01-24T09:24:53.808-0500 I - [initandlisten] Detected data files in c:\data\db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 2018-01-24T09:24:53.808-0500 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7679M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress), 2018-01-24T09:24:54.029-0500 I STORAGE [initandlisten] WiredTiger message [1516803894:28660][640:140720456536192], txn-recover: Main recovery loop: starting at 20/11264 2018-01-24T09:24:54.197-0500 I STORAGE [initandlisten] WiredTiger message [1516803894:196669][640:140720456536192], txn-recover: Recovering log 20 through 21 2018-01-24T09:24:54.297-0500 I STORAGE [initandlisten] WiredTiger message [1516803894:296682][640:140720456536192], txn-recover: Recovering log 21 through 21 2018-01-24T09:24:55.031-0500 I CONTROL [initandlisten] 2018-01-24T09:24:55.031-0500 I CONTROL [initandlisten] ** WARNING: The file system cache of this machine is configured to be greater than 40% of the total memory. This can lead to increased memory pressure and poor performance. 2018-01-24T09:24:55.031-0500 I CONTROL [initandlisten] See http://dochub.mongodb.org/core/wt-windows-system-file-cache 2018-01-24T09:24:55.031-0500 I CONTROL [initandlisten] 2018-01-24T09:24:55.231-0500 W FTDC [initandlisten] Failed to initialize Performance Counters for FTDC: WindowsPdhError: PdhExpandCounterPathW failed with 'The specified object was not found on the computer.' for counter '\Memory\Available Bytes' 2018-01-24T09:24:55.231-0500 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'c:/data/db/diagnostic.data' 2018-01-24T09:24:55.232-0500 I NETWORK [initandlisten] waiting for connections on port 27017 2018-01-24T09:24:55.232-0500 I STORAGE [initandlisten] Service running 2018-01-24T09:24:53.807-0500 I CONTROL[initandlisten]选项:{config:“C:\data\mongod.cfg”,net:{bindIp:“127.0.0.1192.168.1.11”,端口:27017},安全性:{authorization:“enabled”},服务:true,存储:{dbPath:“C:\data\db”},系统日志:{destination:“file”,路径:“C:\data\log\mongod.log”} 2018-01-24T09:24:53.808-0500 I网络[initandlisten]getaddrinfo(“192.168.1.11”)失败:未知主机。 2018-01-24T09:24:53.808-0500 W网络[initandlisten]未找到192.168.1.11的地址 2018-01-24T09:24:53.808-0500 I-[initandlisten]检测到由“wiredTiger”存储引擎创建的c:\data\db中的数据文件,因此将活动存储引擎设置为“wiredTiger”。 2018-01-24T09:24:53.808-0500 I STORAGE[initandlisten]wiredtiger\u open config:create,cache\u size=7679M,session\u max=20000,execution=(threads\u min=4,threads\u max=4),config\u base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file\u manager=(close\u idle\u time=100000),statistics\u log=(等待=0),verbose=(恢复进度), 2018-01-24T09:24:54.029-0500 I存储[initandlisten]有线数字信号[1516803894:28660][640:140720456536192],txn恢复:主恢复循环:从20/11264开始 2018-01-24T09:24:54.197-0500 I存储[initandlisten]有线数据记录器消息[1516803894:196669][640:140720456536192],txn恢复:恢复日志20到21 2018-01-24T09:24:54.297-0500 I存储[initandlisten]有线数据记录器消息[1516803894:296682][640:140720456536192],txn恢复:恢复日志21到21 2018-01-24T09:24:55.031-0500 I控制[初始化监听] 2018-01-24T09:24:55.031-0500 I CONTROL[initandlisten]**警告:此机器的文件系统缓存配置为大于总内存的40%。这可能导致内存压力增加和性能降低。 2018-01-24T09:24:55.031-0500 I控制[初始化侦听]参见http://dochub.mongodb.org/core/wt-windows-system-file-cache 2018-01-24T09:24:55.031-0500 I控制[初始化监听] 2018-01-24T09:24:55.231-0500 W FTDC[initandlisten]无法初始化FTDC的性能计数器:WindowsPdhError:PDHexPandCounterPath失败,原因是“在计算机上找不到指定的对象”。对于计数器“\Memory\Available Bytes” 2018-01-24T09:24:55.231-0500 I FTDC[initandlisten]正在使用目录“c:/data/db/diagnostic.data”初始化全职诊断数据捕获 2018-01-24T09:24:55.232-0500 I网络[initandlisten]正在等待端口27017上的连接 2018-01-24T09:24:55.232-0500 I存储[initandlisten]服务正在运行
我试过很多方法,用[]{}:;并且总是抛出错误,但是当我使用0.0.0.0离开bindIp时,它允许我从其他IP连接。请帮忙。谢谢。

bindIp
不是客户端IP,而是服务器IP,代表mongodb正在监听的接口
0.0.0.0
是一种特殊情况,它告诉mongodb监听所有可用接口

如果您想限制特定客户端的IP地址对mongodb的访问,您可以在级别上进行。在这种情况下,服务器仍将侦听所有允许的接口,但不允许来自未知IP的用户登录

当您启动mongod或在中启动时,此功能由
--auth
命令行选项启用

请阅读如何正确启用身份验证

允许
testUser
仅从
192.168.1.11
IP连接的命令示例:

db.createUser({ user: "testUser",
                pwd: "testPassword",
                roles: [ { role: "readWriteAnyDatabase", db: "admin" } ],
                authenticationRestrictions: [ { clientSource: ["192.168.1.11"] } ]
              });

clientSource
数组可以用CIDR表示法列出精确的IP或/和网络掩码,例如,
192.168.1.0/24
将允许用户从任何IP连接到
192.168.1.0
192.168.1.255

您好,我按照说明将用户添加到数据库,但是我试着用robo3t连接,他抛出了下面的信息“网络不可访问”当你启动mongod而没有
--auth
选项时,它可以访问吗?谢谢,你救了我的命