当前位置:   article > 正文

MongoDB允许其它IP地址访问

给mongodb添加多个可访问ip

网址:https://blog.csdn.net/sl1992/article/details/83964310

 

文章目录
1.允许所有地址访问
2.绑定内网IP
3.绑定多个IP

Linux服务器上安装MongoDB后,允许其它客户端IP访问MongoDB服务器。
阿里云服务器需要设置入站规则,可参见使用外网访问阿里云服务器ZooKeeper

1.允许所有地址访问
NOTE:

net.bindIp and net.bindIpAll are mutually exclusive. That is, you can specify one or the other, but not both.
net.bindIp和net.bindIpAll是互斥的。也就是说,您可以指定其中一个,但不能同时指定两者。

可直接设置bindIpAll: true,即允许所有的IPv4和IPv6地址访问

# network interfaces
net:
port: 27017
bindIpAll: true
1
2
3
4
也可以根据后面注释提示,将bindIp修改为0.0.0.0,::

# network interfaces
net:
port: 27017
bindIp: 0.0.0.0,:: # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
1
2
3
4
2.绑定内网IP
阿里云服务器可以只绑定内网IP,阿里云服务器外网配置入站规则,由阿里云服务器的外网向内网转发。

配置主机名和内网IP的映射
sudo vi /etc/hosts,添加配置项192.168.1.200 solang

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.200 solang
1
2
3
4
[solang@solang ~]$ sudo vi /etc/mongod.conf
# network interfaces
net:
port: 27017
bindIp: solang # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
1
2
3
4
5
启动MongoDB服务时,访问外网端口是通的,服务器上使用mongo shell时需要指定对应的地址,即mongo solang:27017

3.绑定多个IP
The hostnames and/or IP addresses and/or full Unix domain socket paths on which mongos and mongodshould listen for client connections. You may attach mongos and mongod to any interface. To bind to multiple addresses, enter a list of comma-separated values.
主机名和/或IP地址和/或完整的Unix域套接字路径,mongos和mongod应该监听客户端连接。 您可以将mongos和mongod附加到任何界面。 要绑定到多个地址,请输入逗号分隔值列表。

EXAMPLE

localhost,/tmp/mongod.sock
1
MongoDB4.0修改bindIp值,只允许按照如上方式设置,即域名或IP,文本地址列表,文本地址列表可自定义名称,多个地址需要用逗号分隔。

配置主机名和内网IP的映射
sudo vi /etc/hosts,添加配置项192.168.1.200 solang

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.200 solang
 
例:

[solang@solang ~]$ vi /usr/local/app/mongod.socks

输公网IP

[solang@solang ~]$ sudo vi /etc/mongod.conf
# network interfaces
net:
port: 27017
bindIp: solang,/usr/local/app/mongod.socks # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
---------------------
作者:LifeIsForSharing
来源:CSDN
原文:https://blog.csdn.net/sl1992/article/details/83964310
版权声明:本文为博主原创文章,转载请附上博文链接!

转载于:https://www.cnblogs.com/zxtceq/p/10978995.html

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号