1. mongodb

1.1. 官方工具

1.2. mac 下安装社区版

$ brew install mongodb --with-openssl

1.2.1. 自启动

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

1.3. ubuntu 安装企业版

1.4. CentOS 安装企业版

1.5. 配置

1.5.1. 用户

创建用户

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

登录用户

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

1.6. mongodb

1.6.1. 启动

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

1.6.2. 查看状态

$ ./bin/mongostat

1.6.3. 关闭

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

$ ./bin/mongod --shutdown

available only on Linux systems

1.7. mongo shell

1.7.1. 进入命令行模式

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

1.7.2. 创建数据库

use <db_name>

1.7.3. 查看所有的 collection

show collections

1.7.4. 查看 collection 所有数据

db.foo.find()

foo 为对应 collection 名字

1.8. Questions

1.8.1. 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

1.8.2. 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

1.8.3. 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

results matching ""

    No results matching ""