解压缩mongodb-linux-x86_64-rhel70-3.4.9.tgz,重新命名
mv mongodb-linux-i686-2.6.7 mongodb
配置目录log和db,即mkdir –p /data/log和mkdir –p /data/db
新建一个配置文件并写入配置信息vi mongodb.conf
配置信息如下:
dbpath = /data/db #数据文件存放目录
logpath = /data/log/mongodb.log #日志文件存放目录
port = 27017 #端口
fork = true #以守护程序的方式启用,即在后台运行
nohttpinterface = true
在bin文件夹下启动./mongod --config mongodb.conf
创建数据库liunnTest,用如下命令:
use liunnTest
switched to db liunnTest
db
liunnTest
show liunnTest
local 0.078GB
test 0.078GB
可以看到,我们刚创建的数据库 liunnTest并不在数据库的列表中,要显示它,我们需要向liunnTest数据库插入一些数据,如下:
db.liunnTest.insert({“name”:“test0”})
WriteResult({ “nInserted” : 1 })
show dbs
local 0.078GB
liunnTest 0.078GB
test 0.078GB
创建用户及密码
use liunnTest
db.createUser({user:“admin”,pwd:“testPwd”,roles:[{role:“readWrite”,db:“liunnTest”}]})