- 浏览: 16980 次
文章分类
最新评论
【MongoDB】2、安装MongoDB 2.6.1 on Unbuntu 14.04(学习流水账)
计划:
装一个虚机,ubuntu吧,14.04 Trusty Tahr。
安装MongoDB
网络资源:
http://mirrors.aliyun.com/ubuntu-releases/14.04/ubuntu-14.04-server-amd64.iso.torrent(公网)
http://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/14.04/ubuntu-14.04-server-amd64.iso.torrent(教育网)
http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
虚拟机:
处理器数量1:内核数:1(多核对MongoDB帮助不大);MM 1G(RAM瓶颈应该会出现);HD 20G。
安装Unbuntu,用户名:gd,密码:cgdc。
TO小超超,服务器在1.4.3x,一起玩儿吧。
由于Ubuntu官方APT源里的MongoDB版本比较旧,这里用MongoDB提供的APT源进行安装。
要使用第三方源上的软件,除了在sources.list上添加对应的源外,还要有增加相应的公钥Key才能正确安装软件。
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-org
报错:unable to locate package
sudo apt-get install mongodb就可以,可能版本会老一点,无所谓吧。
要更新的包包括:libboost、libc、libgcc、mongodb、mongodb-clients、mongodb-dev、mongodb-server。
一共38个,下载41.5M,90多K,速度还好,可以先去看会儿书了。
下载到一半,断了。
F!
弃用apt。
sudo apt-get install openssh-server
这个很快。
用“netstat -tlp”或“ps -e | grep ssh”确认sshd启动。
http://www.cnblogs.com/chen1987lei/archive/2010/12/02/1894768.html
解压后得到一堆二进制可执行文件,除了bsondump其他都是mongo打头的。拷贝到 /usr/bin 下面。
chmod a+x
到此,装好。
/*
如果安装特定版本:
apt-get install mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1
禁用自动升级:
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
运行:
sudo /etc/init.d/mongod start
sudo /etc/init.d/mongod stop
sudo /etc/init.d/mongod restart
*/
启动,报错,说dbpath不存在,需要手动创建目录。
创建了 /data/mongodb1 目录。
启动的时候加--dbpath。
启动没有报错,但忘了 --fork方式启动了。
还好,可以ssh连。
报错:sda1:WRITE SAME faild.Manually zeroing.没有修改配置,后来没见过这个问题了。为什么呢?
数据目录没开写权限?sudo启动服务器都不行?
use admin
db.shutdownServer()
启动config:
启动选项很多,每次在命令行敲麻烦死了,写在config文件里吧。
选项包括:
--port
--fork(以守护进程方式执行)
--logpath
--config
配置文件写法:
port = 110271
fork = true
logpath = mongodb.log
无论如何,进入Shell了。
敲help,先爽一下吧。
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory, 'global' is default
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
如果是方法,敲上括号是调用,不敲括号,输出方法原型。
客户端Shell:
运行./mongo既可以启动Shell对mongodb进行管理。
Shell使用Javascipt语法,可以对数据进行管理,可以对数据库进行管理。
官网版本:http://try.mongodb.org/。 可以上手玩玩。
很简单,没什么可说的。
创建个数据库吧:
>
> use cgdc
switched to db cgdc
> show collections
> show dbs
admin (empty)
cgdc (empty)
local 0.078GB
> db.users.help()
DBCollection help
db.users.find().help() - show DBCursor help
db.users.count()
db.users.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
db.users.convertToCapped(maxBytes) - calls {convertToCapped:'users', size:maxBytes}} command
db.users.dataSize()
db.users.distinct( key ) - e.g. db.users.distinct( 'x' )
db.users.drop() drop the collection
db.users.dropIndex(index) - e.g. db.users.dropIndex( "indexName" ) or db.users.dropIndex( { "indexKey" : 1 } )
db.users.dropIndexes()
db.users.ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups
db.users.reIndex()
db.users.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
e.g. db.users.find( {x:77} , {name:1, x:1} )
db.users.find(...).count()
db.users.find(...).limit(n)
db.users.find(...).skip(n)
db.users.find(...).sort(...)
db.users.findOne([query])
db.users.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )
db.users.getDB() get DB object associated with collection
db.users.getPlanCache() get query plan cache associated with collection
db.users.getIndexes()
db.users.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
db.users.insert(obj)
db.users.mapReduce( mapFunction , reduceFunction , <optional params> )
db.users.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor
db.users.remove(query)
db.users.renameCollection( newName , <dropTarget> ) renames the collection.
db.users.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
db.users.save(obj)
db.users.stats()
db.users.storageSize() - includes free space allocated to this collection
db.users.totalIndexSize() - size in bytes of all the indexes
db.users.totalSize() - storage allocated for all data and indexes
db.users.update(query, object[, upsert_bool, multi_bool]) - instead of two flags, you can pass an object with fields: upsert, multi
db.users.validate( <full> ) - SLOW
db.users.getShardVersion() - only for use with sharding
db.users.getShardDistribution() - prints statistics about data distribution in the cluster
db.users.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
db.users.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set
db.users.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection
db.users.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
> db.users.save({name:"liuhailong",hometown:"Hebei"});
WriteResult({ "nInserted" : 1 })
> show dbs;
admin (empty)
cgdc 0.078GB
local 0.078GB
> db.cgdc.users.find()
> ;
> cgdc.users.find()
2014-05-17T03:14:37.528-0700 ReferenceError: cgdc is not defined
> db.users.find()
{ "_id" : ObjectId("5377366b70e0a3f0e2e28f91"), "name" : "liuhailong", "hometown" : "Hebei" }
>
HOHO
安全和权限:
use [databasename]
db.addUser(username,pwd,isReadOnly);
> use admin
switched to db admin
> db.addUser("gd","cgdc");
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "gd", "roles" : [ "root" ] }
> use cgdc
switched to db cgdc
> db.createUser("cgdc","cgdc");
2014-05-17T03:17:58.058-0700 Error: couldn't add user: no such cmd: 0 at src/mongo/shell/db.js:1004
> db.addUser("cgdc","cgdc");
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "cgdc", "roles" : [ "dbOwner" ] }
> db.createUser().help()
2014-05-17T03:19:16.032-0700 TypeError: Cannot read property 'user' of undefined at src/mongo/shell/db.js:979
> db.createUser
function (userObj, writeConcern) {
var commandExisted = this._createUser(userObj, writeConcern);
if (!commandExisted) {
throw Error("'createUser' command not found. This is most likely because you are " +
"talking to an old (pre v2.6) MongoDB server");
}
}
> db.addUser("cgdc_readonly","cgdc",true);
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "cgdc_readonly", "roles" : [ "read" ] }
>
--fork 运行,一定要指定logpath --
启动服务器时,加 --auth 选项。
gd@ubuntu:~$ sudo /usr/bin/mongo
MongoDB shell version: 2.6.1
connecting to: test
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
> show dbs
2014-05-17T03:24:14.308-0700 listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
} at src/mongo/shell/mongo.js:47
>
登录操作:
db.auth(username,pwd)
登录不成功,去掉--auth选项重新连。
> db.system.users.find()
{ "_id" : "admin.gd", "user" : "gd", "db" : "admin", "credentials" : { "MONGODB-CR" : "d41a08d27097c5b67823dfdd85e9494d" }, "roles" : [ { "role" : "root", "db" : "admin" } ] }
{ "_id" : "cgdc.cgdc", "user" : "cgdc", "db" : "cgdc", "credentials" : { "MONGODB-CR" : "714ab4fd93e3012475de54246a444516" }, "roles" : [ { "role" : "dbOwner", "db" : "cgdc" } ] }
{ "_id" : "cgdc.cgdc_readonly", "user" : "cgdc_readonly", "db" : "cgdc", "credentials" : { "MONGODB-CR" : "c1a9ebbe08d3d0a27a33bd0435ee86f1" }, "roles" : [ { "role" : "read", "db" : "cgdc" } ] }
>
删掉重来:
> db.system.users.remove();
2014-05-17T03:33:45.736-0700 remove needs a query at src/mongo/shell/collection.js:299
> db.system.users.remove({});
WriteResult({ "nRemoved" : 3 })
> db.system.users.find();
>
删除用户:
db.system.users.remove({"user":username});
这次语法是这样:
use admin
db.createUser( {
user: "admin",
pwd: "cgdc",
roles: [ {
role: "userAdminAnyDatabase",
db: "admin"
} ]
}
);
db.createUser( {
user: "root",
pwd: "cgdc",
roles: [ { role: "root", db: "admin" } ]
}
);
use cgdc
db.createUser({
user: "cgdc",
pwd: "cgdc",
roles:[{
role: "dbOwner",
db: "cgdc"
}]
}
);
真难用!!
试试看
gd@ubuntu:~$ sudo /usr/bin/mongo -u admin -p
MongoDB shell version: 2.6.1
Enter password:
connecting to: test
2014-05-17T03:43:55.825-0700 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
gd@ubuntu:~$ sudo /usr/bin/mongo -u cgdc -p
MongoDB shell version: 2.6.1
Enter password:
connecting to: test
2014-05-17T03:44:10.909-0700 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
gd@ubuntu:~$ sudo /usr/bin/mongo
MongoDB shell version: 2.6.1
connecting to: test
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
> db.auth("cgdc","cgdc");
Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 }
0
>
还是不行。
看看日志。
switched to db cgdc
> db.auth("cgdc","cgdc");
1
>
遇到问题多看日志!!!
其他安全考虑:
--bindip localhost
--noscripting (禁止服务器端JavaScript执行)
--nohttpinterface
传输加密(SSH隧道)
先到这里吧。
装一个虚机,ubuntu吧,14.04 Trusty Tahr。
安装MongoDB
网络资源:
http://mirrors.aliyun.com/ubuntu-releases/14.04/ubuntu-14.04-server-amd64.iso.torrent(公网)
http://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/14.04/ubuntu-14.04-server-amd64.iso.torrent(教育网)
http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
虚拟机:
处理器数量1:内核数:1(多核对MongoDB帮助不大);MM 1G(RAM瓶颈应该会出现);HD 20G。
安装Unbuntu,用户名:gd,密码:cgdc。
TO小超超,服务器在1.4.3x,一起玩儿吧。
安装指导:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/由于Ubuntu官方APT源里的MongoDB版本比较旧,这里用MongoDB提供的APT源进行安装。
要使用第三方源上的软件,除了在sources.list上添加对应的源外,还要有增加相应的公钥Key才能正确安装软件。
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-org
报错:unable to locate package
sudo apt-get install mongodb就可以,可能版本会老一点,无所谓吧。
要更新的包包括:libboost、libc、libgcc、mongodb、mongodb-clients、mongodb-dev、mongodb-server。
一共38个,下载41.5M,90多K,速度还好,可以先去看会儿书了。
下载到一半,断了。
F!
弃用apt。
sudo apt-get install openssh-server
这个很快。
用“netstat -tlp”或“ps -e | grep ssh”确认sshd启动。
http://www.cnblogs.com/chen1987lei/archive/2010/12/02/1894768.html
解压后得到一堆二进制可执行文件,除了bsondump其他都是mongo打头的。拷贝到 /usr/bin 下面。
chmod a+x
到此,装好。
/*
如果安装特定版本:
apt-get install mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1
禁用自动升级:
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
运行:
sudo /etc/init.d/mongod start
sudo /etc/init.d/mongod stop
sudo /etc/init.d/mongod restart
*/
启动,报错,说dbpath不存在,需要手动创建目录。
创建了 /data/mongodb1 目录。
启动的时候加--dbpath。
启动没有报错,但忘了 --fork方式启动了。
还好,可以ssh连。
报错:sda1:WRITE SAME faild.Manually zeroing.没有修改配置,后来没见过这个问题了。为什么呢?
数据目录没开写权限?sudo启动服务器都不行?
use admin
db.shutdownServer()
启动config:
启动选项很多,每次在命令行敲麻烦死了,写在config文件里吧。
选项包括:
--port
--fork(以守护进程方式执行)
--logpath
--config
配置文件写法:
port = 110271
fork = true
logpath = mongodb.log
无论如何,进入Shell了。
敲help,先爽一下吧。
> helpdb.help() help on db methods
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory, 'global' is default
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
如果是方法,敲上括号是调用,不敲括号,输出方法原型。
客户端Shell:
运行./mongo既可以启动Shell对mongodb进行管理。
Shell使用Javascipt语法,可以对数据进行管理,可以对数据库进行管理。
官网版本:http://try.mongodb.org/。 可以上手玩玩。
很简单,没什么可说的。
创建个数据库吧:
>
> use cgdc
switched to db cgdc
> show collections
> show dbs
admin (empty)
cgdc (empty)
local 0.078GB
> db.users.help()
DBCollection help
db.users.find().help() - show DBCursor help
db.users.count()
db.users.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
db.users.convertToCapped(maxBytes) - calls {convertToCapped:'users', size:maxBytes}} command
db.users.dataSize()
db.users.distinct( key ) - e.g. db.users.distinct( 'x' )
db.users.drop() drop the collection
db.users.dropIndex(index) - e.g. db.users.dropIndex( "indexName" ) or db.users.dropIndex( { "indexKey" : 1 } )
db.users.dropIndexes()
db.users.ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups
db.users.reIndex()
db.users.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
e.g. db.users.find( {x:77} , {name:1, x:1} )
db.users.find(...).count()
db.users.find(...).limit(n)
db.users.find(...).skip(n)
db.users.find(...).sort(...)
db.users.findOne([query])
db.users.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )
db.users.getDB() get DB object associated with collection
db.users.getPlanCache() get query plan cache associated with collection
db.users.getIndexes()
db.users.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
db.users.insert(obj)
db.users.mapReduce( mapFunction , reduceFunction , <optional params> )
db.users.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor
db.users.remove(query)
db.users.renameCollection( newName , <dropTarget> ) renames the collection.
db.users.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
db.users.save(obj)
db.users.stats()
db.users.storageSize() - includes free space allocated to this collection
db.users.totalIndexSize() - size in bytes of all the indexes
db.users.totalSize() - storage allocated for all data and indexes
db.users.update(query, object[, upsert_bool, multi_bool]) - instead of two flags, you can pass an object with fields: upsert, multi
db.users.validate( <full> ) - SLOW
db.users.getShardVersion() - only for use with sharding
db.users.getShardDistribution() - prints statistics about data distribution in the cluster
db.users.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
db.users.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set
db.users.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection
db.users.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
> db.users.save({name:"liuhailong",hometown:"Hebei"});
WriteResult({ "nInserted" : 1 })
> show dbs;
admin (empty)
cgdc 0.078GB
local 0.078GB
> db.cgdc.users.find()
> ;
> cgdc.users.find()
2014-05-17T03:14:37.528-0700 ReferenceError: cgdc is not defined
> db.users.find()
{ "_id" : ObjectId("5377366b70e0a3f0e2e28f91"), "name" : "liuhailong", "hometown" : "Hebei" }
>
HOHO
安全和权限:
use [databasename]
db.addUser(username,pwd,isReadOnly);
> use admin
switched to db admin
> db.addUser("gd","cgdc");
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "gd", "roles" : [ "root" ] }
> use cgdc
switched to db cgdc
> db.createUser("cgdc","cgdc");
2014-05-17T03:17:58.058-0700 Error: couldn't add user: no such cmd: 0 at src/mongo/shell/db.js:1004
> db.addUser("cgdc","cgdc");
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "cgdc", "roles" : [ "dbOwner" ] }
> db.createUser().help()
2014-05-17T03:19:16.032-0700 TypeError: Cannot read property 'user' of undefined at src/mongo/shell/db.js:979
> db.createUser
function (userObj, writeConcern) {
var commandExisted = this._createUser(userObj, writeConcern);
if (!commandExisted) {
throw Error("'createUser' command not found. This is most likely because you are " +
"talking to an old (pre v2.6) MongoDB server");
}
}
> db.addUser("cgdc_readonly","cgdc",true);
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "cgdc_readonly", "roles" : [ "read" ] }
>
--fork 运行,一定要指定logpath --
启动服务器时,加 --auth 选项。
gd@ubuntu:~$ sudo /usr/bin/mongo
MongoDB shell version: 2.6.1
connecting to: test
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
> show dbs
2014-05-17T03:24:14.308-0700 listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
} at src/mongo/shell/mongo.js:47
>
登录操作:
db.auth(username,pwd)
登录不成功,去掉--auth选项重新连。
> db.system.users.find()
{ "_id" : "admin.gd", "user" : "gd", "db" : "admin", "credentials" : { "MONGODB-CR" : "d41a08d27097c5b67823dfdd85e9494d" }, "roles" : [ { "role" : "root", "db" : "admin" } ] }
{ "_id" : "cgdc.cgdc", "user" : "cgdc", "db" : "cgdc", "credentials" : { "MONGODB-CR" : "714ab4fd93e3012475de54246a444516" }, "roles" : [ { "role" : "dbOwner", "db" : "cgdc" } ] }
{ "_id" : "cgdc.cgdc_readonly", "user" : "cgdc_readonly", "db" : "cgdc", "credentials" : { "MONGODB-CR" : "c1a9ebbe08d3d0a27a33bd0435ee86f1" }, "roles" : [ { "role" : "read", "db" : "cgdc" } ] }
>
删掉重来:
> db.system.users.remove();
2014-05-17T03:33:45.736-0700 remove needs a query at src/mongo/shell/collection.js:299
> db.system.users.remove({});
WriteResult({ "nRemoved" : 3 })
> db.system.users.find();
>
删除用户:
db.system.users.remove({"user":username});
这次语法是这样:
use admin
db.createUser( {
user: "admin",
pwd: "cgdc",
roles: [ {
role: "userAdminAnyDatabase",
db: "admin"
} ]
}
);
db.createUser( {
user: "root",
pwd: "cgdc",
roles: [ { role: "root", db: "admin" } ]
}
);
use cgdc
db.createUser({
user: "cgdc",
pwd: "cgdc",
roles:[{
role: "dbOwner",
db: "cgdc"
}]
}
);
真难用!!
试试看
gd@ubuntu:~$ sudo /usr/bin/mongo -u admin -p
MongoDB shell version: 2.6.1
Enter password:
connecting to: test
2014-05-17T03:43:55.825-0700 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
gd@ubuntu:~$ sudo /usr/bin/mongo -u cgdc -p
MongoDB shell version: 2.6.1
Enter password:
connecting to: test
2014-05-17T03:44:10.909-0700 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
gd@ubuntu:~$ sudo /usr/bin/mongo
MongoDB shell version: 2.6.1
connecting to: test
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
> db.auth("cgdc","cgdc");
Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 }
0
>
还是不行。
看看日志。
晕死,日志里说,test数据库不是你想连,想连就能练。当然啊,没有给test加用户。
连cgdc库
> use cgdcswitched to db cgdc
> db.auth("cgdc","cgdc");
1
>
遇到问题多看日志!!!
其他安全考虑:
--bindip localhost
--noscripting (禁止服务器端JavaScript执行)
--nohttpinterface
传输加密(SSH隧道)
先到这里吧。
相关推荐
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
详细描述MongoDB 安装步骤以及中途遇到的问题解决
文中的系统版本: centos7.7 参阅官网 link 1.创建源 sudo vim /etc/yum.repos.d/mongodb-org-4.2.repo 写入: [mongodb-org-4.2] name=MongoDB Repository baseurl=...2.执行安装 因为我们此处只
nosql实验六- MongoDB的安装与基本操作.docx
此文件中包含了目前最新的MongoDB的安装文件以及补丁文件。还提供了一个MongoDB的可视化工具。如有需要请下载
本教程是最新版MongoDB数据库,鉴于网上其他资料和安装教程都是基于MongoDB老版本的,最新版的教程与老版本的安装程序有些改变。希望本教程能够帮助大家更好地入门学习MongoDB,特别是对使用Python网络爬虫、数据...
mongod.exe --install --dbpath=d:\mongodb\data --logpath=d:\mongodb\log\log.log -auth -serviceName "serviceName" 2.卸载服务 mongod.exe --remove --serviceName "serviceName" 3.启动服务 ...
windows下mongodb数据库的安装
下载Pycharm最新版本 ...到此这篇关于Pycharm连接MongoDB数据库安装教程的文章就介绍到这了,更多相关Pycharm连接MongoDB内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
本教材为redhat linux 4系统下安装mongodb 32位版本,mongodb是一个文件数据库,其他linux系统下安装都是类似的。
02★MongoDB学习★MongoDB的安装
mongodb安装、测试、规划、代码、命令、linux系统、大众化,简单易懂
mongoDB学习 命令 安装 总结 mongoDB学习 命令 安装 总结mongoDB学习 命令 安装 总结mongoDB学习 命令 安装 总结mongoDB学习 命令 安装 总结mongoDB学习 命令 安装 总结mongoDB学习 命令 安装 总结
MongoDb的安装教程
mongodb的安装资料,包括如果安装和部署mongodb,如何进行分布式处理等。
整理完善的资料,详细介绍mongodb的安装和使用,欢迎大家下载
本课程是一套关于MongoDB应用开发的实战性教程,名为《深入浅出MongoDB应用实战开发(基础、开发指南、系统管理、集群及系统架构)》,教程侧重于讲解MongoDB的常用特性及高级特性,从实际开发的角度出发对MongoDB...
本资料是在线教育课程第一天中使用的mongoDB的安装资料以及使用指南
整理完善的资料,详细介绍mongodb的安装和使用,欢迎大家下载
MongoDB安装文档