Centos6.5 x64简单安装MongoDB

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos6.5 x64简单安装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的主要内容,如果未能解决你的问题,请参考以下文章

MongoDB学习Centos6.5下安装mongoDB

Centos6.5安装配置mongodb

CentOS6.5下安装Mongodb3.2.4

Centos6.5 MongoDB安装以及php_mongo扩展的安装

CentOS6.5_X64下安装配置MongoDB数据库

Mongodb 3.4 + Centos6.5 配置 + mysql.sql转为csv 或 json导入和导出Mongo (64位系统)