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",240);">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