Installation and start-up of MongoDB under Linux __linux

Source: Internet
Author: User
Tags create directory mongodb mongodb port number iptables
Installation

1> Set MongoDB Directory

Cd/home/apps: CentOS Create directory command Mkdir/home/apps

2> Download MongoDB

Curl-o http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.6.tgz

Either download it or copy it directly or upload it to the specified directory with xftp

3> Uncompressed files

Tar xzf mongodb-linux-x86_64-2.4.6.tgz

4> Start Service

./mongodb/bin/mongod-dbpath=/data/mongodb/db-logpath=/data/mongodb/log

MongoDB is the MONGO after the unpacked directory, hereinafter

5> the MongoDB service into a random boot

Vi/etc/rc.local

Use the VI Editor to open the configuration file and add the following line of code to it

/home/apps/mongodb/bin/mongod--dbpath/data/mongodb/db--port 27017--logpath/data/mongodb/log--logappend

This method ensures that the boot Mongod process can be turned on, but is not running as a service

6> to boot Mongod as a service

First under the/ETC/RC.D/INIT.D with vi new file Mongod

The contents are as follows:

#!/bin/bash
#
#chkconfig: 2345 80 90
#description: MongoDB
Start () {
/usr/mongodb/bin/mongod--config/usr/mongodb/config/mongod.conf
}

Stop () {
/usr/mongodb/bin/mongod--config/usr/mongodb/config/mongod.conf--shutdown
}

Case "$" in
Start
Start
;;

Stop
Stop
;;

Restart)
Stop
Start
;;
*)
Echo
$ "Usage: $ {Start|stop|restart}"
Exit 1
Esac

Save

The contents of the/usr/mongodb/config/mongod.conf configuration file are as follows

#master. conf
dbpath=/usr/mongodb/data/db
Logpath=/usr/mongodb/log/db.log
Pidfilepath=/usr/mongodb/db.pid
Directoryperdb=true
Logappend=true
bind_ip=192.168.1.7
port=27017
oplogsize=1000
Fork=true
Noprealloc=true
Nojournal=true
Smallfiles=true

2, increase service and boot
chmod +x/etc/rc.d/init.d/mongod
Chkconfig--add Mongod
Chkconfig--level 345 Mongod on
Chkconfig--list Mongod

Service Mongod Start
After you execute the script, you can start start|stop|restart|list your service.

After the shutdown and then start will automatically start MONGO, if the same machine needs to start more than Mongod according to this method can be

Temporarily only know this set to boot up service, if there is a better way please tell Oh, thank you first.

7> Connection MongoDB

./mongodb/bin/mongo 27017

You can connect to the MONGO


Here, MongoDB installed in Linux has been completed, local connection MongoDB has also been successful, then we have to consider another problem, lan how to connect MongoDB it. How do Windows machines in the LAN connect to the MongoDB in the Linux machine?

In fact, the practice is just as simple:./mongodb/bin/mongo 192.168.10.234:port.

But notice here, we need to open the MongoDB port number on the CentOS, and then we'll talk about how to open the specified port on the CentOS.

We open the configuration file/etc/sysconfig/iptables and add the following to the file:

-A rh-firewall-l-input-p tcp-m TCP--dport MongoDB port number-j

and restart the service.

Service Iptables Restart


At this point, you can begin to access the MongoDB deployed on the CentOS via the LAN

By the way, add a bit of CentOS to Windows Exchange, for example, we want to transplant files from MongoDB that were originally on a Windows machine to CentOS, which can be copied with a removable storage device, But what I'm talking about here is how Linux (CentOS) can access Windows shared directories, as follows:

MOUNT-T cifs//ip/shared directory name/mnt/sharefile-o username=,password=

The above command maps the shared directory of Windows to the/mnt/sharefile directory on Linux

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.