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
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM