鑑於最近 mongodb 的裸奔事件頻傳
我也來設定一下我的 mongodb
順便玩一下 MongoHub for Mac 這套 GUI

以前 mongodb 的設計呢
是只要建立了 user 就會啟用 auth
但新版的不是這樣

記錄一下我這次 2.6.10 版的設定情況

首先

在預設的設定下(listening local only)

1
2
3
4
5
6
7
8
9
$ mongo
> use admin
> db.createUser({
user: "root",
pwd: "password",
roles: [{
role: "userAdminAnyDatabase", db: "admin"
}]
})

然後

1
$ sudo vim /etc/mongodb.conf

加上 server 的 public ip 到 bind_ip
auth = true 給 uncomment


You have to uncomment auth = true here

to make server running with Authentication

not just create users

也就是如果你照以前的作法只建了 user

那你就成了裸奔的 mongodb 管理者

if u did,

you will be one of mongodb admin

who putting naked servers straight onto the Internet 😅

最後
記得

1
$ sudo service mongodb restart


話說, 這裡還有一個坑~

if you type service mongod start on DigitalOcean build

it will always complain about No such config file…😫

但好像有一些 build 是 mongod 不是 mongodb