Ubuntu apt-get 安裝Mongodb

最近要用mongodb做個項目,環境是Ubuntu.

切換到root用戶

apt-get update更新源,源使用的是阿里雲的源,感覺速度快,好用。

apt-get mongodb


查看進程是否啓動

wKiom1TYbZKxWf6SAADGNt_b3rw168.jpg

mongo查看版本

wKioL1TYb86hFAhLAAKxQW82mAs260.jpg

mongodb安裝到哪裏了呢?

【1】 mongodb的主程序目錄在 /usr/bin/下面 mongod


【2】 mongo的log日誌的位置/var/log/mongodb/mongodb.log


【3】mongo 配置文件位置 /etc/mongodb.conf


需要創建data/db在/var/lib/mongdb/下面
dbpath 位置 /var/lib/mongdb/data/db

logpath 位置 /var/log/mongdb/mongdb.log


啓動mongdb

/usr/bin/mongod -dbpath=/var/lib/mongodb/data/db --auth --port 27017

 --logpath=/var/log/mongodb/mogodb.log --logappend 


cd /usr/bin

./mongod --dbpath=/var/lib/mongodb/data/db --port=27017 --auth --logpath=/var/log/mongodb/mogodb.log --logappend


關閉啓動mongodb服務

sudo service mongodb stop
sudo service mongodb start


mongodb啓動起來後,需要重新開一個窗口來進行操作

wKiom1TZW8DwNjyfAAZXwLCurhI328.jpg

wKioL1TZXNTibpWUAAg0rUZlQ4M089.jpg


root@ubuntu-bug20114:/# pgrep mongo -l
1384 mongod
root@ubuntu-bug20114:/# mongo
MongoDB shell version: 2.6.3
connecting to: test
> show dbs
admin  (empty)
local  0.078GB
> use admin
switched to db admin
> db.system.user.find()
> db.addUser("super","super")
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "super", "roles" : [ "root" ] }
> db.system.users.find()
error: { "$err" : "not authorized for query on admin.system.users", "code" : 13 }
> db.auth("super","super")
1
> db.system.users.find()
{ "_id" : "admin.super", "user" : "super", "db" : "admin", "credentials" : { "MONGODB-CR" : "9c93023a901c2adf9c7377076b8c963a" }, "roles" : [ { "role" : "root", "db" : "admin" } ] }
> use test
switched to db test
> db.addUser("test","test")
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "test", "roles" : [ "dbOwner" ] }
> db.addUser("readonly","readonly",true)
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "readonly", "roles" : [ "read" ] }
> use admin
switched to db admin
> db.system.users.find()
{ "_id" : "admin.super", "user" : "super", "db" : "admin", "credentials" : { "MONGODB-CR" : "9c93023a901c2adf9c7377076b8c963a" }, "roles" : [ { "role" : "root", "db" : "admin" } ] }
{ "_id" : "test.test", "user" : "test", "db" : "test", "credentials" : { "MONGODB-CR" : "a6de521abefc2fed4f5876855a3484f5" }, "roles" : [ { "role" : "dbOwner", "db" : "test" } ] }
{ "_id" : "test.readonly", "user" : "readonly", "db" : "test", "credentials" : { "MONGODB-CR" : "68eda9b099ddb587da03a33273a9f4da" }, "roles" : [ { "role" : "read", "db" : "test" } ] }


exit退出

重新驗證用戶權限

wKioL1TZYRGjznC-AAL5W6PCfCA399.jpg

報錯,沒有認證



參考這個

http://blog.itpub.net/22664653/viewspace-715617/

http://blog.csdn.net/weiwangsisoftstone/article/details/39269373

http://www.cnblogs.com/zj1111184556/p/3599828.html



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章