惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LINUX DO - 最新话题
罗磊的独立博客
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Hacker News: Front Page
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Hacker News
The Hacker News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
大猫的无限游戏
大猫的无限游戏
PCI Perspectives
PCI Perspectives
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Proofpoint News Feed
NISL@THU
NISL@THU
小众软件
小众软件
S
Security Affairs
腾讯CDC
人人都是产品经理
人人都是产品经理
C
Check Point Blog
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Project Zero
Project Zero
G
Google Developers Blog
博客园 - 三生石上(FineUI控件)
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园_首页
Jina AI
Jina AI
The Cloudflare Blog
C
Cisco Blogs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
L
Lohrmann on Cybersecurity
Y
Y Combinator Blog
W
WeLiveSecurity
V
Visual Studio Blog
Scott Helme
Scott Helme
N
News | PayPal Newsroom
I
Intezer
C
CXSECURITY Database RSS Feed - CXSecurity.com
Attack and Defense Labs
Attack and Defense Labs
Spread Privacy
Spread Privacy
Webroot Blog
Webroot Blog
T
Threatpost
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
N
News and Events Feed by Topic

博客园 - K!ngZ

常用正则 MongoDB学习笔记(9)--优化器 profile MongoDB学习笔记(8)--索引及优化索引 MongoDB学习笔记(6)--数据备份数据恢复 MongoDB学习笔记(5)--数据导入导出mongoexport MongoDB学习笔记(4)--Capped Collection MongoDB学习笔记(3)--高级查询 MongoDB学习笔记(2)--增删改查 MongoDB学习笔记(1)--了解MongoDB 远程文件抓取类 [转]BizTalk开发系列(三十四) Xpath SQL Server 2005 命令行实用工具 [转]雅虎公司C#笔试题 [转] OLE DB 访问接口 "SQLNCLI" 返回了消息 "未指定的错误"。 Asp.net中的日期处理函数 [转]正则表达式实现资料验证的技术总结 ajax乱码问题解决 [转]ASP.Net缓存总结 [转]预防按钮的多次点击【恶意刷新】
MongoDB学习笔记(7)--访问控制
K!ngZ · 2011-09-15 · via 博客园 - K!ngZ

官方手册中启动 MongoDB  服务时没有任何参数,一旦客户端连接后可以对数据库任意操作,而且可以远程访问数据库,所以推荐开发阶段可以不设置任何参数,但对于生产环境还

是要仔细考虑一下安全方面的因素,而提高 MongoDB  数据库安全有几个方面: 

  绑定IP内网地址访问MongoDB服务 

  设置监听端口 

  使用用户名和口令登录

绑定IP 内网地址访问MongoDB服务

MongoDB 可以限制只允许某一特定 IP 来访问,只要在启动时加一个参数 bind_ip 即可,如下: 

服务端限制只有192.168.1.103这个IP可以访问MongoDB 服务 

[root@localhost bin]# ./mongod --bind_ip 192.168.1.103  

设置监听端口 

官方默认的监听端口是27017,为了安全起见,一般都会修改这个监听端口,避免恶意的连

接尝试,具体如下: 

将服务端监听端口修改为28018 

[root@localhost bin]# ./mongod --bind_ip 192.168.1.103 --port 28018  

使用用户名和口令登录 

MongoDB默认的启动是不验证用户名和密码的,启动MongoDB后,可以直接用MongoDB连接上来,对所有的库具有root权限。所以启动的时候指定参数,可以阻止客户端的访问和连接。

先启用系统的登录验证模块,  只需在启动时指定 auth  参数即可,如

[root@localhost bin]# ./mongod --auth  

建立系统root帐号

在admin库中新添一个用户root:  

[root@localhost bin]# ./mongo 

MongoDB shell version: 1.8.1 

connecting to: test 

> db.addUser("root","111") 

        "user" : "root", 

        "readOnly" : false, 

        "pwd" : "e54950178e2fa777b1d174e9b106b6ab" 

> db.auth("root","111")  

本地客户端连接,指定用户,结果如下:  

 [root@localhost bin]# ./mongo -u root -p 

MongoDB shell version: 1.8.1 

Enter password:  

connecting to: test 

> show collections; 

system.indexes 

system.users 

建立指定权限用户 

MongoDB 也支持为某个特定的数据库来设置用户,如我们为 test 库设一个只读的用户user_reader:  

[root@localhost bin]# ./mongo -u root -p 

MongoDB shell version: 1.8.1 

Enter password:  

connecting to: test 

> show collections; 

system.indexes 

system.users 

> use test 

switched to db test 

> db.addUser("user_reader", "user_pwd", true) 

        "user" : "user_reader", 

        "readOnly" : true, 

        "pwd" : "0809760bb61ee027199e513c5ecdedc6" 

}