Ubuntu apt-get 安装Mongodb
最近要用mongodb做个项目,环境是Ubuntu.
切换到root用户
apt-get update更新源,源使用的是阿里云的源,感觉速度快,好用。
apt-get mongodb
查看进程是否启动
mongo查看版本
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启动起来后,需要重新开一个窗口来进行操作
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退出
重新验证用户权限
报错,没有认证
参考这个
http://blog.itpub.net/22664653/viewspace-715617/
http://blog.csdn.net/weiwangsisoftstone/article/details/39269373
http://www.cnblogs.com/zj1111184556/p/3599828.html