Alibaba Cloud CentOS6.3 Installation MongoDB Tutorial

Source: Internet
Author: User
Tags mongodb tutorial iptables

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

Installation

[Email protected]/]# CD usr/local/

[[email protected]/] #wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.9.tgz

[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
[[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
Note: If an error occurs:
Error:child process failed, exited with ERROR number 0
Delete the Mongod.lock in the data directory, and then the boot is OK.
RM  - f   /data/mongod.lock
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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.