網址:https://blog.csdn.net/sl1992/article/details/83964310shell
文章目錄
1.容許全部地址訪問
2.綁定內網IP
3.綁定多個IP服務器
Linux服務器上安裝MongoDB後,容許其它客戶端IP訪問MongoDB服務器。
阿里雲服務器須要設置入站規則,可參見使用外網訪問阿里雲服務器ZooKeeperapp
1.容許全部地址訪問
NOTE:dom
net.bindIp and net.bindIpAll are mutually exclusive. That is, you can specify one or the other, but not both.
net.bindIp和net.bindIpAll是互斥的。也就是說,您能夠指定其中一個,但不能同時指定二者。socket
可直接設置bindIpAll: true,即容許全部的IPv4和IPv6地址訪問阿里雲
# network interfaces
net:
port: 27017
bindIpAll: true
1
2
3
4
也能夠根據後面註釋提示,將bindIp修改成0.0.0.0,::.net
# 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,阿里雲服務器外網配置入站規則,由阿里雲服務器的外網向內網轉發。blog
配置主機名和內網IP的映射
sudo vi /etc/hosts,添加配置項192.168.1.200 solangip
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6ci
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 interfacesnet: 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 版權聲明:本文爲博主原創文章,轉載請附上博文連接!