网址: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
版权声明:本文为博主原创文章,转载请附上博文链接!

最新文章

  1. 【SQL】关于无法附加文件的错误
  2. JavaScript编码规范
  3. 在Java filter中调用service层方法
  4. poj 2985 The k-th Largest Group 树状数组求第K大
  5. Codeforces 404D [DP]
  6. JavaScript基础-对象<2>
  7. PHP添加、更新solr索引
  8. calendar中set方法和静态属性带来的坑
  9. hidden symbol `pthread_atfork'
  10. Oracle 服务启动关闭
  11. 15分钟在阿里云Kubernetes服务上快速建立Jenkins X Platform并运用GitOps管理应用发布
  12. VMware与CentOS的安装与Linux简单指令
  13. redhat7.3安装python3 pip3
  14. 【转】学习Java虚拟机没用? 听听当事人是怎么说的!
  15. AWS CSAA -- 04 AWS Object Storage and CDN - S3 Glacier and CloudFront(三)
  16. BZOJ 1076 奖励关 状态压缩DP
  17. 蓝牙开发<coreBluetooth/CoreBluetooth.h>
  18. php strcmp()函数
  19. C# 采用钩子捕获键盘和鼠标事件-验证是否处于无人操作状态
  20. 十六、dbms_space_admin(提供了局部管理表空间的功能)

热门文章

  1. LINQ按多列分组(Group By)并计算总和(Sum) (转载)
  2. Yarn Nodemanager启动不了报YarnRuntimeException: Failed to initialize container executor error=13 权限不够
  3. python 执行系统命令模块比较
  4. 使用Cloudera Manager搭建Impala环境
  5. JavaSE字符串日期与时间拼接小列子与JSON小列子
  6. Codes: MODERN ROBOTICS Ch.3_Expo. Coods.基础代码实现
  7. 基于Java+Selenium的WebUI自动化测试框架(十一)-----读取Excel文件(POI)(1)
  8. Can you answer these queries? (线段树
  9. linux简单的命令
  10. P1345 [USACO5.4]奶牛的电信[拆点+最小割]