Ubuntu apt-get 安装Mongodb
2015-02-09 16:24
211 查看
最近要用mongodb做个项目,环境是Ubuntu.
切换到root用户
apt-get update更新源,源使用的是阿里云的源,感觉速度快,好用。
apt-get mongodb
查看进程是否启动
![](http://s3.51cto.com/wyfs02/M00/59/95/wKiom1TYbZKxWf6SAADGNt_b3rw168.jpg)
mongo查看版本
![](http://s3.51cto.com/wyfs02/M00/59/92/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启动起来后,需要重新开一个窗口来进行操作
![](http://s3.51cto.com/wyfs02/M01/59/99/wKiom1TZW8DwNjyfAAZXwLCurhI328.jpg)
![](http://s3.51cto.com/wyfs02/M02/59/95/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退出
重新验证用户权限
![](http://s3.51cto.com/wyfs02/M01/59/96/wKioL1TZYRGjznC-AAL5W6PCfCA399.jpg)
报错,没有认证
参考这个
http://blog.itpub.net/22664653/viewspace-715617/
http://blog.csdn.net/weiwangsisoftstone/article/details/39269373
/article/7044583.html
本文出自 “无可取代” 博客,转载请与作者联系!
切换到root用户
apt-get update更新源,源使用的是阿里云的源,感觉速度快,好用。
apt-get mongodb
查看进程是否启动
![](http://s3.51cto.com/wyfs02/M00/59/95/wKiom1TYbZKxWf6SAADGNt_b3rw168.jpg)
mongo查看版本
![](http://s3.51cto.com/wyfs02/M00/59/92/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启动起来后,需要重新开一个窗口来进行操作
![](http://s3.51cto.com/wyfs02/M01/59/99/wKiom1TZW8DwNjyfAAZXwLCurhI328.jpg)
![](http://s3.51cto.com/wyfs02/M02/59/95/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退出
重新验证用户权限
![](http://s3.51cto.com/wyfs02/M01/59/96/wKioL1TZYRGjznC-AAL5W6PCfCA399.jpg)
报错,没有认证
参考这个
http://blog.itpub.net/22664653/viewspace-715617/
http://blog.csdn.net/weiwangsisoftstone/article/details/39269373
/article/7044583.html
本文出自 “无可取代” 博客,转载请与作者联系!
相关文章推荐
- Ubuntu14.04下Mongodb(在线安装方式|apt-get)安装部署步骤(图文详解)(博主推荐)
- mongodb3 ubuntu离线安装(非apt-get)及用户管理
- Ubuntu16.04下Mongodb(离线安装方式|非apt-get)安装部署步骤(图文详解)(博主推荐)
- Ubuntu apt-get安装 mongodb
- Ubuntu14.04下Mongodb(离线安装方式|非apt-get)安装部署步骤(图文详解)(博主推荐)
- Ubuntu16.04下Mongodb(离线安装方式|非apt-get)安装部署步骤(图文详解)
- Ubuntu安装MongoDB(非apt-get方式)
- Ubuntu下MongoDB的安装与使用(离线安装方式|非apt-get)
- ubuntu 10.04安装xbmc 媒体中心sudo apt-get install xbmc
- Ubuntu安装Cacti,Nagios.Smokeping(apt-get方法)
- ubuntu 12.04 apt-get/wget/gem 使用代理安装软件
- ubuntu自动安装软件apt-get命令
- Ubuntu 用apt-get 安装sun jdk
- Ubuntu apt-get安装软件包典型应用
- Ubuntu使用命令安装jdk失败的解决方案--sudo apt-get install sun-java6-jdk
- ubuntu:apt-get方式安装ibus输入法
- ubuntu用apt-get方法安装mysql5 + Apache2 + PHP5+Phpmyadmin
- Ubuntu切记 源码安装lamp后 不用使用 APT-GET 安装相关模块
- ubuntu自动安装软件apt-get命令
- ubuntu图下安装软件出现You might want to run 'apt-get -f install' to correct these解决