1,下载安装
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz # 下载 tar -zxvf mongodb-linux-x86_64-3.0.6.tgz # 解压 mv mongodb-linux-x86_64-3.0.6/ /usr/local/mongodb # 将解压包拷贝到指定目录
2,创建配置文件,用于后台启动。
cd /usr/local/mongodb chmod -R 700 /usr/local/mongodb/bin/
mkdir dbdata,mkdri logs vi mongod.conf 输入: dbpath=/usr/local/mongodb/dbdata logpath=/usr/local/mongodb/logs/mongodb.log logappend = true port = 27017 fork = true
3,启动,关闭 ./mongod -f /usr/local/mongodb/mongod.conf
$ ./mongo > db.shutdownServer()
4,测试 cd /usr/local/mongodb/bin ./mongo db.runoob.insert({x:10}) db.runoob.find()
auth=true #开启权限验证
use admin
db.createUser({user:"sa",pwd:"123456",roles:[{role:"__system",db:"admin"}]})
use mydb
db.createUser({user:"test",pwd:"123456",roles:[{role:"dbOwner",db:"mydb"}]})