(turn) Install MongoDB on CentOS7

Source: Internet
Author: User
Tags install mongodb mongodb client mongodb version time interval

Installing MongoDB on the CentOS7

1 connect to CentOS7 server via SECURECRT;

2 Go to the/usr/local/directory:
Cd/usr/local

3 Create the Tools directory under the current directory:
Mkdir-p Tools

4 enter into the Tools directory:
CD Tools

5 Download the mongodb-linux-x86_64-rhel70-3.2.4.tgz file that matches the CentOS system:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.4.tgz

6 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;

7 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

8 go back to the top level directory and create the MongoDB directory:
Cd.. /
Mkdir-p MongoDB

9 Move the mongodb3.2.4 file from the/usr/local/tools directory to the/usr/local/mongodb directory:
MV tools/mongodb3.2.4/mongodb/

10 enter into the/usr/local/mongodb/mongodb3.2.4 directory:
CD mongodb/mongodb3.2.4

11 Create a directory in the/usr/local/mongodb/mongodb3.2.4/bin/directory that holds the log:
Mkdir-p Data/test/logs

12 Create a directory in the/usr/local/mongodb/mongodb3.2.4/bin/directory that holds the data files:
Mkdir-p data/test/db

13 Enter the Bin directory:
CD bin/

14 Creating the configuration file mongodb.conf:
VI mongodb.conf

Write the following in mongodb.conf:
# idae-mongodb Config start-2016-05-02

# Set up directory for data files
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 is 27017)
Port = 27017

# set to run as daemon, i.e. run in background
Fork = True

  # Nohttpinterface = True
  nohttpinterface = True
  # idae-mongodb config end -2016-05-02
 
  ": Wq" in the English state to save and exit;
 
  parameter explanation:  
  --dbpath Database Path ( Data file)
  --logpath log file path
  --master specified as slave machine
  --slave
   --SOURCE Specifies the IP address of the host machine
  --pologsize Specifies that the log file size does not exceed 64M. Because the resync is extremely operational and time consuming, it is best to avoid resync by setting a large enough oplogsize (the default oplog size is 5% of the free disk size).
  --logappend log file is added at the end, that is, write the log using append
  --journal enable log
  --port enable port number
  --fork run
  --only in the background specifies which database is replicated only
  --slavedelay the time interval from replication detection
   --auth Whether you need to verify permissions logon (user name and password)
  --syncdelay data is written to the hard disk (in seconds), 0 is not waiting, write directly
  --notablescan The table is not allowed to scan
  --maxconns The maximum number of concurrent connections, default 2000  
  --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

15 Start MongoDB Service:
15.1 start with a custom MongoDB configuration file:
./mongod--config mongodb.conf
15.2 start MongoDB in Repair mode:
./mongod--repair-f mongodb.conf
15.3 Start in parametric style:
./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 number 1
It is possible that the path inconsistency problem is configured in mongodb.conf;
If the following error is reported:
Error:child process failed, exited with error number 100
It is likely that there is no normal shutdown, so you can delete the Mongod.lock file

15 Viewing the MongoDB process:
PS aux |grep MongoDB

16 viewing the running logs for MongoDB services:
Tail-200f/usr/local/mongodb/mongodb3.2.4/bin/data/test/logs/mongodb.log

17 Check if the port has been started:
NETSTAT-LANP | grep 27017

18 to kill the MongoDB process, you can close the MongoDB service:
Kill-15 PID
PID can be found through step 16

19 If the following conditions occur
warning:failed to connect to 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 the/usr/local/mongodb/mongodb3.2.4/bin/data directory and its subdirectories, and take the absolute path way:
./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 Add the MongoDB service to the self-boot file:
Vi/etc/rc.local
Append the following command to the end of the file:
/usr/local/mongodb/mongodb3.2.4/bin/mongod--config mongodb.conf
Save and exit:
: wq!

21 Common commands for clients:
Db.version (); # View the MongoDB version
Use test; # into the specified data, here is the test database

22 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


23 Enter ip:27017 in the browser, such as:
http://101.201.212.129:27017/
Can view the version information of MongoDB;

(turn) Install MongoDB on CentOS7

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.