最近工作终于到了使用mongodb,以前从来没有接触过mongodb,只知道它属于nosql类型的数据库,这里将安装记录如下:
1、到官网下载安装文件:
这里下载版本为:mongodb-linux-x86_64-2.6.6.gz
[root@localhost tools]# ll mongodb-linux-x86_64-2.6.6.gz
-rw-r--r-- 1 root root 116039527 Dec 23 2014 mongodb-linux-x86_64-2.6.6.gz
[root@localhost tools]# tar xf mongodb-linux-x86_64-2.6.6.gz
[root@localhost tools]# ll mongodb-linux-x86_64-2.6.6*
-rw-r--r-- 1 root root 116039527 Dec 23 2014 mongodb-linux-x86_64-2.6.6.gz
mongodb-linux-x86_64-2.6.6:
total 64
drwxr-xr-x 2 root root 4096 Jul 22 02:48 bin
-rw-r--r-- 1 1046 1046 34520 Dec 8 2014 GNU-AGPL-3.0
-rw-r--r-- 1 1046 1046 1359 Dec 8 2014 README
-rw-r--r-- 1 1046 1046 17793 Dec 8 2014 THIRD-PARTY-NOTICES
[root@localhost tools]#
[root@localhost tools]# mv mongodb-linux-x86_64-2.6.6 /usr/local/mongodb
[root@localhost tools]# cd /usr/local/mongodb/
[root@localhost mongodb]# pwd
/usr/local/mongodb
[root@localhost mongodb]#
2、定义配置文件:
[root@localhost mongodb]# mkdir conf
[root@localhost mongodb]# cd conf
[root@localhost conf]# vim mongodb.conf
port = 30000
bind_ip = 192.168.19.25
dbpath = /data/mongo/data/db
logpath = /data/mongo/data/log/log
logappend = true
fork = true
pidfilepath = /data/mongo/data/mongod.pid
[root@localhost conf]#
[root@localhost conf]# mkdir -p /data/mongo/data/
[root@localhost conf]# mkdir -p /data/mongo/data/log
[root@localhost conf]# mkdir -p /data/mongo/data/db
配置文件解释:
#port = 30000 监听端口
#bind_ip = 192.168.19.25 在哪个ip地址上启动
#dbpath = /data/mongo/data/db 定义数据库文件路径
#logpath = /data/mongo/data/log/log 定义日志存放路径
#logappend = true 定义日志存放方式
#fork = true 定义mongodb进程启动方式,这里以守护进程方式启动
#pidfilepath = /data/mongo/data/mongod.pi 定义进程pid文件存放路径
3、添加环境变量:
[root@localhost mongodb]# cd bin/
[root@localhost bin]# pwd
/usr/local/mongodb/bin
[root@localhost bin]# vim /etc/profile
export PATH=/usr/local/mongodb/bin:$PATH
[root@localhost bin]# source /etc/profile
[root@localhost bin]#
4、启动mongodb
[root@localhost bin]# mongod -f /usr/local/mongodb/conf/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 1735
child process started successfully, parent exiting
[root@localhost bin]#
[root@localhost bin]# netstat -lnput|grep mongo
tcp 0 0 192.168.19.25:30000 0.0.0.0:* LISTEN 1735/mongod
[root@localhost bin]#
[root@localhost ~]# mongo --host 192.168.19.25 --port 30000
MongoDB shell version: 2.6.6
connecting to: 192.168.19.25:30000/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
>
出现以上界面表示mongo安装成功,至此mongo安装完毕,至于一些常用命令可以到/usr/local/mongo/bin目录下查看,
[root@localhost ~]# cd /usr/local/mongodb/bin/
[root@localhost bin]# ll
total 283568
-rwxr-xr-x 1 1046 1046 23603184 Dec 8 2014 bsondump
-rwxr-xr-x 1 1046 1046 11900240 Dec 8 2014 mongo
-rwxr-xr-x 1 1046 1046 23773296 Dec 8 2014 mongod
-rwxr-xr-x 1 1046 1046 23676016 Dec 8 2014 mongodump
-rwxr-xr-x 1 1046 1046 23619312 Dec 8 2014 mongoexport
-rwxr-xr-x 1 1046 1046 23667776 Dec 8 2014 mongofiles
-rwxr-xr-x 1 1046 1046 23644016 Dec 8 2014 mongoimport
-rwxr-xr-x 1 1046 1046 23614480 Dec 8 2014 mongooplog
-rwxr-xr-x 1 1046 1046 23424896 Dec 8 2014 mongoperf
-rwxr-xr-x 1 1046 1046 23713104 Dec 8 2014 mongorestore
-rwxr-xr-x 1 1046 1046 18433232 Dec 8 2014 mongos
-rwxr-xr-x 1 1046 1046 23663984 Dec 8 2014 mongostat
-rwxr-xr-x 1 1046 1046 23607088 Dec 8 2014 mongotop
[root@localhost bin]#
本文出自 “平平淡淡才是真” 博客,请务必保留此出处http://ucode.blog.51cto.com/10837891/1828805
原文地址:http://ucode.blog.51cto.com/10837891/1828805