Skip to content

Latest commit

 

History

History
191 lines (132 loc) · 4.44 KB

mongodb.md

File metadata and controls

191 lines (132 loc) · 4.44 KB

mongodb

官方工具

mac 下安装社区版

$ brew install mongodb --with-openssl

自启动

cp $(brew --prefix mongodb)/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

ubuntu 安装企业版

CentOS 安装企业版

配置

用户

创建用户

mongo
use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

登录用户

mongo
use admin
db.auth("myUserAdmin", "abc123" )

mongodb

启动

./bin/mongod --dbpath ~/mongodb/db --fork --logpath ~/mongodb/log/mongodb.log --logappend

查看状态

$ ./bin/mongostat

关闭

$ ./bin/mongo
> use admin
> db.shutdownServer()

$ ./bin/mongod --shutdown

available only on Linux systems

mongo shell

进入命令行模式

$ cd <mongodb installation dir>
$ ./bin/mongo

创建数据库

use <db_name>

查看所有的 collection

show collections

查看 collection 所有数据

db.foo.find()

foo 为对应 collection 名字

Questions

1 启动警告

2016-12-13T13:58:04.601+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-12-13T13:58:04.601+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-12-13T13:58:04.601+0800 I CONTROL  [initandlisten]
2016-12-13T13:58:04.601+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-12-13T13:58:04.601+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

解决方法:

/etc/rc.local 中写入

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then  
   echo never > /sys/kernel/mm/transparent_hugepage/enabled  
fi  
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then  
   echo never > /sys/kernel/mm/transparent_hugepage/defrag  
fi  

2 最大文件数太小

** WARNING: soft rlimits too low. rlimits set to 1024 processes, 100000 files. Number of processes should be at least 50000 : 0.5 times number of files.

解决方法:

参考 Recommended ulimit Settings

ulimit -n 64000
ulimit -u 64000

3

** WARNING: Access control is not enabled for the database.
**          Read and write access to data and configuration is unrestricted.

解决方法:

参考 security.authorization

/etc/mongod.conf 配置:

security:
  authorization: enabled