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
1234
也可以根据后面注释提示,将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.
1234

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
1234
[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.
12345
启动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
1234
例:
[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.
123456789
TIP
When possible, use a logical DNS hostname instead of an ip address, particularly when configuring replica set members or sharded cluster members. The use of logical DNS hostnames avoids configuration changes due to ip address changes.
如果可能,请使用逻辑DNS主机名而不是IP地址,尤其是在配置副本集成员或分片集群成员时。 逻辑DNS主机名的使用避免了由于IP地址更改而导致的配置更改。
本文参考:
https://docs.mongodb.com/manual/reference/configuration-options/#net-options
---------------------
版权声明:本文为CSDN博主「LifeIsForSharing」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sl1992/article/details/83964310

MongoDB bindIp 与 bindIpAll的更多相关文章

  1. MongoDB官网配置项目整理

    MongoDB的配置文件共有10个项目: systemLog:processManagement:net:security:storage:operationProfiling:replication ...

  2. mongodb的配置文件详解()

    官方地址  https://docs.mongodb.com/manual/reference/configuration-options/#configuration-file 以下页面描述了Mon ...

  3. MongoDB学习--安装与管理

    一.简介 MongoDB是一种强大.灵活,且易于扩展的通用型数据库.他能扩展出非常多的功能.如二级索引(secondary index).范围查询(range query).排序.聚合(aggrega ...

  4. mongodb安装4.0(rpm)

    虚拟机客户端vmware player linux版本:CentOS Linux release 7.4.1708 (Core) CentOS安装类型:Basic Web Server 参照官网最新文 ...

  5. MongoDB从入门到优化

    目录 一.MongoDB 简介 二.MongoDB 的储存引擎 三.mongodb 配置参数 四.MongoDB 单节点搭建 五.MongoDB 连接 六.MongoDB 常用命令 七.MongoDB ...

  6. MongoDB 菜鸟入门“秘籍”

    1.MongoDB介绍 1.1 什么是MongoDB ? MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添加更多的节点,可以保证服务器性能. Mo ...

  7. 关于python3链接虚拟机MongoDB 遇到的问题总结

    pymongo.errors.ServerSelectionTimeoutError: 192.168.12.230:27017: [Errno 61] Connection refused 1.如果 ...

  8. CentOS 安装 MongoDB

    一.安装mongodb 本文介绍的安装方式是以二进制方式离线安装,相当于windows"绿色"安装版本的概念. 下载mongodb: # https://www.mongodb.c ...

  9. windows系统,MongoDB开启用户验证登录的正确姿势

    MongoDB默认安装并没有开启用户名密码登录,这样太不安全了,百度出来的开启验证登录的文章,对初次使用MongoDB的小白太不友好了,总结下经验,自己写一份指引. 1,我的安装路径是C:\Progr ...

随机推荐

  1. python基础 — turtle 介绍

    一.基础概念 1.画布:画布就是turtle为我们展开用于绘图区域, 我们可以设置它的大小和初始位置.常用的画布方法有两个:screensize()和setup(). (1)turtle.screen ...

  2. JavaScript进行WebSocket字节流通讯示例

    websocket进行通讯时,可以选择采用字符串或者字节流的传输模式.但在发送与接收时,需要考虑数据的分包,即分成一个个请求与响应消息.无论是采用哪种传输模式,都不免要遇到这个问题. 采用字符串传输时 ...

  3. win server 检查是否是ntfs文件系统

    fsutil fsinfo volumeinfo c: | findstr  /i "文件系统名"

  4. jedis参数不当引发的问题总结

    jedis参数不当引发dubbo服务线程池耗尽异常 现象:一个dubbo服务偶发性的出现个别机器甚至整个集群大量报线程池耗尽的问题.一开始对问题的处理比较粗暴,直接增加了10倍的线程数.但是问题依然偶 ...

  5. NEST search查询

    /// <summary> /// GET /megacorp/employee/_search /// </summary> /// <returns></ ...

  6. 查看MacOS中的Swift版本和SDK版本

    查看MacOS中的Swift版本和SDK版本 来源 https://juejin.im/post/5cde5a62f265da1bc55230e5 # 查看Swift版本 xcrun swift -v ...

  7. PKCS 标准

    PKCS 标准 The Public-Key Cryptography Standards (PKCS)是由美国RSA数据安全公司及其合作伙伴制定的一组公钥密码学标准,其中包括证书申请.证书更新.证书 ...

  8. 全面学习 Python 包:包的构建与分发

    首发于公众号:Python编程时光 1. 为什么需要对项目分发打包? 平常我们习惯了使用 pip 来安装一些第三方模块,这个安装过程之所以简单,是因为模块开发者为我们默默地为我们做了所有繁杂的工作,而 ...

  9. JavaScript箭头函数中的this详解

    前言 箭头函数极大地简化了this的取值规则. 普通函数与箭头函数 普通函数指的是用function定义的函数: var hello = function () { console.log(" ...

  10. centos7 编译安装redis

    1.下载redis源码包 cd /opt wget http://download.redis.io/releases/redis-4.0.12.tar.gz 2.解压源码包 tar zxf redi ...