Installation Instructions
System Environment: Centos-6.3
Installation software: mongodb-linux-x86_64-2.2.2.tgz
: Http://www.mongodb.org/downloads
Installation machine: 192.168.15.237
Upload location:/usr/local/
Software Installation Location:/usr/local/mongodb
Data storage location:/var/mongodb/data
Log storage location:/var/mongodb/logs
Check if MongoDB has been installed
Rpm-qa | grep MongoDB
Service MongoDB Status
Install
[[email protected]/]# cd usr/local/
[[email protected]/]# groupadd MongoDB
[[email Protected]/]# useradd mongodb-g mongodb
[[email protected]/]# cd/usr/local
[[email protected] Local ]# tar-zxv-f mongodb-linux-x86_64-2.2.2.tgz
[[email protected] local]# mv mongodb-linux-x86_64-2.2.2 MongoDB
[[email protected] local]# chown-r mongodb:mongodb mongodb
[[email protected] local]# CD MongoDB
[[email protected] mongodb]# mkdir/var/mongodb
[[email protected] mongodb]# Mkdir/var/mongodb/data
[[email protected] mongodb]# mkdir/var/mongodb/logs
[[email protected] mongodb]# Vi/etc/sysconfig /iptables//Add port 27017 to the firewall
This step may see, in the editing file, if not previously configured iptables or is configured, directly copy the existing sentences, change the port number, you use the service iptables restart, will report you just add the port number is wrong. Status display Faild, correct will return green OK, the solution is to use the CentOS system operation, Help automatically write to the/etc/sysconfig/iptables, the method is:
/sbin/iptables-i input-p TCP--dport 27017-j ACCEPT
/etc/rc.d/init.d/iptables Save(These two sentences are glued to the command line window, specify the port number above, save below)
[[Email protected] mongodb]# service iptables restart//restart firewall
Configuration
Add CentOS Boot entry
[Email protected] mongodb]# VI +/etc/rc.d/rc.local
Append the MongoDB Start command to this file:
/usr/local/mongodb/bin/mongod--dbpath=/var/mongodb/data--logpath/var/mongodb/logs/log.log-fork
Start MongoDB
[Email protected] mongodb]#
/usr/local/mongodb/bin/mongod--dbpath=/var/mongodb/data--logpath/var/mongodb/logs/log.log-fork
See the following information stating that the installation has completed and started successfully:
Forked process:18394
All output going to:/var/mongodb/logs/log.log
Test
#终止服务器进程
Db.user.shutdownServer ()
#进入mongodb的shell模式
/usr/local/mongodb/bin/mongo
#查看数据库列表
Show DBS
#切换/CREATE DATABASE (the current database is automatically created when a collection (table) is created)
Use admin;
#增加用户
Db.adduser ("Zhoulf", "123456", True)
#更改密码 (change the password for a user who already exists)
Db.adduser ("Zhoulf", "Zhoulf");
#显示当前db状态
Db.stats ();
#当前db版本
Db.version ();
#删除当前使用数据库
Db.dropdatabase ();
#查看当前db的链接机器地址
Db.getmongo ();
#简单插入数据
Db.user.insert ({"fname": "Zhoulf", "Company": "NavInfo"})
#循环插入数据
for (var i = 1; i <=; i++) db.user.save ({"fname": "Zhoulf" +i, "Company": "NavInfo" +i});
#查询数据
Db.user.find ()
Thank you for Mr. Zhoulf's article. The original address, click here!
[Reproduced and corrected the error]centos-6.5 final MongoDB installation and use, for CentOS-6.3