Objective:
System version: centos-6.5-x86_64
CentOS Compilation installs MongoDB 2.6 system preferably 64-bit, in order to better play MongoDB performance
1. Prepare, download the source file (binary compiled version)
[Email protected] ~]# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
[Email protected] ~]# TAR-ZVXF mongodb-linux-x86_64-2.6.1.tgz
[Email protected] ~]# MV mongodb-linux-x86_64-2.6.1 Usr/local/mongo/mongodb
Configure the PATH environment variable below to ensure that the MongoDB Bin directory is contained in the PATH environment variable.
2 Configuring Path
[Email protected] ~]# Vim/etc/profile
Add the following content:
#set for MongoDB
Export Mongodb_home=/usr/local/mongo/mongodb
Export path= $MONGODB _home/bin: $PATH
Save exit
Verify that the environment variable is in effect
[Email protected] ~]# mongod-version
3. Creating a directory for storing data and logs
3.1 Creating a Directory
[Email protected] ~]# mkdir-p/data/mongodb/journal
[Email protected] ~]# mkdir-p/data/mongodb/log
3.2 Creating a log file
[Email protected] ~]# Touch/data/mongodb/log/mongodb.log
3.3 Setting up the configuration file
[Email protected] ~]# vim/etc/mongodb.conf
Enter the following to save and rewind
Dbpath=/data/mongodb
Logpath=/data/mongodb/log/mongodb.log
Logappend=true
port=27017
Fork=true
Noauth=true
Nojournal = True
Smallfiles = True
Noprealloc = True
4.after restarting, run the Mongod service
[Email protected] ~]# mongod-f/etc/mongodb.conf
5. Test whether the service is normal
5.1 Open another terminal and enter the admin background as an administrator
[[Email protected] ~] #mongo Admin
>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 ()
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
CentOS 6.5 Installation mongodb2.6