MongoDB Installation and verification

Source: Internet
Author: User
Tags create mongodb

Installation Planning:
System Environment: Centos-6.5
Installation software: mongodb-linux-x86_64-2.6.5.tgz
: Http://www.mongodb.org/downloads
Installation machine: 10.10.10.110
Upload location:/data
Software Installation Location:/usr/local/mongodb
Data storage location:/data/mongodb
Log storage location:/var/log/mongodb/mongodb.log
Disable Iptable,ip6tables,selinux
Front-facing work:
1. Check if MongoDB has been installed
[[Email protected] ~] #rpm-qa | grep MongoDB
[[Email protected] ~] #service mongodb Status
2. Create the user and install the required directory and authorize
[Email protected] ~]# Groupadd MongoDB
[Email protected] ~]# useradd-g mongodb-s/sbin/nologin-m MongoDB
[Email protected] data]# mkdir-p/data/mongodb

[Email protected] data]# chown-r Mongodb:mongodb/data/mongodb

[Email protected] data]# mkdir-p/var/log/mongodb

[Email protected] data]# chown-r mongodb:mongodb /var/log/mongodb

installation:
[[email  protected]~]# cd/data/
[[email protected] data]# tar-zxvf mongodb-linux-x86_64-2.6.5.gz
[[email  Protected] data]# mv Mongodb-linux-x86_64-2.6.5/usr/local/mongodb
[[email protected] data]# cd/usr/local/ mongodb/
[[email protected] mongodb]# chown-r mongodb:mongodb *
configuration:
Add MongoDB to CentOS boot entry
[[email protected] mongodb]# vi/etc/rc.d/rc.local
/usr/local/mongodb/bin/mongod --dbpath=/data/mongodb/--logpath/var/mongodb/logs/log.log-fork
Start Method 1:
[[email  Protected] mongodb]#/usr/local/mongodb/bin/mongod--dbpath=/var/mongodb/data--logpath/var/mongodb/logs/log.log– The fork
--fork option means to run MongoDB as a background service process
to see the following information stating that the installation was complete and started successfully:
forked process:18394
All output going to:/var/ Mongodb/logs/log.log
Start Method 2:

Create mongodb.conf

#vi/etc/mongodb.conf

Dbpath=/data/mongodblogpath=/var/log/mongodb/mongodb.loglogappend=tureport=27017rest=truefork=true

When you call MongoDB, you typically use the-f option to work with the mongodb.conf file

#mongod-F mongodb.conf

You can also add this command to/etc/rc.local, let MongoDB boot up;

Testing and validation
Method 1: Command line
#终止服务器进程
Db.user.shutdownServer ()
#进入mongodb的shell模式
[Email protected] data]#/usr/local/mongodb/bin/mongo
MongoDB Shell version:2.6.5
Connecting To: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
Method 2:web Interface
When you visit http://ip:27017 you will be prompted with this information
You is trying to access MongoDB on the native driver port. For HTTP diagnostic access, add the port number
In fact, it is tactful to tell you that you should visit this port: http://ip:28017
If you have root account, then enter the root account and password directly to the normal access!

Related commands:

#查看数据库列表

>show DBS
Admin (empty)
Local 0.078GB
#切换/CREATE DATABASE (the current database is automatically created when a collection (table) is created)
Use admin;
#增加用户
Db.adduser ("Jacson", "111111", True)
#更改密码 (change the password for a user who already exists)
Db.adduser ("Jacson", "123456");
#显示当前db状态
Db.stats ();
#当前db版本
> db.version ();d b.version ();
2.6.5
#删除当前使用数据库
Db.dropdatabase ();
#查看当前db的链接机器地址
Db.getmongo ();
#简单插入数据
Db.user.insert ({"fname": "Jacson", "Company": "NavInfo"})
#循环插入数据
for (var i = 1; i <=; i++) db.user.save ({"fname": "Jacson" +i, "Company": "NavInfo" +i});
Can simulate inserting 10,000 times
for (var i = 1; I <= 10000; i++) Db.user.save ({"fname": "Jacson" +i, "Company": "NavInfo" +i});
#查询数据
Db.user.find ()

MongoDB Installation and verification

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.