CentOS Installation MongoDB

Source: Internet
Author: User
Tags mongodb mongodb client mongodb version

1. Go to the/usr/local/directory:

Cd/usr/local

2. Install the necessary plugins

Yum-y install gcc make gcc-c++ openssl-devel wgetyum Install net-tools

3. Download the mongodb-linux-x86_64-rhel70-3.2.4.tgz file that matches the CentOS system download is slow

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.4.tgz

4. Unzip the mongodb-linux-x86_64-rhel70-3.2.4.tgz file:

TAR-ZXVF mongodb-linux-x86_64-rhel70-3.2. 4. tgz

The mongodb-linux-x86_64-rhel70-3.2.4 folder and the files it belongs to are obtained after the decompression is completed;

5. Rename the mongodb-linux-x86_64-rhel70-3.2.4 file to mongodb3.2.4:

MV mongodb-linux-x86_64-rhel70-3.2. 4 mongodb3. 2.4

6. Create a MongoDB directory

Mkdir-p MongoDB

7. Move the mongodb3.2.4 file from the/usr/local directory to the/usr/local/mongodb directory:

Mv/mongodb3. 2.4/mongodb/

8. Go to the/usr/local/mongodb/mongodb3.2.4 directory:

CD MONGODB/MONGODB3. 2.4

9. Create a directory in the/usr/local/mongodb/mongodb3.2.4/bin/directory that holds the log:

Mkdir-p Data/test/logs

10. Create a directory in the/usr/local/mongodb/mongodb3.2.4/bin/directory that holds the data files:

Mkdir-p data/test/db

11. Enter the Bin directory:

CD bin/

12. Create a configuration file mongodb.conf:

VI mongodb.conf

13. Write the following in mongodb.conf:

# idae-mongodb Config Start- .- to- Geneva# Set the data file's storage directory DBPath=/usr/local/mongodb/mongodb3.2.4/bin/data/test/db# Set the directory where the log files are stored and their log file names LogPath=/usr/local/mongodb/mongodb3.2.4/bin/data/test/logs/mongodb.log# Set the port number (the default port number is27017) Port=27017# set to run as Daemon, which runs fork in the background=true# Nohttpinterface=trueNohttpinterface=true# Idae-MongoDB config End- .- to- Geneva

Save and Exit by ": Wq" in the English state;

Parameter explanation:

--DBPath Database path (data file)--logpath log file path--Master designated as the primary machine--slave specified as slave machine--source Specifies the IP address of the host machine--POLOGSIZE specifies that the log file size does not exceed 64M. Because Resync is extremely operational and time consuming, it is best to avoid resync by setting a sufficiently large oplogsize (the default oplog size is 5% of the free disk size). --Logappend at the end of the log file, that is, write the log using the Append method--journal enable logging--Port Enable port number--Fork runs in the background--only specifies which database to replicate--Slavedelay refers to the time interval from which replication is detected--Auth If you need to verify permissions login (username and password)--Syncdelay data written to hard disk (seconds), 0 is not waiting, write directly--notablescan table scan not allowed--Maxconns Maximum number of concurrent connections, default--Pidfilepath Specifies the process file, does not specify that no process file is generated--BIND_IP bind IP, bind only IP Access service after binding

14. Check if the port has been started: If not installed, install code under Linux classification

27017

If the execution does not start:
To start the MongoDB service:

15.1start with a custom MongoDB configuration file:./mongod--config mongodb.conf15.2start MongoDB in Repair mode: This test doesn't work./mongod--repair-F mongodb.conf15.3start with parametric:./mongod/usr/local/mongodb/mongodb3.2.4/bin/mongod--dbpath=/usr/local/mongodb/mongodb3.2.4/bin/data/test/db--logpath=/usr/local/mongodb/mongodb3.2.4/bin/data/test/logs/mongodb.log--Fork If the following error is reported: Error:child process failed, exited with error number1It is likely that the path inconsistency is configured in the mongodb.conf, if the following error is reported: Error:child process failed, exited with error number -It is likely that there is no normal shutdown, so you can delete the Mongod.LockFile

16. Start MongoDB

MONGO or./mongo

--------------------------------above is the steps to install the database-----------------------------
17 viewing the running logs for MongoDB services:

Tail-200f/usr/local/mongodb/mongodb3. 2.4/bin/data/test/logs/mongodb.log

18 to kill the MongoDB process, you can close the MongoDB service:

Kill- PID

PID can be found through step 17

19 If the following conditions occur

127.0. 0.1:27017, Reason:errno:111 Connection refused

There are two ways to solve this:
18.1 If the database appears to be unable to connect the reason, may be the data directory under the Mongod.lock file problem, can be repaired with the following command:

./bin/mongod--repair

18.2 or delete Mongod.lock directly

Rm-f/usr/local/mongodb/data/db/mongod. Lock  

Then start the MongoDB service:

./mongod--config mongodb.conf

If the above two is still not resolved, it is the path file, we can delete

/usr/local/mongodb/mongodb3. 2.4/bin/The data directory and its subdirectories, using an absolute path:. /mongod/usr/local/mongodb/mongodb3. 2.4/bin/mongod--dbpath=/usr/local/mongodb/mongodb3. 2.4/bin/data/test/db--logpath=/usr/local/mongodb/mongodb3. 2.4/bin/data/test/logs/mongodb.log--fork

20 Common commands for clients:

Db.version (); # view MongoDB version of Use test; # into the specified data, here is the test database

21 in the/usr/local/mongodb/mongodb3.2.4/bin/directory, type the following command, open a MONGODB client program, open a MongoDB shell client, the shell client is also a Java Script Editor, you can enter any JavaScript scripts:

./mongo

Connect to test database by default

22 Enter ip:27017 in the browser, such as:

http://101.201.212.129:27017/


Can view the version information of MongoDB;

CentOS Installation MongoDB

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.