1. 下载安装文件,解压tar zxvf mongodb-linux-x86_64-2.6.8.gz2. 移动到/opt目录 mv mongodb-linux-x86_64-2.6.8/bin /opt/mongodb bin目录说明: mongo 客户端程序,连接MongoDB mongod 服务端程序,启动MongoDB mongodump 备份程序 mongoexport 数据导出程序 mongofiles GridFS工具,内建的分布式文件系统 mongoimport 数据导入程序 mongorestore 数据恢复程序 mongos 数据分片程序,支持数据的横向扩展 mongostat 监视程序3. 创建data、log目录 cd /opt/mongodb mkdir data log touch log/mongodb.log //建立日志文件4. 创建配置文件 vim /etc/mongod.conf
#mongo. Confdbpath=/opt/mongodb/datalogpath=/opt/mongodb/log/mongodb.loglogappend= true true27017 true True #journal =truenojournal=true
5. 创建系统服务脚本
#!/bin/bash# #chkconfig:2345 the -#description: Mongodbstart () {RM-f/opt/mongodb/data/Mongod.lock/opt/mongodb/bin/mongod--config/etc/Mongod.conf}stop () {/opt/mongodb/bin/mongod--config/etc/mongod.conf--shutdown} Case " $" inchstart) Start; stop) stop;; restart) stop start;; *) Echo$"Usage: $ {Start|stop|restart}"Exit1 ;;EsacExit0
6. 添加到系统服务,并设置开机启动
chkconfig --add mongodb
chkconfig --level 35 mongodb on
7. 启动mongodb service mongodb start (如存在权限问题就用chmod 777命令)8. 将/opt/mongodb/bin目录添加到环境变量PATH中 vim /etc/profile export PATH=$PATH:/usr/local/node/bin:/opt/mongodb/bin/ 保存退出,source /etc/profile9. mongodb测试 使用命令mongo,进入mongo界面,默认链接的是test数据库,为admin数据库添加账号和密码: use admin; db.addUser("root", "103279"); db.auth("root", "103279"); exit; 然后连接admin数据库: mongo admin -u root -p 输入密码进入命令界面10. 防火墙要开放27107端口,centos可以使用setup命令进入设置界面
How to install MongoDB--transfer from friend Weibo