下载安装文件:
下载 wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.6.3.tgz
解压: tar xzf mongodb-linux-x86_64-1.6.3.tgz
创建日志文件: touch /usr/local/mongodb/logs
创建数据文件夹: mkdir /usr/local/mongodb/data
启动:/usr/local/mongodb/mongodb-linux-x86_64-1.6.3/bin/mongod --dbpath=/usr/local/mongodb/data/ -logpath=/usr/local/mongodb/logs --auth -port 27017 -fork
开机启动: echo "usr/local/mongodb/mongodb-linux-x86_64-1.6.3/bin/mongod --dbpath=/usr/local/mongodb/data/ -logpath=/usr/local/mongodb/logs --auth -port 27017" >>/etc/rc.local
控制台:mongodb-linux-x86_64-1.6.3/bin/mongo
添加用户:
> use admin
switched to db admin
> db.addUser('root','******‘)
{
"user" : "root",
"readOnly" : false,
"pwd" : "a1ce1476ead3c005fd6c741f8417d01d"
}
> db.auth('root','******')
1
创建数据库:
use user_center;
switched to db user_center
db.shutdownServer();停止数据库
关于mongoDB 文章:
http://www.youkuaiyun.com/article/2014-04-09/2819221-build-high-avialable-mongodb-cluster-part-1/
PS:mongoDB 3.0 创建用户方法已经不再是addUser 方法 而是db.createUser(userDocument),
具体的使用:
db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]
db.auth(username, password)
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., capped : ..., max : ... } )
db.createUser(userDocument)
db.currentOp() displays currently executing operations in the db
db.dropDatabase()
db.eval(func, args) run code server-side
db.fsyncLock() flush data to disk and lock server for backups
db.fsyncUnlock() unlocks server following a db.fsyncLock()
db.getCollection(cname) same as db['cname'] or db.cname
db.getCollectionInfos()
db.getCollectionNames()
db.getLastError() - just returns the err msg string
db.getLastErrorObj() - return full status object
db.getLogComponents()
db.getMongo() get the server connection object
db.getMongo().setSlaveOk() allow queries on a replication slave server
db.getName()
db.getPrevError()
db.getProfilingLevel() - deprecated
db.getProfilingStatus() - returns if profiling is on and slow threshold
db.getReplicationInfo()
db.getSiblingDB(name) get the db at the same server as this one
db.getWriteConcern() - returns the write concern used for any operations on this db, inherited from server object if set
db.hostInfo() get details about the server's host
db.isMaster() check replica primary status
db.killOp(opid) kills the current operation in the db
db.listCommands() lists all the db commands
db.loadServerScripts() loads all the scripts in db.system.js
db.logout()
db.printCollectionStats()
db.printReplicationInfo()
db.printShardingStatus()
db.printSlaveReplicationInfo()
db.dropUser(username)
db.repairDatabase()
db.resetError()
db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into { cmdObj : 1 }
db.serverStatus()
db.setLogLevel(level,<component>)
db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all
db.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the db
db.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the db
db.setVerboseShell(flag) display extra information in shell output
db.shutdownServer()
db.stats()
db.version() current version of the server
官网文档:http://docs.mongodb.org/manual/reference/method/db.createUser/