1、安装MongoDB
[root@mongo ~] vim/etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
[root@mongo ~] yuminstall-y mongodb-org
[root@mongo ~] chkconfig mongod on
2、修改配置文件
[root@mongo ~] vim/etc/mongod.conf
logpath=/u/mongodb/log/mongod.log
logappend=true
fork=true
port=27017
dbpath=/u/mongodb/data/
3、启动MongoDB
[root@mongo ~] service mongod start
4、添加管理员账号
[root@mongo ~]# mongo
MongoDB shell version: 2.6.5
connecting to:test
> use admin
> db.addUser("root","123456")
>exit
5、修改配置文件,开启账号认证
[root@mongo ~] vim/etc/mongod.conf
auth=true
[root@mongo ~]# service mongod restart
6、验证管理员账号及创建数据库blog
[root@mongo ~]# mongo
MongoDB shell version: 2.6.5
connecting to:test
> use admin
> db.auth("root","123456")
> show dbs
> use blog
> show collections
> show dbs
>exit
网友评论