码迷,mamicode.com
首页 > 数据库 > 详细

Centos6.5 x64简单安装MongoDB

时间:2016-10-25 20:16:19      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:profile   local   mongodb   

Centos6.4 x64简单安装MongoDB

一、下载MongoDB2.4.9


下载MongoDB

wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.9.tgz

解压MongoDB

tar -zxvf mongodb-linux-x86_64-2.4.9.tgz -C /usr/src

移动MongoDB目录

mv /usr/src/mongodb-linux-x86_64-2.4.9 /usr/local/mongodb


二、部署MongoDB


进入MongoDB目录

cd /usr/local/mongodb


创建数据目录和日志目录

mkdir -p /data/mongodb/db

mkdir -p /data/mongodb/log


vi /etc/profile


PATH=$PATH:/usr/local/mongodb/bin


source /etc/profile


以后台方式启动MongoDB


mongod --dbpath=/data/mongodb/db --logpath=/data/mongodb/log/mongodb.log --fork

about to fork child process, waiting untilserver is ready for connections.

forked process: 6440

all output going to:/data/mongodb/log/mongodb.log

child process started successfully, parentexiting

设置开机启动MongoDB

echo "mongod --dbpath=/data/mongodb/db --logpath=/data/mongodb/log/mongodb.log --fork" >> /etc/rc.local


查看是否运行

pgrep mongo -l

6440 mongod


进入数据库

mongo

MongoDB shell version: 2.4.9

connecting to: test

Welcome to the MongoDB shell.

For interactive help, type"help".

For more comprehensive documentation, see

      http://docs.mongodb.org/

Questions? Try the support group

      http://groups.google.com/group/mongodb-user

>

> show dbs

local  0.078125GB

>exit

bye


查看端口

netstat -nalupt | grep  mongo

tcp       0      0 0.0.0.0:28017               0.0.0.0:*                   LISTEN      6440/mongod

tcp       0      0 0.0.0.0:27017               0.0.0.0:*                   LISTEN      6440/mongod


二,添加验证登录

进入数据库

mongo

###添加账户

db.addUser("root","123456");

db.system.users.find();

db.auth("root","123456");

exit


###验证登录

mongo admin -u root -p 123456


###关闭mongodb

pgrep mongo

kill -9 21797


###加验证重启mongodb

pgrep mongo

mongod --dbpath=/data/mongodb/db --logpath=/data/mongodb/log/mongodb.log --auth --fork

mongo

MongoDB shell version: 2.4.9

connecting to: test

> show dbs;

Tue Oct 25 17:57:15.772 listDatabases failed:{ "ok" : 0, "errmsg" : "unauthorized" } at src/mongo/shell/mongo.js:46

> exit


###使用验证方式登录mongodb

mongo admin -u root -p 123456


Centos6.5 x64简单安装MongoDB

标签:profile   local   mongodb   

原文地址:http://haowen.blog.51cto.com/3486731/1865321

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!